:root {
  --bg: #000;
  --fg: #ffffff;
  --card: #0a0a0a;
  --card-edge: rgba(255,255,255,0.06);
  --muted: rgba(255,255,255,0.72);
  --faint: rgba(255,255,255,0.42);
  --hairline: rgba(255,255,255,0.08);
  --btn-bg: #ffffff;
  --btn-fg: #000000;
  --new-red: #ff3b30;
}
html[data-theme="light"] {
  --bg: #f6f6f6;
  --fg: #000000;
  --card: #ffffff;
  --card-edge: rgba(0,0,0,0.06);
  --muted: rgba(0,0,0,0.72);
  --faint: rgba(0,0,0,0.42);
  --hairline: rgba(0,0,0,0.08);
  --btn-bg: #000000;
  --btn-fg: #ffffff;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: 'Onest', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background 0.4s ease, color 0.4s ease;
  min-height: 100vh;
}

/* --- top nav --- */
nav.top {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 18px 32px;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--hairline);
}
.wordmark {
  font-family: 'Fraunces', serif;
  font-weight: 900;
  font-size: 26px;
  letter-spacing: -0.025em;
  color: var(--fg);
  text-decoration: none;
  line-height: 1;
}
.nav-spacer { flex: 1; }
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--fg);
  text-decoration: none;
  font-size: 14px;
  opacity: 0.62;
  transition: opacity 0.2s;
}
.back-link:hover { opacity: 1; }
.back-link svg { width: 18px; height: 18px; stroke-width: 1.6; }
.nav-actions { display: flex; gap: 14px; align-items: center; }
.icon-btn {
  background: none;
  border: none;
  color: var(--fg);
  cursor: pointer;
  padding: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: opacity 0.2s;
  opacity: 0.85;
}
.icon-btn:hover { opacity: 1; }
.icon-btn svg { width: 24px; height: 24px; stroke-width: 1.5; }

/* ============================ HOME ============================ */
/* home fills exactly one viewport, never scrolls */
html.home-lock, html.home-lock body { height: 100%; overflow: hidden; }
html.home-lock body { min-height: 0; }
html.home-lock #app { height: 100%; display: flex; flex-direction: column; }
html.home-lock nav.top { flex: none; }

.home-main {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
  padding: clamp(20px, 3vh, 44px) 28px clamp(22px, 3.4vh, 48px);
  display: grid;
  grid-template-columns: minmax(340px, 40%) 1fr;
  gap: clamp(28px, 4vw, 64px);
  align-items: stretch;
}
.hero {
  align-self: center;
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 1.4vh, 16px);
  min-width: 0;
}
.hero-kicker {
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--faint);
}
.hero h1 {
  font-family: 'Fraunces', serif;
  font-weight: 900;
  font-size: clamp(38px, 5vw, 88px);
  line-height: 0.92;
  letter-spacing: -0.045em;
}
.hero p {
  font-size: clamp(14px, 1.45vw, 17px);
  color: var(--muted);
  max-width: 620px;
  line-height: 1.5;
}

