/*
 * theme.css — Country Chain.
 * Mood: a sunny classroom atlas — warm paper, deep navy ink, a coral
 * "go" colour, with sun-yellow, sky-blue and mint as the toy-box accents.
 * Playful like Duolingo, but warmer and more paper-like.
 */

:root {
  --canvas: #fff6e6;
  --surface: #ffffff;
  --surface-2: #ffecc8;
  --border: #f0dcb8;
  --border-strong: #c9b48f;
  --ink: #1d2340;
  --muted: #545a78;
  --accent: #d23c1f;
  --accent-hover: #b8321a;
  --accent-ink: #ffffff;
  --accent-text: #b5321a;
  --accent-strong: #9e2a12;
  --accent-soft: #ffe0d6;
  --accent-border: #f5a58f;
  --success: #0f7a56;
  --success-ink: #ffffff;
  --success-soft: #d6f5e8;
  --success-strong: #0b6b4a;
  --warning: #a35f00;
  --warning-ink: #ffffff;
  --warning-soft: #fff0c7;
  --warning-strong: #8a5200;
  --danger: #b82a38;
  --danger-ink: #ffffff;
  --danger-soft: #ffe0e3;
  --danger-strong: #a3212e;
  --chart-1: #d23c1f;
  --chart-2: #2d6fe0;
  --chart-3: #0f7a56;
  --chart-4: #7a4fe0;
  --chart-5: #d99a00;
  --chart-6: #1d2340;

  --x-sun: #ffc53d;
  --x-sky: #3d86f5;
  --x-mint: #22c58f;
  --x-grape: #8b5cf6;
  --x-tile: #1d2340;
  --x-tile-ink: #fff6e6;
  --x-dot: #f2ddb6;

  --font-display: "Fredoka", ui-rounded, system-ui, sans-serif;
  --font-body: "Nunito", ui-sans-serif, system-ui, sans-serif;
  --font-sans: "Nunito", ui-sans-serif, system-ui, sans-serif;
  --font-mono: "JetBrains Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --display-weight: 700;
  --display-tracking: -0.01em;
  --eyebrow-tracking: 0.08em;

  --radius-btn: 999px;
  --radius-card: 2rem;
  --radius-input: 1.25rem;
  --border-w: 2px;
  --shadow-card: 0 6px 0 rgba(0, 0, 0, 0.06), 0 24px 48px -28px rgba(0, 0, 0, 0.3);
  --shadow-raised: 0 10px 0 rgba(0, 0, 0, 0.08), 0 30px 60px -30px rgba(0, 0, 0, 0.35);
  --shadow-btn: 0 4px 0 rgba(0, 0, 0, 0.18);
  --btn-weight: 700;
}

html[data-theme="dark"] {
  --canvas: #121733;
  --surface: #1b2149;
  --surface-2: #242b5c;
  --border: #2f3770;
  --border-strong: #4c5596;
  --ink: #f7f4ff;
  --muted: #b3b8dc;
  --accent: #ff7a5c;
  --accent-hover: #ff9478;
  --accent-ink: #2a0b04;
  --accent-text: #ff9a80;
  --accent-strong: #ffc2b2;
  --accent-soft: #3d2236;
  --accent-border: #7a3a3a;
  --success: #35d39c;
  --success-ink: #04211a;
  --success-soft: #15363a;
  --success-strong: #8af0c8;
  --warning: #ffc53d;
  --warning-ink: #2a1c00;
  --warning-soft: #3a3020;
  --warning-strong: #ffdc85;
  --danger: #ff6b7a;
  --danger-ink: #2a050a;
  --danger-soft: #3e1d33;
  --danger-strong: #ffb0b9;
  --chart-1: #ff7a5c;
  --chart-2: #6fa6ff;
  --chart-3: #35d39c;
  --chart-4: #b294ff;
  --chart-5: #ffc53d;
  --chart-6: #f7f4ff;

  --x-sun: #ffc53d;
  --x-sky: #6fa6ff;
  --x-mint: #35d39c;
  --x-grape: #b294ff;
  --x-tile: #ffc53d;
  --x-tile-ink: #1d2340;
  --x-dot: #1d2452;
}

