:root {
  --ink: #0A0A0A; --paper: #FAFAFA; --accent: #E8D48A; --accent-hi: #F4E3A6;
  --up: #6BE39A; --dn: #FF7A6B; --panel: #111412; --line: rgba(255,255,255,.09);
  --hud: 1;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --heavy: "Arial Black", "Segoe UI Black", "Segoe UI", system-ui, sans-serif;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; background: #0A0A0A; color: var(--paper); font-family: var(--font); }
body { user-select: none; -webkit-user-select: none; }
canvas#c { display: block; position: fixed; inset: 0; width: 100%; height: 100%; }
#ui { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#ui button, #ui input, #ui select, .screen.on, .overlay.on, #save.on, .btns { pointer-events: auto; }
.off { display: none !important; }

/* white text with a heavy black stroke (the stroke sits behind the fill) */
.stroke { position: relative; display: inline-block; color: var(--paper); font-family: var(--heavy); font-weight: 900; z-index: 0; }
.stroke::before { content: attr(data-t); position: absolute; left: 0; top: 0; z-index: -1; -webkit-text-stroke: .2em var(--ink); color: var(--ink); white-space: nowrap; }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; transition: opacity .2s ease-out; }
#hud.hidden { opacity: 0; }
#hud .lvl { position: absolute; top: calc(18px * var(--hud)); left: 50%; transform: translateX(-50%); text-align: center; }
#hud .lvl-n { font-size: calc(clamp(1.6rem, 3.4vw, 2.6rem) * var(--hud)); letter-spacing: .04em; line-height: 1; white-space: nowrap; }
#hud .lvl-n.pop { animation: pop .35s ease-out; }
#hud .lvl-bar { width: calc(180px * var(--hud)); height: 6px; margin: 10px auto 0; border-radius: 99px; background: rgba(10,10,10,.55); overflow: hidden; border: 1px solid rgba(255,255,255,.12); }
#hud .lvl-bar i { display: block; height: 100%; background: var(--accent); transform-origin: left; transform: scaleX(0); transition: transform .4s ease-out; }
#hud .stats { position: absolute; top: calc(16px * var(--hud)); left: 16px; display: flex; gap: 14px; align-items: center;
  font: 800 calc(15px * var(--hud)) var(--font); text-shadow: 0 1px 3px rgba(0,0,0,.8); font-variant-numeric: tabular-nums; opacity: .9; }
#hud .deaths { display: inline-flex; align-items: center; gap: 6px; }
#hud .deaths svg { width: 1.1em; height: 1.1em; opacity: .9; }
#hud .cross { position: absolute; left: 50%; top: 50%; width: 4px; height: 4px; margin: -2px 0 0 -2px; border-radius: 50%; background: rgba(250,250,250,.75); box-shadow: 0 0 0 1px rgba(0,0,0,.5); }
#toasts { position: absolute; left: 0; right: 0; top: 30%; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.toast { animation: toastIn .22s ease-out both; }
.toast span { font-size: calc(clamp(1.4rem, 3vw, 2.2rem) * var(--hud)); letter-spacing: .04em; white-space: nowrap; }
.toast.big span { font-size: calc(clamp(2rem, 5.4vw, 4rem) * var(--hud)); }
.toast.up span { color: #8EF5B5; } .toast.dn span { color: #FF9C8E; } .toast.cp span { color: var(--accent-hi); }
.toast.out { opacity: 0; transform: translateY(-10px); transition: opacity .35s ease-out, transform .35s ease-out; }
#hint { position: absolute; left: 50%; bottom: calc(36px * var(--hud)); transform: translate(-50%, 8px); max-width: min(92vw, 640px); text-align: center;
  font: 700 calc(16px * var(--hud)) var(--font); padding: 10px 16px; border-radius: 12px; background: rgba(10,10,10,.62); border: 1px solid var(--line);
  opacity: 0; transition: opacity .2s ease-out, transform .2s ease-out; }
