/* ===========================================================================
   Zero to Claude Code — 零到 Claude Code
   Warm Claude aesthetic: cream + orange + warm dark
   =========================================================================== */

:root {
  /* Warm cream/clay palette */
  --bg: #F0ECE4;            /* page background */
  --bg-soft: #F6F2EA;       /* softer */
  --bg-card: #FAF7F1;       /* cards */
  --bg-card-2: #EDE7DA;     /* alt cards */
  --bg-inset: #E6DFD0;      /* insets */
  --line: #D8CFBC;          /* hairlines */
  --line-soft: #E4DCC9;

  /* Warm dark inks */
  --ink: #2D2B28;
  --ink-2: #3D3A36;
  --ink-3: #5B564E;
  --ink-mute: #7A756C;
  --ink-faint: #A8A196;

  /* Brand orange (Claude) */
  --accent: #D97757;        /* primary, softer than logo */
  --accent-strong: #C45A35; /* hover */
  --accent-soft: #F2C9B4;
  --accent-bg: #FBEDDF;

  /* Status */
  --ok: #4DA656;
  --ok-bg: #DDEAD8;
  --warn: #D4A843;
  --err: #E85B4A;
  --err-bg: #F4D5CF;

  /* Terminal */
  --term-bg: #1F1B16;
  --term-bg-2: #2A241D;
  --term-ink: #F0ECE4;
  --term-ink-dim: #B3A99B;
  --term-prompt: #E8A06A;
  --term-ok: #95C97A;
  --term-err: #E89080;
  --term-folder: #7FB8E0;

  /* Radii / shadow */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --r-xl: 22px;
  --r-pill: 999px;

  --shadow-sm: 0 1px 2px rgba(45, 43, 40, 0.06), 0 1px 1px rgba(45, 43, 40, 0.04);
  --shadow-md: 0 4px 14px rgba(45, 43, 40, 0.08), 0 1px 2px rgba(45, 43, 40, 0.04);
  --shadow-lg: 0 18px 40px rgba(45, 43, 40, 0.12), 0 2px 6px rgba(45, 43, 40, 0.05);
  --shadow-inset: inset 0 1px 0 rgba(255,255,255,0.5), inset 0 -1px 0 rgba(45,43,40,0.05);

  /* Type */
  --font-sans: "Noto Sans TC", "PingFang TC", "Hiragino Sans TC", "Microsoft JhengHei", system-ui, -apple-system, sans-serif;
  --font-serif: "Noto Serif TC", "Songti TC", "PingFang TC", Georgia, serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

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

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  overflow-wrap: break-word;
  word-break: break-word;
}

/* Selection */
::selection { background: var(--accent-soft); color: var(--ink); }

/* Headings */
h1, h2, h3, h4 { font-family: var(--font-serif); color: var(--ink); font-weight: 600; letter-spacing: -0.01em; margin: 0; line-height: 1.25; }
h1 { font-size: clamp(40px, 5vw, 64px); letter-spacing: -0.02em; line-height: 1.1; }
h2 { font-size: clamp(28px, 3vw, 40px); }
h3 { font-size: 22px; }

p { margin: 0; color: var(--ink-2); }

a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; padding: 0; }

code, pre, .mono { font-family: var(--font-mono); }

/* Layout helpers */
.container { max-width: 1200px; margin: 0 auto; padding: 0 32px; }
.container-narrow { max-width: 880px; margin: 0 auto; padding: 0 32px; }

/* ─── Top Nav ─────────────────────────────────────────── */
.nav {
  position: sticky; top: 0; z-index: 50;
  background: rgba(240, 236, 228, 0.85);
  backdrop-filter: saturate(140%) blur(12px);
  -webkit-backdrop-filter: saturate(140%) blur(12px);
  border-bottom: 1px solid var(--line-soft);
}
.nav-inner {
  display: flex; align-items: center; justify-content: space-between;
  height: 64px; max-width: 1200px; margin: 0 auto; padding: 0 32px;
}
.brand { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--ink); color: var(--bg);
  display: grid; place-items: center;
  font-family: var(--font-serif); font-weight: 700; font-size: 18px;
  letter-spacing: -0.02em;
  position: relative; overflow: hidden;
}
.brand-mark::after {
  content: ""; position: absolute; right: -6px; top: -6px;
  width: 18px; height: 18px; border-radius: 50%; background: var(--accent);
}
.brand-text { font-family: var(--font-serif); font-weight: 600; font-size: 18px; color: var(--ink); }
.brand-text small { color: var(--ink-mute); font-weight: 400; font-size: 13px; margin-left: 6px; }

