/* RGT Games — aligned with main platform shell (white/blue/red palette) */
:root {
  --bg: oklch(1 0 0);                     /* white */
  --bg-alt: oklch(0.96 0.005 220);        /* light blue-gray secondary */
  --ink: oklch(0.25 0.08 220);            /* primary blue #133c51 */
  --ink-2: oklch(0.40 0.06 220);
  --ink-3: oklch(0.55 0.04 220);
  --line: oklch(0.92 0.01 220);           /* platform border */
  --line-2: oklch(0.86 0.015 220);
  --accent: oklch(0.55 0.22 15);          /* platform red #E20D18 */
  --accent-ink: oklch(1 0 0);             /* white text on red */
  --signal: oklch(0.55 0.22 15);          /* same red — destructive/warn */
  --blue: oklch(0.25 0.08 220);
  --yellow: oklch(0.85 0.15 85);
  --black: oklch(0.18 0.08 220);          /* dark blue */
  --white: oklch(1 0 0);

  /* Platform radius scale: --radius = 0.75rem (12px) */
  --r-sm: 8px;
  --r-md: 10px;
  --r-lg: 12px;
  --r-xl: 16px;

  --font-ui: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Inter, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, "Space Mono", Consolas, monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  font-family: var(--font-ui);
  color: var(--ink);
  background: var(--bg);
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}
body {
  min-height: 100vh;
  min-height: 100dvh;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; padding: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#root { min-height: 100vh; min-height: 100dvh; }

/* ====== App shell ====== */
.app-shell {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 18px 120px;
  position: relative;
}
@media (min-width: 760px) {
  .app-shell { padding: 32px 28px 140px; max-width: 880px; }
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 0 18px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 22px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-size: 14px; letter-spacing: -0.01em;
}
.brand-mark {
  width: 32px; height: 32px;
  background: var(--ink); color: var(--white);
  border-radius: 8px;
  display: grid; place-items: center;
  font-weight: 700; font-size: 12px;
  letter-spacing: 0.04em;
}
.brand-name { font-weight: 600; }
.brand-sub { color: var(--ink-3); margin-left: 4px; font-size: 11px; }

.profile-pill {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-alt);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px 6px 6px;
  font-size: 13px;
  color: var(--ink);
}
.profile-pill-btn {
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.profile-pill-btn:hover {
  border-color: var(--ink-3);
  background: var(--white);
}
.profile-avatar {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent); color: var(--white);
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700;
}

/* Name prompt input */
.name-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  font-family: inherit;
  font-size: 16px;
  color: var(--ink);
  background: var(--white);
  margin: 8px 0 0;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.name-input:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 3px oklch(0.92 0.01 220 / 0.6);
}
.form-error {
  margin-top: 6px;
  font-size: 13px;
  color: var(--signal);
}

/* ====== Hub ====== */
.hub-hero {
  padding: 8px 0 24px;
}
.hub-eyebrow {
  font-size: 13px;
  color: var(--ink-3);
  margin-bottom: 8px;
  font-weight: 500;
}
.hub-title {
  font-size: clamp(28px, 6vw, 44px);
  line-height: 1.05;
  letter-spacing: -0.02em;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 12px;
}
.hub-title em {
  font-style: normal;
  color: var(--accent);
}
.hub-blurb {
  font-size: 15px;
  color: var(--ink-2);
  max-width: 52ch;
  line-height: 1.5;
  margin: 0 0 18px;
}

.progress-strip {
  display: flex; gap: 4px;
  margin: 14px 0 4px;
}
.progress-strip > div {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
}
.progress-strip > div.done { background: var(--ink); }
.progress-strip > div.current { background: var(--accent); }
.progress-meta {
  font-size: 12px;
  color: var(--ink-3);
  display: flex; justify-content: space-between;
  margin-top: 8px;
}

