:root {
  --bg: #0e1013;
  --panel: #1b2027;
  --panel-2: #232a33;
  --ink: #eef1f5;
  --ink-dim: #9aa5b1;
  --line: rgba(255, 255, 255, 0.08);
  --good: #3ddc97;
  --s0: #e5484d;
  --s1: #f2a93b;
  --s2: #c7d92b;
  --s3: #2bb3a3;
  --s4: #3b82f6;
  --s5: #8b5cf6;
  --s6: #e5399a;
  --s7: #57c7ff;
  --neutral: #7b8794;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  box-sizing: border-box;
}
:root[data-theme="light"] {
  --bg: #f4f2ee;
  --panel: #ffffff;
  --panel-2: #eceae4;
  --ink: #1c1e22;
  --ink-dim: #6b7178;
  --line: rgba(20, 20, 20, 0.1);
}
* { box-sizing: border-box; }
html, body {
  height: 100%;
  overflow: hidden; /* the game itself scrolls internally if it ever needs to — the page never does */
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', -apple-system, sans-serif;
  display: flex; justify-content: center;
}
h1, .display { font-family: 'Space Grotesk', 'Inter', sans-serif; }

.stage-label { font-size: 12px; color: var(--ink-dim); text-align: center; line-height: 1.5; }
.stage-label b { color: var(--ink); }

/* The game fills the real browser viewport edge-to-edge on a phone.
   100svh ("small viewport height") accounts for mobile browser chrome
   (address bar, etc.) so the layout never runs taller than what's
   actually visible — with 100vh as a fallback for older browsers.
   The max-width just keeps it from stretching absurdly wide if opened
   on a desktop browser during testing — it has no effect on a phone. */
.screen {
  width: 100%; max-width: 480px;
  height: 100vh;
  height: 100svh;
  background: var(--bg);
  position: relative; display: flex; flex-direction: column;
  padding: calc(16px + env(safe-area-inset-top, 0px)) 18px calc(14px + env(safe-area-inset-bottom, 0px));
  overflow-y: auto; /* safety net only — normal play should never need to scroll */
}

/* ---------------- landscape guard ---------------- */
/* This game is portrait-only. On a real Android build this gets locked
   properly (screenOrientation="portrait" in the app manifest); on the
   web, the best we can do is detect it and ask the player to rotate back. */
.rotate-guard {
  display: none;
  position: fixed; inset: 0; z-index: 50;
  background: var(--bg);
  color: var(--ink);
  align-items: center; justify-content: center;
  text-align: center;
  padding: 24px;
  font-size: 15px;
  line-height: 1.5;
}
@media (orientation: landscape) and (max-height: 500px) {
  .rotate-guard { display: flex; }
  .screen { display: none; }
}

.field { margin-top: 14px; }
.field label { display: block; font-size: 12px; color: var(--ink-dim); margin-bottom: 6px; }
input[type=text], select {
  width: 100%; background: var(--panel); border: 1px solid var(--line); color: var(--ink);
  font-size: 14px; padding: 11px 12px; border-radius: 9px; font-family: inherit;
}
.row2 { display: flex; gap: 8px; }
.row2 > div { flex: 1; }

.screen-top { display: flex; justify-content: space-between; align-items: center; font-size: 10px; color: var(--ink-dim); margin-bottom: 8px; }
.deck-pill { background: var(--panel); border: 1px solid var(--line); padding: 4px 8px; border-radius: 100px; }
.deck-pill b { color: var(--ink); }

.card-zone { flex: 1; display: flex; flex-direction: column; align-items: stretch; justify-content: center; min-height: 0; }
.held-card {
  flex: 1; min-height: 0; border-radius: 24px; padding: 14px 14px;
  display: flex; flex-direction: column; justify-content: space-between;
}
.held-card.ink-light { color: #ffffff; }
.held-card.ink-dark { color: #161616; }
.card-face { display: flex; flex-direction: column; align-items: center; flex-shrink: 0; }
.card-face.mirrored { transform: rotate(180deg); }
.card-face .glyph-box {
  width: clamp(64px, 16vh, 112px); height: clamp(64px, 16vh, 112px); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; margin-bottom: clamp(8px, 2vh, 16px);
  color: currentColor; filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.15));
}
.card-face .glyph-box svg { width: 100%; height: 100%; display: block; }
.card-face .topic { font-size: clamp(18px, 4.5vh, 30px); font-weight: 700; line-height: 1.2; text-align: center; color: currentColor; padding: 0 4px; }