/* app.css — Country Chain: the playground ground, the game pieces and every animation. */

/* ---------- Ground: a dotted atlas paper ---------- */
.play-ground {
  background-color: var(--canvas);
  background-image: radial-gradient(var(--x-dot) 1.6px, transparent 1.7px);
  background-size: 22px 22px;
}
.brand-dot {
  display: inline-grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 999px;
  background: var(--x-sky);
  color: var(--x-tile-ink);
}
html[data-theme="dark"] .brand-dot { color: var(--canvas); }
.screen { animation: screen-in .5s cubic-bezier(.2, .8, .2, 1) both; }
@keyframes screen-in { from { transform: translateY(18px); } to { transform: none; } }

/* ---------- Title wave ---------- */
.wave-title .wave-letter { display: inline-block; animation: wave 2.8s ease-in-out infinite; }
.wave-title .space { display: inline-block; width: .3em; }
.wave-title .c0 { color: var(--accent-text); }
.wave-title .c1 { color: var(--ink); }
.wave-title .c2 { color: var(--x-sky); }
.wave-title .c3 { color: var(--ink); }
.wave-title .c4 { color: var(--success); }
.wave-title span:nth-child(1) { animation-delay: 0s; }
.wave-title span:nth-child(2) { animation-delay: .08s; }
.wave-title span:nth-child(3) { animation-delay: .16s; }
.wave-title span:nth-child(4) { animation-delay: .24s; }
.wave-title span:nth-child(5) { animation-delay: .32s; }
.wave-title span:nth-child(6) { animation-delay: .4s; }
.wave-title span:nth-child(7) { animation-delay: .48s; }
.wave-title span:nth-child(9) { animation-delay: .64s; }
.wave-title span:nth-child(10) { animation-delay: .72s; }
.wave-title span:nth-child(11) { animation-delay: .8s; }
.wave-title span:nth-child(12) { animation-delay: .88s; }
.wave-title span:nth-child(13) { animation-delay: .96s; }
@keyframes wave { 0%, 60%, 100% { transform: translateY(0) rotate(0); } 30% { transform: translateY(-.12em) rotate(-4deg); } }

/* ---------- Example chain ---------- */
.example { display: flex; flex-wrap: nowrap; gap: .5rem; overflow-x: auto; padding-bottom: .5rem; }
.example-chip {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  padding: .55rem .9rem;
  border-radius: 999px;
  background: var(--surface);
  border: 2px solid var(--border);
  font-weight: 800;
  font-size: 1.05rem;
  animation: chip-hop 4.8s ease-in-out infinite;
}
.example-chip b { color: var(--accent-ink); background: var(--accent); border-radius: 999px; padding: 0 .4rem; margin-left: .1rem; }
.example-next { border-style: dashed; }
.example-next b { margin-left: 0; margin-right: .25rem; }
.example-chip:nth-child(2) { animation-delay: .6s; }
.example-chip:nth-child(3) { animation-delay: 1.2s; }
.example-chip:nth-child(4) { animation-delay: 1.8s; }
.example-chip:nth-child(5) { animation-delay: 2.4s; }
@keyframes chip-hop { 0%, 20%, 100% { transform: translateY(0); } 8% { transform: translateY(-10px) scale(1.05); } }

