:root {
  color-scheme: dark;
  --bg: #111113;
  --surface: #1a1a1e;
  --surface-2: #232328;
  --ink: #e4e2de;
  --muted: #8a857e;
  --line: #2e2e33;
  --accent: #3ecaad;
  --accent-soft: rgba(62, 202, 173, 0.12);
  --danger: #e85d4a;
  --danger-soft: rgba(232, 93, 74, 0.12);
  --success: #3ecaad;
  --radius: 8px;
  font-family: -apple-system, "Inter", "Segoe UI", sans-serif;
}

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

body {
  background: var(--bg);
  color: var(--ink);
  height: 100vh;
  overflow: hidden;
}

/* ── Topbar ────────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
  height: 48px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.topbar-left h1 {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-meta {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.topbar-sig code {
  font-size: 11px;
  color: var(--muted);
  background: var(--surface-2);
  padding: 2px 8px;
  border-radius: 4px;
  font-family: 'SF Mono', 'Fira Code', monospace;
}

.sidebar-toggle {
  background: none;
  border: none;
  color: var(--ink);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}
.sidebar-toggle:hover { background: var(--surface-2); }

/* ── Progress bar ──────────────────────────────────────────────────────── */

.progress-bar-wrap {
  width: 80px;
  height: 4px;
  background: var(--surface-2);
  border-radius: 2px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s;
}

.progress-text {
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ── Workspace ─────────────────────────────────────────────────────────── */

.workspace {
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: calc(100vh - 48px);
  overflow: hidden;
}

.workspace.sidebar-open {
  grid-template-columns: 260px 1fr 1fr;
}

/* ── Sidebar drawer ────────────────────────────────────────────────────── */

.sidebar {
  display: none;
  background: var(--surface);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  flex-direction: column;
}

.sidebar-open .sidebar {
  display: flex;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.sidebar-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
  padding: 0 4px;
}

.sidebar-body {
  padding: 8px;
}

.module-group {
  margin-bottom: 4px;
}

.module-heading {
  padding: 8px 12px;
  cursor: pointer;
  border-radius: var(--radius);
  font-size: 13px;
  display: flex;
  gap: 8px;
  align-items: center;
  list-style: none;
}
.module-heading::-webkit-details-marker { display: none; }
.module-heading:hover { background: var(--surface-2); }

.module-kicker {
  font-size: 10px;
  color: var(--accent);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.lesson-links {
  display: grid;
  gap: 2px;
  padding: 4px 0 8px 12px;
}

.lesson-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  border: none;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  border-radius: 6px;
  text-align: left;
}
.lesson-link:hover { background: var(--surface-2); }

.lesson-link.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.lesson-link.completed .lesson-link-order {
  color: var(--accent);
}

.lesson-link-order {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  min-width: 18px;
  text-align: center;
}

/* ── Instructions panel ────────────────────────────────────────────────── */

.instructions-panel {
  overflow-y: auto;
  padding: 24px;
  border-right: 1px solid var(--line);
}

.instructions-panel h2 {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  margin-bottom: 12px;
}

.instructions-panel h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 20px 0 8px;
}

.instructions-panel p {
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink);
}

.checks-list {
  list-style: none;
  padding: 0;
}

.checks-list li {
  padding: 6px 0;
  font-size: 13px;
  line-height: 1.5;
  border-bottom: 1px solid var(--line);
}
.checks-list li:last-child { border-bottom: none; }

.checks-list code {
  font-size: 12px;
  background: var(--surface-2);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: 'SF Mono', 'Fira Code', monospace;
}

/* ── Hints ─────────────────────────────────────────────────────────────── */

.hints-section {
  margin-top: 16px;
}

.hint-btn {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
  margin-right: 6px;
  margin-bottom: 6px;
}
.hint-btn:hover { border-color: var(--accent); }
.hint-btn.open {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.hint-body {
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink);
  margin-top: 8px;
  padding: 10px 14px;
  background: var(--surface-2);
  border-radius: var(--radius);
}

/* ── Go Reference ──────────────────────────────────────────────────────── */

.go-reference {
  margin-top: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.go-reference summary {
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  color: var(--accent);
  user-select: none;
}
.go-reference summary:hover { background: var(--accent-soft); border-radius: var(--radius); }
.go-reference[open] summary { border-bottom: 1px solid var(--line); border-radius: var(--radius) var(--radius) 0 0; }

.reference-list {
  list-style: none;
  padding: 6px 14px;
}

.reference-list li {
  padding: 4px 0;
  font-size: 12px;
  line-height: 1.4;
  border-bottom: 1px solid var(--line);
}
.reference-list li:last-child { border-bottom: none; }

.reference-list code {
  font-size: 11px;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  white-space: nowrap;
}

.ref-desc { color: var(--muted); font-size: 11px; }

/* ── Editor panel ──────────────────────────────────────────────────────── */

.editor-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.editor-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  gap: 8px;
  flex-shrink: 0;
}

