* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #0a0a0f;
  --surface: #16161f;
  --border: #2a2a3a;
  --text: #e8e8f0;
  --text-dim: #888898;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --correct: #22c55e;
  --wrong: #ef4444;
  --skipped: #666;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 20px;
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.screen {
  display: none;
  flex-direction: column;
  gap: 24px;
  flex: 1;
}

.screen.active {
  display: flex;
}

h1 {
  font-size: 28px;
  font-weight: 700;
  text-align: center;
  margin-top: 40px;
}

h2 {
  font-size: 22px;
  font-weight: 600;
  text-align: center;
}

.subtitle {
  text-align: center;
  color: var(--text-dim);
  margin-top: -12px;
}

/* Settings */
.setting {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.setting label {
  font-size: 14px;
  color: var(--text-dim);
  font-weight: 500;
}

.stepper {
  display: flex;
  align-items: center;
  gap: 4px;
}

.stepper input {
  width: 80px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 18px;
  font-weight: 600;
  padding: 10px 4px;
  -moz-appearance: textfield;
}

.stepper input::-webkit-inner-spin-button,
.stepper input::-webkit-outer-spin-button {
  -webkit-appearance: none;
}

.stepper-btn {
  flex: 1;
  padding: 10px 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.stepper-btn:active {
  background: var(--border);
}

/* Checkbox */
.setting input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin-right: 8px;
  vertical-align: middle;
  accent-color: var(--accent);
}

/* Buttons */
.btn-primary, .btn-secondary {
  padding: 14px 24px;
  border: none;
  border-radius: 12px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn-primary:active, .btn-secondary:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

/* Playback */
#screen-playback {
  align-items: center;
  justify-content: center;
}

#playback-status {
  text-align: center;
}

#digit-display {
  font-size: 120px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  min-height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#digit-display.countdown {
  color: var(--accent);
  font-size: 80px;
}

#progress-text {
  font-size: 16px;
  color: var(--text-dim);
  margin-top: 12px;
  font-variant-numeric: tabular-nums;
}

/* Recall */
#recall-input {
  width: 100%;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 20px;
  font-family: 'SF Mono', 'Menlo', monospace;
  letter-spacing: 4px;
  resize: vertical;
  line-height: 1.6;
}

#recall-input:focus {
  outline: none;
  border-color: var(--accent);
}

.recall-hint {
  font-size: 13px;
  color: var(--text-dim);
}

.recall-actions, .results-actions {
  display: flex;
  gap: 12px;
}

.recall-actions .btn-primary,
.recall-actions .btn-secondary,
.results-actions .btn-primary,
.results-actions .btn-secondary {
  flex: 1;
}

/* Results */
#score-summary {
  text-align: center;
  font-size: 18px;
  padding: 16px;
  background: var(--surface);
  border-radius: 12px;
}

#score-summary .score-big {
  font-size: 48px;
  font-weight: 700;
  display: block;
  margin-bottom: 4px;
}

#score-summary .score-detail {
  color: var(--text-dim);
  font-size: 14px;
}

#results-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  justify-content: flex-start;
  padding: 8px;
  background: var(--surface);
  border-radius: 12px;
  max-height: 300px;
  overflow-y: auto;
}

.result-cell {
  width: 28px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  font-family: 'SF Mono', 'Menlo', monospace;
  border-radius: 4px;
}

.result-cell.correct {
  background: rgba(34, 197, 94, 0.15);
  color: var(--correct);
}

.result-cell.wrong {
  background: rgba(239, 68, 68, 0.15);
  color: var(--wrong);
}

.result-cell.skipped {
  background: rgba(100, 100, 100, 0.1);
  color: var(--skipped);
}

/* Row separator in results */
.result-row-break {
  width: 100%;
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

/* History */
#history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 60vh;
  overflow-y: auto;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--surface);
  border-radius: 10px;
  font-size: 14px;
}

.history-item .h-date {
  color: var(--text-dim);
  font-size: 12px;
}

.history-item .h-score {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.history-item .h-detail {
  color: var(--text-dim);
  font-size: 12px;
}

/* Safe area for iPhone notch */
@supports (padding-top: env(safe-area-inset-top)) {
  #app {
    padding-top: calc(20px + env(safe-area-inset-top));
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }
}