#hint.on { opacity: 1; transform: translate(-50%, 0); }
#legend { position: absolute; right: 16px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 6px; }
#legend .lg { display: flex; align-items: center; gap: 10px; justify-content: flex-end; }
#legend kbd { font: 900 calc(13px * var(--hud)) var(--font); min-width: 2em; text-align: center; padding: 4px 7px; border-radius: 7px; background: rgba(10,10,10,.7); border: 1px solid rgba(255,255,255,.2); }
#legend span { font-size: calc(18px * var(--hud)); }
#legend .up span { color: #8EF5B5; } #legend .dn span, #legend .rs span { color: #FF9C8E; } #legend .sv span { color: #8EF5B5; }
#fps { position: absolute; right: 64px; top: 22px; font: 800 12px var(--font); opacity: .7; text-shadow: 0 1px 2px #000; }

.btns { position: fixed; top: 14px; right: 14px; z-index: 30; display: flex; gap: 8px; }
.btns button { width: 40px; height: 40px; border: 0; border-radius: 12px; background: rgba(10,10,10,.42); backdrop-filter: blur(6px);
  color: var(--paper); cursor: pointer; display: flex; align-items: center; justify-content: center; opacity: .55;
  transition: opacity .18s ease-out, transform .18s ease-out; }
.btns button:hover { opacity: 1; transform: translateY(-1px); }
.btns button:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; opacity: 1; }
.btns svg { width: 20px; height: 20px; }

/* ---------- buttons ---------- */
.btn { border: 0; border-radius: 12px; padding: 14px 26px; cursor: pointer; font: 800 16px var(--font); letter-spacing: .02em;
  transition: transform .15s ease-out, background .15s ease-out, opacity .15s ease-out; }
.btn.sm { padding: 10px 18px; font-size: 14px; }
.btn.primary { background: var(--paper); color: var(--ink); }
.btn.primary:hover { transform: translateY(-1px); background: #fff; }
.btn.ghost { background: rgba(250,250,250,.08); color: var(--paper); border: 1px solid rgba(250,250,250,.16); }
.btn.ghost:hover { background: rgba(250,250,250,.15); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

/* ---------- screens ---------- */
.screen { position: absolute; inset: 0; display: none; }
.screen.on { display: flex; }
#title { align-items: flex-end; padding: clamp(24px, 6vw, 72px); background: linear-gradient(90deg, rgba(10,10,10,.72) 0%, rgba(10,10,10,.25) 55%, rgba(10,10,10,0) 80%); }
#title .t-wrap { max-width: 720px; animation: rise .5s ease-out both; }
#title .t-h { font-size: clamp(2.6rem, 7.4vw, 6.2rem); line-height: .95; letter-spacing: .01em; white-space: normal; }
#title .t-h::before { white-space: normal; }
#title .t-sub { margin: 18px 0 28px; font-size: clamp(1rem, 1.6vw, 1.25rem); font-weight: 600; opacity: .88; max-width: 34ch; line-height: 1.4; text-shadow: 0 1px 4px rgba(0,0,0,.7); }
#title .t-row { display: flex; gap: 10px; flex-wrap: wrap; }
#title .t-keys { margin-top: 22px; font-size: 13px; font-weight: 700; opacity: .6; letter-spacing: .03em; text-shadow: 0 1px 3px #000; }
#pause { align-items: center; justify-content: center; background: rgba(10,10,10,.55); backdrop-filter: blur(6px); }
.p-card { display: flex; flex-direction: column; gap: 10px; min-width: 280px; padding: 28px; border-radius: 20px; background: var(--panel); border: 1px solid var(--line); animation: rise .2s ease-out both; }
.p-card h2 { font-size: 22px; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; margin-bottom: 8px; }

/* ---------- settings ---------- */
.overlay { position: absolute; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center;
  background: rgba(10,10,10,.6); backdrop-filter: blur(7px); opacity: 0; pointer-events: none; transition: opacity .2s ease-out; }
.overlay.on { opacity: 1; pointer-events: auto; }
.panel { width: min(600px, calc(100vw - 32px)); max-height: min(90vh, 860px); background: var(--panel); border-radius: 20px; border: 1px solid var(--line);
  padding: 22px 8px 18px 22px; display: flex; flex-direction: column; transform: translateY(8px); transition: transform .2s ease-out; }
.overlay.on .panel { transform: none; }
.p-head { display: flex; align-items: center; padding-right: 14px; }
.p-head h2 { font-size: 20px; font-weight: 900; letter-spacing: .14em; text-transform: uppercase; flex: 1; }
.x { width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255,255,255,.05); color: var(--paper); cursor: pointer; font-size: 14px; }
.x:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 16px 14px 14px 0; }
.tab { border: 1px solid var(--line); background: rgba(255,255,255,.05); color: var(--paper); border-radius: 10px; padding: 8px 13px; cursor: pointer;
  font: 800 13px var(--font); opacity: .75; transition: background .15s ease-out, opacity .15s ease-out; }
