/* theme.css — SVG Studio design system (nan.fyi-inspired editorial course shell) */

/* ── Color tokens (light) ─────────────────────────────────────────────── */
:root {
  --blue-1: #fbfdff;
  --blue-2: #f4faff;
  --blue-3: #e6f4fe;
  --blue-4: #d5efff;
  --blue-5: #c2e5ff;
  --blue-6: #acd8fc;
  --blue-7: #8ec8f6;
  --blue-8: #5eb1ef;
  --blue-9: #0090ff;
  --blue-10: #0588f0;
  --blue-11: #0d74ce;
  --blue-12: #113264;

  --gray-1: #fcfcfd;
  --gray-2: #f8f8f8;
  --gray-3: #eeeeee;
  --gray-4: #e4e4e7;
  --gray-5: #d4d4d8;
  --gray-6: #a1a1aa;
  --gray-7: #71717a;
  --gray-8: #52525b;
  --gray-9: #27272a;
  --gray-10: #18181b;
  --gray-11: #111113;
  --gray-12: #09090b;

  --teal-9: #12b594;
  --amber-9: #ffb224;
  --red-9: #f2555a;

  /* Semantic aliases */
  --bg: var(--blue-1);
  --bg-subtle: var(--blue-2);
  --bg-muted: var(--gray-2);
  --surface: var(--gray-1);
  --surface-raised: #ffffff;
  --border: var(--gray-4);
  --border-subtle: var(--gray-3);
  --text: var(--gray-12);
  --text-muted: var(--gray-7);
  --text-subtle: var(--gray-6);
  --accent: var(--blue-9);
  --accent-hover: var(--blue-10);
  --accent-subtle: var(--blue-3);
  --accent-text: var(--blue-11);
  --link: var(--blue-11);
  --code-bg: var(--gray-12);
  --code-fg: var(--gray-2);
  --editor-bg: var(--gray-12);
  --editor-fg: var(--gray-2);
  --preview-checker-a: var(--gray-3);
  --preview-checker-b: var(--gray-1);
  --shadow-sm: 0 1px 2px rgba(9, 9, 11, 0.04);
  --shadow-md: 0 8px 24px rgba(9, 9, 11, 0.06);
  --shadow-lg: 0 16px 48px rgba(9, 9, 11, 0.08);
  --hero-glow: var(--blue-4);

  /* Typography */
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --font-mono: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, Consolas, monospace;

  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 2rem;
  --text-4xl: clamp(2.5rem, 6vw, 4.25rem);

  /* Spacing scale (4px base) */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;

  /* Layout */
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 999px;
  --maxw: 1080px;
  --maxw-prose: 68ch;
  --header-h: 3.5rem;
  --transition: 150ms ease;
}

/* ── Dark mode tokens ─────────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1117;
    --bg-subtle: #0f1520;
    --bg-muted: #141a24;
    --surface: #151b26;
    --surface-raised: #1a2230;
    --border: #2a3344;
    --border-subtle: #1f2836;
    --text: #eef2f7;
    --text-muted: #8b95a8;
    --text-subtle: #6b7589;
    --accent-subtle: #0d2840;
    --accent-text: #5eb1ef;
    --link: #8ec8f6;
    --code-bg: #0a0e14;
    --code-fg: #d4dae4;
    --editor-bg: #0a0e14;
    --editor-fg: #d4dae4;
    --preview-checker-a: #1a2230;
    --preview-checker-b: #151b26;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.5);
    --hero-glow: #113264;
  }
}

/* ── Reset & base ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  color: var(--text);
  background: var(--bg);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img, svg { display: block; max-width: 100%; }
a { color: var(--link); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent); text-decoration: underline; }

code, kbd, samp {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--bg-muted);
  padding: 0.1em 0.35em;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

pre, textarea.playground {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

.wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 var(--space-6);
}

/* ── Site header (lessons) ────────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--header-h);
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border-subtle);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.site-header .wrap {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

.site-logo {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--text);
  text-decoration: none;
}

.site-logo:hover { text-decoration: none; color: var(--accent); }

.site-logo-mark {
  width: 1.5rem;
  height: 1.5rem;
  flex-shrink: 0;
}

.site-header-meta {
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

/* ── Hero (home) ────────────────────────────────────────────────────────── */
.hero {
  position: relative;
  padding: var(--space-16) 0 var(--space-12);
  border-bottom: 1px solid var(--border-subtle);
  background:
    radial-gradient(900px 420px at 85% -5%, var(--hero-glow), transparent 65%),
    radial-gradient(600px 300px at 10% 80%, color-mix(in srgb, var(--accent) 8%, transparent), transparent 70%),
    var(--bg);
  overflow: hidden;
}

