@import url('./fonts.css');

:root {
  --pine: #2d4a3a; --pine-soft: #5c7567; --paper: #fff8e6; --line: rgba(45, 74, 58, .14);
  --gold: #ffcf57; --water: #3fb8d0; --coral: #ef6a4f; --leaf: #6fb352;
  --sticker: 0 3px 0 rgba(45, 74, 58, .18), 0 10px 24px rgba(45, 74, 58, .14);
  font-family: 'DM Sans', system-ui, sans-serif; color: var(--pine); font-synthesis: none;
}
* { box-sizing: border-box; }
body { margin: 0; overflow: hidden; height: 100dvh; background: #c4e9f4; overscroll-behavior: none; -webkit-user-select: none; user-select: none; }
button, input { -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; border: 0; cursor: pointer; }
button:disabled { cursor: wait; opacity: .7; }
button:focus-visible, input:focus-visible + i { outline: 3px solid var(--coral); outline-offset: 3px; }
[hidden] { display: none !important; }
h1, h2, p, ol { margin: 0; padding: 0; }
h1, h2 { font-family: 'Libre Caslon Display', Georgia, serif; font-weight: 400; }
svg { display: block; width: 100%; height: 100%; }
kbd { font: inherit; font-size: .82em; font-weight: 700; padding: 2px 7px; border-radius: 6px; background: #fff; border: 1.5px solid rgba(45, 74, 58, .28); box-shadow: 0 2px 0 rgba(45, 74, 58, .22); white-space: nowrap; }

#world { position: fixed; inset: 0; width: 100%; height: 100%; outline: none; touch-action: none; }
.vignette { position: fixed; inset: 0; pointer-events: none; transition: opacity .5s; background: linear-gradient(90deg, #17382eee 0%, #1c3a30d9 16%, #233d3159 37%, #223d3000 62%), linear-gradient(0deg, #153a2d3b, transparent 36%); }
body.playing .vignette { opacity: 0; }

/* Menu */
.menu-screen { position: absolute; inset: 0; pointer-events: none; color: #faf0d3; }
.menu-screen button { pointer-events: auto; }
.hero { position: absolute; top: 29%; left: 7%; width: 510px; }
.hero h1 { font-size: clamp(76px, 6.6vw, 110px); letter-spacing: -4px; line-height: .94; margin: 0 0 44px; text-shadow: 0 3px 35px #142b2433; width: max-content; }
.hero h1 em { font-style: normal; color: #dfd19d; }
.play-button { display: flex; align-items: center; justify-content: center; gap: 12px; min-height: 52px; padding: 14px 22px; border-radius: 14px; background: var(--pine); color: #fff4d5; font-size: 16px; font-weight: 600; box-shadow: 0 4px 0 rgba(20, 40, 30, .35); transition: transform .15s, background .15s; }
.play-button:hover { transform: translateY(-2px); background: #3b5e4a; }
.play-button:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(20, 40, 30, .35); }
.hero .play-button { width: 238px; min-height: 62px; justify-content: flex-start; gap: 22px; padding: 16px 26px; background: #f1e5bc; color: #294638; font-family: 'Libre Caslon Display', Georgia, serif; font-size: 27px; font-weight: 400; box-shadow: 0 5px 0 #0c2a2855, 0 12px 30px #0c2a2833; }
.hero .play-button:hover { background: #fff1c9; }
.play-symbol { font-family: 'DM Sans', sans-serif; font-size: 13px; color: #6e7d57; }
.secondary-actions { display: flex; align-items: center; gap: 20px; margin-top: 26px; }
.secondary-actions button { background: none; padding: 6px 0; font-size: 15px; font-weight: 500; color: #eee5cb; }
.secondary-actions button:hover { color: #fff; text-decoration: underline; text-underline-offset: 4px; }
.divider { width: 1px; height: 16px; background: #e4dfb744; }
.best-line { display: flex; align-items: baseline; gap: 10px; margin-top: 30px; font-size: 13px; color: #ded8b6; }
.best-line strong { font-size: 18px; font-weight: 600; color: #fff4d5; font-variant-numeric: tabular-nums; }
.round-button { display: grid; place-items: center; width: 46px; height: 46px; padding: 11px; border-radius: 50%; background: var(--paper); box-shadow: var(--sticker); transition: transform .15s; }
.round-button:hover { transform: translateY(-2px); }
.menu-audio { position: absolute; top: max(24px, env(safe-area-inset-top)); right: 4%; }
#load-error { position: absolute; left: 7%; bottom: 10%; max-width: 450px; padding: 18px 20px; border-radius: 14px; background: var(--paper); color: var(--pine); font-size: 15px; line-height: 1.5; pointer-events: auto; }

/* HUD: one goal, two numbers, one bucket. Everything else appears only when it matters. */
#hud { position: absolute; inset: 0; pointer-events: none; }
#hud button { pointer-events: auto; }
.hud-top { position: absolute; top: max(16px, env(safe-area-inset-top)); left: max(16px, env(safe-area-inset-left)); right: max(16px, env(safe-area-inset-right)); display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.goal { display: flex; align-items: center; gap: 12px; min-width: 0; padding: 8px 20px 8px 8px; border-radius: 999px; background: var(--paper); box-shadow: var(--sticker); }
.goal-icon { flex: none; width: 46px; height: 46px; padding: 10px; border-radius: 50%; background: #ffe7a1; color: #8a5a12; transition: background .3s; }
.goal-icon.well { background: #c5eff5; color: #1c7f96; }
.goal-text { min-width: 0; }
.goal-text strong { display: block; font-size: 17px; font-weight: 700; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.goal-text span { display: block; font-size: 13px; color: var(--pine-soft); line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-stats { display: flex; align-items: center; gap: 8px; flex: none; }
.stat { display: flex; align-items: center; gap: 7px; height: 46px; padding: 0 16px 0 12px; border-radius: 999px; background: var(--paper); box-shadow: var(--sticker); }
.stat strong { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-icon { width: 20px; height: 20px; color: var(--pine-soft); }
.stat.time.urgent { background: var(--coral); color: #fff; animation: pulse .8s ease-in-out infinite; }
.stat.time.urgent .stat-icon { color: #fff; }
.progress { position: absolute; top: calc(max(16px, env(safe-area-inset-top)) + 72px); left: max(22px, env(safe-area-inset-left)); display: flex; align-items: center; gap: 7px; }
.progress i { width: 15px; height: 15px; border-radius: 50%; background: var(--paper); box-shadow: inset 0 0 0 2.5px rgba(45, 74, 58, .45), 0 2px 0 rgba(45, 74, 58, .18); }
.progress i.done { background: var(--gold); box-shadow: inset 0 0 0 2px var(--pine); }
.progress span { margin-left: 4px; padding: 4px 11px; border-radius: 999px; background: var(--pine); color: #fff4d5; font-size: 13px; font-weight: 600; }
.progress span.home { background: var(--leaf); color: #14321c; }

#marker { position: absolute; left: 0; top: 0; width: 0; height: 0; will-change: transform; }
.marker-pill { position: absolute; display: flex; align-items: center; gap: 6px; transform: translate(-50%, -50%); padding: 5px 13px 5px 7px; border-radius: 999px; background: var(--pine); color: #fff4d5; font-size: 14px; font-weight: 700; white-space: nowrap; box-shadow: 0 3px 0 rgba(20, 40, 30, .3); }
.marker-pill span { width: 22px; height: 22px; padding: 3px; border-radius: 50%; background: var(--gold); color: var(--pine); }
#marker.well .marker-pill span { background: #9fe7f1; }
#marker-arrow { position: absolute; left: -8px; top: -8px; width: 16px; height: 16px; background: var(--pine); clip-path: polygon(0 0, 100% 50%, 0 100%); }
#prompt { position: absolute; left: 0; top: 0; display: flex; align-items: center; gap: 9px; padding: 8px 14px 8px 9px; border-radius: 14px; background: var(--pine); color: #fff4d5; font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; box-shadow: 0 3px 0 rgba(20, 40, 30, .3); will-change: transform; }
#prompt.quiet { background: var(--paper); color: var(--pine-soft); font-weight: 600; padding-left: 14px; box-shadow: var(--sticker); }
#prompt kbd { color: var(--pine); border-color: transparent; box-shadow: 0 2px 0 rgba(0, 0, 0, .25); }
#prompt-fill { position: absolute; left: 0; bottom: 0; height: 5px; width: 0; background: #7fe3f0; }
#bubble { position: absolute; left: 0; top: 0; max-width: 250px; padding: 10px 15px; border-radius: 16px; background: #fff; color: var(--pine); font-size: 14px; font-weight: 600; line-height: 1.35; text-align: center; box-shadow: var(--sticker); will-change: transform; }
#bubble::after { content: ''; position: absolute; left: 50%; bottom: -8px; width: 16px; height: 16px; margin-left: -8px; background: #fff; transform: rotate(45deg); border-radius: 3px; }
.pop { position: absolute; left: 0; top: 0; font-size: 30px; font-weight: 800; color: var(--gold); text-shadow: 0 2px 0 var(--pine), 2px 0 0 var(--pine), -2px 0 0 var(--pine), 0 -2px 0 var(--pine), 0 5px 0 rgba(20, 40, 30, .35); animation: rise 1.4s ease-out forwards; white-space: nowrap; }
#toast { position: absolute; left: 50%; top: calc(max(16px, env(safe-area-inset-top)) + 106px); transform: translateX(-50%); max-width: min(460px, calc(100vw - 32px)); padding: 10px 18px; border-radius: 14px; background: var(--pine); color: #fff4d5; font-size: 15px; font-weight: 600; line-height: 1.35; text-align: center; box-shadow: 0 3px 0 rgba(20, 40, 30, .3); animation: drop .25s ease-out; }
#toast.bad { background: var(--coral); color: #fff; }
#toast.good { background: var(--leaf); color: #14321c; }

.hud-bottom { position: absolute; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 12px; }
.bucket { position: relative; display: flex; align-items: center; gap: 11px; padding: 9px 18px 9px 13px; border-radius: 999px; background: var(--paper); box-shadow: var(--sticker); }
.bucket-icon { width: 28px; height: 28px; color: var(--pine); }
.bucket-track { width: 210px; height: 16px; border-radius: 8px; background: #e2ead6; overflow: hidden; box-shadow: inset 0 0 0 2px rgba(45, 74, 58, .1); }
.bucket-track i { display: block; height: 100%; width: 0; border-radius: 8px; background: var(--water); transition: width .12s linear, background .2s; }
.bucket strong { width: 46px; font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.bucket.wobbly .bucket-track i { background: #f0b03f; }
.bucket.spilling .bucket-track i { background: var(--coral); }
.bucket.spilling { animation: shake .28s linear infinite; }
.bucket.empty strong { color: var(--pine-soft); }
.bucket-state { position: absolute; right: -6px; top: -17px; padding: 3px 11px; border-radius: 999px; background: #f0b03f; color: #40300a; font-size: 13px; font-weight: 700; white-space: nowrap; box-shadow: 0 2px 0 rgba(45, 74, 58, .25); transform: rotate(2deg); }
.bucket.spilling .bucket-state { background: var(--coral); color: #fff; }
#coach { position: absolute; left: 50%; bottom: calc(max(20px, env(safe-area-inset-bottom)) + 62px); transform: translateX(-50%); padding: 9px 16px; border-radius: 14px; background: var(--paper); font-size: 15px; font-weight: 600; box-shadow: var(--sticker); animation: drop .3s ease-out; white-space: nowrap; }

/* Touch: a floating thumb-stick on the left, two round buttons on the right. */
#touch { display: none; position: absolute; inset: 0; }
body.touch #touch { display: block; }
#stick-zone { position: absolute; left: 0; bottom: 0; width: 58%; height: 64%; pointer-events: auto; touch-action: none; }
#stick { position: absolute; left: 30px; bottom: calc(30px + env(safe-area-inset-bottom)); width: 124px; height: 124px; border-radius: 50%; background: rgba(255, 248, 230, .32); box-shadow: inset 0 0 0 3px rgba(255, 248, 230, .8), 0 6px 18px rgba(45, 74, 58, .2); opacity: .75; transition: opacity .2s; }
#stick.active { opacity: 1; }
#stick.run { box-shadow: inset 0 0 0 4px var(--gold), 0 6px 18px rgba(45, 74, 58, .25); }
#stick-knob { position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px; border-radius: 50%; background: var(--paper); box-shadow: 0 3px 0 rgba(45, 74, 58, .3); }
#stick.run #stick-knob { background: var(--gold); }
.touch-buttons { position: absolute; right: max(18px, env(safe-area-inset-right)); bottom: calc(26px + env(safe-area-inset-bottom)); display: flex; align-items: flex-end; gap: 12px; }
.touch-buttons button { display: grid; place-items: center; align-content: center; gap: 2px; border-radius: 50%; touch-action: none; font-weight: 700; box-shadow: 0 4px 0 rgba(20, 40, 30, .35), 0 8px 18px rgba(45, 74, 58, .2); }
#touch-steady { width: 68px; height: 68px; background: var(--paper); font-size: 13px; }
#touch-action { width: 92px; height: 92px; background: var(--pine); color: #fff4d5; font-size: 15px; opacity: .8; }
#touch-action span { width: 30px; height: 30px; }
#touch-action.ready { background: var(--gold); color: var(--pine); opacity: 1; animation: pulse 1s ease-in-out infinite; }
.touch-buttons button.held { transform: translateY(3px); box-shadow: 0 1px 0 rgba(20, 40, 30, .35); filter: brightness(.94); }
.touch-tip { display: none; }
body.touch .touch-tip { display: block; }
body.touch .controls-guide, body.touch #prompt kbd { display: none; }
body.touch .hud-bottom { bottom: auto; top: calc(max(16px, env(safe-area-inset-top)) + 100px); }
body.touch #coach { left: 22px; bottom: calc(176px + env(safe-area-inset-bottom)); transform: none; max-width: 62vw; white-space: normal; }
body.touch .bucket { padding: 6px 14px 6px 10px; }
body.touch #toast { top: calc(max(16px, env(safe-area-inset-top)) + 158px); }
body.touch #prompt { padding-left: 14px; }

/* Dialogs */
dialog { color: var(--pine); border: 0; }
dialog::backdrop { background: #1f3529c9; backdrop-filter: blur(6px); }
.paper-dialog { width: min(480px, calc(100vw - 28px)); max-height: calc(100dvh - 28px); padding: 34px 34px 28px; border-radius: 24px; background: var(--paper); box-shadow: 0 25px 80px #10201755; overflow-y: auto; }
.paper-dialog h2 { font-size: 44px; line-height: 1; letter-spacing: -1.4px; margin-bottom: 20px; }
.paper-dialog .play-button { width: 100%; margin-top: 22px; }
.dialog-close { position: absolute; right: 14px; top: 12px; width: 40px; height: 40px; border-radius: 50%; background: transparent; font-size: 28px; line-height: 1; color: var(--pine-soft); }
.dialog-close:hover { background: rgba(45, 74, 58, .08); }
.steps { list-style: none; }
.steps li { display: flex; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.steps li > span { flex: none; width: 40px; height: 40px; padding: 9px; border-radius: 50%; background: #ffe7a1; color: #8a5a12; }
.steps strong { display: block; font-size: 16px; margin-bottom: 3px; }
.steps p, .tip { font-size: 15px; line-height: 1.5; color: var(--pine-soft); }
.controls-guide { display: flex; flex-wrap: wrap; gap: 10px 18px; margin-top: 18px; font-size: 14px; color: var(--pine-soft); }
.controls-guide span { display: flex; align-items: center; gap: 7px; }
.controls-guide b { color: var(--pine); font-weight: 600; }
.tip { margin-top: 16px; }
.setting-row { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 15px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.setting-row strong { display: block; font-size: 16px; font-weight: 600; }
.setting-row small { display: block; margin-top: 2px; font-size: 14px; color: var(--pine-soft); }
.setting-row input { position: absolute; right: 0; width: 48px; height: 28px; margin: 0; opacity: 0; cursor: pointer; }
.setting-row i { flex: none; position: relative; width: 48px; height: 28px; border-radius: 14px; background: #cfd6c0; pointer-events: none; transition: background .2s; }
.setting-row i::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); transition: transform .2s; }
.setting-row input:checked + i { background: var(--leaf); }
.setting-row input:checked + i::after { transform: translateX(20px); }
.compact-dialog { text-align: center; width: min(380px, calc(100vw - 28px)); }
.compact-dialog h2 { margin-bottom: 6px; }
.compact-dialog .tip { margin-top: 0; }
.text-button { display: block; width: 100%; padding: 11px 8px; border-radius: 12px; background: transparent; font-size: 16px; font-weight: 600; }
.text-button:hover { background: rgba(45, 74, 58, .07); }
.paper-dialog .play-button + .text-button { margin-top: 10px; }
.text-button.muted { color: var(--pine-soft); font-weight: 500; }
.results-dialog { text-align: center; }
.eyebrow { display: block; margin-bottom: 8px; font-size: 13px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; color: #a57b2a; }
.results-dialog h2 { margin-bottom: 8px; }
.results-dialog > p { font-size: 15px; color: var(--pine-soft); line-height: 1.5; }
.result-score { margin: 20px 0 16px; padding: 16px 0 14px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.result-score > span { display: block; font-size: 14px; color: var(--pine-soft); }
.result-score strong { display: block; font-family: 'Libre Caslon Display', Georgia, serif; font-size: 76px; font-weight: 400; line-height: 1.05; letter-spacing: -3px; }
.result-score small { display: block; font-size: 14px; font-weight: 600; color: #a57b2a; }
.result-stats { display: flex; justify-content: space-around; }
.result-stats strong { display: block; font-size: 24px; font-weight: 700; }
.result-stats span { display: block; font-size: 13px; color: var(--pine-soft); }

@keyframes pulse { 50% { transform: scale(1.06); } }
@keyframes shake { 25% { transform: translate(-2px, 1px) rotate(-.6deg); } 75% { transform: translate(2px, -1px) rotate(.6deg); } }
@keyframes drop { from { opacity: 0; translate: 0 -8px; } }
@keyframes rise { from { opacity: 0; translate: 0 10px; scale: .6; } 18% { opacity: 1; scale: 1.15; } 30% { scale: 1; } 75% { opacity: 1; } to { opacity: 0; translate: 0 -70px; } }

@media (max-width: 1100px) { .hero { left: 6%; width: 450px; } .hero h1 { font-size: 84px; } }
@media (max-width: 760px) {
  .hero { top: auto; bottom: 14%; left: 8%; width: 84%; }
  .hero h1 { font-size: clamp(60px, 13vw, 87px); line-height: .93; letter-spacing: -2.7px; margin-bottom: 30px; }
  .hero .play-button { width: 206px; min-height: 56px; font-size: 24px; }
  .vignette { background: linear-gradient(0deg, #17392e 0%, #18392eea 17%, #1e3d3080 47%, #153a2c00 80%); }
  .menu-audio { right: 7%; }
  .hud-top { left: 10px; right: 10px; gap: 6px; }
  .goal { gap: 9px; padding: 6px 14px 6px 6px; }
  .goal-icon { width: 38px; height: 38px; padding: 8px; }
  .goal-text strong { font-size: 14px; line-height: 1.15; white-space: normal; }
  .goal-text span { display: none; }
  .hud-stats { gap: 6px; }
  .stat { height: 38px; padding: 0 11px 0 9px; gap: 5px; }
  .stat strong { font-size: 16px; }
  .stat-icon { width: 16px; height: 16px; }
  .round-button { width: 38px; height: 38px; padding: 9px; }
  .progress { top: calc(max(16px, env(safe-area-inset-top)) + 58px); left: 16px; }
  .bucket-track { width: 130px; }
  body.touch .hud-bottom { top: calc(max(16px, env(safe-area-inset-top)) + 88px); }
  body.touch #toast { top: calc(max(16px, env(safe-area-inset-top)) + 146px); }
  .paper-dialog { padding: 28px 22px 22px; }
  .paper-dialog h2 { font-size: 38px; }
  .result-score strong { font-size: 62px; }
}
@media (max-height: 680px) and (max-width: 760px) { .hero { bottom: 9%; } .hero h1 { font-size: 58px; margin-bottom: 22px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
