:root {
  --bg-1: #edf7ff;
  --bg-2: #c7e2b1;
  --ink: #203424;
  --card: rgba(245, 252, 240, 0.84);
  --card-border: rgba(64, 104, 65, 0.26);
  --accent: #d88e40;
  --accent-2: #4f9c57;
  --accent-3: #2f6f3f;
  --warning: #aa2f20;
  --shadow: 0 10px 30px rgba(41, 84, 53, 0.16);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: "Manrope", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(120% 70% at 50% -10%, rgba(255, 255, 255, 0.86), transparent 45%),
    radial-gradient(80% 42% at 18% 100%, rgba(248, 228, 178, 0.55), transparent 60%),
    linear-gradient(180deg, var(--bg-1), var(--bg-2));
  overflow: hidden;
}

body {
  display: flex;
  justify-content: center;
  align-items: stretch;
}

body.start-mode {
  overflow: hidden;
}

.app {
  width: 100vw;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 0;
}

body.start-mode .app {
  width: 100vw;
  height: 100dvh;
  min-height: 100dvh;
  padding: 0;
  gap: 0;
  grid-template-rows: 1fr;
}

body.start-mode .hud,
body.start-mode .controls {
  display: none;
}

.hud,
.decorate-panel {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  backdrop-filter: blur(6px);
  box-shadow: var(--shadow);
}

.hud {
  display: none;
}

.chip {
  background: rgba(243, 252, 239, 0.74);
  border-radius: 12px;
  padding: 8px;
  text-align: center;
}