/* Levels list */
.levels {
  display: flex; flex-direction: column;
  gap: 12px;
  margin-top: 18px;
}
.level-card {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  gap: 14px;
  align-items: center;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 14px;
  text-align: left;
  transition: transform 0.12s ease, border-color 0.12s ease;
  width: 100%;
  position: relative;
  overflow: hidden;
}
.level-card:active { transform: scale(0.98); }
.level-card:hover { border-color: var(--ink-3); }
.level-card.locked { opacity: 0.5; }
.level-card.locked:active { transform: none; }
.level-card.complete { border-color: var(--accent); }

.level-num {
  width: 56px; height: 56px;
  border-radius: 12px;
  background: var(--bg-alt);
  border: 1px solid var(--line);
  display: grid; place-items: center;
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
  position: relative;
  flex-shrink: 0;
}
.level-card:hover .level-num {
  border-color: var(--ink-3);
}
.level-card.complete .level-num {
  background: oklch(0.96 0.005 220);
  border-color: var(--accent);
  color: var(--accent);
}
.level-num .robot-glyph {
  position: absolute; inset: 0;
  display: grid; place-items: center;
}

.level-info { min-width: 0; }
.level-cat {
  font-size: 12px;
  color: var(--ink-3);
  margin-bottom: 2px;
}
.level-name {
  font-size: 16px; font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.level-desc {
  font-size: 13px; color: var(--ink-2);
  line-height: 1.4;
}
.level-meta {
  display: flex; gap: 8px; align-items: center;
  margin-top: 8px;
  font-size: 12px;
  color: var(--ink-3);
}
.level-meta .dot { width: 3px; height: 3px; border-radius: 50%; background: var(--line-2); }
.level-best {
  font-size: 12px;
  text-align: right;
  color: var(--ink-3);
  flex-shrink: 0;
}
.level-best strong {
  display: block;
  color: var(--ink);
  font-size: 18px;
  font-weight: 700;
}
.level-card.locked .level-best::before {
  content: "🔒";
  font-size: 18px;
}

/* ====== Game screen ====== */
.game-screen {
  position: fixed; inset: 0;
  background: var(--bg);
  z-index: 50;
  display: flex; flex-direction: column;
  overflow: hidden;
}

.game-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  z-index: 2;
}
.icon-btn {
  width: 38px; height: 38px;
  border-radius: 12px;
  background: var(--bg-alt);
  border: 1px solid var(--line);
  display: grid; place-items: center;
  font-size: 18px;
}
.icon-btn:hover { border-color: var(--ink-3); }