.editor-nav, .editor-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.btn-ghost {
  background: none;
  border: 1px solid var(--line);
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
}
.btn-ghost:hover { background: var(--surface-2); }
.btn-ghost:disabled { opacity: 0.3; cursor: default; }

.btn-reset { color: var(--muted); border-color: transparent; }
.btn-reset:hover { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }

.btn-primary {
  background: var(--accent);
  border: none;
  color: #111;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 18px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}
.btn-primary:hover { filter: brightness(1.1); }
.btn-primary:disabled { opacity: 0.5; cursor: default; }

.btn-primary kbd {
  font-size: 10px;
  background: rgba(0,0,0,0.2);
  padding: 2px 5px;
  border-radius: 3px;
  font-family: inherit;
}

/* ── CodeMirror container ──────────────────────────────────────────────── */

.cm-wrapper {
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

.cm-wrapper .cm-editor {
  height: 100%;
}

/* ── Results ───────────────────────────────────────────────────────────── */

.results-panel {
  flex-shrink: 0;
  max-height: 45%;
  overflow-y: auto;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.results-panel h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 8px;
}

.result-list {
  list-style: none;
  padding: 0;
}

.result-list li {
  display: grid;
  gap: 4px;
  padding: 8px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--line);
}
.result-list li:last-child { border-bottom: none; }

.result-list li.passed strong { color: var(--accent); }
.result-list li.failed strong { color: var(--danger); }

.terminal {
  overflow: auto;
  padding: 12px;
  border-radius: var(--radius);
  background: #0d0d0f;
  color: #c8c4bb;
  font: 12px/1.5 'SF Mono', 'Fira Code', monospace;
  max-height: 160px;
  margin-top: 8px;
}

/* ── Status banners ────────────────────────────────────────────────────── */

.status-banner {
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  margin-bottom: 10px;
}

.status-banner.success {
  background: var(--accent-soft);
  color: var(--accent);
}

.status-banner.error {
  background: var(--danger-soft);
  color: var(--danger);
}

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

code {
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
}

/* ── Kata suggestions ──────────────────────────────────────────────────── */

.kata-suggestions {
  margin-top: 12px;
  display: grid;
  gap: 6px;
}

.kata-suggestions-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 4px;
}

.kata-suggestion {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  text-align: left;
}
.kata-suggestion:hover { filter: brightness(1.15); }
.kata-suggestion strong { color: var(--accent); }
.kata-suggestion span { color: var(--muted); font-size: 12px; }

.kata-next-actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
}

.btn-back-to-lesson {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent);
  font: inherit;
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 6px;
  cursor: pointer;
}
.btn-back-to-lesson:hover { filter: brightness(1.1); }

.kata-topbar { border-bottom-color: var(--accent); }

/* ── Inline katas on lesson page ───────────────────────────────────────── */

.kata-inline-section {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.kata-inline-desc {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 12px;
}

.kata-inline-skill {
  margin-bottom: 10px;
}

.kata-inline-skill-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.kata-inline-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  margin-bottom: 4px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  text-align: left;
}

.kata-inline-btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.kata-inline-btn.completed {
  border-color: var(--accent);
  opacity: 0.7;
}

.kata-inline-status {
  font-size: 10px;
  color: var(--accent);
  min-width: 14px;
}

.kata-kicker { color: #e0a830 !important; }

.kata-group { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 8px; }

.kata-skill-group { margin-bottom: 8px; }

.kata-skill-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 4px 12px 2px;
}

.kata-link { font-size: 12px !important; }

/* ── Cheat Sheet Modal ─────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-content {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  width: 90vw;
  max-width: 900px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}

.modal-header h2 {
  font-size: 16px;
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 24px;
  cursor: pointer;
  padding: 0 4px;
}

.modal-body {
  overflow-y: auto;
  padding: 20px;
}

.cheat-category {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  margin: 24px 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}

.cheat-category:first-child { margin-top: 0; }

.cheat-entry {
  margin-bottom: 16px;
}

.cheat-desc {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}

.cheat-comparison {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.cheat-col {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cheat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}

.cheat-code {
  margin: 0;
  padding: 8px 10px;
  border-radius: 6px;
  font: 12px/1.5 'SF Mono', 'Fira Code', monospace;
  overflow-x: auto;
  white-space: pre;
}

.cheat-code.ts {
  background: #1e1e2e;
  color: #cdd6f4;
}

.cheat-code.go {
  background: #1a1a1e;
  color: #98c379;
}

/* ── Home page ─────────────────────────────────────────────────────────── */

