:root {
  --bg: #f4ecd8;
  --ink: #5b4a33;
  --chip: #fffaf0;
  --chip-edge: #d9cdb0;
  --on: #ffe29a;
  --accent: #6f9a5f;
  --accent-ink: #ffffff;
  --gap: 12px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --vh: 100vh;
  --board: min(
    calc(100vw - var(--safe-l) - var(--safe-r) - 2 * var(--gap)),
    calc(var(--vh) - var(--safe-t) - var(--safe-b) - 2 * var(--gap))
  );
  color-scheme: light;
}
@supports (height: 100dvh) {
  :root { --vh: 100dvh; }
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Fredoka", ui-rounded, "Arial Rounded MT Bold", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
  overflow: hidden;
}
button {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
  cursor: pointer;
}
.hidden { display: none !important; }

/* Leaves and flowers in the margins; the board covers the middle. */
body {
  background:
    radial-gradient(circle at 6% 70%, #a9cf8e 0 26px, transparent 27px),
    radial-gradient(circle at 10% 86%, #8bbf74 0 20px, transparent 21px),
    radial-gradient(circle at 94% 30%, #a9cf8e 0 24px, transparent 25px),
    radial-gradient(circle at 91% 76%, #8bbf74 0 22px, transparent 23px),
    radial-gradient(circle at 4% 20%, #ffd3df 0 14px, transparent 15px),
    radial-gradient(circle at 96% 58%, #d9cffb 0 14px, transparent 15px),
    var(--bg);
}

/* ---------- setup ---------- */
#setup {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: calc(var(--safe-t) + 16px) calc(var(--safe-r) + 16px) calc(var(--safe-b) + 16px) calc(var(--safe-l) + 16px);
  overflow-y: auto;
}
.setup-card {
  width: min(760px, 100%);
  background: var(--chip);
  border: 3px solid var(--chip-edge);
  border-radius: 36px;
  padding: 28px 28px 32px;
  text-align: center;
  box-shadow: 0 14px 40px rgba(91, 74, 51, 0.15);
}
h1 { font-size: clamp(34px, 5vw, 52px); margin: 0 0 4px; color: #6f9a5f; letter-spacing: 0.5px; }
.prompt { font-size: 26px; margin: 4px 0 18px; font-weight: 600; }
.animal-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}
.animal {
  position: relative;
  border: 3px solid var(--chip-edge);
  background: #fff;
  border-radius: 28px;
  padding: 12px 8px 10px;
  min-height: 140px;
  display: grid;
  justify-items: center;
  gap: 4px;
  font-size: 22px;
  font-weight: 600;
  transition: transform 0.12s ease, background 0.12s ease;
}
.animal svg { width: 84px; height: 84px; overflow: visible; }
.animal[aria-pressed="true"] { background: var(--on); border-color: #e7b84a; transform: translateY(-3px); }
.animal .order {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: none;
  place-items: center;
  font-size: 20px;
  font-weight: 700;
}
.animal[aria-pressed="true"] .order { display: grid; }
.pick-hint { font-size: 18px; margin: 14px 0 10px; opacity: 0.8; }
.board-choice { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: center; margin: 4px 0 18px; }
.board-choice .label { font-size: 18px; opacity: 0.8; margin-right: 4px; }
.board-choice button, .card .row button, #win-new-players {
  border: 2px solid var(--chip-edge);
  background: #fff;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 18px;
  min-height: 48px;
}
.board-choice button[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
.big-button {
  border: 0;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 30px;
  font-weight: 700;
  border-radius: 999px;
  padding: 16px 48px;
  min-height: 72px;
  box-shadow: 0 6px 0 #557d47;
}
.big-button:active { transform: translateY(3px); box-shadow: 0 3px 0 #557d47; }
.big-button:disabled { background: #c9c2b0; box-shadow: 0 6px 0 #aaa38f; cursor: default; }

/* ---------- play ---------- */
#play { position: fixed; inset: 0; }
.stage {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
}
.board-wrap {
  position: relative;
  width: var(--board);
  height: var(--board);
  touch-action: none;
}
.board-wrap > svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 10px 18px rgba(91, 74, 51, 0.22));
}
#pieces .ring { animation: pulse 1.1s ease-in-out infinite alternate; }
@keyframes pulse { from { opacity: 0.45; } to { opacity: 1; } }

/* die (drawn in SVG above the board) */
#dice-layer { pointer-events: none; filter: none; }
#dice-layer .die-hit { pointer-events: auto; cursor: pointer; outline: none; }
.die .die-glow { display: none; }
.die.can-roll .die-glow { display: inline; animation: glow 0.9s ease-in-out infinite alternate; }
.die.result .die-glow { display: inline; stroke: #ffffff; }
@keyframes glow { from { opacity: 0.25; } to { opacity: 1; } }

/* HUD: small, in the margins, never shrinking the board */
.hud { position: absolute; z-index: 5; }
.hud-players {
  display: flex;
  flex-direction: column;
  gap: 10px;
  left: calc(var(--safe-l) + 14px);
  top: calc(var(--safe-t) + 14px);
  width: min(210px, calc((100vw - var(--board)) / 2 - 28px));
}
.player-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--chip);
  border: 2px solid var(--chip-edge);
  border-radius: 999px;
  padding: 4px 14px 4px 4px;
  font-size: 20px;
  font-weight: 500;
  min-height: 56px;
  transition: transform 0.2s ease, background 0.2s ease;
}
.player-chip svg { width: 46px; height: 46px; flex: none; overflow: visible; }
.player-chip.current { background: var(--on); border-color: #e7b84a; font-weight: 700; transform: scale(1.06); transform-origin: left center; }
.hud-message {
  left: calc(var(--safe-l) + 14px);
  bottom: calc(var(--safe-b) + 18px);
  width: min(220px, calc((100vw - var(--board)) / 2 - 28px));
  font-size: 24px;
  font-weight: 600;
  line-height: 1.2;
}
.hud-controls {
  right: calc(var(--safe-r) + 14px);
  top: calc(var(--safe-t) + 14px);
  display: flex;
  gap: 12px;
}
.round {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid var(--chip-edge);
  background: var(--chip);
  display: grid;
  place-items: center;
  padding: 0;
}
.round svg { width: 26px; height: 26px; fill: var(--ink); }

/* Portrait: players across the top, message and controls along the bottom. */
@media (max-aspect-ratio: 4/5) {
  .hud-players {
    flex-direction: row;
    flex-wrap: wrap;
    width: auto;
    right: calc(var(--safe-r) + 14px);
    justify-content: center;
  }
  .player-chip.current { transform-origin: center; }
  .hud-message { width: auto; right: 160px; text-align: left; }
  .hud-controls { top: auto; bottom: calc(var(--safe-b) + 14px); }
}
/* Near-square windows: tiny chips over the board corner instead of shrinking it. */
@media (min-aspect-ratio: 4/5) and (max-aspect-ratio: 5/4) {
  .hud-players { width: auto; gap: 6px; }
  .player-chip { padding: 2px; min-height: 0; font-size: 0; gap: 0; }
  .player-chip svg { width: 38px; height: 38px; }
  .hud-message { display: none; }
  .round { width: 46px; height: 46px; }
}

/* overlays */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(60, 48, 30, 0.35);
  padding: 16px;
}
.card {
  background: var(--chip);
  border: 3px solid var(--chip-edge);
  border-radius: 32px;
  padding: 26px 28px;
  display: grid;
  gap: 16px;
  justify-items: center;
  min-width: min(420px, 100%);
  text-align: center;
}
.card h2 { margin: 0; font-size: 40px; }
.card .row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.card .meta { margin: 0; font-size: 14px; opacity: 0.6; }
#win { background: rgba(60, 48, 30, 0.2); }
#win-face { width: 140px; height: 160px; overflow: visible; }
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 30; }

@media (prefers-reduced-motion: reduce) {
  #pieces .ring, .die.can-roll .die-glow { animation: none; }
}
.reduced #pieces .ring, .reduced .die.can-roll .die-glow { animation: none; }

/* question card: over the board, big tap targets, English only */
#pause { z-index: 25; }
#question { z-index: 18; background: rgba(60, 48, 30, 0.28); }
.q-card {
  width: min(760px, 100%);
  max-height: calc(var(--vh) - 32px);
  overflow-y: auto;
  gap: 14px;
  padding: 18px 24px 22px;
}
.q-head { width: 100%; display: flex; justify-content: space-between; align-items: center; }
#q-who { display: flex; align-items: center; gap: 8px; font-size: 22px; font-weight: 600; }
#q-who svg { width: 48px; height: 48px; overflow: visible; }
#q-reveal {
  border: 2px solid var(--chip-edge);
  background: #fff;
  border-radius: 999px;
  padding: 6px 16px;
  font-size: 16px;
  min-height: 40px;
  opacity: 0.75;
}
#q-prompt { font-size: clamp(30px, 4.6vw, 46px); line-height: 1.15; letter-spacing: 0.5px; }
.q-show { min-height: 0; }
.q-emoji { font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif; line-height: 1; }
.q-big { font-size: 96px; }
.q-show .q-many { font-size: 56px; letter-spacing: 6px; display: block; max-width: 620px; word-break: break-all; }
.q-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; width: 100%; }
.q-option {
  min-height: 150px;
  border: 3px solid var(--chip-edge);
  border-radius: 26px;
  background: #fff;
  display: grid;
  place-items: center;
  padding: 10px;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
}
.q-option:active { transform: scale(0.96); }
.q-option .q-emoji { font-size: 84px; }
.q-option .q-many { font-size: 40px; letter-spacing: 2px; word-break: break-all; }
.q-label { font-size: 44px; font-weight: 700; }
.q-swatch { width: 96px; height: 96px; border-radius: 50%; box-shadow: inset 0 0 0 3px rgba(0, 0, 0, 0.12); }
.q-option.correct { background: #dff3d4; border-color: #46a758; transform: scale(1.04); }
.q-option.picked { background: #fff3c4; border-color: #e7b84a; transform: scale(1.03); }
.q-option:disabled { cursor: default; color: inherit; }
.q-feedback { margin: 0; min-height: 0; font-size: 28px; font-weight: 700; color: #46a758; }
@media (max-height: 640px) {
  .q-option { min-height: 110px; }
  .q-option .q-emoji { font-size: 64px; }
  .q-big { font-size: 72px; }
}
#q-reveal:disabled { opacity: 0.35; cursor: default; }
#q-next { padding: 12px 56px; min-height: 64px; font-size: 28px; }
.q-reveal-text { margin: 0; font-size: clamp(28px, 4vw, 40px); font-weight: 700; color: #46a758; }
.q-show .q-big { font-size: 120px; }