/* ---------- Globe ---------- */
.globe-wrap {
  position: absolute;
  width: 11rem;
  height: 11rem;
  right: -1.5rem;
  top: -4.5rem;
  z-index: 2;
  animation: float 6s ease-in-out infinite;
  pointer-events: none;
}
@media (max-width: 640px) { .globe-wrap { width: 7rem; height: 7rem; right: -.5rem; top: -3rem; } }
.globe { width: 100%; height: 100%; overflow: visible; }
.globe-sea { fill: var(--x-sky); stroke: var(--ink); stroke-width: 4; }
.globe-lines { fill: none; stroke: rgba(255, 255, 255, .5); stroke-width: 2; }
.globe-spin { transform-origin: 100px 100px; animation: spin-x 5s linear infinite; }
.globe-land { fill: var(--x-mint); stroke: var(--ink); stroke-width: 3; stroke-linejoin: round; }
@keyframes spin-x { from { transform: scaleX(1); } 50% { transform: scaleX(-1); } to { transform: scaleX(1); } }
@keyframes float { 0%, 100% { transform: translateY(0) rotate(-6deg); } 50% { transform: translateY(-12px) rotate(4deg); } }

.setup-card { padding: 1.75rem; }
@media (min-width: 768px) { .setup-card { padding: 2.25rem; } }
.player-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: .75rem; }
.player-swatch { width: 2.5rem; height: 2.5rem; border-radius: 999px; display: grid; place-items: center; font-weight: 800; color: var(--surface); }
.go-btn { box-shadow: 0 5px 0 var(--accent-strong); transition: transform .12s ease, box-shadow .12s ease; }
.go-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--accent-strong); }

/* ---------- How-to cards ---------- */
.how-card { border-radius: 2rem; padding: 1.75rem; border: 2px solid var(--ink); box-shadow: 0 6px 0 var(--ink); transition: transform .25s ease; }
.how-card:hover { transform: translateY(-6px) rotate(-1deg); }
.how-card p { color: var(--ink); }
.how-sun { background: var(--warning-soft); }
.how-sky { background: var(--surface); }
.how-mint { background: var(--success-soft); }
.how-icon { width: 2.25rem; height: 2.25rem; color: var(--accent-text); }

/* ---------- Player colours ---------- */
.p-0 { --pc: var(--chart-1); }
.p-1 { --pc: var(--chart-2); }
.p-2 { --pc: var(--chart-3); }
.p-3 { --pc: var(--chart-4); }
.player-swatch { background: var(--pc); }