.hero-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-10);
  align-items: center;
}

.hero-copy { max-width: 36rem; }

.hero .eyebrow {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent-text);
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  border-radius: var(--radius-full);
  padding: var(--space-1) var(--space-3);
  margin-bottom: var(--space-4);
}

.hero h1 {
  font-family: var(--font-serif);
  font-size: var(--text-4xl);
  line-height: 1.05;
  margin: 0 0 var(--space-4);
  letter-spacing: -0.025em;
  font-weight: 400;
}

.hero .sub {
  font-size: var(--text-lg);
  color: var(--text-muted);
  max-width: 42ch;
  margin: 0;
  line-height: 1.6;
}

.hero-demo {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface-raised);
  box-shadow: var(--shadow-md);
  aspect-ratio: 4 / 3;
}

.hero-demo svg {
  width: 100%;
  height: auto;
  max-height: 280px;
}

@media (max-width: 768px) {
  .hero { padding: var(--space-12) 0 var(--space-10); }
  .hero-grid { grid-template-columns: 1fr; gap: var(--space-8); }
  .hero-demo { order: -1; max-height: 220px; }
}

/* ── Module grid ────────────────────────────────────────────────────────── */
.modules {
  padding: var(--space-12) 0 var(--space-16);
}

.section-head {
  margin-bottom: var(--space-8);
}

.section-head h2 {
  font-family: var(--font-serif);
  font-size: var(--text-3xl);
  font-weight: 400;
  margin: 0 0 var(--space-2);
  letter-spacing: -0.02em;
}

.section-head p {
  margin: 0;
  color: var(--text-muted);
  font-size: var(--text-lg);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: var(--space-4);
}

.card {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  text-decoration: none;
  color: inherit;
  transition: border-color var(--transition), transform var(--transition), box-shadow var(--transition);
}

.card:hover {
  border-color: var(--blue-6);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  text-decoration: none;
  color: inherit;
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
}

.card-icon {
  width: 2.5rem;
  height: 2.5rem;
  flex-shrink: 0;
  padding: var(--space-2);
  border-radius: var(--radius);
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
}

.card .num {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.04em;
}

.card h3 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: var(--text-xl);
  font-weight: 400;
  letter-spacing: -0.01em;
}

.card p {
  color: var(--text-muted);
  font-size: var(--text-sm);
  margin: 0;
  flex: 1;
  line-height: 1.55;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-top: auto;
  padding-top: var(--space-2);
}

.status {
  display: inline-flex;
  align-items: center;
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.2em 0.6em;
  border-radius: var(--radius-full);
}

.status-live { background: var(--teal-9); color: #fff; }
.status-next { background: var(--accent-subtle); color: var(--accent-text); border: 1px solid var(--border); }
.status-later { background: var(--bg-muted); color: var(--text-muted); border: 1px solid var(--border-subtle); }

.card[href="#"] {
  opacity: 0.72;
  cursor: default;
  pointer-events: none;
}

/* ── Lesson layout ──────────────────────────────────────────────────────── */
.lesson-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
  font-size: var(--text-sm);
  background: var(--bg-subtle);
}

.lesson-nav .crumb { color: var(--text-muted); }
.lesson-nav .crumb a { color: var(--text-muted); }
.lesson-nav .crumb a:hover { color: var(--accent); }

.lesson {
  padding: var(--space-10) 0 var(--space-16);
}

.lesson h1 {
  font-family: var(--font-serif);
  font-size: clamp(2rem, 4vw, 2.75rem);
  font-weight: 400;
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin: 0 0 var(--space-4);
}

.lesson > .sub {
  font-size: var(--text-lg);
  color: var(--text-muted);
  max-width: var(--maxw-prose);
  margin: 0 0 var(--space-8);
  line-height: 1.6;
}

.lesson h2 {
  font-family: var(--font-serif);
  font-size: var(--text-2xl);
  font-weight: 400;
  margin: var(--space-10) 0 var(--space-4);
  letter-spacing: -0.01em;
}

