:root {
  color-scheme: dark;
  --bg: #101923;
  --bg-top: #1e3244;
  --panel: #223445;
  --panel-strong: #162330;
  --canvas: #4b657a;
  --border: #5f768a;
  --text: #f3f7fb;
  --muted: #9fb2c4;
  --label: #e1eaf2;
  --accent: #5ee6b3;
  --accent-strong: #20c997;
  --accent-soft: #d2faea;
  --warm: #f2d28b;
  --info: #8fcbff;
  --warning: #ffb488;
  --expert: #d7bcff;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: radial-gradient(circle at top, var(--bg-top), var(--bg) 58%);
  color: var(--text);
}

.container {
  max-width: 920px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

h1 {
  margin: 0 0 8px;
  font-size: clamp(20px, 5vw, 28px);
}

h2 {
  margin: 0 0 8px;
}

.subtitle {
  color: var(--muted);
  margin: 0 0 20px;
  line-height: 1.6;
}

.panel {
  background: color-mix(in oklab, var(--panel), black 10%);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 20px 46px rgb(7 13 20 / 24%);
}

/* Collapsible instructions */
details.controls summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

details.controls summary::-webkit-details-marker {
  display: none;
}

details.controls summary::before {
  content: '▶';
  font-size: 10px;
  transition: transform 180ms;
}

details.controls[open] summary::before {
  transform: rotate(90deg);
}

details.controls p {
  margin: 10px 0 2px;
}

button {
  border: 0;
  padding: 12px 16px;
  border-radius: 10px;
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  color: #0d2a21;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: filter 120ms, transform 80ms, box-shadow 120ms;
  box-shadow:
    0 8px 18px rgb(32 201 151 / 22%),
    inset 0 1px 0 rgb(255 255 255 / 18%);
}

button:hover:not(:disabled) {
  filter: brightness(1.12);
  box-shadow:
    0 10px 22px rgb(32 201 151 / 28%),
    inset 0 1px 0 rgb(255 255 255 / 20%);
}

button:active:not(:disabled) {
  transform: scale(0.97);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.note {
  color: var(--muted);
  font-size: 13px;
}

.feedback-success {
  color: var(--accent-soft) !important;
  text-shadow: 0 0 12px rgb(88 197 154 / 38%);
  animation: pulseSuccess 480ms ease-out;
  font-size: clamp(24px, 4.4vw, 32px);
}

@keyframes pulseSuccess {
  0% {
    transform: scale(0.96);
    opacity: 0.55;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Stimulus section */
.stimulus-wrap {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.session-top {
  width: 100%;
}

.main-area {
  display: flex;
  gap: 16px;
  align-items: center;
}

.target-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 150px;
  flex-shrink: 0;
}

.target-label-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.options-area {
  flex: 1;
  min-width: 200px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.options-header {
  text-align: center;
}

.stimulus-label {
  font-weight: 600;
  color: var(--label);
}

.candidate-warmup-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(92%, 560px);
  transform: translate(-50%, -50%);
  z-index: 1;
  padding: 0;
  font-size: clamp(16px, 2vw, 20px);
  font-weight: 700;
  color: var(--warm);
  text-shadow: 0 2px 10px rgb(20 32 43 / 70%);
  line-height: 1.45;
  letter-spacing: 0.2px;
  text-align: center;
  pointer-events: none;
}

/* Difficulty badge */
.difficulty-badge {
  padding: 3px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.difficulty-badge.level-0 {
  background: rgb(143 203 255 / 18%);
  color: var(--info);
}

.difficulty-badge.level-1 {
  background: rgb(94 230 179 / 18%);
  color: var(--accent-soft);
}

.difficulty-badge.level-2 {
  background: rgb(255 180 136 / 18%);
  color: var(--warning);
}

.difficulty-badge.level-3 {
  background: rgb(215 188 255 / 18%);
  color: var(--expert);
}

/* Match count badge */
.match-count-badge {
  background: color-mix(in oklab, var(--panel-strong), var(--accent) 16%);
  border: 1px solid color-mix(in oklab, var(--border), var(--accent) 42%);
  border-radius: 10px;
  padding: 8px 12px;
  text-align: center;
  width: 100%;
  box-shadow: 0 0 16px rgb(32 201 151 / 18%);
}

.match-count-number {
  font-size: 44px;
  font-weight: 900;
  color: var(--accent-soft);
  line-height: 1;
  letter-spacing: -1px;
}

.match-count-label {
  font-size: 12px;
  color: var(--accent);
  margin-top: 2px;
}

/* Progress */
.progress-wrap {
  width: 100%;
}

.progress-start-btn {
  width: 100%;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: #c9d6e2;
  margin-bottom: 6px;
}

.progress-track {
  width: 100%;
  height: 10px;
  background: rgb(95 118 138 / 42%);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #8ff5cd, var(--accent-strong));
  transition: width 220ms ease;
}

/* Canvas */
canvas {
  display: block;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--canvas);
}

#targetCanvas {
  width: min(140px, 100%);
  height: auto;
}

#optionsCanvas {
  width: 100%;
  height: auto;
  touch-action: manipulation;
}

.options-stage {
  width: 100%;
  position: relative;
  margin: 0 auto;
  overflow: hidden;
}

/* Result cards */
.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.stat-card {
  background: var(--panel-strong);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 10px;
  text-align: center;
}

.stat-card.highlight {
  border-color: color-mix(in oklab, var(--accent), white 10%);
  background: color-mix(in oklab, var(--accent), var(--panel-strong) 78%);
  box-shadow: 0 12px 24px rgb(32 201 151 / 12%);
}

.stat-value {
  font-size: 22px;
  font-weight: 800;
  color: #f9fafb;
  line-height: 1.1;
}

.stat-label {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

/* History list */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}

.history-item {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--panel-strong);
  border: 1px solid var(--border);
  font-size: 14px;
}

.history-date {
  color: var(--muted);
  font-size: 12px;
  flex-shrink: 0;
}

.history-score {
  font-weight: 700;
  color: var(--accent-soft);
}

.history-stats {
  color: var(--label);
}

/* Celebration */
.celebration-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  z-index: 2;
}

