:root {
  color-scheme: dark;
  --bg: #111111;
  --panel: #1b1b1b;
  --panel-strong: #222222;
  --line: #323232;
  --text: #f4f0e8;
  --muted: #b8afa0;
  --accent: #6dd3a6;
  --accent-strong: #ffd166;
  --danger: #ff7b72;
  --stage: #080808;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", "PingFang SC", sans-serif;
  background:
    radial-gradient(circle at top, rgba(109, 211, 166, 0.1), transparent 26%),
    radial-gradient(circle at bottom right, rgba(255, 209, 102, 0.12), transparent 24%),
    var(--bg);
  color: var(--text);
}

button, input, select { font: inherit; }

.app-shell {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  gap: 20px;
  padding: 20px;
  min-height: 100vh;
}

.sidebar, .stage-frame, .panel, .info-card {
  background: rgba(27, 27, 27, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.sidebar {
  display: grid;
  align-content: start;
  grid-auto-rows: max-content;
  gap: 16px;
  padding: 20px;
}

.brand h1, .stage-topbar h2, .panel h2, .info-card h3 { margin: 0; }

.eyebrow, .bar-label {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.subtitle, .hint, .info-card p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.panel { padding: 16px; }
.panel.compact { padding-bottom: 14px; }

.mode-list, .difficulty-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.mode-button, .difficulty-button {
  display: grid;
  gap: 4px;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #161616;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.2s ease, transform 0.2s ease;
}

.mode-button:hover, .mode-button:focus-visible,
.difficulty-button:hover, .difficulty-button:focus-visible {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.mode-button.active, .difficulty-button.active {
  border-color: var(--accent-strong);
  background: #202020;
}

.mode-button span, .difficulty-button span {
  color: var(--muted);
  font-size: 14px;
}

.primary-button, .secondary-button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.primary-button {
  background: var(--accent);
  color: #0d2219;
  font-weight: 700;
}

.secondary-button {
  background: #303030;
  color: var(--text);
}

.secondary-button:disabled, .primary-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.stats-header, .response-bar, .info-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.stats-grid {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.metric-card {
  padding: 14px;
  border-radius: 8px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
}

.metric-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.metric-card strong { font-size: 22px; }

.status-pill {
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--line);
}
.status-pill.idle { color: var(--muted); }
.status-pill.running { color: var(--accent); border-color: rgba(109, 211, 166, 0.45); }
.status-pill.finished { color: var(--accent-strong); border-color: rgba(255, 209, 102, 0.4); }

.main-stage {
  display: grid;
  grid-template-rows: minmax(72vh, 1fr) auto;
  gap: 20px;
}

.stage-frame {
  position: relative;
  display: grid;
  grid-template-rows: auto auto minmax(72vh, 1fr) auto;
  padding: 20px;
  min-height: 0;
}

.stage-topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.stage-topbar-actions {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.stage-meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.stage-timer-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 52px;
}

.stage-timer {
  font-size: clamp(28px, 3.4vw, 40px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0;
  color: var(--accent-strong);
  text-align: center;
}

.stage-meta span {
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  min-width: 92px;
  text-align: center;
}

.stop-button {
  min-width: 112px;
}

.stage-feedback {
  position: absolute;
  left: 20px;
  right: 20px;
  top: 108px;
  min-height: 24px;
  display: flex;
  align-items: center;
  font-weight: 700;
  pointer-events: none;
  z-index: 3;
}

.stage-feedback.is-hidden { opacity: 0; visibility: hidden; }
.stage-feedback.success { color: #9ff0cb; }
.stage-feedback.error, .stage-feedback.miss { color: #ffb0ab; }

.stage {
  position: relative;
  margin: 24px 0 18px;
  min-height: min(78vh, 920px);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #2f2f2f;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent), var(--stage);
}

.stage.feedback-success { box-shadow: inset 0 0 0 2px rgba(109, 211, 166, 0.5); }
.stage.feedback-error, .stage.feedback-miss { box-shadow: inset 0 0 0 2px rgba(255, 123, 114, 0.5); }

.stage-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 20px;
  background: rgba(8, 8, 8, 0.74);
  z-index: 5;
}

.overlay-content {
  display: grid;
  justify-items: center;
  gap: 16px;
}

.stage-overlay.hidden, .hidden { display: none; }
.overlay-title { font-size: 24px; margin: 0 0 10px; }
.overlay-copy { margin: 0; max-width: 460px; line-height: 1.6; color: var(--muted); }
.overlay-button { min-width: 180px; padding: 0 22px; }

.stimulus, .focus-target {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
}

.stimulus {
  font-size: clamp(88px, 12vw, 138px);
  line-height: 1;
  letter-spacing: 0;
  user-select: none;
}

.focus-target {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 32px rgba(109, 211, 166, 0.4);
}

.focus-target.alert {
  background: var(--accent-strong);
  box-shadow: 0 0 42px rgba(255, 209, 102, 0.5);
}

.distractor-layer { position: absolute; inset: 0; }
.distractor { position: absolute; user-select: none; pointer-events: none; }
.distractor-text { color: rgba(244, 240, 232, 0.78); transform: translate(-50%, -50%); }
.distractor-image { border-radius: 6px; box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28); }

.schulte-board {
  position: absolute;
  inset: 24px;
  display: grid;
  grid-template-columns: repeat(var(--grid-size, 5), minmax(0, 1fr));
  gap: 12px;
  align-content: center;
}

.schulte-cell {
  min-height: 92px;
  border: 1px solid rgba(244, 240, 232, 0.12);
  border-radius: 8px;
  background: #171717;
  color: var(--text);
  font-size: clamp(22px, 3vw, 34px);
  font-weight: 700;
  cursor: pointer;
}

.schulte-cell.done {
  background: rgba(109, 211, 166, 0.18);
  color: #9ff0cb;
  border-color: rgba(109, 211, 166, 0.35);
}

.schulte-cell.press-correct {
  background: rgba(109, 211, 166, 0.28);
  color: #b6f4d9;
  border-color: rgba(109, 211, 166, 0.7);
}

.schulte-cell.press-error {
  background: rgba(255, 123, 114, 0.24);
  color: #ffd2ce;
  border-color: rgba(255, 123, 114, 0.72);
}

.response-bar {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
  gap: 16px;
  padding: 14px 16px;
  border-radius: 8px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
}

.response-bar strong { display: block; margin-top: 4px; }

.info-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 12px;
}

.info-card { overflow: hidden; align-items: stretch; }
.info-card img { width: 36%; min-height: 100%; object-fit: cover; }
.info-card div { padding: 16px; }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .main-stage { order: -1; grid-template-rows: auto auto; }
  .sidebar { order: 1; }
}

@media (max-width: 720px) {
  .app-shell { padding: 12px; gap: 12px; }
  .sidebar, .stage-frame { padding: 14px; }
  .stage { min-height: 62vh; }
  .schulte-board { inset: 16px; gap: 8px; }
  .schulte-cell { min-height: 64px; }
  .stats-grid, .info-strip { grid-template-columns: 1fr; }
  .info-card { display: grid; }
  .info-card img { width: 100%; aspect-ratio: 16 / 9; }
  .response-bar, .stage-topbar, .stage-topbar-actions {
    align-items: flex-start;
    flex-direction: column;
  }
  .stage-timer-wrap { min-height: 44px; }
  .stage-feedback { left: 14px; right: 14px; top: 118px; }
}
