:root {
  --bg: #050806; --ink: #d7ffe4; --green: #39ff88; --dim: #1f8a4c; --amber: #ffb000; --red: #ff4d4d; --cyan: #4de3ff;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
  --mono: ui-monospace, "SF Mono", Menlo, "DejaVu Sans Mono", "Cascadia Mono", Consolas, monospace;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden;
  position: fixed; inset: 0; background: var(--bg); color: var(--ink);
  font-family: var(--mono);
  touch-action: none; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  -webkit-text-size-adjust: 100%;
}
canvas#game { position: fixed; inset: 0; display: block; width: 100vw; height: 100vh; touch-action: none; }
#safe-probe { position: fixed; visibility: hidden; pointer-events: none;
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l); }
.hidden { display: none !important; }

#hud-btns {
  position: fixed; top: calc(6px + var(--safe-t)); right: calc(8px + var(--safe-r));
  display: flex; gap: 8px; z-index: 5;
}
.icon-btn {
  width: 44px; height: 44px; border-radius: 10px; border: 1px solid rgba(57,255,136,.4);
  background: rgba(5,8,6,.75); color: var(--green); display: grid; place-items: center; padding: 0;
  cursor: pointer; touch-action: manipulation;
}
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }
.icon-btn:active { transform: scale(.94); }
#debug-badge { position: fixed; left: 6px; top: 50%; font: 10px var(--mono);
  background: #ff3b6b; color: #fff; padding: 2px 5px; border-radius: 4px; pointer-events: none; opacity: .7; z-index: 6; }

