:root {
    --bg: #0b1a24; --chrome: #0f2230; --well: #0a1720; --edge: #2a4c63; --panel: rgba(8, 18, 26, .95);
    --ink: #e6efe9; --muted: #8fa9b3; --bobber: #ff5a3c; --coin: #ffcf3f; --ad: #4f7083;
    --common: #c9d4d8; --uncommon: #7ee07e; --rare: #6cb6ff; --epic: #c792ff; --legendary: #ffcf3f;
    --f-display: "Pixelify Sans", "Courier New", monospace;
    --f-body: "Atkinson Hyperlegible", system-ui, sans-serif;
    color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font-family: var(--f-body); font-size: 16px; line-height: 1.45; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; }
button:focus-visible { outline: 3px solid var(--coin); outline-offset: 2px; }

#app {
    margin: 0 auto; display: grid; grid-template-columns: minmax(0, calc((100vh - 230px) * 16 / 9)) 300px; justify-content: center; gap: 16px;
    padding: 12px max(16px, env(safe-area-inset-right, 0px)) 12px max(16px, env(safe-area-inset-left, 0px));
}
.gamecol { display: grid; gap: 8px; min-width: 0; align-content: start; }
.rail { display: grid; gap: 16px; align-content: start; }

.hud { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; background: var(--well); border: 2px solid var(--edge); padding: 6px 8px; font-family: var(--f-display); font-size: clamp(17px, .95vw, 24px); }
.hud .stat { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.hud em { font-style: normal; color: var(--muted); font-size: .88em; }
.hud b { font-weight: 600; font-variant-numeric: tabular-nums; }
.hud .btns { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.coin { width: 12px; height: 12px; background: var(--coin); box-shadow: inset -2px -2px 0 #c8901a; display: inline-block; flex: none; }

.pbtn, .scene-pill {
    font-family: var(--f-display); font-size: clamp(15px, .85vw, 21px); background: #1d3d52; border: 2px solid #050d14; cursor: pointer;
    box-shadow: inset 0 -3px 0 #12293a, inset 0 2px 0 #2f5a74; padding: 3px 10px 5px; white-space: nowrap; line-height: 1.2;
}
.pbtn:hover:not(:disabled), .scene-pill:hover { filter: brightness(1.15); }
.pbtn:active:not(:disabled) { box-shadow: inset 0 3px 0 #12293a; padding: 5px 10px 3px; }
.pbtn.hot { background: var(--bobber); box-shadow: inset 0 -3px 0 #b8341c, inset 0 2px 0 #ff8a70; }
.pbtn[aria-pressed="true"] { background: #2f5a74; }
#btn-sound[aria-pressed="false"] { color: var(--muted); }
.pbtn:disabled { opacity: .5; cursor: default; }
.scene-pill { display: flex; align-items: center; gap: 6px; background: #163246; }
.scene-pill .pin { width: 8px; height: 10px; background: var(--bobber); clip-path: polygon(0 0, 100% 0, 100% 60%, 50% 100%, 0 60%); }

.stage {
    position: relative; aspect-ratio: 16 / 9; width: min(100%, calc((100vh - 230px) * 16 / 9)); min-height: 220px; justify-self: center;
    border: 2px solid var(--edge); background: var(--well); overflow: hidden; cursor: pointer;
    touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.stage > canvas { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; display: block; }
.pops { position: absolute; inset: 0; pointer-events: none; }
.pop { position: absolute; transform: translate(-50%, -100%); font-family: var(--f-display); font-weight: 700; font-size: clamp(20px, 1.3vw, 34px); color: var(--coin); text-shadow: 2px 2px 0 #08141c; animation: rise .95s steps(10) forwards; white-space: nowrap; }
.pop.big { font-size: clamp(28px, 1.9vw, 48px); }
.pop.dressed { color: #f8a8e0; }
.pop.idle { color: #bfe7ff; font-size: clamp(16px, 1vw, 26px); }
@keyframes rise { to { transform: translate(-50%, -260%); opacity: 0; } }

.banner { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); background: rgba(8, 18, 26, .86); border: 2px solid currentColor; font-family: var(--f-display); font-size: clamp(16px, 1vw, 24px); padding: 3px 10px; white-space: nowrap; pointer-events: none; max-width: calc(100% - 16px); overflow: hidden; text-overflow: ellipsis; }
.toasts { position: absolute; right: 8px; bottom: 8px; display: grid; gap: 6px; justify-items: end; pointer-events: none; max-width: calc(100% - 16px); }
.toast { background: rgba(8, 18, 26, .92); border: 2px solid currentColor; font-family: var(--f-display); font-size: clamp(16px, .95vw, 24px); padding: 4px 10px; transition: opacity .4s; }
.toast.out { opacity: 0; }

.log { font-size: clamp(15px, .85vw, 20px); color: var(--muted); min-height: 21px; font-variant-numeric: tabular-nums; }
.log b { font-weight: 700; }
.log .dressed { color: #f8a8e0; }
.badge { display: inline-block; min-width: 1.3em; padding: 0 4px; margin-left: 2px; background: var(--coin); color: #1a1205; font-size: .85em; text-align: center; }
.fx { position: absolute; top: 8px; left: 8px; display: flex; flex-direction: column; gap: 4px; pointer-events: none; z-index: 2; }
.chip { font-family: var(--f-display); font-size: clamp(14px, .85vw, 20px); background: rgba(8, 18, 26, .86); border: 2px solid var(--c); color: var(--c); padding: 1px 8px; white-space: nowrap; }
.chip b { font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.r-Common { color: var(--common); } .r-Uncommon { color: var(--uncommon); } .r-Rare { color: var(--rare); } .r-Epic { color: var(--epic); } .r-Legendary { color: var(--legendary); }

/* panels sit over the water so the ads around the game stay visible */
.panel { font-size: clamp(16px, .9vw, 21px); position: absolute; inset: 6px; background: var(--panel); border: 2px solid var(--edge); display: flex; flex-direction: column; cursor: default; z-index: 5; }
.phead { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-bottom: 2px solid var(--edge); }
.phead h2 { font-family: var(--f-display); font-size: 1.4em; font-weight: 600; margin: 0; }
.pcoins { display: flex; align-items: center; gap: 6px; font-family: var(--f-display); font-size: 1.1em; font-variant-numeric: tabular-nums; }
.pclose { margin-left: auto; background: none; border: 2px solid var(--edge); font-family: var(--f-display); font-size: 1em; padding: 2px 12px; cursor: pointer; }
.pbody { overflow: auto; padding: 10px; flex: 1; min-height: 0; }
.pnote { color: var(--muted); font-size: .9em; margin: 14px 0 0; }
.pnote.top { margin: 0 0 10px; }
.psub { font-family: var(--f-display); font-weight: 600; font-size: 1.1em; margin: 4px 0 8px; }
.psub ~ .psub { margin-top: 16px; }
.linkbtn { background: none; border: 0; color: var(--bobber); text-decoration: underline; cursor: pointer; padding: 0; font-size: 1em; }

.mapgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(17em, 1fr)); gap: 10px; }
.mcard { display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: 10px; background: #102534; border: 2px solid var(--edge); padding: 8px; align-items: start; }
.mcard.here { border-color: var(--bobber); }
.mcard img { width: 112px; height: 63px; image-rendering: pixelated; display: block; border: 1px solid #05101a; }
.mcard.locked img { filter: grayscale(1) brightness(.55); }
.minfo { display: grid; gap: 4px; justify-items: start; min-width: 0; }
.minfo b { font-family: var(--f-display); font-size: 1.2em; font-weight: 600; }
.minfo small { color: var(--muted); font-size: .9em; line-height: 1.35; }
.mult { color: var(--coin); font-size: .8em; font-weight: 400; }
.mreq.met { color: var(--uncommon); }
.minfo .pbtn { font-size: .95em; margin-top: 2px; }

.shoplist { display: grid; gap: 8px; }
.srow { display: flex; align-items: center; gap: 12px; background: #102534; border: 2px solid var(--edge); padding: 8px 10px; }
.sinfo { display: grid; gap: 2px; flex: 1; min-width: 0; }
.sinfo b { font-family: var(--f-display); font-size: 1.2em; font-weight: 600; }
.sinfo .lvl { color: var(--muted); font-size: .8em; font-weight: 400; }
.sinfo small { color: var(--muted); font-size: .92em; }
.sinfo small.next { color: var(--uncommon); }
.srow .pbtn { display: flex; align-items: center; gap: 6px; flex: none; font-size: 1em; }
.srow.active { border-color: var(--uncommon); }
.timeleft { font-family: var(--f-display); font-size: 1.1em; color: var(--uncommon); font-variant-numeric: tabular-nums; flex: none; }
.iicon { width: 1.9em; height: 1.9em; flex: none; background: var(--c); box-shadow: inset -4px -4px 0 rgba(0,0,0,.28), inset 3px 3px 0 rgba(255,255,255,.35); border: 2px solid #050d14; }
.empty { display: grid; gap: 10px; justify-items: start; color: var(--muted); }
.empty p { margin: 0; }

.dtabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.dtab { background: #102534; border: 2px solid var(--edge); font-family: var(--f-display); font-size: 1em; padding: 3px 11px; cursor: pointer; }
.dtab.on { border-color: var(--bobber); }
.dtab:disabled { color: var(--muted); cursor: default; }
.dgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(10em, 1fr)); gap: 8px; }
.dcell { background: #102534; border: 2px solid var(--edge); padding: 8px; display: grid; gap: 2px; align-content: start; }
.dcell.special { border-color: #6a5a20; }
.dcell b { font-family: var(--f-display); font-size: 1.1em; font-weight: 600; }
.dcell small { color: var(--muted); font-size: .88em; }
.diw { height: 3.4em; display: flex; align-items: center; justify-content: center; margin-bottom: 4px; }
.dicon { image-rendering: pixelated; max-width: 100%; max-height: 3.4em; }

.welcome { margin: auto; max-width: 380px; text-align: center; display: grid; gap: 10px; padding: 18px; justify-items: center; }
.welcome h2 { font-family: var(--f-display); font-size: 1.7em; margin: 0; }
.welcome p { margin: 0; color: var(--muted); }
.welcome .coins { color: var(--coin); }

.ad-slot:empty { display: none; }
.ph { border: 2px dashed var(--ad); color: var(--ad); display: grid; place-items: center; font-family: var(--f-display); font-size: 13px; width: 100%; height: 100%; }
.ad-banner-desktop { width: 100%; max-width: 728px; aspect-ratio: 728 / 90; justify-self: center; }
.ad-video { aspect-ratio: 16 / 9; }
.ad-mrec { width: 300px; height: 250px; }
.ad-banner-mobile { display: none; }

.foot { display: flex; gap: 16px; justify-content: center; padding: 8px 16px 20px; font-size: 13px; }
.foot a { color: var(--muted); }

@media (max-width: 1000px) {
    #app { grid-template-columns: minmax(0, 1fr); }
    .rail { grid-template-columns: repeat(2, max-content); justify-content: center; }
    .ad-video { width: 300px; }
}

/* phone: game fills the screen, one sticky banner below it */
@media (max-width: 719px) {
    html, body { height: 100%; overflow: hidden; }
    body { display: flex; flex-direction: column; padding-top: env(safe-area-inset-top, 0px); }
    #app { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 0; gap: 0; }
    .gamecol { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 0; }
    .rail, .ad-banner-desktop, .foot { display: none !important; }
    .hud { border-width: 0 0 2px; font-size: 15px; gap: 4px 12px; padding: 6px max(8px, env(safe-area-inset-left, 0px)); }
    .hud em { font-size: 14px; }
    .hud .long { display: none; }
    .hud { font-size: 16px; }
    .fx { top: 44px; }
    .hud .btns { gap: 4px; }
    .pbtn, .scene-pill { font-size: 14px; padding: 3px 7px 5px; }
    #btn-sound { font-size: 0; width: 34px; }
    #btn-sound::before { content: "♪"; font-size: 15px; }
    #btn-sound[aria-pressed="false"]::before { content: "×"; }
    .stage { flex: 1; min-height: 0; width: 100%; aspect-ratio: auto; border-width: 0; }
    .log { padding: 4px 10px; font-size: 14px; min-height: 0; height: 38px; overflow: hidden; border-top: 2px solid var(--edge); }
    .ad-banner-mobile { display: block; flex: none; height: calc(50px + env(safe-area-inset-bottom, 0px)); padding-bottom: env(safe-area-inset-bottom, 0px); background: #060f16; }
    .ad-banner-mobile .ph { border-width: 2px 0 0; }
    .panel { font-size: 15.5px; }
    .mcard { grid-template-columns: 88px minmax(0, 1fr); }
    .mcard img { width: 88px; height: auto; }
    .dgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: reduce) { .pop { animation-duration: .01s; } }