.home {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 24px;
  overflow-y: auto;
  height: 100vh;
}

.home-hero {
  position: relative;
  padding: 80px 0 48px;
  text-align: center;
}

.auth-status { font-size: 13px; color: #94a3b8; }
.auth-status strong { color: #cfd; }
.auth-signin-btn, .auth-signout-btn { font-size: 12px !important; }

.home-eyebrow {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 12px;
}

.home-hero h1 {
  font-size: 36px;
  font-weight: 700;
  line-height: 1.2;
  margin: 0 0 16px;
  background: linear-gradient(135deg, var(--ink) 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.home-subtitle {
  font-size: 17px;
  color: var(--muted);
  line-height: 1.6;
  max-width: 600px;
  margin: 0 auto 28px;
}

.home-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.home-cta {
  font-size: 15px;
  padding: 10px 28px;
}

.home-progress {
  margin-top: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: 13px;
  color: var(--muted);
}

.home-progress-bar {
  width: 160px;
  height: 6px;
  background: var(--surface-2);
  border-radius: 3px;
  overflow: hidden;
}

.home-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.3s;
}

.home-section {
  padding: 40px 0;
  border-top: 1px solid var(--line);
}

.home-section h2 {
  font-size: 20px;
  margin: 0 0 12px;
}

.home-section > p {
  font-size: 15px;
  color: var(--muted);
  line-height: 1.6;
  max-width: 700px;
}

.home-features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-top: 24px;
}

.home-feature {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 20px;
}

.home-feature-icon {
  font-size: 24px;
  display: block;
  margin-bottom: 8px;
}

.home-feature h3 {
  font-size: 15px;
  margin: 0 0 6px;
}

.home-feature p {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
  margin: 0;
}

.home-modules {
  display: grid;
  gap: 12px;
  margin-top: 20px;
}

.home-module-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 20px;
}

.home-module-kicker {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  font-weight: 700;
}

.home-module-card h3 {
  font-size: 16px;
  margin: 4px 0 6px;
}

.home-module-card p {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
  margin: 0 0 12px;
}

.home-module-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.home-module-progress {
  font-size: 12px;
  color: var(--muted);
}

.home-start-btn {
  font-size: 12px;
  padding: 6px 14px;
}

.home-footer {
  padding: 40px 0;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  border-top: 1px solid var(--line);
}

.home-footer a {
  color: var(--accent);
  text-decoration: none;
}

/* ── Responsive ────────────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }
  .workspace.sidebar-open {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    top: 48px;
    left: 0;
    bottom: 0;
    width: 280px;
    z-index: 10;
  }
  .instructions-panel { border-right: none; border-bottom: 1px solid var(--line); }
  .topbar-sig { display: none; }
}

/* Home page mobile */
@media (max-width: 640px) {
  .home { padding: 0 16px; }

  .home-hero { padding: 48px 0 32px; }

  .home-hero h1 {
    font-size: 24px;
    line-height: 1.3;
  }

  .home-subtitle {
    font-size: 15px;
    margin-bottom: 20px;
  }

  .home-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .home-actions .btn-ghost,
  .home-actions .btn-primary {
    text-align: center;
    justify-content: center;
  }

  .home-cta { font-size: 14px; padding: 12px 20px; }

  .home-features {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .home-feature {
    padding: 14px;
  }

  .home-feature-icon { font-size: 20px; margin-bottom: 6px; }
  .home-feature h3 { font-size: 13px; }
  .home-feature p { font-size: 12px; }

  .home-section h2 { font-size: 18px; }
  .home-section > p { font-size: 14px; }

  .home-module-card { padding: 16px; }
  .home-module-card h3 { font-size: 15px; }

  .home-module-footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .home-start-btn { width: 100%; text-align: center; justify-content: center; }

  .home-progress {
    flex-direction: column;
    gap: 6px;
  }

  .home-progress-bar { width: 100%; }

  /* Cheat sheet modal mobile */
  .modal-content {
    width: 95vw;
    max-height: 90vh;
    border-radius: 8px;
  }

  .cheat-comparison {
    grid-template-columns: 1fr;
  }

  .cheat-code { font-size: 11px; }
}

@media (max-width: 380px) {
  .home-hero h1 { font-size: 20px; }
  .home-features { grid-template-columns: 1fr; }
}