.empty-state { text-align: center; color: var(--ink-dim); font-size: 13px; line-height: 1.5; padding: 0 8px; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.empty-state .big { font-size: 30px; margin-bottom: 10px; }

.points-strip { text-align: center; font-size: 12px; color: var(--ink-dim); margin-top: 8px; }
.points-strip b { color: var(--ink); font-weight: 700; font-size: 14px; }

.action-btn { width: 100%; padding: 15px; border-radius: 13px; border: none; font-size: 14.5px; font-weight: 700; cursor: pointer; font-family: 'Space Grotesk', inherit; margin-top: 14px; }
.action-btn.primary { background: linear-gradient(180deg, #fff, #e9edf2); color: #12151a; box-shadow: 0 5px 0 rgba(0, 0, 0, 0.28); }
.action-btn.secondary { background: var(--panel-2); color: var(--ink); border: 1px solid var(--line); }
.action-btn:active { transform: translateY(2px); }
.action-btn.disabled { background: var(--panel); color: var(--ink-dim); border: 1px solid var(--line); cursor: default; }

.setup-btn { margin-top: auto; }

.race-sheet { position: absolute; left: 0; right: 0; bottom: 0; background: var(--panel); border-top: 1px solid var(--line); border-radius: 22px 22px 0 0; padding: 18px 16px 20px; box-shadow: 0 -12px 30px rgba(0, 0, 0, 0.4); }
.race-sheet .tag { font-size: 11px; color: var(--ink-dim); text-align: center; margin-bottom: 10px; }
.race-btns { display: flex; flex-direction: column; gap: 7px; margin-top: 10px; }
.race-btns button { padding: 12px; border-radius: 10px; border: none; font-weight: 600; font-size: 13px; font-family: inherit; cursor: pointer; }
.btn-i-won { background: var(--good); color: #062017; }
.btn-i-lost { background: var(--panel-2); color: var(--ink); border: 1px solid var(--line); }
.btn-tie { background: var(--panel-2); color: var(--ink-dim); border: 1px solid var(--line); }
.countdown { text-align: center; font-size: 40px; font-weight: 700; padding: 16px 0; font-family: 'Space Grotesk', sans-serif; }

.link-btn { background: none; border: none; color: var(--ink-dim); font-size: 11.5px; text-decoration: underline; cursor: pointer; margin-top: 10px; font-family: inherit; }
.back-btn { background: none; border: none; color: var(--ink-dim); font-size: 12px; cursor: pointer; font-family: inherit; padding: 0; display: flex; align-items: center; gap: 4px; }

.theme-toggle { display: flex; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 100px; padding: 3px; align-self: flex-end; }
.theme-toggle button { border: none; background: none; color: var(--ink-dim); font-size: 11px; padding: 5px 10px; border-radius: 100px; cursor: pointer; font-family: inherit; }
.theme-toggle button.active { background: var(--panel-2); color: var(--ink); }
.intro-title { font-size: clamp(20px, 5vh, 22px); font-weight: 700; margin-top: 12px; text-align: center; }
.intro-sub { font-size: 12px; color: var(--ink-dim); text-align: center; margin-top: 6px; line-height: 1.5; }
.steps { margin-top: clamp(10px, 3vh, 20px); display: flex; flex-direction: column; gap: clamp(6px, 1.8vh, 12px); flex: 1; justify-content: flex-start; }
.step { display: flex; gap: 10px; align-items: flex-start; }
.step .n { width: 22px; height: 22px; border-radius: 50%; background: var(--panel-2); color: var(--ink); font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0; margin-top: 1px; }
.step .t { font-size: 12.5px; line-height: 1.5; color: var(--ink); padding-top: 2px; }
.step .t b { color: var(--ink); }

.loading-state { flex: 1; display: flex; align-items: center; justify-content: center; text-align: center; color: var(--ink-dim); font-size: 13px; padding: 0 20px; }