.lesson p {
  max-width: var(--maxw-prose);
  margin: 0 0 var(--space-4);
}

.lesson .principle {
  max-width: var(--maxw-prose);
  background: var(--bg-subtle);
  border-left: 3px solid var(--blue-8);
  padding: var(--space-4) var(--space-5);
  border-radius: 0 var(--radius) var(--radius) 0;
  margin: var(--space-4) 0 var(--space-6);
  font-size: var(--text-sm);
  border-top: 1px solid var(--border-subtle);
  border-right: 1px solid var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle);
}

.lesson .principle strong { color: var(--accent-text); }

.challenge {
  max-width: var(--maxw-prose);
  border: 1px dashed var(--amber-9);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  margin: var(--space-8) 0;
  background: color-mix(in srgb, var(--amber-9) 6%, var(--surface-raised));
}

.challenge h3 {
  margin: 0 0 var(--space-3);
  font-family: var(--font-serif);
  font-size: var(--text-xl);
  font-weight: 400;
}

.challenge p { margin-bottom: var(--space-3); }

details.solution { margin-top: var(--space-4); }
details.solution summary {
  cursor: pointer;
  color: var(--accent-text);
  font-weight: 600;
  font-size: var(--text-sm);
}

pre.example {
  background: var(--code-bg);
  color: var(--code-fg);
  padding: var(--space-4);
  border-radius: var(--radius);
  overflow-x: auto;
  border: 1px solid var(--border);
  font-size: var(--text-sm);
  line-height: 1.6;
  max-width: 100%;
}

.cmd {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent-text);
}

table.cmp {
  width: 100%;
  max-width: 100%;
  border-collapse: collapse;
  margin: var(--space-4) 0 var(--space-6);
  font-size: var(--text-sm);
}

table.cmp th,
table.cmp td {
  border: 1px solid var(--border);
  padding: var(--space-2) var(--space-3);
  text-align: left;
  vertical-align: top;
}

table.cmp th {
  background: var(--bg-subtle);
  font-weight: 600;
}

.credits {
  font-size: var(--text-sm);
  color: var(--text-muted);
  border-top: 1px solid var(--border-subtle);
  margin-top: var(--space-12);
  padding-top: var(--space-5);
  max-width: var(--maxw-prose);
}

.credits p { margin: 0; max-width: none; }

/* ── Playground / editor chrome ─────────────────────────────────────────── */
.playground-wrap {
  margin: var(--space-6) 0;
  max-width: 100%;
}

.pane {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--surface-raised);
  box-shadow: var(--shadow-sm);
}

.pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  background: var(--bg-muted);
  border-bottom: 1px solid var(--border);
}

.pane-label {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  font-weight: 600;
}

.pane-labels {
  display: flex;
  gap: var(--space-4);
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  border-bottom: 1px solid var(--border);
}

.split > * {
  min-width: 0;
}

.split .editor-col {
  border-right: 1px solid var(--border);
}

.split-label {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-subtle);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-muted);
  border-bottom: 1px solid var(--border-subtle);
}

textarea.playground {
  width: 100%;
  height: 320px;
  border: 0;
  resize: vertical;
  padding: var(--space-4);
  background: var(--editor-bg);
  color: var(--editor-fg);
  line-height: 1.55;
  outline: none;
  tab-size: 2;
  white-space: pre;
  overflow: auto;
  font-size: 0.8125rem;
}

textarea.playground:focus {
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 40%, transparent);
}

.code-editor {
  --editor-line-height: 1.3125rem;
  min-width: 0;
  overflow: hidden;
  background: var(--editor-bg);
}

.code-editor__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  min-height: 2.5rem;
  padding: 0 var(--space-3);
  border-bottom: 1px solid var(--gray-9);
  background: var(--gray-10);
  color: var(--gray-6);
  font: 600 var(--text-xs)/1 var(--font-mono);
}

.code-editor__file {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--gray-3);
}

.code-editor__dot {
  width: 0.5rem;
  height: 0.5rem;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--teal-9);
  box-shadow: 0 0 0 3px rgba(18, 181, 148, 0.13);
}

