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

:root {
  --bg: #0d1117;
  --card-bg: #161b22;
  --card-front: #1c2333;
  --card-back: #1a2332;
  --accent: #58a6ff;
  --green: #3fb950;
  --red: #f85149;
  --orange: #d29922;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --border: #30363d;
  --radius: 12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Header ─────────────────────────────────── */
header {
  text-align: center;
  padding: 28px 20px 12px;
}
header h1 {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}
header h1 span { color: var(--accent); }

/* ── Tab bar ─────────────────────────────────── */
.tab-bar {
  display: flex;
  justify-content: center;
  gap: 0;
  padding: 0 20px 16px;
  max-width: 420px;
  margin: 0 auto;
}
.tab-bar button {
  flex: 1;
  background: var(--card-bg);
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 9px 18px;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.tab-bar button:first-child {
  border-radius: 8px 0 0 8px;
  border-right: none;
}
.tab-bar button:last-child {
  border-radius: 0 8px 8px 0;
}
.tab-bar button.active {
  background: var(--accent);
  color: #0d1117;
  border-color: var(--accent);
  font-weight: 600;
}
.tab-bar .tab-count {
  font-size: 0.7rem;
  opacity: 0.7;
  margin-left: 4px;
}

/* ── Stats bar ──────────────────────────────── */
.stats {
  display: flex;
  justify-content: center;
  gap: 24px;
  padding: 8px 20px 18px;
  font-size: 0.82rem;
  color: var(--text-dim);
}
.stats b { color: var(--text); }
.stats .got-it b { color: var(--green); }
.stats .missed b { color: var(--red); }

/* ── Category filter ────────────────────────── */
.filters {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  padding: 0 20px 20px;
  max-width: 760px;
  margin: 0 auto;
}
.filters button {
  background: var(--card-bg);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 14px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.15s;
}
.filters button:hover { border-color: var(--accent); color: var(--text); }
.filters button.active {
  background: var(--accent);
  color: #0d1117;
  border-color: var(--accent);
  font-weight: 600;
}

/* ── Card scene ─────────────────────────────── */
.card-scene {
  perspective: 900px;
  width: min(520px, calc(100% - 40px));
  min-height: 340px;
  margin: 0 auto 18px;
  cursor: pointer;
}

.card {
  position: relative;
  width: 100%;
  min-height: 340px;
  transition: transform 0.45s cubic-bezier(.4,.2,.2,1);
  transform-style: preserve-3d;
}
.card.flipped { transform: rotateY(180deg); }

.card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: var(--radius);
  padding: 28px 28px 24px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.card-front {
  background: var(--card-front);
  border: 1px solid var(--border);
}
.card-back {
  background: var(--card-back);
  border: 1px solid var(--accent);
  transform: rotateY(180deg);
}

.card-category {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin-bottom: 14px;
  font-weight: 600;
}

.card-front .question {
  font-size: 1.15rem;
  line-height: 1.55;
  font-weight: 500;
  flex: 1;
}

.card-back .answer {
  font-size: 0.88rem;
  line-height: 1.65;
  flex: 1;
  white-space: pre-wrap;
}
.card-back .answer code {
  background: rgba(110,118,129,0.2);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.84em;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
}
.card-back .answer pre {
  background: rgba(0,0,0,0.35);
  padding: 12px 14px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 10px 0;
  font-size: 0.82em;
  line-height: 1.5;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
}

.hint {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 14px;
}

/* ── Buttons ────────────────────────────────── */
.actions {
  display: flex;
  justify-content: center;
  gap: 14px;
  padding: 0 20px 14px;
}
.actions button {
  padding: 10px 28px;
  border-radius: 8px;
  border: none;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.15s;
}
.actions button:active { transform: scale(0.96); }

.btn-forgot {
  background: rgba(248,81,73,0.15);
  color: var(--red);
  border: 1px solid rgba(248,81,73,0.3) !important;
}
.btn-got-it {
  background: rgba(63,185,80,0.15);
  color: var(--green);
  border: 1px solid rgba(63,185,80,0.3) !important;
}
.btn-skip {
  background: var(--card-bg);
  color: var(--text-dim);
  border: 1px solid var(--border) !important;
}

/* ── Progress bar ───────────────────────────── */
.progress-wrap {
  max-width: 520px;
  margin: 0 auto 10px;
  padding: 0 20px;
}
.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s;
}

/* ── Keyboard hint ──────────────────────────── */
.keys-hint {
  text-align: center;
  padding: 6px 0 24px;
  font-size: 0.72rem;
  color: var(--text-dim);
}
kbd {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-family: inherit;
  font-size: 0.9em;
}

/* ── Mode toggle ────────────────────────────── */
.mode-toggle {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 0 20px 16px;
}
.mode-toggle button {
  background: var(--card-bg);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 14px;
  font-size: 0.76rem;
  cursor: pointer;
  transition: all 0.15s;
}
.mode-toggle button.active {
  background: var(--accent);
  color: #0d1117;
  border-color: var(--accent);
  font-weight: 600;
}

/* ── Completion screen ──────────────────────── */
.done-screen {
  text-align: center;
  padding: 60px 20px;
}
.done-screen h2 { font-size: 1.4rem; margin-bottom: 12px; }
.done-screen p { color: var(--text-dim); margin-bottom: 20px; }
.done-screen button {
  background: var(--accent);
  color: #0d1117;
  border: none;
  border-radius: 8px;
  padding: 10px 24px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

/* ── Live Editor / Console ──────────────────── */
.editor-panel {
  max-width: 520px;
  margin: 0 auto 18px;
  padding: 0 20px;
  display: none;
}
.editor-panel.visible { display: block; }
.editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.editor-header span {
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  font-weight: 600;
}
.editor-btns { display: flex; gap: 6px; }
.editor-btns button {
  background: var(--card-bg);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 0.74rem;
  cursor: pointer;
  transition: all 0.15s;
}
.editor-btns button:hover { border-color: var(--accent); color: var(--text); }
.btn-run {
  background: rgba(63,185,80,0.15) !important;
  color: var(--green) !important;
  border-color: rgba(63,185,80,0.3) !important;
  font-weight: 600;
}
.editor-textarea {
  width: 100%;
  min-height: 120px;
  background: #0d1117;
  color: #e6edf3;
  border: 1px solid var(--border);
  border-radius: 8px 8px 0 0;
  padding: 12px 14px;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 0.82rem;
  line-height: 1.5;
  resize: vertical;
  outline: none;
  tab-size: 2;
}
.editor-textarea:focus { border-color: var(--accent); }
.console-output {
  width: 100%;
  min-height: 50px;
  max-height: 200px;
  overflow-y: auto;
  background: #010409;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-top: 1px dashed var(--border);
  border-radius: 0 0 8px 8px;
  padding: 10px 14px;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 0.78rem;
  line-height: 1.5;
  white-space: pre-wrap;
}
.console-output .log-line { color: var(--text); }
.console-output .error-line { color: var(--red); }
.console-output .promise-line { color: var(--orange); }
.console-output .info-line { color: var(--accent); font-style: italic; }

/* ── Side nav (resources) ───────────────────── */
.sidebar-toggle {
  position: fixed;
  top: 12px;
  right: 12px;
  background: var(--card-bg);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 0.78rem;
  cursor: pointer;
  z-index: 1001;
  transition: all 0.15s;
}
.sidebar-toggle:hover { border-color: var(--accent); color: var(--text); }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1002;
}
.sidebar-overlay.open { display: block; }

.sidebar {
  position: fixed;
  top: 0;
  right: -340px;
  width: 320px;
  height: 100vh;
  background: var(--card-bg);
  border-left: 1px solid var(--border);
  z-index: 1003;
  overflow-y: auto;
  transition: right 0.25s ease;
  padding: 20px;
}
.sidebar.open { right: 0; }

.sidebar h3 {
  font-size: 0.85rem;
  font-weight: 600;
  margin: 18px 0 8px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.sidebar h3:first-child { margin-top: 0; }

.sidebar a {
  display: block;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.8rem;
  padding: 5px 0;
  border-bottom: 1px solid rgba(48,54,61,0.5);
  transition: color 0.1s;
  line-height: 1.4;
}
.sidebar a:hover { color: var(--accent); }
.sidebar .link-desc {
  font-size: 0.7rem;
  color: rgba(139,148,158,0.6);
}

/* ── Mobile responsive ──────────────────────── */
@media (max-width: 600px) {
  header {
    padding: 18px 12px 8px;
  }
  header h1 {
    font-size: 1.2rem;
  }

  .sidebar-toggle {
    top: 8px;
    right: 8px;
    padding: 5px 10px;
    font-size: 0.72rem;
  }

  .tab-bar {
    max-width: 100%;
    padding: 0 12px 12px;
  }
  .tab-bar button {
    padding: 8px 10px;
    font-size: 0.76rem;
  }

  .stats {
    gap: 12px;
    padding: 6px 12px 12px;
    font-size: 0.74rem;
    flex-wrap: wrap;
    justify-content: center;
  }

  .progress-wrap {
    padding: 0 12px;
  }

  .filters {
    padding: 0 12px 14px;
    gap: 5px;
  }
  .filters button {
    padding: 4px 10px;
    font-size: 0.72rem;
  }

  .mode-toggle {
    gap: 5px;
    padding: 0 12px 12px;
  }
  .mode-toggle button {
    padding: 4px 10px;
    font-size: 0.72rem;
  }

  .card-scene {
    width: calc(100% - 24px);
    min-height: 280px;
  }
  .card {
    min-height: 280px;
  }
  .card-face {
    padding: 18px 16px 16px;
  }
  .card-front .question {
    font-size: 1rem;
  }
  .card-back .answer {
    font-size: 0.8rem;
    line-height: 1.55;
  }
  .card-back .answer pre {
    padding: 8px 10px;
    font-size: 0.75em;
  }

  .actions {
    gap: 8px;
    padding: 0 12px 10px;
  }
  .actions button {
    padding: 8px 16px;
    font-size: 0.82rem;
  }

  .keys-hint {
    display: none;
  }

  .editor-panel {
    padding: 0 12px;
  }
  .editor-textarea {
    min-height: 100px;
    font-size: 0.76rem;
  }
  .editor-btns button {
    padding: 3px 8px;
    font-size: 0.7rem;
  }

  .sidebar {
    width: 85vw;
    right: -90vw;
  }

  .done-screen {
    padding: 40px 16px;
  }
  .done-screen h2 {
    font-size: 1.2rem;
  }
}

@media (max-width: 380px) {
  .stats {
    gap: 8px;
    font-size: 0.7rem;
  }
  .actions button {
    padding: 7px 12px;
    font-size: 0.78rem;
  }
  .tab-bar button {
    font-size: 0.72rem;
    padding: 7px 8px;
  }
}
