:root {
  --bg: #0b0b0f;
  --card: #15151c;
  --line: #262631;
  --text: #f2f2f5;
  --muted: #9a9aab;
  --accent: #ffcc33;
  --accent-ink: #1a1400;
  --danger: #ff6b6b;
  --genesis: #4d8dff;
  --psx: #b38cff;
  --radius: 14px;
  --btn: rgba(255, 255, 255, 0.1);
  --btn-line: rgba(255, 255, 255, 0.22);
  --btn-on: rgba(255, 204, 51, 0.55);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* No double-tap zoom on taps anywhere (menus included); the game screen also blocks it in JS. */
html { touch-action: manipulation; -webkit-text-size-adjust: 100%; }
#game, #game * { -webkit-user-select: none; -webkit-touch-callout: none; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body.playing { overflow: hidden; position: fixed; inset: 0; touch-action: none; user-select: none; -webkit-user-select: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
h1 { font-size: 28px; margin: 0; letter-spacing: -0.02em; }
h2 { font-size: 18px; margin: 0 0 8px; }
code, kbd { font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; }
kbd { background: var(--line); border-radius: 6px; padding: 2px 6px; }

.view { max-width: 640px; margin: 0 auto; padding: max(20px, env(safe-area-inset-top)) 16px 32px; }
.top { margin: 8px 0 18px; }
.sub { color: var(--muted); margin: 4px 0 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.row-between { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.inline { display: flex; gap: 8px; }
.stack { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
#enter-code { text-transform: uppercase; letter-spacing: 0.06em; }
#enter-code::placeholder { text-transform: none; letter-spacing: 0; }
.foot { text-align: center; }
.eyebrow { margin: 0 0 4px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }

input[type="password"], input[type="text"] { font-size: 16px; flex: 1; min-width: 0; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font: inherit; }
.button { display: inline-flex; justify-content: center; align-items: center; min-height: 46px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line); background: #1e1e27; color: var(--text); font-family: inherit; font-size: 15px; font-weight: 600; line-height: 1; cursor: pointer; }
.button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.link { background: none; border: 0; color: var(--accent); font-family: inherit; font-size: 14px; font-weight: 600; cursor: pointer; padding: 6px 0; }
.link.danger { color: var(--danger); }

.games { list-style: none; margin: 8px 0 0; padding: 0; }
.games li + li { margin-top: 6px; }
.games button { width: 100%; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; text-align: left; background: var(--bg); border: 1px solid var(--line); color: var(--text); border-radius: 12px; padding: 12px; font: inherit; cursor: pointer; }
.games .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.games .meta { color: var(--muted); font-size: 13px; }
.sys { font-size: 11px; font-weight: 700; padding: 3px 7px; border-radius: 6px; text-transform: uppercase; letter-spacing: 0.04em; }
.sys.genesis { background: color-mix(in srgb, var(--genesis) 22%, transparent); color: var(--genesis); }
.sys.psx { background: color-mix(in srgb, var(--psx) 22%, transparent); color: var(--psx); }

.progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin: 10px 0 4px; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }

.sheet { position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, 0.6); display: flex; align-items: center; justify-content: center; padding: 16px; }
.sheet-body { width: 100%; max-width: 380px; max-height: calc(100dvh - 32px); overflow: auto; margin: 0; }
.code { font: 700 40px/1 ui-monospace, Menlo, monospace; letter-spacing: 0.12em; margin: 4px 0 8px; }
.keys { margin-top: 14px; }
.keys summary { cursor: pointer; color: var(--muted); font-size: 14px; }
.keys table { margin-top: 8px; border-collapse: collapse; font-size: 14px; }
.keys td { padding: 3px 12px 3px 0; }

/* ---------- Game ---------- */
#game { position: fixed; inset: 0; background: #000; overflow: hidden; }
.screen { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; }
#canvas { width: var(--screen-w); height: var(--screen-h); image-rendering: pixelated; image-rendering: crisp-edges; background: #000; }

#controls { position: absolute; inset: 0; display: none; touch-action: none; }
body.touch #controls { display: block; }
.pad-side {
  --col: max(var(--side), 34vh);
  position: absolute; top: 0; bottom: 0;
  width: var(--col);
  padding: max(10px, env(safe-area-inset-top)) 0 max(12px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center;
}
.pad-side.left { left: 0; padding-left: env(safe-area-inset-left); }
.pad-side.right { right: 0; padding-right: env(safe-area-inset-right); }
/* Top slot holds shoulders/START; the stick and face buttons sink to the bottom, under the thumbs. */
.slot { display: flex; gap: 8px; align-items: center; }
.slot.top { min-height: 34px; margin-bottom: auto; }
.slot.bottom:not(:empty) { min-height: 30px; margin-top: 10px; }

.btn { display: flex; align-items: center; justify-content: center; background: var(--btn); border: 1.5px solid var(--btn-line); color: rgba(255, 255, 255, 0.85); font-weight: 700; pointer-events: none; transition: background 0.05s, transform 0.05s; }
.btn.on { background: var(--btn-on); border-color: var(--accent); }

.shoulder { width: 64px; height: 34px; border-radius: 10px; font-size: 13px; }
.meta { height: 32px; padding: 0 16px; border-radius: 16px; font-size: 11px; letter-spacing: 0.08em; }

.stick { position: relative; width: min(calc(var(--col) * 0.84), 48vh); aspect-ratio: 1; margin-bottom: 2vh; }
.stick-base { position: absolute; inset: 0; border-radius: 50%; background: radial-gradient(circle, rgba(255, 255, 255, 0.04) 0 55%, rgba(255, 255, 255, 0.1) 100%); border: 1.5px solid var(--btn-line); }
.stick-base i { position: absolute; width: 0; height: 0; border: 7px solid transparent; opacity: 0.35; transition: opacity 0.05s; }
.stick-base i.on { opacity: 1; }
.stick-base .up { left: 50%; top: 7%; transform: translateX(-50%); border-bottom: 9px solid #fff; border-top-width: 0; }
.stick-base .down { left: 50%; bottom: 7%; transform: translateX(-50%); border-top: 9px solid #fff; border-bottom-width: 0; }
.stick-base .left { top: 50%; left: 7%; transform: translateY(-50%); border-right: 9px solid #fff; border-left-width: 0; }
.stick-base .right { top: 50%; right: 7%; transform: translateY(-50%); border-left: 9px solid #fff; border-right-width: 0; }
.knob { position: absolute; left: 30%; top: 30%; width: 40%; height: 40%; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #5a5a66, #2a2a33 70%); border: 1.5px solid rgba(255, 255, 255, 0.3); box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5); transition: transform 0.08s ease-out; pointer-events: none; }
.stick.active .knob { transition: none; background: radial-gradient(circle at 35% 30%, #6c6c7a, #34343f 70%); }

.face { position: relative; }
.face.diamond { width: min(calc(var(--col) * 0.86), 46vh); aspect-ratio: 1; }
.face.diamond .face-btn { position: absolute; transform: translate(-50%, -50%); width: 31%; aspect-ratio: 1; border-radius: 50%; font-size: clamp(14px, 4.5vh, 24px); }
.face-btn.tri span { color: #5fe3b0; }
.face-btn.cir span { color: #ff7a8a; }
.face-btn.crs span { color: #8fb3ff; }
.face-btn.sqr span { color: #ff9be6; }

/* Mega Drive: A, B, C stacked, big, one color each. */
.face.column { display: flex; flex-direction: column; gap: 2.4vh; margin-bottom: 1vh; }
.face.column .face-btn { width: min(calc(var(--col) * 0.6), 24vh); aspect-ratio: 1; border-radius: 50%; font-size: clamp(18px, 7vh, 32px); border-width: 2px; color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4); }
.face-btn.md-a { background: rgba(255, 90, 95, 0.45); border-color: rgba(255, 120, 125, 0.9); }
.face-btn.md-b { background: rgba(255, 196, 40, 0.45); border-color: rgba(255, 214, 90, 0.9); }
.face-btn.md-c { background: rgba(70, 140, 255, 0.45); border-color: rgba(120, 170, 255, 0.9); }
.face-btn.md-a.on { background: rgba(255, 90, 95, 0.9); transform: scale(0.94); }
.face-btn.md-b.on { background: rgba(255, 196, 40, 0.9); transform: scale(0.94); }
.face-btn.md-c.on { background: rgba(70, 140, 255, 0.9); transform: scale(0.94); }

.hud { position: absolute; top: max(6px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); font: 600 11px ui-monospace, Menlo, monospace; color: rgba(255, 255, 255, 0.55); pointer-events: none; text-shadow: 0 1px 2px #000; }
.menu-btn { position: absolute; top: max(6px, env(safe-area-inset-top)); right: calc(var(--side) + 6px); width: 36px; height: 30px; border-radius: 8px; border: 0; background: rgba(0, 0, 0, 0.35); display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 3px; z-index: 5; cursor: pointer; }
.menu-btn span { width: 16px; height: 2px; background: rgba(255, 255, 255, 0.7); border-radius: 1px; }
.toast { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); background: rgba(20, 20, 28, 0.92); border: 1px solid var(--line); padding: 8px 14px; border-radius: 10px; font-size: 14px; z-index: 40; }
.rotate { display: none; }

@media (orientation: portrait) and (pointer: coarse) {
  #game .rotate { display: flex; position: absolute; inset: 0; z-index: 50; background: var(--bg); align-items: center; justify-content: center; text-align: center; padding: 24px; font-size: 18px; font-weight: 600; }
}