/* ---------- Scoreboard ---------- */
.scoreboard { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: .75rem; flex: 1; min-width: 0; }
.score-chip {
  display: flex;
  align-items: center;
  gap: .6rem;
  min-width: 0;
  padding: .6rem .9rem;
  border-radius: 1.25rem;
  background: var(--surface);
  border: 2px solid var(--border);
  transition: transform .3s cubic-bezier(.3, 1.6, .5, 1), border-color .2s ease, box-shadow .2s ease;
}
.score-chip .dot { width: .85rem; height: .85rem; border-radius: 999px; background: var(--pc); flex-shrink: 0; }
.score-chip .nm { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 800; }
.score-chip .pts { margin-left: auto; font-family: var(--font-display); font-weight: 700; font-size: 1.35rem; flex-shrink: 0; }
.score-chip.is-turn { border-color: var(--pc); box-shadow: 0 5px 0 var(--pc); transform: translateY(-4px); }
.score-chip .pts.bump { animation: bump .5s cubic-bezier(.3, 1.8, .5, 1); }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.6); } 100% { transform: scale(1); } }
@media (max-width: 640px) { .scoreboard { grid-auto-flow: row; grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ---------- Play card ---------- */
.play-card { padding: 1.5rem; }
@media (min-width: 768px) { .play-card { padding: 2.25rem; } }
.turn-label .who { color: var(--pc); }
.letter-tile {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 8.5rem;
  height: 8.5rem;
  border-radius: 2rem;
  background: var(--x-tile);
  color: var(--x-tile-ink);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 5.5rem;
  line-height: 1;
  box-shadow: 0 8px 0 var(--x-sun);
  perspective: 600px;
}
.letter-tile.flip { animation: flip .7s cubic-bezier(.3, 1.4, .5, 1); }
@keyframes flip { 0% { transform: rotateY(90deg) scale(.8); } 100% { transform: rotateY(0) scale(1); } }

.notice {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 1rem 1.25rem;
  border-radius: 1.25rem;
  background: var(--warning-soft);
  color: var(--warning-strong);
  font-weight: 800;
  border: 2px dashed var(--warning-strong);
  animation: drop-in .6s cubic-bezier(.3, 1.5, .5, 1);
}
@keyframes drop-in { from { transform: translateY(-14px) scale(.96); } to { transform: none; } }

.answer-form { display: grid; grid-template-columns: 1fr auto auto; gap: .6rem; align-items: center; }
.answer-input { font-size: 1.35rem; font-weight: 800; padding-top: .9rem; padding-bottom: .9rem; }
.answer-form.shake { animation: shake .45s ease; }
@keyframes shake { 20% { transform: translateX(-10px); } 40% { transform: translateX(9px); } 60% { transform: translateX(-6px); } 80% { transform: translateX(4px); } }

.mic-btn {
  position: relative;
  display: grid;
  place-items: center;
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 999px;
  background: var(--x-sky);
  color: var(--x-tile-ink);
  box-shadow: 0 4px 0 rgba(0, 0, 0, .2);
  transition: transform .15s ease;
}
html[data-theme="dark"] .mic-btn { color: var(--canvas); }
.mic-btn .icon { width: 1.5rem; height: 1.5rem; }
.mic-btn:hover { transform: scale(1.06); }
.mic-btn.is-listening { background: var(--accent); color: var(--accent-ink); }
.mic-btn.is-listening::before,
.mic-btn.is-listening::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 999px;
  border: 3px solid var(--accent);
  animation: ring 1.4s ease-out infinite;
}
.mic-btn.is-listening::after { animation-delay: .7s; }
@keyframes ring { from { transform: scale(1); opacity: .9; } to { transform: scale(1.9); opacity: 0; } }

.feedback:empty { display: none; }
.feedback .fb {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .9rem 1.1rem;
  border-radius: 1.25rem;
  font-weight: 700;
  animation: drop-in .45s cubic-bezier(.3, 1.5, .5, 1);
}
.fb-good { background: var(--success-soft); color: var(--success-strong); }
.fb-bad { background: var(--danger-soft); color: var(--danger-strong); }
.fb-info { background: var(--surface-2); color: var(--ink); }
.fb-actions { display: flex; gap: .5rem; margin-left: auto; flex-shrink: 0; }
.hint-word { font-family: var(--font-display); font-size: 1.6rem; letter-spacing: .2em; }

/* ---------- Quiz ---------- */
.quiz { padding: 1.5rem; border-radius: 1.5rem; background: var(--surface-2); animation: drop-in .5s cubic-bezier(.3, 1.5, .5, 1); }
.quiz-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .75rem; }
.quiz-opt {
  height: 5rem;
  border-radius: 1.5rem;
  background: var(--surface);
  border: 3px solid var(--ink);
  box-shadow: 0 5px 0 var(--ink);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 2.5rem;
  transition: transform .12s ease;
  animation: pop .5s cubic-bezier(.3, 1.8, .5, 1) both;
}
.quiz-opt:nth-child(2) { animation-delay: .08s; }
.quiz-opt:nth-child(3) { animation-delay: .16s; }
.quiz-opt:hover { transform: translateY(-3px); }
.quiz-opt.is-right { background: var(--success); color: var(--success-ink); border-color: var(--success); }
.quiz-opt.is-wrong { background: var(--danger-soft); color: var(--danger-strong); animation: shake .45s ease; }
@keyframes pop { from { transform: scale(.4); } to { transform: scale(1); } }