.tab:hover { opacity: 1; }
.tab[aria-selected=true] { background: var(--paper); color: var(--ink); opacity: 1; border-color: transparent; }
.tab:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.panel-body { overflow-y: auto; padding-right: 14px; flex: 1 1 auto; scrollbar-width: thin; }
.panel-body::-webkit-scrollbar { width: 8px; }
.panel-body::-webkit-scrollbar-thumb { background: rgba(232,212,138,.3); border-radius: 99px; }
.grp-h { font-size: 11px; font-weight: 900; letter-spacing: .2em; text-transform: uppercase; color: var(--accent); margin: 18px 0 6px; }
.set { display: flex; align-items: center; gap: 12px; min-height: 42px; font-size: 14px; font-weight: 700; border-bottom: 1px solid rgba(255,255,255,.04); }
.set label { flex: 1 1 auto; line-height: 1.25; }
.set label small { display: block; font-size: 11px; font-weight: 600; opacity: .45; margin-top: 2px; }
.set input[type=range] { flex: 0 0 170px; accent-color: var(--accent); cursor: pointer; }
.set input[type=range]:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.set output { flex: 0 0 56px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 900; font-size: 13px; opacity: .85; }
.chips-row { flex-wrap: wrap; padding: 6px 0; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.1); color: var(--paper); border-radius: 9px; padding: 8px 12px; cursor: pointer;
  font: 800 12.5px var(--font); transition: background .14s ease-out; }
.chip:hover { background: rgba(255,255,255,.14); }
.chip[aria-pressed=true] { background: var(--accent); color: var(--ink); border-color: transparent; }
.chip:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.sw { position: relative; width: 48px; height: 26px; border: 0; border-radius: 99px; cursor: pointer; background: rgba(255,255,255,.16); transition: background .16s ease-out; flex: 0 0 auto; }
.sw::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--paper); transition: transform .16s ease-out; }
.sw[aria-checked=true] { background: var(--accent); }
.sw[aria-checked=true]::after { transform: translateX(22px); background: var(--ink); }
.sw:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.note { font-weight: 600; font-size: 12.5px; opacity: .55; line-height: 1.45; margin-bottom: 10px; }
.bind { display: flex; align-items: center; gap: 8px; min-height: 46px; border-bottom: 1px solid rgba(255,255,255,.04); }
.bind .tag { flex: 0 0 70px; font: 900 12px var(--font); letter-spacing: .12em; }
.bind.up .tag, .bind.sv .tag { color: var(--up); }
.bind.dn .tag, .bind.rs .tag { color: var(--dn); }
.bind.pn .tag { color: var(--accent); }
.bind.mv .tag { flex-basis: 120px; letter-spacing: .02em; font-weight: 800; color: var(--paper); }
.bind .amt { flex: 1 1 auto; display: flex; align-items: center; gap: 6px; }
.bind .amt.hint { font-size: 12px; font-weight: 600; opacity: .5; line-height: 1.3; }
.bind .sign { font: 900 18px var(--font); width: 12px; text-align: center; }
.bind .unit { font-size: 12px; opacity: .5; font-weight: 700; }
.bind input[type=number] { width: 74px; background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.14); color: var(--paper); border-radius: 9px;
  padding: 8px 10px; font: 900 14px var(--font); font-variant-numeric: tabular-nums; }
.bind input[type=number]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.keybtn { flex: 0 0 96px; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.16); color: var(--paper); border-radius: 9px; padding: 10px 6px;
  cursor: pointer; font: 900 12.5px var(--font); letter-spacing: .06em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; transition: background .14s ease-out; }