.grid-wrap {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: clamp(12px, 1.6vh, 18px);
}
.grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: clamp(12px, 1.6vh, 18px);
}
.tile {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 104px;
  min-height: 0;
  min-width: 0;
  background: var(--card);
  border: 1px solid var(--card-edge);
  border-radius: 18px;
  overflow: hidden;
  text-decoration: none;
  color: var(--fg);
  transition: transform 0.16s ease, border-color 0.3s ease;
}
.tile:hover { transform: translateY(-3px); border-color: color-mix(in srgb, var(--fg) 18%, transparent); }
.tile-body { padding: clamp(16px, 2vh, 24px) 22px; display: flex; flex-direction: column; gap: 8px; min-width: 0; min-height: 0; overflow: hidden; }
.tile-title {
  font-family: 'Fraunces', serif;
  font-weight: 900;
  font-size: clamp(26px, 2.3vw, 36px);
  line-height: 0.95;
  letter-spacing: -0.03em;
}
.tile-tagline {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.tile-cta {
  margin-top: auto;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.tile-cta svg { width: 14px; height: 14px; stroke-width: 1.8; transition: transform 0.16s ease; }
.tile:hover .tile-cta svg { transform: translateX(4px); }
.tile-wave { position: relative; overflow: hidden; }
.tile-wave svg { position: absolute; inset: 0; width: 100%; height: 100%; }

/* full-width 7th game as a single line */
.tile-wide {
  flex: none;
  height: clamp(64px, 11vh, 104px);
  grid-template-columns: 1fr 160px;
}
.tile-wide .tile-body {
  flex-direction: row;
  align-items: center;
  gap: clamp(16px, 2.4vw, 40px);
  padding: 0 28px;
}
.tile-wide .tile-title { font-size: clamp(24px, 2.6vw, 34px); flex: none; }
.tile-wide .tile-tagline { -webkit-line-clamp: 1; flex: 1; }
.tile-wide .tile-cta { margin-top: 0; margin-left: auto; flex: none; }

.new-pill {
  position: absolute;
  top: 12px;
  right: 12px;
  background: var(--new-red);
  color: #fff;
  font-size: 10px;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 999px;
  line-height: 1;
  letter-spacing: 0.02em;
  z-index: 3;
}
.tile-wide .new-pill { top: 12px; right: 14px; }

/* ============================ GAME PAGE ============================ */
.game-main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 56px 24px 100px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(380px, 460px);
  gap: 56px;
  align-items: start;
}
.game-info { display: flex; flex-direction: column; gap: 26px; position: sticky; top: 96px; }
.game-info h1 {
  font-family: 'Fraunces', serif;
  font-weight: 900;
  font-size: clamp(72px, 11vw, 128px);
  line-height: 0.88;
  letter-spacing: -0.045em;
}
.game-info .tagline { font-size: 18px; color: var(--muted); max-width: 460px; line-height: 1.45; }
.card-spec {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px 32px;
  max-width: 500px;
}
.spec-row dt {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 5px;
  font-weight: 500;
}
.spec-row dd { font-size: 14px; color: var(--fg); line-height: 1.45; }
.controls-row { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; margin-top: 4px; }

.ios-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.ios-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.ios-toggle .track {
  width: 44px;
  height: 26px;
  background: color-mix(in srgb, var(--fg) 18%, transparent);
  border-radius: 999px;
  position: relative;
  transition: background 0.2s ease;
  flex-shrink: 0;
}
.ios-toggle .track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  background: #ffffff;
  border-radius: 50%;
  transition: transform 0.2s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}
.ios-toggle input:checked ~ .track { background: #34c759; }
.ios-toggle input:checked ~ .track::after { transform: translateX(18px); }

/* stage */
.game-stage {
  position: relative;
  min-height: 620px;
  background: var(--card);
  border: 1px solid var(--card-edge);
  border-radius: 24px;
  overflow: hidden;
}
.stage-wave {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  opacity: 0.9;
  transition: opacity 0.5s ease, filter 0.6s ease;
}
.game-stage.playing .stage-wave { opacity: 0.05; }
.intro-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  text-align: center;
  padding: 40px;
}
.intro-overlay .lead { font-size: 15px; color: var(--muted); max-width: 300px; }
.start-btn {
  background: var(--btn-bg);
  color: var(--btn-fg);
  border: none;
  border-radius: 999px;
  padding: 15px 40px;
  font: 500 15px 'Onest', sans-serif;
  cursor: pointer;
  text-transform: lowercase;
  letter-spacing: 0.01em;
  transition: transform 0.1s, opacity 0.2s;
}
.start-btn:hover { opacity: 0.92; }
.start-btn:active { transform: scale(0.97); }

