:root {
  --bg: #0b0f1a;
  --bg2: #121a2e;
  --ink: #e8ecf6;
  --muted: #8b95b0;
  --hazard: #ffc928;
  --cyan: #3ee6ff;
  --pink: #ff4fa3;
  --green: #5dff9c;
  --glass: rgba(14, 20, 36, 0.72);
  --line: rgba(160, 190, 255, 0.16);
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "Space Grotesk", system-ui, -apple-system, Segoe UI, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--ink);
  font-family: var(--sans);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
canvas#world {
  position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh;
  display: block; touch-action: none; cursor: crosshair;
}
button { font: inherit; color: inherit; }
code, kbd { font-family: var(--mono); }
kbd {
  display: inline-block; padding: 1px 6px; border-radius: 5px;
  border: 1px solid var(--line); border-bottom-width: 2px;
  background: rgba(255,255,255,0.05); font-size: 0.78em; color: var(--ink);
}

/* ---------- top bar ---------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: max(12px, env(safe-area-inset-top)) 16px 0;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.brand {
  font-weight: 700; font-size: 20px; letter-spacing: -0.02em;
  color: var(--ink); text-decoration: none; display: flex; align-items: center; gap: 8px;
}
.brand b { color: var(--hazard); }
.brand-icon { display: inline-block; animation: wave 3s ease-in-out infinite; transform-origin: 70% 80%; }
@keyframes wave { 0%, 60%, 100% { transform: rotate(0); } 70% { transform: rotate(-18deg); } 80% { transform: rotate(14deg); } 90% { transform: rotate(-8deg); } }
.actions { display: flex; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--glass); backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 999px; padding: 7px 14px; cursor: pointer; font-size: 14px;
  display: inline-flex; align-items: center; gap: 6px; transition: border-color .2s, transform .1s;
}
.chip:hover { border-color: var(--hazard); }
.chip:active { transform: scale(0.96); }
.chip.icon { width: 36px; height: 36px; padding: 0; justify-content: center; }
.count {
  font-family: var(--mono); font-size: 12px; background: var(--hazard); color: #000;
  border-radius: 999px; padding: 0 7px; font-weight: 700;
}

/* ---------- hero ---------- */
.hero {
  position: fixed; z-index: 3; left: 50%; top: 64px; transform: translateX(-50%);
  width: min(680px, calc(100vw - 32px)); text-align: center;
  pointer-events: none; transition: opacity .35s;
  text-shadow: 0 2px 18px rgba(0,0,0,0.85);
}
.hero.dim { opacity: 0.25; }
.tape {
  overflow: hidden; margin: 0 auto 14px; width: min(520px, 100%);
  background: repeating-linear-gradient(-45deg, var(--hazard) 0 14px, #111 14px 28px);
  padding: 4px 0; transform: rotate(-1.6deg); border-radius: 3px;
  box-shadow: 0 6px 24px rgba(255, 201, 40, 0.18);
}
.tape-track {
  display: flex; width: max-content; animation: tape 14s linear infinite;
}
.tape-track span {
  font-family: var(--mono); font-weight: 700; font-size: 12px; letter-spacing: .08em;
  background: var(--hazard); color: #111; padding: 2px 0; white-space: nowrap; text-shadow: none;
}
@keyframes tape { to { transform: translateX(-50%); } }
.hero h1 {
  margin: 0; font-size: clamp(30px, 6.2vw, 64px); line-height: 1.02; letter-spacing: -0.035em;
}
.glitch { position: relative; color: var(--hazard); display: inline-block; }
.glitch::before, .glitch::after {
  content: attr(data-text); position: absolute; inset: 0; pointer-events: none;
}
.glitch::before { color: var(--cyan); mix-blend-mode: screen; animation: glitch 3.2s infinite steps(1); }
.glitch::after { color: var(--pink); mix-blend-mode: screen; animation: glitch 2.7s infinite reverse steps(1); }
@keyframes glitch {
  0%, 86%, 100% { transform: none; clip-path: none; opacity: 0; }
  88% { transform: translate(-3px, 1px); clip-path: inset(10% 0 55% 0); opacity: 1; }
  91% { transform: translate(3px, -2px); clip-path: inset(60% 0 8% 0); opacity: 1; }
  94% { transform: translate(-1px, 2px); clip-path: inset(30% 0 40% 0); opacity: 1; }
}
.lede { margin: 14px auto 6px; font-size: clamp(14px, 1.9vw, 18px); line-height: 1.5; color: #d4dbef; max-width: 600px; }
.lede b { color: var(--ink); }
.lede code { color: var(--pink); font-size: .92em; }
.fine { margin: 0; font-size: 13px; color: var(--muted); font-style: italic; }
.advisory {
  display: inline-flex; align-items: center; gap: 10px; margin-top: 14px;
  font-family: var(--mono); font-size: 12px; text-transform: uppercase; letter-spacing: .08em;
  background: var(--glass); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px;
  text-shadow: none;
}
.advisory-bar { width: 120px; height: 8px; border-radius: 4px; background: rgba(255,255,255,0.08); overflow: hidden; }
.advisory-bar i {
  display: block; height: 100%; width: 55%;
  background: linear-gradient(90deg, var(--green), var(--hazard), var(--pink));
  background-size: 120px 100%; transition: width .3s; animation: jitter .18s infinite alternate;
}
@keyframes jitter { to { transform: translateX(-3px); } }
#advisory-label { color: var(--hazard); min-width: 9ch; text-align: left; }

/* ---------- HUD ---------- */
.hud {
  position: fixed; z-index: 4; right: 16px; top: 64px; width: 220px;
  background: var(--glass); border: 1px solid var(--line); border-radius: 14px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  padding: 12px 14px; font-size: 13px;
}
.hud-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.mode {
  font-family: var(--mono); font-size: 11px; font-weight: 700; letter-spacing: .1em;
  padding: 3px 8px; border-radius: 6px; background: rgba(255,79,163,0.15); color: var(--pink);
  border: 1px solid rgba(255,79,163,0.4);
}
.mode.manual { background: rgba(93,255,156,0.12); color: var(--green); border-color: rgba(93,255,156,0.4); }
.goal { font-size: 12px; color: var(--muted); }
.hud dl { margin: 0; display: grid; gap: 3px; }
.hud dl div { display: flex; justify-content: space-between; gap: 8px; }
.hud dt { color: var(--muted); }
.hud dd { margin: 0; font-family: var(--mono); font-weight: 700; }
#s-best { color: var(--green); }
#s-robot { color: var(--pink); }
.rank { margin: 8px 0 6px; padding-top: 8px; border-top: 1px solid var(--line); color: var(--muted); }
.rank b { color: var(--hazard); }
.slop { display: grid; gap: 4px; color: var(--muted); }
.slop span { display: flex; justify-content: space-between; }
.slop output { font-family: var(--mono); color: var(--hazard); font-weight: 700; }
.slop input { width: 100%; accent-color: var(--hazard); }
.hud.bump { animation: bump .5s; }
@keyframes bump { 30% { transform: scale(1.06) rotate(-1deg); } }

/* ---------- log & controls ---------- */
.log {
  position: fixed; z-index: 2; left: 16px; bottom: 12px; margin: 0; padding: 0; list-style: none;
  font-family: var(--mono); font-size: 12px; color: var(--muted); pointer-events: none;
  max-width: min(440px, calc(100vw - 32px));
}
.log li { opacity: .9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; animation: logIn .3s; }
.log li:nth-last-child(n+2) { opacity: .55; }
.log li:nth-last-child(n+3) { opacity: .3; }
.log li b { color: var(--cyan); font-weight: 400; }
@keyframes logIn { from { transform: translateX(-10px); opacity: 0; } }
.controls {
  position: fixed; z-index: 2; right: 16px; bottom: 18px; display: flex; gap: 14px; white-space: nowrap;
  justify-content: flex-end; font-size: 12px; color: var(--muted); pointer-events: none;
}

/* ---------- touch pad ---------- */
.pad {
  position: fixed; z-index: 4; right: 12px; bottom: max(12px, env(safe-area-inset-bottom));
  display: grid; grid-template-columns: repeat(4, auto); gap: 8px;
}
.pad button {
  width: 52px; height: 52px; border-radius: 16px; border: 1px solid var(--line);
  background: var(--glass); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  font-size: 22px; touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.pad button.big, .pad button[data-act="yeet"] { font-family: var(--mono); font-size: 12px; font-weight: 700; }
.pad button.big { width: 72px; background: rgba(255, 201, 40, 0.18); border-color: rgba(255,201,40,.6); color: var(--hazard); }
.pad button:active { transform: scale(0.93); background: rgba(255,255,255,0.12); }
.pad button.holding { background: var(--hazard); color: #111; }

.touch-only { display: none; }
@media (hover: none) and (pointer: coarse) {
  .touch-only { display: grid; }
  .desktop-only { display: none; }
  .log { bottom: calc(max(12px, env(safe-area-inset-bottom)) + 64px); }
}

/* ---------- dialogs ---------- */
dialog.sheet {
  width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 48px);
  border: 1px solid var(--line); border-radius: 18px; padding: 22px 22px 18px;
  background: #10172a; color: var(--ink); box-shadow: 0 30px 80px rgba(0,0,0,0.6);
}
dialog::backdrop { background: rgba(5, 8, 15, 0.6); backdrop-filter: blur(3px); }
dialog[open] { animation: pop .25s cubic-bezier(.2,1.4,.4,1); }
@keyframes pop { from { transform: scale(.92) rotate(-1deg); opacity: 0; } }
dialog h2 { margin: 0 0 4px; font-size: 22px; }
dialog h3 { margin: 0 0 6px; font-size: 14px; color: var(--hazard); }
dialog .sub { color: var(--muted); font-size: 14px; line-height: 1.5; }
dialog ul { margin: 0; padding-left: 18px; font-size: 14px; line-height: 1.8; }
.close {
  float: right; border: 0; background: rgba(255,255,255,0.06); border-radius: 10px;
  width: 32px; height: 32px; cursor: pointer;
}
.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 520px) { .help-grid { grid-template-columns: 1fr; } }
.site-list { list-style: none; padding: 0 !important; display: grid; gap: 10px; }
.site-list a {
  display: block; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: rgba(255,255,255,0.03); color: var(--ink); text-decoration: none;
}
.site-list a:hover { border-color: var(--hazard); }
.site-list a b { display: block; }
.site-list a span { color: var(--muted); font-size: 13px; }
.site-list .slot {
  padding: 12px 14px; border-radius: 12px; border: 1px dashed var(--line); color: var(--muted);
  font-family: var(--mono); font-size: 13px; line-height: 1.5;
}
.site-list .slot b { color: var(--ink); }

/* ---------- toast ---------- */
.toast {
  position: fixed; z-index: 6; left: 50%; bottom: 22%; transform: translate(-50%, 20px) scale(.9);
  font-family: var(--mono); font-weight: 700; font-size: clamp(16px, 3vw, 26px);
  padding: 10px 18px; border-radius: 12px; background: var(--hazard); color: #111;
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s cubic-bezier(.2,1.6,.4,1);
  white-space: nowrap; box-shadow: 0 10px 40px rgba(255,201,40,0.35);
}
.toast.show { opacity: 1; transform: translate(-50%, 0) scale(1) rotate(-2deg); }
.toast.bad { background: var(--pink); box-shadow: 0 10px 40px rgba(255,79,163,0.35); }

/* ---------- mid-size screens: keep the hero clear of the HUD ---------- */
@media (max-width: 1180px) { .controls { display: none; } }
@media (max-width: 1180px) and (min-width: 761px) {
  .hero { left: 16px; transform: none; width: calc(100vw - 272px); }
}

/* ---------- small screens ---------- */
@media (max-width: 760px) {
  .topbar { padding-left: 12px; padding-right: 12px; }
  .brand { font-size: 17px; }
  .chip { padding: 6px 11px; font-size: 13px; }
  .hero .fine { display: none; }
  .tape { margin-bottom: 10px; }
  .lede { margin-top: 10px; }
  .advisory { margin-top: 10px; padding: 5px 10px; gap: 8px; font-size: 10px; }
  .advisory-bar { width: 70px; }
  .hero { top: 124px; }
  .hud {
    top: 52px; left: 12px; right: 12px; width: auto; padding: 7px 10px; font-size: 11px;
    display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 6px 10px;
  }
  .hud-head { margin: 0; }
  .hud-head .goal, .hud dl div:nth-child(4), .hud dl div:nth-child(5), .rank { display: none; }
  .hud dl { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .hud dl div { flex-direction: column; gap: 0; }
  .hud dd { font-size: 12px; }
  .slop { grid-column: 1 / -1; grid-template-columns: auto 1fr; align-items: center; gap: 10px; }
  .slop span { gap: 6px; }
  .log { display: none; }
}
@media (max-height: 560px) and (min-width: 761px) {
  .hero .fine, .hero .lede { display: none; }
}
/* phones in landscape & other very short screens */
@media (max-height: 500px) {
  .hero { top: 54px; left: 12px; transform: none; width: calc(100vw - 344px); text-align: left; }
  .hero .lede, .hero .fine, .hero .advisory { display: none; }
  .hero h1 { font-size: clamp(20px, 3.4vw, 30px); }
  .tape { margin: 0 0 8px; width: 100%; }
  .hud { top: 52px; left: auto; right: 12px; width: 320px; }
}
@media (prefers-reduced-motion: reduce) {
  .tape-track, .advisory-bar i, .brand-icon, .glitch::before, .glitch::after { animation: none; }
}