.celebration-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: color-mix(in oklab, var(--panel-strong), black 6%);
  padding: 24px 34px;
  font-size: clamp(28px, 5vw, 40px);
  font-weight: 800;
  color: var(--accent-soft);
  text-shadow: 0 0 18px rgb(88 197 154 / 28%);
  animation: popIn 180ms ease-out;
  pointer-events: auto;
}

@keyframes popIn {
  from {
    transform: scale(0.92);
    opacity: 0.7;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@media (max-width: 720px) {
  .container {
    padding: 16px 12px 32px;
  }

  .panel {
    padding: 14px;
  }

  .main-area {
    flex-direction: column;
    gap: 14px;
  }

  .target-area {
    width: 100%;
    max-width: none;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    grid-template-areas:
      'label label label'
      'badge canvas spacer';
    align-items: center;
    column-gap: 12px;
    row-gap: 10px;
  }

  .target-label-row {
    grid-area: label;
  }

  #targetCanvas {
    grid-area: canvas;
    justify-self: center;
  }

  .match-count-badge {
    grid-area: badge;
    max-width: 240px;
    margin: 0;
    justify-self: end;
  }

  .target-area::after {
    content: '';
    grid-area: spacer;
  }

  .options-area {
    width: 100%;
    min-width: 0;
  }

  .candidate-warmup-hint {
    width: min(88%, 420px);
    font-size: clamp(15px, 4vw, 18px);
  }

  .celebration-card {
    padding: 18px 22px;
    font-size: clamp(24px, 7vw, 32px);
  }
}

@media (max-width: 480px) {
  body {
    font-size: 15px;
  }

  button {
    padding: 14px 16px;
  }

  .match-count-number {
    font-size: 36px;
  }

  .result-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .history-item {
    gap: 6px 10px;
    font-size: 13px;
  }
}