.game-pane {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  padding: 26px 24px;
  gap: 12px;
  background: var(--card);
  overflow: hidden;
  font-family: 'Onest', sans-serif;
}
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--faint);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  flex-shrink: 0;
}
.game-exit {
  background: none;
  border: none;
  color: var(--faint);
  cursor: pointer;
  font: 500 11px 'Onest', sans-serif;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 4px;
}
.game-exit:hover { color: var(--fg); }
.game-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  min-height: 0;
  overflow-y: auto;
  text-align: center;
}
.game-footer {
  display: flex;
  justify-content: center;
  min-height: 44px;
  flex-shrink: 0;
}
.game-status { font-size: 12px; color: var(--faint); letter-spacing: 0.02em; }
.game-btn {
  background: var(--btn-bg);
  color: var(--btn-fg);
  border: none;
  border-radius: 999px;
  padding: 11px 24px;
  font: 500 13px 'Onest', sans-serif;
  cursor: pointer;
  text-transform: lowercase;
  letter-spacing: 0.01em;
  transition: transform 0.1s, opacity 0.2s;
}
.game-btn:hover { opacity: 0.92; }
.game-btn:active { transform: scale(0.96); }
.game-btn.ghost { background: transparent; color: var(--fg); border: 1px solid var(--card-edge); }
.game-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.game-btn:disabled:hover { opacity: 0.35; }
.score-big {
  font-family: 'Fraunces', serif;
  font-weight: 900;
  font-size: 72px;
  line-height: 1;
  letter-spacing: -0.03em;
  animation: scoreReveal 0.4s ease-out;
}
@keyframes scoreReveal {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.score-meta {
  font-size: 11px;
  color: var(--faint);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.score-rounds { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.score-rounds span {
  background: var(--card-edge);
  color: var(--fg);
  padding: 4px 10px;
  border-radius: 6px;
  font: 500 12px 'Onest', sans-serif;
  font-variant-numeric: tabular-nums;
}
.huge-display {
  font-family: 'Fraunces', serif;
  font-weight: 900;
  font-size: 56px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}

/* --- color --- */
.color-swatch { width: 240px; height: 130px; border-radius: 12px; border: 1px solid var(--card-edge); }
.color-swatch.sm { width: 90px; height: 64px; }
.color-sliders { width: 100%; max-width: 320px; display: flex; flex-direction: column; gap: 10px; }
.slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11px;
  color: var(--faint);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.slider-row span:first-child { min-width: 10px; }
.slider-row span:last-child { min-width: 30px; text-align: right; color: var(--fg); font-variant-numeric: tabular-nums; }
.color-sliders input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  background: color-mix(in srgb, var(--fg) 12%, transparent);
  height: 6px;
  border-radius: 999px;
  outline: none;
}
.color-sliders input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--fg);
  cursor: grab;
  border: 3px solid var(--card);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--fg) 30%, transparent);
  transition: transform 0.1s;
}
.color-sliders input[type="range"]::-webkit-slider-thumb:active { cursor: grabbing; transform: scale(1.18); }
.color-sliders input[type="range"]::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--fg); cursor: grab; border: 3px solid var(--card);
}
.swatch-pair { display: flex; gap: 16px; }
.swatch-col { display: flex; flex-direction: column; align-items: center; gap: 6px; }