.nav-links { display: flex; align-items: center; gap: 4px; }
.nav-link {
  padding: 8px 14px; border-radius: var(--r-pill);
  font-size: 14px; color: var(--ink-2); font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: var(--bg-card-2); }
.nav-link.active { background: var(--ink); color: var(--bg); }

/* ─── Buttons ─────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 14px 22px; border-radius: var(--r-pill);
  font-weight: 600; font-size: 15px;
  transition: transform 0.06s, box-shadow 0.15s, background 0.15s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--accent-strong); box-shadow: var(--shadow-md); }
.btn-ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn-ghost:hover { background: var(--bg-card); }
.btn-dark { background: var(--ink); color: var(--bg); }
.btn-dark:hover { background: #1a1816; }
.btn-sm { padding: 8px 14px; font-size: 13px; }

/* ─── Pill / Tag ─────────────────────────────────────────── */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: var(--r-pill);
  background: var(--bg-card); border: 1px solid var(--line-soft);
  font-size: 12px; color: var(--ink-3); font-weight: 500;
}
.pill-accent { background: var(--accent-bg); border-color: var(--accent-soft); color: var(--accent-strong); }
.pill-ok { background: var(--ok-bg); border-color: #BAD5B0; color: #2E6A36; }
.pill-dot::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; display: inline-block;
}