.keybtn:hover { background: rgba(255,255,255,.16); }
.keybtn.listening { background: var(--accent); color: var(--ink); border-color: transparent; }
.keybtn:focus-visible, .test:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.test { flex: 0 0 auto; background: transparent; border: 1px solid rgba(255,255,255,.16); color: var(--paper); border-radius: 9px; padding: 9px 10px; cursor: pointer; font: 800 12px var(--font); opacity: .8; }
.test:hover { opacity: 1; background: rgba(255,255,255,.08); }
.foot { display: flex; gap: 8px; align-items: center; padding: 14px 14px 0 0; margin-top: 4px; border-top: 1px solid var(--line); }
.foot .sp { flex: 1; }

/* ---------- SAVE countdown ---------- */
#save { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(120,0,0,0) 40%, rgba(150,0,0,.55) 100%); }
#save.on { display: flex; animation: redPulse 1s ease-in-out infinite; }
#save .sv-card { display: flex; flex-direction: column; align-items: center; gap: 6px; animation: rise .25s ease-out both; }
#save .sv-row { display: flex; align-items: center; gap: .35em; font-size: clamp(3.4rem, 10vw, 7.5rem); line-height: 1; }
#save .sv-word { letter-spacing: .04em; }
#save .sv-num { min-width: 1.6em; text-align: left; color: #FFE05A; font-variant-numeric: tabular-nums; }
#save.urgent .sv-num { color: #FF5A4A; }
#save .sv-num.tick { animation: tick .3s ease-out; }
#save .sv-img { width: clamp(150px, 20vw, 230px); height: auto; image-rendering: auto; filter: drop-shadow(0 6px 18px rgba(0,0,0,.5)); animation: bob 1.4s ease-in-out infinite; }
#save.saved .sv-card { animation: savedOut .6s ease-out forwards; }
#save.lost .sv-card { animation: lostOut .45s ease-in forwards; }

/* ---------- ending / caught / fade ---------- */
#ending { align-items: center; justify-content: center; background: radial-gradient(ellipse at center, rgba(255,250,235,.0), rgba(255,246,220,.25)); }
.e-card { text-align: center; animation: rise .6s ease-out both; }
.e-card h2 { font-size: clamp(3rem, 9vw, 7rem); letter-spacing: .02em; line-height: 1; }
.e-stats { margin: 18px 0 26px; font-size: clamp(1rem, 1.8vw, 1.3rem); font-weight: 700; color: #1a1a1a; text-shadow: 0 1px 0 rgba(255,255,255,.4); }
.e-stats b { font-weight: 900; }
#caught { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; opacity: 0; transition: opacity .25s ease-out; }
#caught.on { opacity: 1; }
#caught span { font-size: clamp(2.4rem, 7vw, 5.4rem); color: #FF4D3D; letter-spacing: .06em; }
#fade { position: absolute; inset: 0; background: #0A0A0A; opacity: 0; transition: opacity .3s ease-out; pointer-events: none; }

@keyframes pop { 0% { transform: scale(1.18); } 100% { transform: scale(1); } }
@keyframes toastIn { from { opacity: 0; transform: scale(.85) translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes tick { 0% { transform: scale(1.25); } 100% { transform: scale(1); } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes redPulse { 0%, 100% { background-color: rgba(60,0,0,.1); } 50% { background-color: rgba(90,0,0,.22); } }
@keyframes savedOut { 0% { transform: scale(1); opacity: 1; } 40% { transform: scale(1.12); } 100% { transform: scale(.9) translateY(-30px); opacity: 0; } }
@keyframes lostOut { to { transform: scale(.7); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .toast, #title .t-wrap, .p-card, .e-card, #save .sv-card, #save .sv-img, #save.on, #hud .lvl-n.pop, #save .sv-num.tick { animation: none !important; }
  #hint, .overlay, .panel { transition: none !important; }
}
@media (max-width: 560px) {
  .set input[type=range] { flex-basis: 120px; }
  .bind .tag { flex-basis: 52px; }
  .keybtn { flex-basis: 76px; }
  #legend { display: none; }
}
