:root {
  --ink: #14110f; --paper: #f6efe0; --paper2: #ebe2cd; --yellow: #ffd23f; --red: #ff5a3c; --green: #2fbf71; --blue: #6aa9ff;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --stripes: repeating-linear-gradient(115deg, var(--ink) 0 14px, var(--paper) 14px 28px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--ink); color: var(--ink); font-family: var(--sans); overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; touch-action: manipulation; }
[hidden] { display: none !important; }
#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#grain { position: fixed; inset: -64px; pointer-events: none; opacity: 0; mix-blend-mode: overlay; animation: grain .5s steps(4) infinite; }
@keyframes grain { 0% { transform: translate(0, 0) } 25% { transform: translate(-30px, 20px) } 50% { transform: translate(24px, -36px) } 75% { transform: translate(-14px, 40px) } 100% { transform: translate(0, 0) } }

/* HUD */
#hud { position: fixed; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 10px; padding: calc(8px + env(safe-area-inset-top)) 10px 8px; pointer-events: none; z-index: 5; }
#hud > * { pointer-events: auto; }
.hud-btn { background: var(--ink); color: var(--paper); border-radius: 10px; padding: 7px 10px; line-height: 1; box-shadow: 0 2px 0 rgba(0, 0, 0, .35); display: flex; flex-direction: column; align-items: flex-start; }
.hud-btn.sq { width: 36px; height: 36px; align-items: center; justify-content: center; font-size: 16px; }
.hud-btn.sq.off { opacity: .5; text-decoration: line-through; }
.logo { font-weight: 800; font-size: 17px; letter-spacing: -.02em; } .logo b { color: var(--yellow); }
.logo-sub { font: 700 8px var(--mono); letter-spacing: .32em; opacity: .7; margin-top: 2px; }
#dots { flex: 1; display: flex; gap: 3px; justify-content: center; min-width: 0; }
#dots i { height: 6px; flex: 1; max-width: 16px; border-radius: 2px; background: rgba(20, 17, 15, .28); }
#dots i.done { background: var(--ink); } #dots i.cur { background: var(--yellow); box-shadow: 0 0 0 1.5px var(--ink); }
.hud-right { display: flex; align-items: center; gap: 8px; }
#starCount { font: 800 13px var(--mono); background: var(--yellow); padding: 7px 9px; border-radius: 10px; box-shadow: 0 2px 0 rgba(0, 0, 0, .35); white-space: nowrap; }

#cta { position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 4; background: var(--yellow); border: 3px solid var(--ink); border-radius: 16px; padding: 14px 20px; font-weight: 800; font-size: 17px; box-shadow: 0 5px 0 var(--ink); max-width: calc(100vw - 32px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#cta:active { transform: translateX(-50%) translateY(3px); box-shadow: 0 2px 0 var(--ink); }
#cta small { display: block; font: 700 10px var(--mono); letter-spacing: .14em; opacity: .7; margin-bottom: 2px; }
#toast { position: fixed; top: calc(64px + env(safe-area-inset-top)); left: 50%; transform: translate(-50%, -20px); background: var(--ink); color: var(--paper); padding: 10px 14px; border-radius: 12px; font-weight: 600; font-size: 14px; opacity: 0; transition: .25s; z-index: 9; pointer-events: none; max-width: 86vw; text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Panel (bottom sheet on phones, side panel on desktop) */
#panel { position: fixed; left: 0; right: 0; bottom: 0; height: 58vh; height: 58dvh; background: var(--paper); border-radius: 18px 18px 0 0; transform: translateY(105%); transition: transform .45s cubic-bezier(.2, .8, .2, 1); z-index: 6; display: flex; flex-direction: column; box-shadow: 0 -8px 30px rgba(0, 0, 0, .3); overflow: hidden; }
#panel.open { transform: none; }
.slate { height: 12px; background: var(--stripes); flex: none; }
.slate.big { height: 22px; margin: -22px -22px 18px; }
#phead { display: flex; align-items: center; gap: 10px; padding: 10px 14px 8px; border-bottom: 2px solid var(--ink); flex: none; }
#phead .num { font: 800 12px var(--mono); background: var(--ink); color: var(--yellow); padding: 5px 7px; border-radius: 6px; white-space: nowrap; }
#phead h2 { margin: 0; font-size: 19px; line-height: 1.1; flex: 1; min-width: 0; }
#phead h2 small { display: block; font: 700 10px var(--mono); letter-spacing: .1em; opacity: .6; text-transform: uppercase; }
#phead .time { font: 700 11px var(--mono); border: 1.5px solid var(--ink); padding: 4px 6px; border-radius: 6px; white-space: nowrap; }
#phead .x { width: 30px; height: 30px; border-radius: 8px; background: var(--paper2); font-size: 14px; flex: none; }
#pbody { padding: 12px 14px calc(16px + env(safe-area-inset-bottom)); overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
#pbody p { margin: 0 0 10px; line-height: 1.4; font-size: 15px; }
.tagline { font-weight: 700; font-size: 16px !important; }
.rules { list-style: none; margin: 0 0 12px; padding: 0; counter-reset: r; }
.rules li { position: relative; padding: 8px 10px 8px 38px; background: #fff; border: 1.5px solid var(--ink); border-radius: 10px; margin-bottom: 6px; font-size: 14.5px; line-height: 1.35; counter-increment: r; }
.rules li::before { content: counter(r); position: absolute; left: 9px; top: 8px; width: 20px; height: 20px; border-radius: 50%; background: var(--yellow); font: 800 11px/20px var(--mono); text-align: center; }
.note { font-size: 13.5px !important; border-left: 4px solid var(--yellow); padding: 4px 0 4px 10px; opacity: .85; }
.btn { display: block; width: 100%; padding: 13px 16px; border-radius: 13px; font-weight: 800; font-size: 16px; border: 2.5px solid var(--ink); background: #fff; box-shadow: 0 4px 0 var(--ink); margin-top: 10px; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn.primary { background: var(--yellow); }
.btn.ghost { box-shadow: none; border-color: transparent; background: none; font-size: 14px; opacity: .7; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.pips { display: flex; gap: 4px; margin-bottom: 10px; }
.pips i { flex: 1; height: 5px; border-radius: 3px; background: var(--paper2); } .pips i.done { background: var(--green); } .pips i.cur { background: var(--ink); }
.q { font-weight: 700; font-size: 16px !important; }
.opts { display: grid; gap: 7px; }
.opt { text-align: left; padding: 11px 12px; border-radius: 11px; border: 2px solid var(--ink); background: #fff; font-size: 14.5px; font-weight: 600; line-height: 1.3; }
.opt.right { background: var(--green); color: #06301a; } .opt.wrong { background: #ffd9d1; border-color: var(--red); opacity: .55; pointer-events: none; text-decoration: line-through; }
.locked .opt { pointer-events: none; }
.fb { margin-top: 10px; padding: 10px 12px; border-radius: 11px; background: #dff5e8; border: 2px solid var(--green); font-size: 14px; line-height: 1.35; }
.fb.bad { background: #ffe5df; border-color: var(--red); }
.fb b { display: block; font: 800 11px var(--mono); letter-spacing: .12em; margin-bottom: 2px; }
.shake { animation: shake .3s; } @keyframes shake { 25% { transform: translateX(-6px) } 75% { transform: translateX(6px) } }

/* sort cards */
.card { background: #fff; border: 2.5px solid var(--ink); border-radius: 14px; padding: 16px 14px; text-align: center; box-shadow: 0 4px 0 var(--ink); margin-bottom: 14px; }
.card b { display: block; font-size: 17px; line-height: 1.25; } .card span { display: block; font: 600 12.5px var(--mono); margin-top: 6px; opacity: .7; }
.card .count { font: 700 10px var(--mono); letter-spacing: .14em; opacity: .5; margin-bottom: 6px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; } .two .btn { margin-top: 0; }
.btn.no { background: #ffd9d1; } .btn.yes { background: #c9f0d9; }

/* pick + order */
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip { border: 2px solid var(--ink); background: #fff; border-radius: 10px; padding: 9px 11px; font-weight: 700; font-size: 14.5px; text-align: center; }
.chip small { display: block; font: 600 10px var(--mono); opacity: .55; margin-top: 2px; }
.chip.sel { background: var(--yellow); box-shadow: inset 0 0 0 2px var(--ink); } .chip.gone { visibility: hidden; }
.frames { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.frames .chip { padding: 3px; border-radius: 7px; } .frames .chip.sel { background: var(--red); }
.frames .chip:nth-child(4n+1) { position: relative; }
.rowlab { font: 700 10px var(--mono); letter-spacing: .12em; opacity: .6; margin: 2px 0 4px; }
.thumb { display: block; position: relative; aspect-ratio: 1; border-radius: 4px; overflow: hidden; background: linear-gradient(#58a6e8 0 58%, #7cc452 58%); }
.thumb .sun { position: absolute; width: 14%; aspect-ratio: 1; border-radius: 50%; background: #fff3a8; top: 10%; right: 12%; }
.thumb .deer { position: absolute; bottom: 30%; width: 26%; height: 16%; background: #b5793c; border-radius: 2px; }
.thumb .deer::before { content: ""; position: absolute; right: -8%; top: -70%; width: 30%; height: 90%; background: #b5793c; border-radius: 2px; }
.thumb.pop .deer { display: none; } .thumb.dark { filter: brightness(.42); }
.ordered { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 5px; counter-reset: o; min-height: 8px; }
.ordered li { counter-increment: o; background: var(--ink); color: var(--paper); border-radius: 9px; padding: 8px 10px; font-weight: 700; font-size: 14px; }
.ordered li::before { content: counter(o) " "; color: var(--yellow); font-family: var(--mono); margin-right: 6px; }

/* tune */
.ctl { margin-bottom: 11px; }
.ctl label { display: flex; justify-content: space-between; font: 700 12px var(--mono); letter-spacing: .04em; margin-bottom: 5px; text-transform: uppercase; }
.ctl label b { background: var(--ink); color: var(--yellow); padding: 1px 6px; border-radius: 5px; }
.seg { display: flex; border: 2px solid var(--ink); border-radius: 10px; overflow: hidden; background: #fff; }
.seg button { flex: 1; padding: 9px 4px; font-weight: 700; font-size: 13px; line-height: 1.15; border-right: 2px solid var(--ink); } .seg button:last-child { border-right: 0; }
.seg button.on { background: var(--ink); color: var(--yellow); }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 30px; background: none; margin: 0; }
input[type=range]::-webkit-slider-runnable-track { height: 10px; border-radius: 6px; background: #fff; border: 2px solid var(--ink); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 26px; height: 26px; border-radius: 50%; background: var(--yellow); border: 2.5px solid var(--ink); margin-top: -10px; }
input[type=range]::-moz-range-track { height: 8px; border-radius: 6px; background: #fff; border: 2px solid var(--ink); }
input[type=range]::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: var(--yellow); border: 2.5px solid var(--ink); }
.meter, .pool { margin-bottom: 8px; } .meter-top { display: flex; justify-content: space-between; font: 700 12px var(--mono); margin-bottom: 3px; }
.meter-bar { height: 10px; border-radius: 6px; background: #fff; border: 2px solid var(--ink); overflow: hidden; } .meter-bar i { display: block; height: 100%; background: var(--red); transition: width .2s; }
.meter.ok .meter-bar i { background: var(--green); } .meter.bad b, .pool.bad b { color: #c22d12; } .meter.ok b, .pool.ok b { color: #0f7a41; }
.pool-bar { position: relative; height: 22px; border-radius: 7px; background: #fff; border: 2px solid var(--ink); overflow: hidden; }
.pool-fill { display: flex; height: 100%; } .pool-fill i { display: block; height: 100%; transition: width .2s; }
.pool-bar u { position: absolute; top: 0; bottom: 0; width: 3px; background: var(--ink); margin-left: -3px; }
.pool.bad .pool-bar { animation: shake .3s 2; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 10px; font: 600 10.5px var(--mono); margin-top: 5px; } .legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 4px; }
.fine { font-size: 12px !important; opacity: .65; }

/* preview */
.pv { display: grid; grid-template-columns: 1fr auto; gap: 6px; margin-bottom: 7px; }
.pv .opt { display: flex; align-items: center; gap: 8px; } .pv .play { width: 46px; border-radius: 11px; border: 2px solid var(--ink); background: var(--ink); color: var(--yellow); font-size: 15px; }
.pv .opt.right + .play { visibility: hidden; }
.spot-count { font: 800 26px var(--mono); text-align: center; margin: 6px 0 2px; } .spot-count small { font-size: 12px; opacity: .6; display: block; letter-spacing: .1em; }

/* result */
.stars { font-size: 44px; text-align: center; letter-spacing: 6px; color: var(--yellow); -webkit-text-stroke: 2px var(--ink); margin: 2px 0 6px; }
.stars .off { color: var(--paper2); }
.takeaway { background: var(--ink); color: var(--paper); border-radius: 12px; padding: 12px; font: 700 13px/1.45 var(--mono); }
.takeaway b { color: var(--yellow); display: block; font-size: 10px; letter-spacing: .16em; margin-bottom: 3px; }

/* overlays */
.overlay { position: fixed; inset: 0; z-index: 20; display: none; align-items: center; justify-content: center; padding: 18px; background: rgba(20, 17, 15, .55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.overlay.show { display: flex; }
.title-card { background: var(--paper); border: 3px solid var(--ink); border-radius: 20px; padding: 22px; width: min(400px, 100%); max-height: 100%; overflow: auto; text-align: center; box-shadow: 0 8px 0 var(--ink); }
.title-card h1 { margin: 0 0 8px; font-size: 54px; line-height: .9; letter-spacing: -.04em; } .title-card h1 b { color: var(--yellow); -webkit-text-stroke: 2.5px var(--ink); }
.title-card h1 span { display: block; font: 800 13px var(--mono); letter-spacing: .5em; margin-top: 10px; padding-left: .5em; }
.title-card h2 { margin: 0 0 6px; font-size: 28px; }
.title-card p { line-height: 1.4; font-size: 15px; margin: 10px 0; } .title-card small { display: block; margin-top: 12px; font: 600 10.5px var(--mono); opacity: .6; }
#certList { text-align: left; font: 600 12.5px var(--mono); padding: 0; margin: 10px 0 0; list-style: none; columns: 2; column-gap: 12px; } #certList li { padding: 2px 0; break-inside: avoid; } #certList span { color: #c9930a; }
.sheet { background: var(--paper); border: 3px solid var(--ink); border-radius: 18px; width: min(420px, 100%); max-height: 100%; display: flex; flex-direction: column; overflow: hidden; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-bottom: 2px solid var(--ink); background: var(--yellow); } .sheet-head h2 { margin: 0; font-size: 18px; }
#mapList { overflow: auto; padding: 8px; }
.row { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border-radius: 10px; text-align: left; font-weight: 700; font-size: 15px; }
.row:active { background: var(--paper2); } .row .n { font: 800 11px var(--mono); background: var(--ink); color: var(--yellow); padding: 4px 6px; border-radius: 5px; min-width: 30px; text-align: center; }
.row .s { margin-left: auto; font: 700 13px var(--mono); color: #c9930a; white-space: nowrap; } .row.lock { opacity: .4; } .row.cur { background: #fff; box-shadow: inset 0 0 0 2px var(--ink); }

@media (min-width: 900px) {
  #panel { left: auto; top: 0; width: 420px; height: 100%; border-radius: 18px 0 0 18px; transform: translateX(105%); }
  #pbody p { font-size: 15.5px; }
  #hud { transition: right .45s; } body.po #hud { right: 420px; }
}
@media (max-height: 640px) and (max-width: 899px) { #panel { height: 64vh; height: 64dvh; } }
@media (prefers-reduced-motion: reduce) { #grain { animation: none; } }