/* ─── Card ─────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-lg);
  padding: 24px;
}
.card-flat { background: var(--bg-soft); border: 1px solid var(--line-soft); border-radius: var(--r-md); padding: 16px; }

/* ─── Terminal window ─────────────────────────────────────────── */
.term {
  background: var(--term-bg);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--term-ink);
}
.term-chrome {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  background: var(--term-bg-2);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.term-dot { width: 12px; height: 12px; border-radius: 50%; }
.term-dot.red { background: #FF5F56; }
.term-dot.yellow { background: #FFBD2E; }
.term-dot.green { background: #27C93F; }
.term-title { margin: 0 auto; font-size: 12px; color: var(--term-ink-dim); font-family: var(--font-sans); letter-spacing: 0.04em; }
.term-body { padding: 16px 18px; min-height: 220px; }
.term-line { white-space: pre-wrap; word-break: break-all; line-height: 1.55; }
.term-prompt { color: var(--term-prompt); }
.term-path { color: var(--term-folder); }
.term-ok { color: var(--term-ok); }
.term-err { color: var(--term-err); }
.term-dim { color: var(--term-ink-dim); }
.term-folder { color: var(--term-folder); }
.term-input-row { display: flex; align-items: center; gap: 6px; }
.term-input {
  flex: 1; background: transparent; border: none; outline: none;
  color: var(--term-ink); font-family: inherit; font-size: inherit; padding: 0;
  caret-color: var(--term-prompt);
}
.term-caret {
  display: inline-block; width: 8px; height: 1.1em; background: var(--term-prompt);
  vertical-align: text-bottom; animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ─── Misc ─────────────────────────────────────────── */
.muted { color: var(--ink-mute); }
.divider { height: 1px; background: var(--line-soft); border: 0; margin: 24px 0; }

.fade-in { animation: fadeIn 0.3s ease both; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.shake { animation: shake 0.32s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-4px); }
  40%, 80% { transform: translateX(4px); }
}

/* Focus rings (subtle) */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ─── Scrollbar (webkit) ─────────────────────────────────────────── */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-faint); }
::-webkit-scrollbar-track { background: transparent; }

/* ─── Layout primitives that respond to viewport ─────────────────── */
.hero-grid {
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  gap: 56px;
  align-items: center;
}

.lesson-grid {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 0;
  max-width: 1200px;
  margin: 0 auto;
}
.lesson-sidebar {
  padding: 32px 16px 32px 32px;
  border-right: 1px solid var(--line-soft);
  position: sticky;
  top: 128px;
  align-self: flex-start;
  height: calc(100vh - 128px);
  overflow-y: auto;
}
.lesson-main {
  padding: 40px 56px 100px;
  min-width: 0;
  max-width: 100%;
}

.lesson-subheader-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* FileGallery — desktop side-by-side, mobile stacked */
.file-gallery {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 18px;
}

/* File tree node names — never break mid-word */
.file-name-label { white-space: nowrap; }

.level-row-button {
  padding: 20px 24px;
  gap: 20px;
}
.level-row-badge {
  width: 52px;
  height: 52px;
  font-size: 20px;
}
.level-row-meta {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-end;
}
.level-row-progress { width: 100px; }

/* Buttons must never wrap their own text */
.btn { white-space: nowrap; }
.nav-link { white-space: nowrap; }

/* ─── Mobile (≤768px) ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  body { font-size: 15px; }

  .container { padding: 0 16px; }
  .container-narrow { padding: 0 16px; }

  h1 { font-size: clamp(28px, 8vw, 40px); }
  h2 { font-size: clamp(22px, 6vw, 30px); }
  h3 { font-size: 18px; }

  /* TopNav — compact */
  .nav-inner {
    height: 56px;
    padding: 0 16px;
  }
  .brand-text { font-size: 15px; }
  .brand-text small { display: none; }
  .nav-link { padding: 6px 10px; font-size: 12px; }
  .nav-links { gap: 0; }
  .nav-links > span { display: none; } /* kill the inline spacer */
  .nav-links .btn { padding: 7px 12px; font-size: 12px; }

  /* Cards */
  .card { padding: 18px; }
  .card-flat { padding: 14px; }

  /* Hero — stacked */
  .hero-grid {
    grid-template-columns: 1fr;
    gap: 32px;
  }

  /* Lesson — stacked, sidebar above content */
  .lesson-grid {
    grid-template-columns: 1fr;
  }
  .lesson-sidebar {
    position: static;
    height: auto;
    padding: 14px 16px 8px;
    border-right: none;
    border-bottom: 1px solid var(--line-soft);
    overflow-y: visible;
  }
  /* Section-list becomes horizontal scroll pills */
  .lesson-sidebar-sections {
    flex-direction: row !important;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    padding-bottom: 6px;
    gap: 8px !important;
  }
  .lesson-sidebar-sections > li > button {
    white-space: nowrap;
    scroll-snap-align: start;
  }
  /* Hide "其他課" sibling list on mobile */
  .lesson-sidebar-siblings,
  .lesson-sidebar-siblings-label {
    display: none !important;
  }
  .lesson-main {
    padding: 20px 16px 60px;
  }

  /* Lesson sub-header: tighter, hide back-text, shrink id label */
  .lesson-subheader { padding: 8px 16px !important; }
  .lesson-subheader-back-text { display: none; }
  .lesson-subheader-id { display: none; }
  .lesson-subheader-row { gap: 8px; }

  /* Brand subtitle — hide on mobile (selector targets sibling <small>) */
  .brand small,
  .brand-text + small { display: none; }

  /* FileGallery: stack chips and detail panel */
  .file-gallery { grid-template-columns: 1fr; gap: 14px; }

  /* Other 2-column section grids → stacked on mobile */
  .interactive-tree-grid,
  .program-sim-grid,
  .split-2col,
  .guided-terminal-grid {
    grid-template-columns: 1fr !important;
    gap: 14px !important;
  }
  .drag-match-grid {
    grid-template-columns: 1fr !important;
    gap: 8px !important;
  }
  .drag-match-grid > :nth-child(2) { /* arrow column */
    display: none;
  }

  /* File tree text — allow shrink + ellipsis instead of mid-word wrap */
  .file-tree-row { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* Make ALL inline-styled wide containers safe on mobile */
  main, aside, section { max-width: 100%; min-width: 0; }
  pre, code { overflow-x: auto; }

  /* Level row — compact */
  .level-row-button { padding: 14px 14px; gap: 12px; }
  .level-row-badge { width: 40px; height: 40px; font-size: 16px; }
  .level-row-meta { gap: 4px; }
  .level-row-progress { display: none; }   /* keep only "N/M" count */
}

/* ─── Smaller phones (≤400px) ─────────────────────────────────────── */
@media (max-width: 400px) {
  .nav-link { display: none; }
  .brand-text { font-size: 14px; }
  h1 { font-size: 26px; }
  .lesson-main { padding: 20px 12px 60px; }
  .lesson-sidebar { padding: 10px 12px 6px; }
  .container { padding: 0 12px; }
}