.code-editor__position {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.code-editor__body {
  display: grid;
  grid-template-columns: 3.25rem minmax(0, 1fr);
  height: 320px;
}

.code-editor__gutter {
  position: relative;
  z-index: 3;
  overflow: hidden;
  padding-top: var(--space-3);
  border-right: 1px solid var(--gray-9);
  background: #111116;
  color: var(--gray-7);
  text-align: right;
  user-select: none;
  font: 0.75rem/var(--editor-line-height) var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.code-editor__gutter-lines { will-change: transform; }

.code-editor__gutter-lines span {
  display: block;
  height: var(--editor-line-height);
  padding: 0 var(--space-3) 0 var(--space-1);
}

.code-editor__surface {
  position: relative;
  min-width: 0;
  overflow: hidden;
  background: var(--editor-bg);
}

.code-editor__highlight,
.code-editor textarea.playground {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  border: 0;
  padding: var(--space-3);
  tab-size: 2;
  white-space: pre;
  overflow-wrap: normal;
  font: 0.8125rem/var(--editor-line-height) var(--font-mono);
  letter-spacing: 0;
}

.code-editor__highlight {
  z-index: 1;
  min-width: 100%;
  min-height: 100%;
  overflow: visible;
  background: transparent;
  color: var(--editor-fg);
  pointer-events: none;
  will-change: transform;
}

.code-editor textarea.playground,
.code-editor textarea.playground:focus {
  z-index: 2;
  resize: none;
  overflow: auto;
  outline: none;
  box-shadow: none;
  background: transparent;
  color: transparent;
  caret-color: var(--gray-1);
  -webkit-text-fill-color: transparent;
}

.code-editor textarea.playground::selection {
  background: rgba(0, 144, 255, 0.32);
}

.code-editor .token-tag { color: #5de4c7; }
.code-editor .token-attribute { color: #7dcfff; }
.code-editor .token-string { color: #c3e88d; }
.code-editor .token-comment { color: var(--gray-7); font-style: italic; }
.code-editor .token-number { color: #ff9e64; }
.code-editor .token-punctuation { color: #a6accd; }

.code-editor__status {
  min-height: 2rem;
  padding: 0.4rem var(--space-3);
  border-top: 1px solid var(--gray-9);
  background: var(--gray-10);
  color: var(--gray-6);
  font: var(--text-xs)/1.2rem var(--font-mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.code-editor--error .code-editor__dot {
  background: var(--red-9);
  box-shadow: 0 0 0 3px rgba(242, 85, 90, 0.15);
}

.code-editor--error .code-editor__status { color: #ff8b8f; }

.preview-col {
  display: flex;
  min-height: 0;
  flex-direction: column;
}

.preview-col .preview { flex: 1; }

.preview {
  display: grid;
  place-items: center;
  min-height: 320px;
  background:
    repeating-conic-gradient(var(--preview-checker-a) 0 25%, var(--preview-checker-b) 0 50%) 0 0 / 20px 20px;
}

.preview svg {
  max-width: 100%;
  height: auto;
}

.preview-error {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--red-9);
  padding: var(--space-4);
  text-align: center;
  max-width: 32ch;
  line-height: 1.5;
}

.runbar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background: var(--surface);
  border-top: 1px solid var(--border-subtle);
}

.runbar-hint {
  margin-left: auto;
  font-size: var(--text-xs);
  color: var(--text-subtle);
  font-family: var(--font-mono);
}

@media (max-width: 800px) {
  .split { grid-template-columns: 1fr; }
  .split .editor-col { border-right: 0; border-bottom: 1px solid var(--border); }
}

/* ── Buttons ────────────────────────────────────────────────────────────── */
button, .btn {
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  padding: 0.45em 0.9em;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  line-height: 1.4;
}

button:hover, .btn:hover {
  background: var(--bg-muted);
  border-color: var(--gray-5);
}

button.primary, .btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button.primary:hover, .btn.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

button:active, .btn:active { transform: scale(0.98); }

button.success {
  background: var(--teal-9);
  border-color: var(--teal-9);
  color: #fff;
}

button.is-copied {
  background: var(--teal-9);
  border-color: var(--teal-9);
  color: #fff;
}

/* ── Footer ─────────────────────────────────────────────────────────────── */
footer {
  border-top: 1px solid var(--border-subtle);
  padding: var(--space-8) 0 var(--space-10);
  color: var(--text-muted);
  font-size: var(--text-sm);
  background: var(--bg-subtle);
}

footer .wrap {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
}

footer a { color: var(--text-muted); }
footer a:hover { color: var(--accent); }
