:root {
  color-scheme: dark;
  --night: #071c2d;
  --deep: #0b3850;
  --water: #0d6680;
  --foam: #dff8ef;
  --sand: #f3cf7a;
  --coral: #ff8066;
  --leaf: #7fcf9b;
  --ink: #10202c;
  --warning: #ffd166;
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--night); }
body {
  margin: 0;
  min-height: 100vh;
  color: #f7fff9;
  background:
    radial-gradient(circle at 15% 8%, rgba(127, 207, 155, .13), transparent 30rem),
    linear-gradient(#061726 0 34%, #0a3e55 34% 100%);
  overflow-x: hidden;
}
button { font: inherit; }
button:focus-visible { outline: 4px solid #fff2a8; outline-offset: 3px; }
[hidden] { display: none !important; }

.shell { width: min(100%, 980px); margin: 0 auto; padding: 16px clamp(12px, 3vw, 28px) 44px; }
.masthead { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.eyebrow { margin: 0 0 5px; color: #b4f2d0; font-weight: 900; letter-spacing: .12em; font-size: .82rem; }
h1 { margin: 0; font-size: clamp(1.45rem, 5vw, 2.5rem); font-family: Georgia, "Yu Mincho", serif; letter-spacing: .04em; }
h2 { margin: 8px 0 12px; font-size: clamp(1.55rem, 5vw, 2.35rem); }
.round-button, .secondary-button {
  border: 2px solid rgba(255,255,255,.55); background: #13394d; color: #fff; border-radius: 8px;
  min-height: 46px; padding: 8px 14px; font-weight: 800;
}

.start-screen { position: relative; min-height: 610px; border: 3px solid #17364a; background: #cfebdc; color: var(--ink); overflow: hidden; box-shadow: 0 16px 0 #03131f; }
.start-screen::before { content: ""; position: absolute; inset: 0; opacity: .16; background-image: repeating-linear-gradient(0deg, transparent 0 23px, #315f63 24px), repeating-linear-gradient(90deg, transparent 0 23px, #315f63 24px); }
.start-map { position: absolute; inset: 0; background: linear-gradient(#9cd7db 0 46%, #19708c 46%); }
.start-map::after { content: ""; position: absolute; left: -10%; right: -10%; bottom: 0; height: 48%; background: repeating-radial-gradient(ellipse at 50% 110%, transparent 0 19px, rgba(223,248,239,.36) 20px 23px); }
.start-island { position: absolute; display: grid; place-items: center; width: 120px; height: 78px; border-radius: 52% 45% 48% 38%; background: var(--sand); border: 4px solid #4b5a42; font-size: 2rem; font-family: Georgia, "Yu Mincho", serif; font-weight: 900; box-shadow: inset 0 -13px #a4ba75, 0 8px 0 rgba(4,38,52,.35); }
.island-trillion { left: 8%; top: 20%; transform: rotate(-4deg); }
.island-billion { right: 11%; top: 14%; transform: rotate(5deg); }
.island-ten-thousand { left: 18%; top: 52%; transform: rotate(4deg); }
.island-one { right: 18%; top: 54%; transform: rotate(-5deg); }
.start-wave { position: absolute; width: 54%; height: 13px; left: 24%; top: 43%; background: var(--foam); box-shadow: 0 17px #6dd4cf, 0 34px var(--foam); transform: rotate(-8deg); opacity: .8; }
.start-copy { position: relative; z-index: 2; width: min(520px, 88%); margin: 250px auto 32px; padding: 22px clamp(18px,4vw,34px); background: #fff9df; border: 3px solid #1b3f4e; box-shadow: 9px 10px 0 #193c45; }
.start-copy p, .start-copy li { line-height: 1.75; font-weight: 650; }
.start-copy ul { padding-left: 1.25em; }
.primary-button, .send-button {
  border: 0; border-radius: 6px; min-height: 52px; padding: 12px 20px; background: #ff684d; color: #fff;
  font-weight: 950; box-shadow: 0 5px 0 #8f2e24; cursor: pointer;
}
.primary-button:active, .send-button:active { transform: translateY(3px); box-shadow: 0 2px 0 #8f2e24; }
.best-line { margin-bottom: 0; }

.hud { display: grid; grid-template-columns: repeat(4, 1fr); background: #0a2738; border: 2px solid #81c5bd; }
.hud > div { padding: 9px 7px; text-align: center; border-right: 1px dashed #5d958f; }
.hud > div:last-child { border-right: 0; }
.hud span { display: block; color: #a9dace; font-size: .72rem; font-weight: 800; }
.hud strong { font-size: clamp(1rem, 4vw, 1.35rem); }

.number-scroll { background: #f6e7b8; color: var(--ink); border: 3px solid #2a4149; border-top: 0; padding: 12px; box-shadow: inset 0 0 0 5px rgba(142,99,46,.12); }
.number-row { display: grid; grid-template-columns: 64px 1fr; gap: 5px 10px; align-items: center; }
.number-row > span { font-weight: 900; }
.number-row > b { grid-column: 2; font-family: Georgia, "Yu Mincho", serif; font-size: 1.05rem; min-height: 1.5em; }
.chunks { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 5px; }
.chunk { background: #fffdf2; border: 2px solid #4e5a4b; padding: 6px 2px; text-align: center; font-variant-numeric: tabular-nums; font-weight: 950; }
.chunk small { display: block; font-size: .62rem; color: #50605d; }
.pulse-row { display: flex; align-items: center; gap: 10px; margin: 10px 0; padding: 8px; background: #d5f1e8; border-left: 7px solid #16809a; }
.pulse-row p { margin: 0; line-height: 1.5; }
.pulse-chip { flex: 0 0 auto; background: #10394c; color: #fff; padding: 8px 13px; border-radius: 50%; font-weight: 900; }

.waterway-world { position: relative; margin-top: 15px; padding: 12px; border: 3px solid #071c2d; background: #16738b; overflow: hidden; touch-action: pan-y; }
.waterway-world::before { content: ""; position: absolute; inset: 0; background: repeating-radial-gradient(ellipse at 20% 0, transparent 0 31px, rgba(210,250,240,.16) 32px 35px); pointer-events: none; }
.waterway-world.danger { background: #8a5a32; }
.waterway-world.finale { box-shadow: inset 0 0 0 6px #ffe07b; }
.danger-banner { position: relative; z-index: 1; padding: 7px 9px; background: #082b3c; border-left: 7px solid #7fcf9b; font-weight: 850; line-height: 1.45; }
.danger .danger-banner { border-color: #ffe07b; background: #492619; }
.island-row { position: relative; z-index: 1; display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; margin-top: 12px; }
.number-island { min-width: 0; padding: 6px 3px 8px; text-align: center; color: var(--ink); background: #f3cf7a; border: 3px solid #3f5549; border-radius: 42% 52% 38% 48%; box-shadow: inset 0 -8px #8fb575; }
.number-island span { display: block; font-size: clamp(.62rem, 2.5vw, .83rem); font-weight: 800; white-space: nowrap; }
.number-island b { font-size: clamp(1.25rem, 5vw, 2rem); font-family: Georgia, "Yu Mincho", serif; }
.number-island.active { outline: 5px solid #fff; transform: translateY(-4px); }

.pipe-board { position: relative; z-index: 1; width: min(100%, 520px); margin: 8px auto 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.pipe-tile { aspect-ratio: 1; min-width: 0; border: 3px solid #7e6742; border-radius: 8px; background: #f2dfaa; color: #174654; font: 900 clamp(1.65rem, 10vw, 3.3rem)/1 monospace; box-shadow: inset 0 0 0 4px #d7b978, 0 4px 0 rgba(4,33,43,.45); cursor: pointer; touch-action: pan-y; }
.pipe-tile.on-route { background: #e5f8d9; color: #0d7a83; box-shadow: inset 0 0 0 4px #9cd9bc, 0 4px 0 rgba(4,33,43,.45); }
.pipe-tile.selected { outline: 4px solid #fff39a; }
.source-marker { position: relative; z-index: 1; width: min(125px, 34%); margin: 8px auto 0; text-align: center; background: #fff5cf; color: #153441; border: 2px solid #294c58; padding: 6px; font-weight: 950; }
.route-status { position: relative; z-index: 1; min-height: 3.2em; margin: 9px 0; padding: 8px; background: rgba(3,24,34,.82); border: 2px solid rgba(255,255,255,.55); font-weight: 800; line-height: 1.5; }
.risk-row { position: relative; z-index: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.risk-button { min-height: 57px; padding: 8px; border: 2px solid #ffe3a0; background: #153e4b; color: #fff; font-weight: 900; }
.risk-button small { display: block; font-weight: 650; margin-top: 3px; }
.risk-button[aria-pressed="true"] { background: #7b3a28; border-color: #fff2a5; }
.send-button:disabled { background: #61747a; box-shadow: none; cursor: not-allowed; }
.touch-note { position: relative; z-index: 1; margin: 10px 0 0; font-size: .78rem; line-height: 1.55; color: #e7fff6; }

.quiz-screen, .result-screen { background: #f7edc8; color: var(--ink); border: 4px solid #203f49; padding: clamp(18px, 4vw, 34px); box-shadow: 9px 10px 0 #03131f; }
.quiz-screen .eyebrow, .result-screen .eyebrow { color: #28726e; }
.quiz-card { padding: 15px; background: #fffdf3; border: 3px solid #5e674f; }
.quiz-question { font-size: clamp(1.1rem, 4vw, 1.45rem); font-weight: 900; line-height: 1.6; }
.quiz-choices { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
.quiz-choice { min-width: 0; min-height: 52px; padding: 10px; border: 2px solid #2a5860; background: #e8f4dd; color: var(--ink); font-weight: 850; overflow-wrap: anywhere; }
.quiz-choice.correct { border-width: 4px; border-color: #237449; }
.quiz-choice.wrong { border-width: 4px; border-color: #a73a31; }
.quiz-feedback { min-height: 4.4em; margin-top: 12px; padding: 9px; background: #e9e1c2; line-height: 1.6; font-weight: 700; }
.quiz-screen > .primary-button { margin-top: 14px; }

.result-screen { position: relative; overflow: hidden; text-align: center; }
.result-sun { position: absolute; width: 180px; height: 180px; right: -50px; top: -50px; border-radius: 50%; background: #ffd76d; box-shadow: 0 0 0 22px rgba(255,215,109,.24); }
.result-screen > * { position: relative; }
.result-score { width: min(380px, 100%); margin: 18px auto; padding: 15px; color: #fff; background: #0b465b; border: 5px double #dff8ef; }
.result-score span { display: block; }
.result-score strong { font-size: clamp(2.2rem, 10vw, 4rem); font-variant-numeric: tabular-nums; }
.result-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
.ranking-panel { width: min(100%, 620px); margin: 18px auto 0; padding: 10px; text-align: left; background: #0b2c3d; color: #fff; border: 3px solid #8fd6c3; overflow-wrap: anywhere; }
.ranking-panel button, .ranking-panel [role="tab"] { color: #fff !important; background: #28556a !important; }
.ranking-panel button[aria-selected="true"], .ranking-panel .active { color: #10202c !important; background: #fff0a6 !important; }
.toast { position: fixed; z-index: 20; left: 50%; bottom: 20px; width: min(88vw, 620px); transform: translate(-50%, 130%); padding: 12px 16px; background: #071c2d; border: 3px solid #fff; color: #fff; text-align: center; font-weight: 900; transition: transform .25s ease; pointer-events: none; }
.toast.show { transform: translate(-50%, 0); }
.success-burst .number-island.active { animation: island-release .8s ease; }
@keyframes island-release { 0% { transform: scale(.86); } 45% { transform: scale(1.18) rotate(-3deg); } 100% { transform: scale(1); } }

@media (max-width: 620px) {
  .shell { padding-inline: 8px; }
  .masthead { align-items: flex-start; }
  .round-button { padding-inline: 10px; font-size: .82rem; }
  .start-screen { min-height: 650px; }
  .start-island { width: 83px; height: 58px; font-size: 1.45rem; }
  .start-copy { margin-top: 225px; width: 92%; }
  .hud { grid-template-columns: repeat(2, 1fr); }
  .hud > div:nth-child(2) { border-right: 0; }
  .hud > div:nth-child(-n+2) { border-bottom: 1px dashed #5d958f; }
  .number-row { grid-template-columns: 52px 1fr; }
  .chunk { font-size: .76rem; }
  .risk-row { grid-template-columns: 1fr; }
  .quiz-choices { grid-template-columns: 1fr; }
  .result-actions { flex-direction: column; }
  .result-actions button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: .001ms !important; }
}