.chip-primary {
  background: linear-gradient(160deg, #ffe5b9, #f1cf95);
}

.label {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.chip strong {
  font-size: 1.05rem;
}

.stage-wrap {
  position: relative;
  min-height: 50dvh;
  border-radius: 0;
  overflow: hidden;
  box-shadow: none;
  border: none;
  background: linear-gradient(180deg, #dff1ff 0 52%, #95c876 52% 100%);
}

body.start-mode .stage-wrap {
  height: 100%;
  min-height: unset;
  border-radius: 0;
  border: 0;
  box-shadow: none;
}

#grassCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
}

#grassCanvas:focus,
#grassCanvas:focus-visible {
  outline: none;
}

.overlay-message {
  position: absolute;
  inset: 10px;
  display: grid;
  place-items: center;
  text-align: center;
  white-space: pre-line;
  padding: 14px;
  font-family: "Fraunces", Georgia, serif;
  font-size: clamp(1.1rem, 4vw, 1.6rem);
  color: #223523;
  background: rgba(247, 254, 244, 0.78);
  border-radius: 14px;
  border: 1px dashed rgba(56, 95, 53, 0.42);
}

.overlay-message.is-hidden {
  display: none;
}

.overlay-message.top-hint {
  inset: 8px 10px auto;
  display: block;
  padding: 8px 12px;
  font-size: clamp(0.82rem, 2.8vw, 1rem);
  border-radius: 10px;
  background: rgba(244, 252, 236, 0.94);
}

.overlay-message.start-screen {
  inset: 0;
  border-radius: 0;
  border: 0;
  color: #f6ffea;
  font-size: clamp(1.4rem, 4.8vw, 2.3rem);
  text-shadow:
    0 2px 2px rgba(20, 42, 16, 0.9),
    0 10px 28px rgba(0, 0, 0, 0.55);
  background:
    linear-gradient(180deg, rgba(18, 58, 30, 0.2), rgba(12, 30, 18, 0.56)),
    radial-gradient(120% 70% at 50% 12%, rgba(255, 255, 255, 0.24), transparent 52%),
    url("assets/start-cover.jpg") center / cover no-repeat,
    linear-gradient(180deg, #66b7ff 0 48%, #56a145 48% 100%);
  backdrop-filter: blur(1.2px) saturate(1.12);
  letter-spacing: 0.03em;
  line-height: 1.35;
  animation: startZoom 9s ease-in-out infinite alternate;
}

.overlay-message.start-screen::before,
.overlay-message.start-screen::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.overlay-message.start-screen::before {
  background:
    repeating-linear-gradient(
      100deg,
      rgba(255, 255, 255, 0.02) 0,
      rgba(255, 255, 255, 0.02) 16px,
      rgba(0, 0, 0, 0.02) 16px,
      rgba(0, 0, 0, 0.02) 32px
    );
  mix-blend-mode: soft-light;
  opacity: 0.35;
  animation: startShimmer 6.8s linear infinite;
}

.overlay-message.start-screen::after {
  background:
    radial-gradient(80% 45% at 50% 8%, rgba(255, 255, 210, 0.28), transparent 60%),
    conic-gradient(
      from 0deg at 50% 8%,
      rgba(255, 255, 255, 0) 0deg,
      rgba(255, 255, 255, 0.09) 18deg,
      rgba(255, 255, 255, 0) 36deg,
      rgba(255, 255, 255, 0.06) 52deg,
      rgba(255, 255, 255, 0) 360deg
    );
  opacity: 0.62;
  animation: startRays 14s linear infinite;
}

@keyframes startZoom {
  0% {
    transform: scale(1);
  }
  100% {
    transform: scale(1.04);
  }
}

@keyframes startShimmer {
  0% {
    transform: translateX(-6%);
  }
  100% {
    transform: translateX(6%);
  }
}

@keyframes startRays {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.btn-menu-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 22px;
  padding: 0;
  background: rgba(0, 0, 0, 0.18);
  border: none;
  border-radius: 6px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  transition: color 140ms, background 140ms;
}

.btn-menu-toggle:hover {
  color: rgba(255, 255, 255, 0.95);
  background: rgba(0, 0, 0, 0.28);
}

.controls.collapsed .sun-control,
.controls.collapsed .game-action-row,
.controls.collapsed .hall-panel,
.controls.collapsed .decorate-panel {
  display: none;
}

.controls {
  padding: 8px 10px 12px;
  display: grid;
  gap: 8px;
  background: #72a83e;
  border-radius: 0;
  border: none;
  box-shadow: none;
  backdrop-filter: none;
}

.control-title {
  margin: 0 0 6px;
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.sun-control {
  display: grid;
  gap: 0;
}

.sun-pad {
  height: 80px;
  border-radius: 10px;
  border: 1px solid rgba(30, 70, 15, 0.45);
  background:
    radial-gradient(circle at var(--sun-x, 50%) var(--sun-y, 50%), rgba(255, 223, 136, 0.95), rgba(255, 223, 136, 0.28) 18%, transparent 30%),
    linear-gradient(180deg, #a8d8f0 0 38%, #6aaa3a 38% 100%);
  position: relative;
  overflow: hidden;
}

.sun-pad::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid rgba(67, 93, 35, 0.75);
  background: rgba(246, 255, 230, 0.65);
  left: calc(var(--sun-x, 50%) - 10px);
  top: calc(var(--sun-y, 50%) - 10px);
}

.game-action-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
}

.actions.compact {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.hall-panel {
  background: rgba(245, 252, 240, 0.82);
  border: 1px solid rgba(64, 104, 65, 0.22);
  border-radius: 14px;
  padding: 8px 10px;
}

.hall-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.hall-header .control-title {
  margin: 0;
}

.hall-actions {
  display: flex;
  gap: 6px;
}

.hall-clear-btn {
  font-size: 0.72rem;
  padding: 6px 10px;
  border-radius: 10px;
  min-width: 72px;
}

.hall-list {
  margin: 8px 0 0;
  padding-left: 20px;
  display: grid;
  gap: 2px;
  color: #274122;
  font-weight: 700;
  font-size: 0.88rem;
}

.btn,
.swatch {
  border: 2px solid rgba(84, 63, 18, 0.52);
  border-radius: 16px;
  font-weight: 800;
  font-size: 0.94rem;
  padding: 10px 12px;
  color: #fff9df;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  text-shadow:
    0 1px 0 rgba(72, 47, 9, 0.75),
    0 2px 8px rgba(52, 36, 8, 0.38);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.45),
    inset 0 -3px 0 rgba(110, 74, 21, 0.4),
    0 5px 0 rgba(89, 60, 19, 0.36),
    0 10px 18px rgba(42, 28, 7, 0.24);
  transition: transform 120ms ease, filter 120ms ease, box-shadow 120ms ease;
}

.btn {
  background: linear-gradient(180deg, #f6cd57 0%, #e6a524 54%, #cc8316 100%);
}

.btn-primary {
  background:
    radial-gradient(120% 85% at 50% 0%, rgba(255, 244, 174, 0.56), transparent 58%),
    linear-gradient(180deg, #ffd95f 0%, #efb930 55%, #d88f1f 100%);
}

.btn-secondary {
  border-color: rgba(44, 85, 22, 0.6);
  text-shadow:
    0 1px 0 rgba(31, 61, 17, 0.76),
    0 2px 8px rgba(18, 49, 14, 0.34);
  box-shadow:
    inset 0 1px 0 rgba(226, 255, 196, 0.46),
    inset 0 -3px 0 rgba(38, 86, 22, 0.42),
    0 5px 0 rgba(36, 79, 20, 0.36),
    0 10px 18px rgba(20, 46, 11, 0.22);
  background:
    radial-gradient(120% 85% at 50% 0%, rgba(224, 255, 174, 0.5), transparent 56%),
    linear-gradient(180deg, #95d33b 0%, #6eaf2f 58%, #4f8e24 100%);
}

.btn:hover,
.swatch:hover {
  filter: saturate(1.08) brightness(1.05);
}

.btn:active,
.swatch:active {
  transform: translateY(2px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.36),
    inset 0 -2px 0 rgba(69, 46, 13, 0.32),
    0 3px 0 rgba(64, 43, 12, 0.3),
    0 7px 14px rgba(29, 19, 5, 0.22);
}

.btn:disabled {
  opacity: 0.52;
  filter: grayscale(0.16) saturate(0.72);
}

.decorate-panel {
  padding: 10px;
}

.decorate-hint {
  margin: 0 0 8px;
  font-size: 0.82rem;
  color: rgba(38, 71, 45, 0.9);
}

.swatches {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.swatch {
  flex: 1;
  border-color: rgba(44, 85, 22, 0.56);
  text-shadow: none;
  box-shadow:
    inset 0 1px 0 rgba(226, 255, 196, 0.38),
    inset 0 -2px 0 rgba(38, 86, 22, 0.34),
    0 4px 0 rgba(36, 79, 20, 0.28),
    0 8px 14px rgba(20, 46, 11, 0.18);
  background:
    radial-gradient(120% 85% at 50% 0%, rgba(224, 255, 174, 0.5), transparent 56%),
    linear-gradient(180deg, #8cca37 0%, #6aa92d 56%, #4b8c23 100%);
  padding: 6px 4px;
  font-size: 1.5rem;
  line-height: 1;
  min-height: unset;
}

.swatch-icon {
  display: block;
  pointer-events: none;
}

.swatch.active {
  border-color: rgba(95, 63, 14, 0.7);
  box-shadow:
    inset 0 1px 0 rgba(255, 253, 220, 0.42),
    inset 0 -2px 0 rgba(101, 70, 21, 0.35),
    0 4px 0 rgba(86, 57, 17, 0.32),
    0 10px 16px rgba(52, 34, 9, 0.2);
  background:
    radial-gradient(120% 85% at 50% 0%, rgba(255, 244, 174, 0.5), transparent 58%),
    linear-gradient(180deg, #ffd45d 0%, #edb52d 58%, #d38d20 100%);
}

/* Floating fullscreen toggle button */
.btn-fs-float {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 50;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(240, 252, 230, 0.3);
  border-radius: 9px;
  background: rgba(22, 42, 22, 0.52);
  backdrop-filter: blur(4px);
  color: rgba(235, 252, 220, 0.92);
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  transition: background 120ms, transform 120ms;
  -webkit-tap-highlight-color: transparent;
}

.btn-fs-float:hover {
  background: rgba(22, 42, 22, 0.8);
  transform: scale(1.1);
}

.btn-fs-float:active {
  transform: scale(0.95);
}

/* Fullscreen game mode */
body.fullscreen-mode .app {
  position: fixed;
  inset: 0;
  width: 100%;
  max-width: unset;
  padding: 0;
  display: block;
  z-index: 100;
}

body.fullscreen-mode .stage-wrap {
  position: absolute;
  inset: 0;
  min-height: 100%;
  border-radius: 0;
  border: none;
  box-shadow: none;
}

body.fullscreen-mode .hud {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: auto;
  max-width: min(440px, 90vw);
  border-radius: 20px;
  padding: 8px;
  z-index: 200;
}

body.fullscreen-mode .controls {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 8px);
  left: 8px;
  right: 8px;
  max-width: min(560px, 100%);
  margin: 0 auto;
  z-index: 200;
}

/* In fullscreen, only show sun-control (and decorate-panel when active) */
body.fullscreen-mode .hall-panel {
  display: none;
}

body.fullscreen-mode .sun-pad {
  height: 68px;
}

/* Floating fullscreen btn becomes fixed exit in fullscreen mode */
body.fullscreen-mode .btn-fs-float {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 8px);
  right: 8px;
  z-index: 300;
  background: rgba(22, 42, 22, 0.7);
}

@media (min-width: 720px) {
  .stage-wrap {
    min-height: 56dvh;
  }
}