.game-title-block {
  text-align: center;
  flex: 1;
  min-width: 0;
}
.game-title-block .cat {
  font-family: var(--font-mono);
  font-size: 10px; letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.game-title-block .nm {
  font-size: 15px; font-weight: 700;
  letter-spacing: -0.01em;
  margin-top: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* HUD */
.hud {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.hud-stat {
  display: flex; flex-direction: column;
  font-family: var(--font-mono);
}
.hud-stat .lbl {
  font-size: 9px; letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.hud-stat .val {
  font-size: 22px; font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
}
.hud-stat .val.warn { color: var(--signal); }
.hud-stat.center { align-items: center; }
.hud-stat.right { align-items: flex-end; }

/* Game body */
.game-body {
  flex: 1;
  display: flex; flex-direction: column;
  overflow: hidden;
  position: relative;
}
.field-wrap {
  flex: 1;
  display: grid; place-items: center;
  position: relative;
  overflow: hidden;
  padding: 12px;
  background: var(--bg-alt);
}
.field-wrap canvas, .field-wrap svg.field {
  max-width: 100%; max-height: 100%;
  width: auto; height: auto;
  border-radius: var(--r-md);
  box-shadow: 0 1px 0 rgba(0,0,0,0.04), 0 8px 30px rgba(0,0,0,0.05);
  background: var(--white);
  touch-action: none;
}

/* Controls */
.controls {
  padding: 14px 16px 18px;
  background: var(--bg);
  border-top: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px;
}
.dpad {
  position: relative;
  width: 130px; height: 130px;
}
.dpad .stick-base {
  position: absolute; inset: 0;
  border-radius: 50%;
  background: var(--bg-alt);
  border: 1px solid var(--line);
}
.dpad .stick-knob {
  position: absolute;
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--ink);
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  transition: transform 0.06s linear;
  box-shadow: 0 4px 12px rgba(0,0,0,0.18);
  pointer-events: none;
}
.dpad .stick-label {
  position: absolute; bottom: -22px;
  left: 0; right: 0; text-align: center;
  font-family: var(--font-mono);
  font-size: 10px; letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.action-btns {
  display: flex; flex-direction: column;
  gap: 10px; align-items: flex-end;
}
.btn-action {
  min-width: 92px;
  padding: 14px 22px;
  border-radius: 18px;
  background: var(--ink);
  color: var(--white);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.02em;
  display: flex; align-items: center; justify-content: center;
  gap: 8px;
}
.btn-action:active { transform: scale(0.97); }
.btn-action.accent {
  background: var(--accent);
  color: var(--ink);
}
.btn-action.signal {
  background: var(--signal); color: var(--white);
}
.btn-action[disabled] {
  opacity: 0.4; pointer-events: none;
}

/* Universal A/B action pad — used across every game */
.action-pad {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 12px;
  margin-left: auto;
}
.act-btn {
  position: relative;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 4px;
  width: 86px; height: 86px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.08s ease, background 0.15s ease;
  box-shadow: 0 2px 0 var(--line);
}
.act-btn:active, .act-btn.active {
  transform: translateY(2px);
  box-shadow: 0 0 0 var(--line);
}
.act-btn.a {
  background: var(--accent);
  border-color: transparent;
}
.act-btn.b {
  background: var(--surface);
  width: 70px; height: 70px;
}
.act-btn .key-cap {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  opacity: 0.6;
  font-weight: 700;
}
.act-btn .lbl {
  font-size: 12px;
  line-height: 1;
  text-align: center;
  padding: 0 6px;
  text-wrap: balance;
}
.act-btn .hint {
  display: none;
}
.act-btn[disabled] {
  opacity: 0.35;
  pointer-events: none;
}
@media (max-width: 480px) {
  .act-btn { width: 72px; height: 72px; }
  .act-btn.b { width: 60px; height: 60px; }
  .act-btn .lbl { font-size: 11px; }
}

/* ====== Tutorial overlay ====== */
.overlay {
  position: absolute; inset: 0;
  background: oklch(0.20 0.01 60 / 0.55);
  backdrop-filter: blur(4px);
  z-index: 10;
  display: grid; place-items: center;
  padding: 16px;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.overlay-card {
  background: var(--white);
  border-radius: var(--r-xl);
  padding: 22px 22px 18px;
  width: 100%;
  max-width: 440px;
  max-height: 90%;
  overflow: auto;
  border: 1px solid var(--line);
  box-shadow: 0 24px 60px rgba(0,0,0,0.18);
}
.overlay-card h2 {
  margin: 0 0 4px;
  font-size: 22px; font-weight: 700;
  letter-spacing: -0.02em;
}
.overlay-card .eyebrow {
  font-family: var(--font-mono);
  font-size: 10px; letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 8px;
}
.overlay-card p { margin: 0 0 12px; font-size: 14px; line-height: 1.5; color: var(--ink-2); }

.tut-steps {
  display: flex; flex-direction: column;
  gap: 8px;
  margin: 14px 0 18px;
}
.tut-step {
  display: grid; grid-template-columns: 28px 1fr; gap: 12px;
  align-items: flex-start;
}
.tut-step .n {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 12px; font-weight: 700;
  display: grid; place-items: center;
  margin-top: 1px;
}
.tut-step .t {
  font-size: 14px; line-height: 1.45; color: var(--ink);
}
.tut-step .t b { color: var(--ink); font-weight: 700; }

.scoring-table {
  background: var(--bg-alt);
  border-radius: var(--r-md);
  padding: 12px 14px;
  margin: 8px 0 16px;
  font-family: var(--font-mono);
  font-size: 12px;
}
.scoring-row {
  display: flex; justify-content: space-between;
  padding: 4px 0;
  border-bottom: 1px dashed var(--line-2);
}
.scoring-row:last-child { border-bottom: none; }
.scoring-row .pts { font-weight: 700; }
.scoring-row .pts.plus { color: var(--accent-ink); }
.scoring-row .pts.minus { color: var(--signal); }

.btn-primary {
  width: 100%;
  padding: 16px;
  background: var(--ink);
  color: var(--white);
  border-radius: 16px;
  font-weight: 700; font-size: 15px;
  letter-spacing: 0.02em;
}
.btn-primary:active { transform: scale(0.99); }
.btn-secondary {
  width: 100%;
  padding: 14px;
  background: var(--bg-alt);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 16px;
  font-weight: 600; font-size: 14px;
  margin-top: 8px;
}

/* Result screen */
.result {
  text-align: center;
  display: flex; flex-direction: column;
  align-items: center;
}
.result-ribbon {
  font-family: var(--font-mono);
  font-size: 11px; letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 8px;
}
.result-score {
  font-size: 88px;
  line-height: 1;
  font-weight: 700;
  letter-spacing: -0.04em;
  margin: 4px 0 6px;
  font-family: var(--font-mono);
}
.result-score.win { color: var(--accent-ink); }
.result-headline {
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}
.result-sub {
  font-size: 13px; color: var(--ink-3);
  margin-bottom: 18px;
  font-family: var(--font-mono);
}
.result-breakdown {
  width: 100%;
  background: var(--bg-alt);
  border-radius: var(--r-md);
  padding: 12px 14px;
  margin-bottom: 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  text-align: left;
}
.result-breakdown .row {
  display: flex; justify-content: space-between;
  padding: 4px 0;
}
.result-breakdown .row.total {
  border-top: 1px solid var(--line-2);
  margin-top: 4px;
  padding-top: 8px;
  font-weight: 700;
  font-size: 14px;
}

/* Pill chips */
.chip {
  display: inline-flex; align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg-alt);
  border: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-2);
}
.chip.live::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: var(--signal);
  animation: pulse 1s infinite;
}
@keyframes pulse { 50% { opacity: 0.3; } }

/* Leaderboard */
.leaderboard {
  margin-top: 32px;
}
.section-title {
  font-family: var(--font-mono);
  font-size: 11px; letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 12px;
  display: flex; justify-content: space-between;
  align-items: baseline;
}
.section-title .right { color: var(--ink-2); }

.lb-list { display: flex; flex-direction: column; gap: 6px; }
.lb-row {
  display: grid;
  grid-template-columns: 24px 1fr auto auto;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 14px;
}
.lb-row .rank {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-3);
}
.lb-row.you { border-color: var(--ink); }
.lb-row.you .rank { color: var(--ink); }
.lb-row .who { font-weight: 600; }
.lb-row .game {
  font-family: var(--font-mono);
  font-size: 11px; color: var(--ink-3);
}
.lb-row .pts {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 15px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--white);
  padding: 10px 18px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 12px;
  z-index: 200;
  pointer-events: none;
  animation: toast-in 0.3s ease;
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* Misc */
.row-flex { display: flex; gap: 10px; }
.row-flex > * { flex: 1; }
.spacer-sm { height: 8px; }
.spacer-md { height: 16px; }

/* Language switcher in topbar */
.lang-switch {
  display: inline-flex;
  background: var(--bg-alt);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px;
  gap: 0;
}
.lang-btn {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-3);
  letter-spacing: 0.06em;
  transition: background 0.15s, color 0.15s;
}
.lang-btn:hover { color: var(--ink); }
.lang-btn.active {
  background: var(--ink);
  color: var(--accent);
}

/* Game-specific tap targets */
.tap-zone {
  position: absolute;
  border-radius: 8px;
  display: grid; place-items: center;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
  transition: transform 0.1s ease, background 0.15s ease;
}
.tap-zone:active { transform: scale(0.94); }
.tap-zone.hot { background: var(--accent); }
.tap-zone.bad { background: var(--signal); color: var(--white); }
