:root {
  --bg:           #080808;
  --bg-alt:       #0e0e0e;
  --text:         #c8c8c8;
  --muted:        #555;
  --heading:      #f0f0f0;
  --accent:       #00e87a;
  --accent-dim:   rgba(0, 232, 122, 0.12);
  --accent-border:rgba(0, 232, 122, 0.25);
  --border:       rgba(255, 255, 255, 0.07);
  --shadow:       0 0 0 1px rgba(255,255,255,0.04), 0 4px 24px rgba(0,0,0,0.6);
  --error:        #ff6b6b;
  --error-dim:    rgba(255, 107, 107, 0.14);

  --mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', ui-monospace, monospace;
  --sans: 'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif;

  font: 16px/1.6 var(--sans);
  color: var(--text);
  background: var(--bg);
  color-scheme: dark;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

*, *::before, *::after { box-sizing: border-box; }

body { margin: 0; }

#app {
  width: 640px;
  max-width: 100%;
  margin: 0 auto;
  padding: 32px 16px 64px;
}

h1, h2, h3 { font-family: var(--mono); color: var(--heading); line-height: 1.15; margin: 0 0 0.5em; }
p { margin: 0; }

/* ── Header ─────────────────────────────────────────────────────────── */

.header-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 8px;
  position: relative;
}

.header-row h1 {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.5px;
  text-align: center;
  margin: 0;
}

.header-row h1::before {
  content: '> ';
  color: var(--muted);
  font-weight: 400;
}

.header-row .help-btn {
  position: absolute;
  right: 0;
}

.help-btn {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  width: 22px;
  height: 22px;
  line-height: 20px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
}

.help-btn:hover {
  border-color: var(--accent-border);
  color: var(--accent);
}

.hint {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  margin-bottom: 32px;
}

/* ── Card ───────────────────────────────────────────────────────────── */

.card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  background: var(--bg-alt);
  box-shadow: var(--shadow);
}

.source-line {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 14px;
}

.source-line .accent { color: var(--accent); }

.code-display {
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.7;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  padding: 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  cursor: text;
  outline: none;
  min-height: 3em;
}

.code-display:focus {
  border-color: var(--accent-border);
}

.code-display .char-correct { color: var(--text); }
.code-display .char-incorrect { color: var(--error); background: var(--error-dim); border-radius: 2px; }
.code-display .char-pending { color: var(--muted); }
.code-display .char-cursor {
  border-left: 2px solid var(--accent);
  animation: blink 1s step-end infinite;
}
@keyframes blink { 50% { border-color: transparent; } }

/* Real input, visually hidden but focusable/typeable — a hidden input is
   more reliable across mobile keyboards and IME composition than trying
   to capture raw keydown events on a div. */
.sr-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

/* ── Stats ──────────────────────────────────────────────────────────── */

.stat-row {
  display: flex;
  justify-content: space-between;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stat-value {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 700;
  color: var(--heading);
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

/* ── Actions / buttons ──────────────────────────────────────────────── */

.actions {
  display: flex;
  justify-content: center;
  margin-top: 20px;
}

.btn {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.01em;
}

.btn:hover { border-color: var(--accent-border); color: var(--heading); }
.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #000;
  font-weight: 700;
}

.btn-primary:hover { background: #00ff88; border-color: #00ff88; color: #000; }

/* ── Result banner ──────────────────────────────────────────────────── */

.result-banner {
  text-align: center;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--accent);
  margin-top: 14px;
}

/* ── Help modal ─────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.88);
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  backdrop-filter: blur(4px);
}

/* Author CSS always wins over the UA stylesheet's [hidden]{display:none},
   so an unconditional `display: flex` above would keep this covering the
   whole viewport (and intercepting every click) even while `hidden` is
   set. Only apply flex layout when it isn't hidden. */
.modal-overlay:not([hidden]) {
  display: flex;
}

.modal-card {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  width: 100%;
  max-width: 420px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--heading);
}

.modal-card ul {
  padding-left: 1.2em;
  margin: 0;
}

.modal-card li { margin-bottom: 0.8em; font-size: 14px; line-height: 1.5; }
.modal-card li:last-child { margin-bottom: 0; }
