/* The world page: the 3D island full screen, and the HUD drawn over it.
   Big, chunky, friendly type (Fredoka), high contrast cards, everything
   reachable by keyboard and readable on a laptop from a kid's distance. */

:root {
  --y-ink: #1b2d2a;
  --y-cream: #fff8e7;
  --y-lagoon: #2ec4b6;
  --y-sea: #0f6f8f;
  --y-mango: #ff9f1c;
  --y-hibiscus: #ff3d6e;
  --y-leaf: #6cc24a;
  --y-leaf-dark: #3e8e33;
  --y-gold: #ffc93c;
  --y-sand: #f3d9a0;
  --y-mud: #6b4423;
  --y-shadow: 0 10px 0 rgba(27, 45, 42, .18), 0 18px 40px rgba(27, 45, 42, .25);
  --y-font: "Fredoka", "Nunito", ui-rounded, system-ui, sans-serif;
}

body.game-page { margin: 0; overflow: hidden; background: #8fd6f2; overscroll-behavior: none; }
.game-root { position: fixed; inset: 0; overflow: hidden; font-family: var(--y-font); color: var(--y-ink); user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.game-root canvas.island { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.game-root input, .game-root textarea { user-select: text; -webkit-user-select: text; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.hud { position: absolute; inset: 0; pointer-events: none; }
.hud button, .hud a, .hud input, .hud label, .hud form, .hud .popover, .hud .panel, .hud .qcard, .hud .toast { pointer-events: auto; }

/* ---------------------------------------------------------------- buttons */
.game-root .btn {
  font: 600 1.1rem/1 var(--y-font); color: #fff; background: var(--y-hibiscus);
  border: 0; border-radius: 999px; padding: .8em 1.3em; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: .5em;
  box-shadow: 0 5px 0 #c4204e; transition: transform .08s, box-shadow .08s, filter .15s;
}
.game-root .btn:hover { filter: brightness(1.06); }
.game-root .btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #c4204e; }
.game-root .btn:focus-visible, .game-root button:focus-visible, .game-root a:focus-visible, .game-root input:focus-visible { outline: 4px solid var(--y-gold); outline-offset: 3px; }
.game-root .btn-big { font-size: 1.35rem; padding: .85em 1.6em; }
.game-root .btn-small { font-size: .95rem; padding: .55em 1em; box-shadow: 0 3px 0 #c4204e; }
.game-root .btn-ghost { background: var(--y-cream); color: var(--y-ink); box-shadow: 0 5px 0 #d8cdb4; }
.game-root kbd { font: 600 .72em/1 var(--y-font); background: rgba(255,255,255,.25); border: 2px solid rgba(255,255,255,.55); border-radius: 6px; padding: .2em .45em; }
.game-root .btn-ghost kbd, .qcard kbd, .gauge kbd { background: rgba(27,45,42,.08); border-color: rgba(27,45,42,.25); }

/* ---------------------------------------------------------------- top bar */
.hud-top { position: absolute; left: 0; right: 0; top: 0; display: flex; justify-content: space-between; align-items: flex-start; padding: 14px 16px; gap: 12px; }
.chip {
  font: 500 .95rem/1 var(--y-font); color: var(--y-ink); background: rgba(255, 248, 231, .92); border: 0; border-radius: 999px;
  padding: .55em .9em; display: inline-flex; gap: .45em; align-items: center; cursor: pointer; box-shadow: 0 3px 0 rgba(27,45,42,.15);
}
.chip strong { letter-spacing: .06em; }
.chip-label { opacity: .65; }
.chip-copy { font-size: .8em; background: var(--y-lagoon); color: #fff; border-radius: 999px; padding: .3em .6em; }
.icon-btn {
  width: 46px; height: 46px; border-radius: 50%; border: 0; cursor: pointer; font: 600 1.35rem/1 var(--y-font);
  background: rgba(255, 248, 231, .92); color: var(--y-ink); box-shadow: 0 3px 0 rgba(27,45,42,.15); margin-left: 8px;
}
.icon-btn.muted { opacity: .55; text-decoration: line-through; }
.popover {
  position: absolute; top: 70px; right: 16px; background: var(--y-cream); border-radius: 20px; padding: 8px; min-width: 250px; max-width: min(92vw, 340px);
  box-shadow: var(--y-shadow); display: flex; flex-direction: column; gap: 2px; z-index: 30;
}
.popover[hidden] { display: none; }
.pop-item { font: 500 1rem/1.25 var(--y-font); color: var(--y-ink); text-decoration: none; background: none; border: 0; text-align: left; padding: .65em .8em; border-radius: 12px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
.pop-item:hover { background: rgba(46, 196, 182, .15); }
.pop-item small { opacity: .7; font-size: .82em; }
.track-item.on { background: rgba(46, 196, 182, .25); }
.track-item.on strong::after { content: " ♪"; color: var(--y-sea); }
.mute-item { border-top: 2px dashed rgba(27,45,42,.12); margin-top: 4px; }

/* distance meter */
.meter { text-align: center; background: rgba(27, 45, 42, .55); color: #fff; border-radius: 22px; padding: 6px 22px 8px; backdrop-filter: blur(4px); min-width: 170px; }
.meter[hidden] { display: none; }
.meter-value { font: 700 2.6rem/1 var(--y-font); letter-spacing: .02em; text-shadow: 0 3px 0 rgba(0,0,0,.25); font-variant-numeric: tabular-nums; }
.meter-value small { font-size: .5em; margin-left: .15em; opacity: .85; }
.meter-sub { font-size: .9rem; opacity: .9; min-height: 1.1em; }

/* ---------------------------------------------------------------- stage: cards and panels */
.hud-stage { position: absolute; inset: 0; display: grid; place-items: center end; padding: 80px clamp(16px, 5vw, 80px) 24px; }
.game-root .panel, .qcard {
  background: var(--y-cream); border-radius: 28px; box-shadow: var(--y-shadow);
  border: 4px solid #fff; box-sizing: border-box;
}
.game-root .panel[hidden], .qcard[hidden] { display: none; }

/* the question card */
.qcard { width: min(420px, 92vw); padding: 18px 22px 16px; position: relative; }
.qcard.enter { animation: card-in .35s cubic-bezier(.2, 1.6, .4, 1); }
.qcard.nudge { animation: nudge .3s; }
.q-head { display: flex; justify-content: space-between; align-items: center; font-size: 1rem; opacity: .85; gap: 8px; }
.q-weight { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.q-weight .pile { display: inline-flex; flex-wrap: wrap; gap: 2px; max-width: 150px; justify-content: flex-end; }
.q-weight i { width: 11px; height: 11px; border-radius: 4px; background: #8f8b84; box-shadow: inset 0 -2px 0 rgba(0,0,0,.2); }
.q-weight i.gold { background: var(--y-gold); box-shadow: inset 0 -2px 0 #e0a100, 0 0 6px rgba(255, 201, 60, .8); }
.q-weight b { font-size: 1.15rem; min-width: 1.4em; text-align: right; }
.q-prompt { font: 700 clamp(3rem, 9vw, 4.4rem)/1.1 var(--y-font); text-align: center; margin: 14px 0 12px; letter-spacing: .02em; font-variant-numeric: tabular-nums; white-space: nowrap; }
.q-row { display: flex; gap: 10px; }
.q-input {
  flex: 1; min-width: 0; font: 700 2.2rem/1 var(--y-font); text-align: center; color: var(--y-ink);
  border: 4px solid rgba(27,45,42,.15); border-radius: 18px; padding: .25em .3em; background: #fff; font-variant-numeric: tabular-nums;
}
.q-input:focus { border-color: var(--y-lagoon); outline: none; }
.q-go { font-size: 1.25rem; }
.q-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; gap: 10px; }
.q-dots { display: flex; gap: 6px; list-style: none; padding: 0; margin: 0; flex-wrap: wrap; }
.dot { width: 14px; height: 14px; border-radius: 50%; background: rgba(27,45,42,.12); }
.dot.right { background: var(--y-leaf); }
.dot.golden { background: var(--y-gold); box-shadow: 0 0 0 2px #fff, 0 0 8px rgba(255, 201, 60, .9); }
.dot.wrong { background: var(--y-hibiscus); }
.dot.skipped { background: #9aa3a0; }
.q-skip { font: 500 .95rem/1 var(--y-font); color: var(--y-ink); opacity: .75; background: none; border: 0; cursor: pointer; padding: .4em .2em; display: inline-flex; gap: .4em; align-items: center; }
.q-skip:hover { opacity: 1; }
.q-skip:disabled { opacity: .3; cursor: default; }
.qcard.right { border-color: var(--y-leaf); }
.qcard.golden { border-color: var(--y-gold); box-shadow: var(--y-shadow), 0 0 0 6px rgba(255, 201, 60, .45); }
.qcard.study { border-color: var(--y-hibiscus); }
.qcard.jam { border-color: #9aa3a0; }
.q-study { text-align: center; padding: 6px 0 4px; }
.q-study[hidden], .q-body[hidden] { display: none; }
.q-study-line { font: 700 clamp(2.4rem, 7.5vw, 3.6rem)/1.15 var(--y-font); margin: 16px 0 6px; white-space: nowrap; }
.q-study-line strong { color: var(--y-hibiscus); }
.qcard.jam .q-study-line strong { color: var(--y-sea); }
.q-study-hint { margin: 0 0 12px; font-size: 1.1rem; }
.drain { height: 12px; border-radius: 999px; background: rgba(27,45,42,.1); overflow: hidden; }
.drain i { display: block; height: 100%; background: var(--y-hibiscus); transform-origin: left; border-radius: inherit; }
.qcard.jam .drain i { background: #7d8a87; }
.q-pop { position: absolute; left: 50%; top: -18px; transform: translate(-50%, 0) scale(.6); opacity: 0; font: 700 1.4rem/1 var(--y-font); color: #fff; background: var(--y-leaf-dark); padding: .4em .8em; border-radius: 999px; pointer-events: none; white-space: nowrap; }
.q-pop.gold { background: linear-gradient(#ffd23f, #e0a100); color: #5a3b00; }
.q-pop.show { animation: pop-up .9s ease-out forwards; }
.q-pop.hot { background: linear-gradient(90deg, #ff3d6e, #ff9f1c, #ffd23f); color: #fff; text-shadow: 0 2px 0 rgba(90,30,0,.35); }

/* setup */
.setup { width: min(470px, 94vw); padding: 22px 24px 18px; max-height: calc(100vh - 110px); overflow: auto; }
.setup-title { font: 700 2rem/1.1 var(--y-font); margin: 0 0 14px; }
.setup .field { display: block; border: 0; padding: 0; margin: 0 0 14px; font-weight: 600; font-size: 1.05rem; }
.setup .field legend { padding: 0; margin-bottom: 6px; }
.setup .field > input[name="tag"] { display: block; width: 100%; box-sizing: border-box; margin-top: 6px; font: 600 1.2rem/1 var(--y-font); padding: .5em .7em; border-radius: 14px; border: 3px solid rgba(27,45,42,.15); background: #fff; color: var(--y-ink); }
.ops { display: flex; gap: 10px; }
.op-toggle { position: relative; cursor: pointer; }
.op-toggle input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.op-toggle span { display: grid; place-items: center; width: 58px; height: 58px; border-radius: 18px; font: 800 2.3rem/1 ui-rounded, "SF Pro Rounded", system-ui, sans-serif; /* Fredoka draws ÷ so tight it reads as + at this size */ background: #fff; border: 3px solid rgba(27,45,42,.15); color: rgba(27,45,42,.4); transition: all .12s; }
.op-toggle input:checked + span { background: var(--y-lagoon); border-color: var(--y-lagoon); color: #fff; box-shadow: 0 4px 0 #1f9b90; }
.op-toggle input:focus-visible + span { outline: 4px solid var(--y-gold); outline-offset: 2px; }
.grade-readout { margin-left: .4em; color: var(--y-sea); }
.dual { position: relative; height: 34px; }
.dual input[type="range"] { position: absolute; inset: 0; width: 100%; margin: 0; background: none; pointer-events: none; -webkit-appearance: none; appearance: none; }
.dual input[type="range"]::-webkit-slider-runnable-track { height: 10px; border-radius: 999px; background: rgba(27,45,42,.12); }
.dual input[type="range"]:last-child::-webkit-slider-runnable-track { background: transparent; }
.dual input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; pointer-events: auto; width: 30px; height: 30px; margin-top: -10px; border-radius: 50%; background: var(--y-mango); border: 4px solid #fff; box-shadow: 0 3px 0 rgba(27,45,42,.25); cursor: grab; }
.dual input[type="range"]::-moz-range-track { height: 10px; border-radius: 999px; background: rgba(27,45,42,.12); }
.dual input[type="range"]::-moz-range-thumb { pointer-events: auto; width: 24px; height: 24px; border-radius: 50%; background: var(--y-mango); border: 4px solid #fff; cursor: grab; }
.ticks { display: flex; justify-content: space-between; padding: 0 10px; font-size: .85rem; opacity: .6; font-weight: 500; }
.grade-summary { margin: 6px 0 0; font-weight: 400; font-size: .95rem; opacity: .85; min-height: 2.4em; }
.tracks { display: grid; gap: 6px; }
.track { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; padding: .5em .7em; border-radius: 14px; background: #fff; border: 3px solid transparent; font-weight: 400; }
.track input { margin-top: .3em; accent-color: var(--y-lagoon); }
.track span { display: flex; flex-direction: column; gap: 1px; }
.track strong { font-weight: 600; }
.track small { opacity: .7; font-size: .85rem; }
.track:has(input:checked) { border-color: var(--y-lagoon); }
.setup-error { color: #c4204e; font-weight: 600; margin: 0 0 10px; }
.setup-error[hidden] { display: none; }
.setup .btn-big { width: 100%; justify-content: center; }
.setup-hint { text-align: center; font-size: .9rem; opacity: .7; margin: 10px 0 0; }

/* results */
.results { width: min(460px, 94vw); padding: 22px 26px 20px; text-align: center; }
.results.enter { animation: card-in .45s cubic-bezier(.2, 1.6, .4, 1); }
.r-kicker { margin: 0; font-size: 1rem; opacity: .75; }
.r-title { font: 700 clamp(1.8rem, 5vw, 2.4rem)/1.1 var(--y-font); margin: 4px 0 14px; color: var(--y-sea); }
.r-distance { white-space: nowrap; color: var(--y-hibiscus); }
.r-stats { list-style: none; padding: 0; margin: 0 0 12px; display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; }
.r-stats li { background: #fff; border-radius: 16px; padding: 10px 6px; display: flex; flex-direction: column; gap: 2px; }
.r-stats strong { font: 700 1.5rem/1 var(--y-font); }
.r-stats span { font-size: .8rem; opacity: .7; }
.r-note { min-height: 1.2em; margin: 0 0 14px; font-size: 1rem; }
.r-buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---------------------------------------------------------------- swing: gauge, shout */
.gauge { position: absolute; left: 50%; bottom: 6vh; transform: translateX(-50%); width: min(230px, 60vw); text-align: center; background: rgba(255, 248, 231, .9); border-radius: 26px 26px 20px 20px; padding: 10px 14px 10px; box-shadow: var(--y-shadow); }
.gauge[hidden] { display: none; }
.gauge svg { width: 100%; display: block; overflow: visible; }
.g-track { fill: none; stroke: rgba(27,45,42,.15); stroke-width: 12; stroke-linecap: round; }
.g-sweet { fill: none; stroke: var(--y-leaf); stroke-width: 12; stroke-linecap: round; }
.g-needle { stroke: var(--y-ink); stroke-width: 5; stroke-linecap: round; }
.g-hub { fill: var(--y-ink); }
.gauge.sweet { box-shadow: var(--y-shadow), 0 0 0 6px rgba(108, 194, 74, .55); }
.gauge.sweet .g-needle { stroke: var(--y-leaf-dark); }
.g-label { font: 600 1.05rem/1.2 var(--y-font); margin-top: 2px; visibility: hidden; }
.gauge.hint .g-label { visibility: visible; }

.shout { position: absolute; left: 50%; top: 24%; transform: translate(-50%, -50%); font: 700 clamp(1.8rem, 5.5vw, 3.4rem)/1.1 var(--y-font); color: #fff; text-align: center; text-shadow: 0 4px 0 rgba(27,45,42,.5), 0 0 30px rgba(27,45,42,.35); width: min(90vw, 900px); pointer-events: none; }
.shout[hidden] { display: none; }
.shout.in { animation: shout-in .4s cubic-bezier(.2, 1.6, .4, 1); }
.shout.blink { animation: shout-in .4s cubic-bezier(.2, 1.6, .4, 1), blink .55s steps(2, jump-none) .4s infinite; color: var(--y-gold); }

.callouts { position: absolute; left: 0; right: 0; top: 18%; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.callout { font: 700 2rem/1 var(--y-font); color: #fff; text-shadow: 0 3px 0 rgba(27,45,42,.45); animation: callout 1.9s ease-out forwards; white-space: nowrap; }
.callout.small { font-size: 1.4rem; }
.callout.big { font-size: 2.5rem; color: #fff6c9; }
.callout.gold { color: var(--y-gold); font-size: 2.3rem; }
.callout.aero { color: #9fe8ff; font-size: 2.3rem; }
.callout.mud { color: #f3d9a0; }
.callout.water { color: #cff7f0; }
.callout.pass { font-size: 1.6rem; color: #ffe1ea; }
.callout.unhinged { font-size: 2.8rem; color: #fff; -webkit-text-stroke: 2px #c86bfa; paint-order: stroke fill; text-shadow: 3px 3px 0 #ff3d6e, -3px -3px 0 #2ec4b6; }
/* Unhinged mode's glow: a huge slowly turning rainbow disc; JS sets only opacity and transform. */
.disco { position: absolute; left: 50%; top: 50%; width: 150vmax; height: 150vmax; border-radius: 50%; opacity: 0; pointer-events: none; mix-blend-mode: soft-light;
  background: conic-gradient(#ff3d6e, #ffd23f, #6cc24a, #2ec4b6, #1d7bd8, #c86bfa, #ff3d6e); transform: translate(-50%, -50%); will-change: transform, opacity; }
.callout.combo { font-size: 2.6rem; color: #ffd23f; -webkit-text-stroke: 2px #c2410c; paint-order: stroke fill; }

.toast { position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--y-ink); color: #fff; padding: .7em 1em; border-radius: 16px; display: flex; gap: 12px; align-items: center; font-size: 1rem; box-shadow: var(--y-shadow); max-width: 92vw; }
.toast[hidden] { display: none; }

/* loading veil */
.veil { position: absolute; inset: 0; display: grid; place-items: center; background: linear-gradient(#3fa9e8, #8fd6f2 55%, #fbe3b8); z-index: 50; transition: opacity .6s; }
.veil.gone { opacity: 0; pointer-events: none; }
.veil-card { text-align: center; font: 600 1.3rem/1.2 var(--y-font); color: var(--y-ink); }
.veil-gnome { width: 90px; height: 110px; margin: 0 auto 10px; position: relative; animation: veil-bob 1.1s ease-in-out infinite; }
.veil-gnome::before { content: ""; position: absolute; left: 20px; top: 0; border-left: 25px solid transparent; border-right: 25px solid transparent; border-bottom: 62px solid #e0312b; border-radius: 6px; }
.veil-gnome::after { content: ""; position: absolute; left: 18px; top: 52px; width: 54px; height: 50px; border-radius: 50% 50% 45% 45%; background: radial-gradient(circle at 50% 22%, #ff9d8a 0 9px, transparent 10px), radial-gradient(circle at 50% 75%, #faf7f0 0 24px, transparent 25px), #ffcfa8; }
.veil-bar { width: 220px; height: 12px; border-radius: 999px; background: rgba(255,255,255,.5); overflow: hidden; margin: 10px auto 0; }
.veil-bar i { display: block; height: 100%; background: var(--y-hibiscus); transform: scaleX(0); transform-origin: left; transition: transform .3s; }

/* screen effects */
.game-root.flash::after { content: ""; position: absolute; inset: 0; background: #fff; animation: flash .5s ease-out forwards; pointer-events: none; }
.game-root.wipe::after { content: ""; position: absolute; inset: 0; background: radial-gradient(circle, #fff8e7 0 40%, #8fd6f2 100%); animation: wipe .38s ease-in forwards; pointer-events: none; z-index: 40; }
.boot-error { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); padding: 24px; text-align: center; width: min(420px, 90vw); }

/* Transform only: a card must be readable even if its animation never runs. */
@keyframes card-in { from { transform: scale(.82) translateY(16px); } to { transform: none; } }
@keyframes nudge { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
@keyframes pop-up { 0% { opacity: 0; transform: translate(-50%, 10px) scale(.6); } 20% { opacity: 1; transform: translate(-50%, -16px) scale(1.1); } 80% { opacity: 1; transform: translate(-50%, -26px) scale(1); } 100% { opacity: 0; transform: translate(-50%, -40px) scale(.9); } }
@keyframes shout-in { from { transform: translate(-50%, -50%) scale(.5); } to { transform: translate(-50%, -50%) scale(1); } }
@keyframes blink { 50% { opacity: .25; } }
@keyframes callout { 0% { opacity: 1; transform: translateY(20px) scale(.6); } 15% { opacity: 1; transform: translateY(0) scale(1.12); } 25% { transform: scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(-30px); } }
@keyframes flash { from { opacity: .85; } to { opacity: 0; } }
@keyframes wipe { from { opacity: 0; } to { opacity: 1; } }
@keyframes veil-bob { 50% { transform: translateY(-10px) rotate(-4deg); } }

/* Phones and portrait tablets: cards sit at the top (the keyboard covers the bottom). */
@media (max-aspect-ratio: 1/1) {
  .hud-stage { place-items: start center; padding-top: 76px; }
  .qcard { width: min(440px, 94vw); }
  .results { align-self: end; margin-bottom: 8px; }
  .meter { min-width: 0; padding: 4px 14px 6px; }
  .meter-value { font-size: 2rem; }
  .world-chip .chip-label, .world-chip .chip-copy { display: none; }
}
@media (max-height: 560px) {
  .q-prompt { font-size: 2.6rem; margin: 6px 0; }
  .hud-stage { padding-top: 64px; }
  .setup { max-height: calc(100vh - 80px); }
}
@media (prefers-reduced-motion: reduce) {
  .qcard.enter, .results.enter, .shout.in, .callout, .veil-gnome { animation: none !important; }
  .shout.blink { animation: none; }
}
