:root {
  color-scheme: dark;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0b1020;
  color: #f7f8ff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background:
    radial-gradient(circle at 20% 10%, rgba(85, 105, 255, .22), transparent 35%),
    radial-gradient(circle at 90% 90%, rgba(0, 211, 170, .16), transparent 36%),
    #0b1020;
}

.shell { width: min(92vw, 520px); padding: 36px 0; }
.hub-link { margin: 0 0 18px; }
.hub-link a { color: #9aa9ff; font-size: 14px; font-weight: 800; text-decoration: none; }
.eyebrow { margin: 0 0 8px; color: #8da0ff; font-weight: 800; letter-spacing: .12em; }
h1 { margin: 0; font-size: clamp(28px, 8vw, 44px); line-height: 1.08; }
.instruction { color: #b9c1dc; line-height: 1.7; }
a { color: #aeb9ff; }

.analytics-consent {
  margin: 14px 0;
  padding: 14px;
  border: 1px solid rgba(142, 160, 255, .42);
  border-radius: 14px;
  background: rgba(17, 24, 47, .88);
}
.analytics-consent p { margin: 7px 0 10px; color: #b9c1dc; font-size: 13px; line-height: 1.55; }
.consent-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.consent-actions button { min-height: 44px; padding: 9px; border: 0; border-radius: 10px; font: inherit; font-weight: 800; cursor: pointer; }
.consent-allow { color: #071222; background: #8ea0ff; }
.consent-decline { color: #f7f8ff; background: #293254; }
.analytics-state, .privacy-link, footer { color: #8f99b7; font-size: 12px; text-align: center; }
footer { margin-top: 18px; line-height: 1.5; }
.legal { line-height: 1.75; }

.game-card {
  padding: 22px;
  border: 1px solid rgba(255,255,255,.13);
  border-radius: 24px;
  background: rgba(17, 24, 47, .88);
  box-shadow: 0 24px 80px rgba(0,0,0,.32);
}

.level-label { color: #8da0ff; font-weight: 900; text-align: center; }
.challenge-head { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px; }
.challenge-head .level-label { text-align: left; }
.mode-label { padding: 5px 9px; border: 1px solid rgba(142,160,255,.5); border-radius: 999px; color: #cdd4ff; font-size: 11px; font-weight: 900; white-space: nowrap; }
.mode-label.is-generated { color: #071b15; border-color: #48e5b5; background: #48e5b5; }
.level-metrics { margin: 6px 0 10px; color: #b9c1dc; font-size: 12px; text-align: center; }
.progress-track { height: 7px; margin: 0 0 14px; overflow: hidden; border-radius: 999px; background: rgba(255,255,255,.12); }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #8ea0ff, #48e5b5); transition: width .25s ease; }

.status {
  min-height: 28px;
  margin-bottom: 16px;
  padding: 8px 10px;
  border-radius: 12px;
  font-weight: 900;
  text-align: center;
  transition: background .15s ease, color .15s ease, transform .15s ease;
}
.status.is-success { color: #071b15; background: #48e5b5; transform: scale(1.03); }
.status.is-error { color: #fff; background: #b82d4d; }
.grid { display: grid; grid-template-columns: repeat(var(--grid-size, 2), 1fr); gap: 9px; width: min(100%, 330px); margin: 0 auto; }
.tile {
  position: relative;
  aspect-ratio: 1;
  border: 0;
  border-radius: 14px;
  background: var(--tile-color, #293254);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.12);
  transition: transform .12s ease, opacity .18s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.tile[disabled] { cursor: default; }
.tile:not([disabled]):active { transform: scale(.92); }
.tile.is-hidden { opacity: .08; }
.tile.is-correct {
  z-index: 1;
  outline: 6px solid #48e5b5;
  box-shadow: 0 0 0 4px #071b15, 0 0 28px 12px rgba(72,229,181,.8);
  transform: scale(.9);
}
.tile.is-correct::after {
  content: "✓";
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  color: #fff;
  font-size: clamp(34px, 10vw, 72px);
  font-weight: 1000;
  line-height: 1;
  text-shadow: 0 3px 8px rgba(0,0,0,.75);
}
.tile.is-wrong {
  outline: 6px solid #ff6684;
  box-shadow: 0 0 22px 8px rgba(255,102,132,.65);
  transform: scale(.9);
}
.tile.is-wrong::after {
  content: "×";
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  color: #fff;
  font-size: clamp(34px, 10vw, 72px);
  font-weight: 1000;
  line-height: 1;
  text-shadow: 0 3px 8px rgba(0,0,0,.75);
}

button.primary, button.secondary {
  width: 100%; min-height: 48px; margin-top: 18px; padding: 14px 18px; border-radius: 14px;
  border: 0; font: inherit; font-weight: 900; cursor: pointer;
}
.primary { color: #071222; background: #8ea0ff; }
.secondary { color: #071222; background: #48e5b5; }
.music-toggle { display: block; width: max-content; min-height: 36px; margin: 10px auto 0; padding: 7px 12px; border: 1px solid rgba(255,255,255,.16); border-radius: 999px; color: #d8ddf2; background: rgba(255,255,255,.06); font: inherit; font-size: 12px; font-weight: 800; cursor: pointer; }
.music-toggle[aria-pressed="false"] { color: #9ba5c3; opacity: .82; }

.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 0; }
.metrics div { padding: 10px; border-radius: 12px; background: rgba(255,255,255,.06); text-align: center; }
.metrics dt { color: #99a5c8; font-size: 12px; }
.metrics dd { margin: 3px 0 0; font-size: 22px; font-weight: 900; }

@media (max-width: 420px) {
  .shell { width: min(94vw, 520px); padding: 20px 0; }
  h1 { font-size: clamp(27px, 8vw, 34px); }
  .instruction { margin: 12px 0; }
  .game-card { padding: 14px; border-radius: 18px; }
  .grid { gap: 6px; }
  .tile { border-radius: 10px; }
  .status { margin-bottom: 12px; }
  .consent-actions { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .tile { transition: none; }
}