/* ---------- Letter grid ---------- */
.letter-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: .4rem; }
@media (min-width: 640px) and (max-width: 1023px) { .letter-grid { grid-template-columns: repeat(9, minmax(0, 1fr)); } }
.lg-tile {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border-radius: .9rem;
  background: var(--surface-2);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  transition: background .3s ease, transform .3s ease;
}
.lg-tile small { position: absolute; right: .25rem; bottom: .1rem; font-size: .6rem; font-family: var(--font-body); font-weight: 800; color: var(--muted); }
.lg-tile.is-empty { background: transparent; color: var(--border-strong); border: 2px dashed var(--border); }
.lg-tile.is-empty small { display: none; }
.lg-tile.is-current { background: var(--accent); color: var(--accent-ink); transform: scale(1.12); box-shadow: 0 4px 0 var(--accent-strong); }
.lg-tile.is-current small { color: var(--accent-ink); }

/* ---------- Chain ---------- */
.chain { display: flex; flex-wrap: nowrap; gap: .5rem; overflow-x: auto; padding: .5rem .25rem 1rem; scroll-behavior: smooth; }
.chain-card {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: .15rem;
  padding: .85rem 1.1rem;
  border-radius: 1.25rem;
  background: var(--surface);
  border: 2px solid var(--pc);
  box-shadow: 0 4px 0 var(--pc);
  animation: card-in .6s cubic-bezier(.3, 1.6, .5, 1);
}
.chain-card .cn { font-family: var(--font-display); font-weight: 700; font-size: 1.3rem; white-space: nowrap; }
.chain-card .cn b { color: var(--accent-ink); background: var(--accent); border-radius: .4rem; padding: 0 .2rem; }
.chain-card .meta { font-size: .8rem; font-weight: 700; color: var(--muted); white-space: nowrap; }
.chain-link { flex-shrink: 0; align-self: center; color: var(--border-strong); }
@keyframes card-in { from { transform: translateY(24px) scale(.6) rotate(-6deg); } to { transform: none; } }

/* ---------- End screen ---------- */
.trophy {
  display: inline-grid;
  place-items: center;
  width: 7rem;
  height: 7rem;
  border-radius: 999px;
  background: var(--x-sun);
  color: var(--x-tile);
  box-shadow: 0 8px 0 var(--warning-strong);
  animation: trophy 1.2s cubic-bezier(.3, 1.6, .5, 1) both, float 4s ease-in-out 1.2s infinite;
}
html[data-theme="dark"] .trophy { color: var(--canvas); }
.trophy .icon { width: 3.5rem; height: 3.5rem; }
@keyframes trophy { from { transform: scale(.2) rotate(-30deg); } to { transform: none; } }
.podium { display: grid; grid-template-columns: repeat(var(--n, 2), minmax(0, 1fr)); gap: 1rem; align-items: end; max-width: 48rem; margin-left: auto; margin-right: auto; }
.pod { text-align: center; }
.pod .nm { font-family: var(--font-display); font-weight: 700; font-size: 1.35rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pod .block {
  margin-top: .5rem;
  border-radius: 1.5rem 1.5rem .5rem .5rem;
  background: var(--pc);
  color: var(--surface);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 2rem;
  display: grid;
  place-items: center;
  transform-origin: bottom;
  animation: grow .9s cubic-bezier(.3, 1.4, .5, 1) both;
}
html[data-theme="dark"] .pod .block { color: var(--canvas); }
.pod:nth-child(2) .block { animation-delay: .15s; }
.pod:nth-child(3) .block { animation-delay: .3s; }
.pod:nth-child(4) .block { animation-delay: .45s; }
@keyframes grow { from { transform: scaleY(.1); } to { transform: none; } }
.end-chain { display: flex; flex-wrap: wrap; gap: .5rem; }
.end-chain .chain-card { animation: none; }

/* ---------- Confetti ---------- */
.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 60; }

/* ---------- Reduced motion ---------- */
html.reduced-motion *, html.reduced-motion *::before, html.reduced-motion *::after { animation: none !important; transition: none !important; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