/* --- sound --- */
.pitch-control { width: 100%; max-width: 280px; display: flex; flex-direction: column; gap: 14px; align-items: center; }
.pitch-control input[type="range"] { width: 100%; accent-color: var(--fg); }
.dual-bar { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* --- time --- */
.time-orb {
  width: 96px; height: 96px; border-radius: 50%;
  background: rgba(127,127,127,0.18);
  transition: transform 0.3s ease, background 0.3s ease;
}
.time-orb.active { background: var(--fg); transform: scale(1.2); }
.time-hold {
  user-select: none; -webkit-user-select: none;
  width: 140px; height: 140px; border-radius: 50%;
  background: var(--btn-bg); color: var(--btn-fg);
  border: none; cursor: pointer;
  font: 500 13px 'Onest', sans-serif;
  text-transform: lowercase; touch-action: none;
  transition: transform 0.08s, background 0.1s;
}
.time-hold.pressed { background: #ff3b30; color: #fff; transform: scale(0.95); }
.time-hold .hold-label { font: 500 13px 'Onest', sans-serif; pointer-events: none; }
.time-hold.pressed .hold-label {
  font-family: 'Fraunces', serif; font-weight: 900; font-size: 30px;
  font-variant-numeric: tabular-nums; letter-spacing: -0.03em;
}

/* --- shape --- */
.shape-canvas {
  width: min(300px, 80%); aspect-ratio: 1;
  background: rgba(127,127,127,0.06); border-radius: 12px; touch-action: none;
}
.shape-canvas svg { width: 100%; height: 100%; display: block; overflow: visible; }
.vertex { fill: #fff; stroke: var(--card); stroke-width: 2; cursor: grab; touch-action: none; }
.vertex.dragging { fill: #ff3b30; }
[data-theme="light"] .vertex { fill: #000; }
.vertex-num { font: 600 10px 'Onest', sans-serif; fill: var(--card); pointer-events: none; user-select: none; }
[data-theme="light"] .vertex-num { fill: #fff; }

/* --- rhythm --- */
.tap-pad {
  width: 150px; height: 150px; border-radius: 50%;
  background: var(--btn-bg); color: var(--btn-fg);
  border: none; cursor: pointer;
  font: 500 13px 'Onest', sans-serif; text-transform: lowercase;
  transition: transform 0.07s, background 0.05s;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.tap-pad.flash { background: #ff3b30; color: #fff; transform: scale(0.93); }
.tap-pad:disabled { cursor: default; opacity: 0.9; }
.tap-display {
  width: 150px; height: 150px; border-radius: 50%;
  background: rgba(127,127,127,0.18); color: var(--muted);
  display: grid; place-items: center;
  font: 500 13px 'Onest', sans-serif; text-transform: lowercase;
  transition: transform 0.07s, background 0.05s, color 0.05s;
}
.tap-display.flash { background: #ff3b30; color: #fff; transform: scale(1.06); }
.tap-progress { display: flex; gap: 6px; }
.tap-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--card-edge); transition: background 0.1s; }
.tap-dot.lit { background: var(--fg); }
.rhythm-compare { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* --- angle --- */
.dial-ring { width: 180px; height: 180px; cursor: grab; touch-action: none; }
.dial-ring:active { cursor: grabbing; }
.dial-svg { width: 100%; height: 100%; display: block; }
.angle-display {
  font-family: 'Fraunces', serif; font-weight: 900; font-size: 32px;
  font-variant-numeric: tabular-nums; letter-spacing: -0.02em;
}

/* --- position --- */
.grid-board { display: grid; grid-template-columns: repeat(10, 1fr); gap: 2px; width: min(260px, 80%); aspect-ratio: 1; }
.grid-cell { background: rgba(127,127,127,0.1); border-radius: 2px; cursor: pointer; transition: background 0.1s; }
.grid-cell:hover { background: rgba(127,127,127,0.2); }
.grid-cell.target { background: var(--fg); }
.grid-cell.placed { background: #ff3b30; }
.grid-cell.match { background: #34c759; }
.pos-legend {
  display: flex; gap: 14px; font-size: 10.5px; color: var(--faint);
  letter-spacing: 0.04em; align-items: center; flex-wrap: wrap; justify-content: center;
}
.pos-legend span { display: inline-flex; align-items: center; gap: 6px; }
.pos-legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.pos-legend i.match { background: #34c759; }
.pos-legend i.target { background: var(--fg); }
.pos-legend i.placed { background: #ff3b30; }

/* --- footer --- */
footer {
  padding: 28px 32px 40px;
  font-size: 12px;
  color: var(--faint);
  border-top: 1px solid var(--hairline);
  display: flex;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
}
footer a { color: inherit; text-decoration: none; transition: color 0.2s; }
footer a:hover { color: var(--fg); }
footer .sep { opacity: 0.6; }

/* --- responsive --- */
@media (max-width: 860px) {
  nav.top { padding: 14px 20px; }
  /* on small screens, let the home scroll — 7 tiles can't fit a phone viewport */
  html.home-lock, html.home-lock body { height: auto; overflow: visible; }
  html.home-lock #app { height: auto; display: block; }
  .home-main { display: block; padding: 40px 16px 72px; }
  .hero { margin-bottom: 40px; }
  .grid-wrap { height: auto; }
  .grid { display: flex; flex-direction: column; gap: 14px; }
  .tile { grid-template-columns: 1fr 84px; min-height: 170px; }
  .tile-wide { height: auto; grid-template-columns: 1fr 84px; }
  .tile-wide .tile-body { flex-direction: column; align-items: flex-start; gap: 8px; padding: 22px; }
  .tile-wide .tile-tagline { -webkit-line-clamp: 2; }
  .tile-wide .tile-cta { margin-left: 0; margin-top: auto; }
  .tile-wide .new-pill { top: 12px; right: 12px; transform: none; }
  .game-main { grid-template-columns: 1fr; gap: 32px; padding: 36px 16px 80px; }
  .game-info { position: static; }
  .card-spec { grid-template-columns: 1fr; gap: 18px; }
  .game-stage { min-height: 560px; }
}