.screen {
  position: fixed; inset: 0; display: grid; place-items: center; overflow-y: auto; z-index: 10;
  padding: calc(14px + var(--safe-t)) calc(14px + var(--safe-r)) calc(14px + var(--safe-b)) calc(14px + var(--safe-l));
  background: radial-gradient(ellipse at center, rgba(5,8,6,.55), rgba(5,8,6,.92));
  touch-action: pan-y;
}
.panel {
  width: min(420px, 100%); text-align: center; padding: 20px 18px;
  background: linear-gradient(180deg, rgba(8,22,14,.94), rgba(4,8,6,.96));
  border: 1px solid rgba(57,255,136,.35); border-radius: 14px;
  box-shadow: 0 0 0 1px rgba(0,0,0,.6), 0 20px 60px rgba(0,0,0,.7), 0 0 40px rgba(57,255,136,.08) inset;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.col { display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%; }
.logo { width: 80px; height: 80px; filter: drop-shadow(0 4px 18px rgba(57,255,136,.35)); }
.game-name {
  margin: 0; font-size: clamp(34px, 10.5vw, 52px); font-weight: 800; letter-spacing: .04em; line-height: 1;
  color: var(--green); text-shadow: 0 0 14px rgba(57,255,136,.55), 0 0 2px #fff;
}
.game-name span { color: var(--amber); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.tag { margin: 0; opacity: .8; font-size: 14px; }
h2 { margin: 0; letter-spacing: .08em; font-size: 26px; color: var(--green); text-shadow: 0 0 12px rgba(57,255,136,.5); }
.btn {
  width: 100%; max-width: 280px; padding: 14px 18px; font: inherit; font-weight: 800; letter-spacing: .14em; font-size: 16px;
  color: var(--ink); background: rgba(57,255,136,.06); border: 1px solid rgba(57,255,136,.4); border-radius: 10px; cursor: pointer;
  touch-action: manipulation; min-height: 48px;
}
.btn:hover { background: rgba(57,255,136,.14); }
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(180deg, #2bd673, #149b4f); border-color: transparent; color: #021208; box-shadow: 0 0 22px rgba(57,255,136,.35); }
.btn.small { width: auto; padding: 10px 16px; min-height: 44px; }
.btn-row { display: flex; gap: 10px; width: 100%; justify-content: center; }
.btn-row .btn { flex: 1; }
.hint { margin: 0; font-size: 12px; line-height: 1.5; opacity: .65; }
.hint kbd { font: 11px var(--mono); padding: 0 4px; border: 1px solid rgba(215,255,228,.35); border-radius: 3px; }
.howto { list-style: none; margin: 0; padding: 0; text-align: left; font-size: 13px; line-height: 1.45; display: grid; gap: 6px; width: 100%; }
.howto li { padding-left: 16px; position: relative; opacity: .92; }
.howto li::before { content: "$"; position: absolute; left: 0; color: var(--dim); }
.howto b { font-weight: 800; }
.g { color: var(--green); } .c { color: var(--cyan); } .r { color: var(--red); } .a { color: var(--amber); }
.scores-box { width: 100%; border: 1px solid rgba(57,255,136,.2); border-radius: 8px; padding: 6px 8px 4px; background: rgba(0,0,0,.25); }
.scores-head { font-size: 11px; opacity: .55; text-align: left; margin-bottom: 2px; }
.scores { list-style: none; margin: 0; padding: 0; width: 100%; font-variant-numeric: tabular-nums; }
.scores li { display: grid; grid-template-columns: 22px 50px 1fr auto; gap: 6px; padding: 3px 6px; border-radius: 4px; font-size: 13px; text-align: left; }
.scores li:nth-child(odd) { background: rgba(57,255,136,.04); }
.scores li.me { background: rgba(255,176,0,.2); color: #fff; }
.scores li .rk { opacity: .5; } .scores li .nm { font-weight: 800; color: var(--green); } .scores li .sc { text-align: right; color: var(--amber); font-weight: 800; }
.scores li .ex { opacity: .6; font-size: 12px; }
.scores .empty { display: block; text-align: center; opacity: .55; padding: 6px; }
.end-panel { width: min(560px, 100%); }
#end-title.panic { color: var(--red); text-shadow: 0 0 14px rgba(255,77,77,.6); }
#end-title.oom { color: var(--amber); text-shadow: 0 0 14px rgba(255,176,0,.5); }
.dump {
  width: 100%; margin: 0; text-align: left; font: 10.5px/1.35 var(--mono); color: #ffcf73;
  background: #0a0503; border: 1px solid rgba(255,176,0,.25); border-radius: 6px; padding: 8px;
  max-height: 34vh; overflow: auto; white-space: pre-wrap; word-break: break-word; touch-action: pan-y;
}
.dump .hl { color: #fff; font-weight: 800; } .dump .art { color: var(--green); display: block; text-align: center; white-space: pre; }
.dump .cm { color: #7a8f80; }
.stats { font-size: 14px; line-height: 1.5; }
.stats b { color: var(--amber); }
#initials-form { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 13px; }
.initials-row { display: flex; gap: 8px; }
#initials {
  width: 120px; font: 800 24px var(--mono); letter-spacing: .2em; text-align: center; text-transform: uppercase;
  padding: 6px; border-radius: 8px; border: 1px solid var(--green); background: rgba(0,0,0,.5); color: var(--green);
  -webkit-user-select: text; user-select: text;
}
@media (min-width: 700px) and (min-height: 600px) {
  .title-panel { width: min(760px, 100%); flex-direction: row; align-items: stretch; gap: 22px; padding: 26px; }
  .title-panel .col-a { justify-content: center; flex: 1; }
  .title-panel .col-b { justify-content: center; flex: 1.1; }
  .logo { width: 104px; height: 104px; }
  .dump { font-size: 12px; }
}
@media (max-height: 520px) {
  .title-panel { width: min(820px, 100%); flex-direction: row; align-items: stretch; gap: 16px; padding: 12px 16px; }
  .title-panel .col-a { justify-content: center; flex: 0.9; gap: 6px; }
  .title-panel .col-b { justify-content: center; flex: 1.1; gap: 6px; }
  .logo { width: 56px; height: 56px; }
  .game-name { font-size: 34px; }
  .howto { font-size: 12px; gap: 3px; }
  .scores li { padding: 1px 6px; font-size: 12px; }
  .panel { padding: 12px 16px; gap: 6px; }
  .btn { padding: 10px 14px; min-height: 44px; }
  .end-panel { width: min(720px, 100%); }
  .dump { max-height: 34vh; }
  .dump .art { display: none; }
  .end-panel h2 { font-size: 22px; }
}
