:root {
    --paper: #FFFDF8;
    --mint: #DFF3EE;
    --ink: #3B2C22;
    --ink-soft: #7A6A5C;
    --red: #E5484D;
    --red-dark: #A8262C;
    --blue: #5FA0D6;
    --blue-dark: #3A78AE;
    --gold: #F2B544;
    --green: #5DBB63;
    --shadow: 0 6px 16px rgba(40, 70, 70, .16);
    color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; color: var(--ink); overflow-x: clip; }
/* a lab bench: mint tiles under soft light */
body {
    min-height: 100dvh;
    background:
        radial-gradient(circle at 50% 0%, rgba(255,255,255,.7), transparent 55%),
        repeating-linear-gradient(0deg, rgba(60, 120, 110, .06) 0 1px, transparent 1px 44px),
        repeating-linear-gradient(90deg, rgba(60, 120, 110, .06) 0 1px, transparent 1px 44px),
        var(--mint);
    font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, sans-serif;
    -webkit-user-select: none; user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
[hidden] { display: none !important; }

.wrap {
    margin: 0 auto; max-width: 520px; min-height: 100dvh;
    padding: max(8px, env(safe-area-inset-top)) 14px max(10px, env(safe-area-inset-bottom));
    display: flex; flex-direction: column; gap: 8px;
}
body.running .wrap { height: 100dvh; }
body.running .top { display: none; }

.top { display: flex; align-items: center; justify-content: space-between; }
.logo { display: flex; align-items: center; gap: 8px; }
.logo svg { width: 42px; height: 42px; animation: wobble 2.4s ease-in-out infinite; }
.logo h1 { margin: 0; font-size: 24px; line-height: .95; font-weight: 900; letter-spacing: -.5px; }
.logo h1 span { color: var(--blue-dark); }
.wallet { display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: var(--paper); box-shadow: var(--shadow); font-size: 17px; font-weight: 900; }
.coin { display: inline-block; width: 16px; height: 16px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #FFE8A3, var(--gold) 60%, #C98A1E); box-shadow: inset 0 -1.5px 0 rgba(0,0,0,.15); vertical-align: -2px; }

.screen { display: flex; flex-direction: column; gap: 12px; flex: 1; min-height: 0; }

/* --- home ----------------------------------------------------------------- */

.chapter { border-radius: 24px; background: var(--paper); box-shadow: var(--shadow); padding: 14px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 4px; flex: 1; min-height: 0; }
.dish { position: relative; width: 100%; flex: 1; min-height: 180px; }
/* Filling its box exactly: a canvas left to size itself takes its pixel size and overflows. */
.preview { position: absolute; inset: 0; width: 100%; height: 100%; }
.arrow { position: absolute; top: 50%; z-index: 1; width: 40px; height: 40px; margin-top: -20px; border-radius: 50%; background: var(--mint); font-size: 26px; font-weight: 900; line-height: 1; box-shadow: var(--shadow); }
#prev-ch { left: 0; } #next-ch { right: 0; }
.arrow:disabled { opacity: .3; cursor: default; }
.chapter h2 { margin: 8px 0 0; font-size: 26px; font-weight: 900; }
.chapter p { margin: 0; font-size: 14px; font-weight: 800; color: var(--ink-soft); }
.big-btn { padding: 15px; border-radius: 22px; background: var(--red); color: #fff; font-size: 26px; font-weight: 900; box-shadow: 0 5px 0 var(--red-dark), var(--shadow); transition: transform .1s; }
.big-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--red-dark); }
.mid-btn { padding: 11px 18px; border-radius: 16px; background: var(--blue); color: #fff; font-size: 16px; font-weight: 900; box-shadow: 0 4px 0 var(--blue-dark); display: inline-flex; align-items: center; gap: 6px; }
.mid-btn:disabled { opacity: .45; cursor: default; }
.mid-btn:not(:disabled):active { transform: translateY(2px); box-shadow: 0 2px 0 var(--blue-dark); }
.text-btn { font-weight: 900; color: var(--ink-soft); padding: 8px 10px; }

/* --- the run ------------------------------------------------------------------ */

.run { gap: 6px; }
.hud { display: flex; align-items: center; gap: 10px; }
.core { display: flex; align-items: center; gap: 4px; font-size: 18px; font-weight: 900; }
.core .heart { width: 22px; height: 20px; background: var(--red); clip-path: path("M11 20C3 14 0 10 0 6a5.5 5.5 0 0 1 11-2 5.5 5.5 0 0 1 11 2c0 4-3 8-11 14z"); }
.core.low { color: var(--red); animation: throb .6s ease-in-out infinite; }
.track { position: relative; flex: 1; height: 14px; border-radius: 999px; background: rgba(59, 44, 34, .12); }
.track .fill { height: 100%; width: 0; border-radius: 999px; background: linear-gradient(90deg, #7BC96F, var(--green)); transition: width .25s; }
.chests i { position: absolute; top: 50%; width: 20px; height: 18px; transform: translate(-50%, -50%); border-radius: 4px 4px 5px 5px; background: #B9874F; box-shadow: inset 0 -3px 0 #8A5A35, inset 0 3px 0 #D9A86C, 0 0 0 2px var(--paper); }
.chests i.open { background: var(--gold); box-shadow: inset 0 -3px 0 #C98A1E, 0 0 0 2px var(--paper), 0 0 10px 2px rgba(242, 181, 68, .7); animation: pop .5s cubic-bezier(.3, 1.8, .5, 1); }
.chests i:last-child { transform: translate(-90%, -50%); }
.lvl { display: flex; align-items: center; gap: 3px; font-size: 13px; font-weight: 900; position: relative; padding-bottom: 6px; }
.lvl strong { font-size: 18px; }
.xp { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; border-radius: 4px; background: rgba(59,44,34,.12); overflow: hidden; }
.xp-fill { height: 100%; width: 0; background: var(--blue); transition: width .2s; }

.stage { position: relative; flex: 1; min-height: 0; border-radius: 24px; overflow: hidden; background: #F6DFC3; box-shadow: inset 0 0 0 4px #fff, var(--shadow); }
.field { position: absolute; inset: 0; width: 100%; height: 100%; }
.banner {
    position: absolute; left: 50%; top: 38%; z-index: 4; pointer-events: none; opacity: 0; padding: 8px 22px; border-radius: 999px;
    background: var(--paper); box-shadow: var(--shadow); font-size: 26px; font-weight: 900; white-space: nowrap; transform: translate(-50%, -50%);
}
.banner.show { animation: banner 1.4s cubic-bezier(.3, 1.4, .5, 1) both; }
.overlay { position: absolute; inset: 0; z-index: 6; display: grid; place-items: center; padding: 12px; background: rgba(40, 60, 60, .35); animation: fade .25s ease-out both; }
.choose, .end { width: 100%; max-width: 380px; text-align: center; animation: rise .35s cubic-bezier(.3, 1.3, .5, 1) both; }
.choose h2, .end h2 { margin: 0; font-size: 30px; font-weight: 900; color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,.25); }
.choose > p { margin: 0 0 10px; font-weight: 900; color: #fff; text-shadow: 0 1px 0 rgba(0,0,0,.25); }
.picks { display: grid; gap: 10px; }
.pick {
    position: relative; display: grid; grid-template-columns: 52px 1fr; grid-template-rows: auto auto; column-gap: 12px; align-items: center; text-align: left;
    padding: 12px 14px; border-radius: 18px; background: var(--paper); box-shadow: inset 0 -5px 0 var(--t), 0 0 0 3px var(--t), var(--shadow);
}
.pick svg { grid-row: 1 / 3; width: 50px; height: 50px; }
.pick b { font-size: 17px; font-weight: 900; }
.pick small { font-size: 13px; font-weight: 800; color: var(--ink-soft); }
.pick .tag { position: absolute; top: -9px; right: 12px; padding: 1px 10px; border-radius: 999px; background: var(--t); color: #fff; font-size: 11px; font-weight: 900; text-transform: uppercase; letter-spacing: 1px; }
.pick:active { transform: scale(.97); }
.end { padding: 20px 16px; border-radius: 24px; background: var(--paper); box-shadow: var(--shadow); }
.end h2 { color: var(--ink); text-shadow: none; }
.end.won h2 { color: var(--green); }
.end.lost h2 { color: var(--red); }
.end p { margin: 6px 0 10px; font-weight: 800; color: var(--ink-soft); }
.coins-won { font-size: 28px; font-weight: 900; margin-bottom: 12px; animation: grow .6s .2s cubic-bezier(.3, 1.8, .5, 1) both; }
.coins-won .coin { width: 24px; height: 24px; vertical-align: -3px; margin-right: 4px; }
.row { display: flex; justify-content: center; align-items: center; gap: 6px; flex-wrap: wrap; }

.dock { display: flex; align-items: center; gap: 8px; }
.weapons { flex: 1; display: flex; gap: 5px; min-width: 0; }
.wpn { position: relative; width: 38px; height: 38px; border-radius: 12px; background: var(--paper); box-shadow: inset 0 -3px 0 var(--t), var(--shadow); display: grid; place-items: center; }
.wpn svg { width: 28px; height: 28px; }
.wpn b { position: absolute; right: -4px; top: -5px; min-width: 16px; height: 16px; border-radius: 8px; background: var(--t); color: #fff; font-size: 10px; font-weight: 900; display: grid; place-items: center; }
.ult {
    position: relative; width: 58px; height: 58px; border-radius: 50%; flex: none; color: #fff; font-size: 12px; font-weight: 900;
    background: conic-gradient(#6EC8FF var(--charge, 0%), rgba(59,44,34,.25) 0);
    box-shadow: 0 4px 0 #3A78AE, var(--shadow);
}
.ult span { position: absolute; inset: 5px; border-radius: 50%; display: grid; place-items: center; background: var(--blue); }
.ult.ready { animation: ready 1s ease-in-out infinite; }
.ult.ready span { background: #2E8BD8; }
.ult:disabled { cursor: default; }

/* --- toolbar and sheets (the house style) --------------------------------------- */

.toolbar { display: flex; justify-content: center; gap: 12px; }
.tool {
    position: relative; width: 44px; height: 44px; border-radius: 50%; background: var(--paper); border: 1.5px solid #CFE8E1; box-shadow: var(--shadow);
    display: grid; place-items: center; color: var(--ink); flex: none; transition: transform .12s, background .2s, color .2s;
}
.tool svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
#fast-btn svg { fill: currentColor; stroke: none; }
#fast-btn.on { background: var(--ink); color: var(--paper); }
.tool:active { transform: scale(.92); }
a.tool { text-decoration: none; }
.tool::after {
    content: attr(data-label); position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translate(-50%, 4px);
    padding: 5px 12px; border-radius: 999px; background: var(--ink); color: #fff; font-size: 13px; font-weight: 900;
    white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s; z-index: 5;
}
.tool:focus-visible::after { opacity: 1; transform: translate(-50%, 0); }
@media (hover: hover) { .tool:hover::after { opacity: 1; transform: translate(-50%, 0); } }

.sheet { position: fixed; inset: 0; z-index: 30; display: grid; align-items: end; justify-items: center; background: rgba(40, 60, 60, .35); animation: fade .3s ease-out both; }
.sheet.closing { animation: fade .28s ease-in reverse both; }
.sheet-card {
    position: relative; width: min(520px, 100%); max-height: 82dvh; overflow: auto; padding: 22px 18px max(22px, env(safe-area-inset-bottom));
    border-radius: 26px 26px 0 0; background: var(--mint); box-shadow: 0 -10px 40px rgba(40, 60, 60, .25); animation: slide-up .42s cubic-bezier(.2, .9, .3, 1.05) both;
}
.sheet.closing .sheet-card { animation: slide-down .28s cubic-bezier(.5, 0, .9, .5) both; }
.sheet-close { position: absolute; top: 12px; right: 14px; width: 36px; height: 36px; border-radius: 50%; background: var(--paper); font-size: 22px; font-weight: 900; box-shadow: var(--shadow); }
.sheet h2 { margin: 0 0 10px; font-size: 24px; font-weight: 900; }
.sheet h3 { margin: 16px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--ink-soft); }
.sheet p { margin: 0 0 8px; font-size: 15px; font-weight: 700; line-height: 1.4; }
.legend { display: grid; gap: 8px; }
.legend div { display: flex; align-items: center; gap: 10px; }
.legend svg { width: 38px; height: 38px; flex: none; }
.legend p { margin: 0; font-size: 14px; }
.lab { display: grid; gap: 10px; margin-top: 8px; }
.lab-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 16px; background: var(--paper); box-shadow: var(--shadow); }
.lab-ic svg { width: 36px; height: 36px; }
.lab-row p { flex: 1; margin: 0; font-size: 13px; color: var(--ink-soft); }
.lab-row p b { display: block; font-size: 16px; color: var(--ink); }
.lab-row .mid-btn { padding: 8px 12px; font-size: 15px; }

/* --- motion ------------------------------------------------------------------------- */

@keyframes wobble { 0%, 100% { transform: rotate(-4deg) scale(1); } 50% { transform: rotate(4deg) scale(1.05); } }
@keyframes throb { 50% { transform: scale(1.15); } }
@keyframes ready { 50% { box-shadow: 0 4px 0 #3A78AE, 0 0 0 8px rgba(110, 200, 255, .35); } }
@keyframes pop { from { transform: translate(-50%, -50%) scale(0); } }
@keyframes banner { 0% { opacity: 0; transform: translate(-50%, -50%) scale(.4); } 20% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); } 35%, 80% { opacity: 1; transform: translate(-50%, -50%) scale(1); } 100% { opacity: 0; transform: translate(-50%, -80%) scale(.9); } }
@keyframes grow { from { transform: scale(0); } }
@keyframes rise { from { opacity: 0; transform: translateY(24px) scale(.96); } }
@keyframes fade { from { opacity: 0; } }
@keyframes slide-up { from { transform: translateY(100%); } }
@keyframes slide-down { to { transform: translateY(100%); } }

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