  :root {
    --bg: #FFFFFF;
    --ink: #0A0A0A;
    --body: #1C1C1C;
    --secondary: #6B6B6B;
    --border: #D0D0D0;
    --subtle: #F2F2F2;
    --accent: #D4541A;
    --accent-light: #FAE8DF;
    --accent-dark: #B03E0E;
    --serif: 'DM Serif Display', Georgia, serif;
    --sans: 'Outfit', system-ui, sans-serif;
    --mono: 'DM Mono', monospace;
    --radius: 6px;
    --transition: 0.2s ease;
  }

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

  html { scroll-behavior: smooth; }

  body {
    font-family: var(--sans);
    background: var(--bg);
    color: var(--body);
    font-size: 16px;
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
  }

  /* ── LAYOUT ── */
  .app { display: flex; min-height: 100vh; }

  /* ── SIDEBAR ── */
  .sidebar {
    width: 280px;
    flex-shrink: 0;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    background: var(--bg);
    z-index: 10;
  }

  .sidebar-header {
    padding: 28px 24px 20px;
    border-bottom: 1px solid var(--border);
  }

  .logo {
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 500;
    color: var(--secondary);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    margin-bottom: 10px;
  }

  .sidebar-title {
    font-family: var(--serif);
    font-size: 18px;
    color: var(--ink);
    line-height: 1.25;
  }

  .sidebar-title em {
    font-style: italic;
    color: var(--accent);
  }

  /* Progress bar */
  .progress-wrap {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
  }

  .progress-label {
    font-family: var(--mono);
    font-size: 10px;
    color: var(--secondary);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

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

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

  /* Nav */
  .nav { padding: 12px 0; flex: 1; }

  .nav-section {
    padding: 8px 24px 4px;
    font-family: var(--mono);
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--secondary);
    margin-top: 4px;
  }

  .nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 24px;
    cursor: pointer;
    transition: background var(--transition);
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    position: relative;
  }

  .nav-item:hover { background: var(--subtle); }

  .nav-item.active {
    background: var(--accent-light);
  }

  .nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--accent);
    border-radius: 0 2px 2px 0;
  }

  .nav-num {
    font-family: var(--mono);
    font-size: 10px;
    color: var(--secondary);
    width: 18px;
    flex-shrink: 0;
  }

  .nav-item.active .nav-num { color: var(--accent); }

  .nav-text {
    font-size: 13px;
    font-weight: 500;
    color: var(--body);
    line-height: 1.3;
  }

  .nav-item.active .nav-text { color: var(--ink); }

  .nav-check {
    margin-left: auto;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1.5px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--transition);
    font-size: 9px;
  }

  .nav-check.done {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
  }

  /* ── MAIN CONTENT ── */
  .main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
  }

  /* Top bar */
  .topbar {
    padding: 16px 32px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(8px);
    z-index: 5;
  }

  .topbar-breadcrumb {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--secondary);
  }

  .topbar-breadcrumb span { color: var(--accent); }

  .topbar-actions { display: flex; gap: 10px; align-items: center; }

  .btn {
    font-family: var(--sans);
    font-size: 13px;
    font-weight: 500;
    padding: 8px 18px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    border: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
  }

  .btn-ghost {
    background: none;
    color: var(--secondary);
    border: 1px solid var(--border);
  }

  .btn-ghost:hover {
    background: var(--subtle);
    color: var(--body);
  }

  .btn-primary {
    background: var(--accent);
    color: white;
  }

  .btn-primary:hover { background: var(--accent-dark); }

  .btn-primary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
  }

  /* Content area */
  .content {
    max-width: 760px;
    margin: 0 auto;
    padding: 56px 48px 80px;
    width: 100%;
  }

  /* Chapter header */
  .chapter-tag {
    font-family: var(--mono);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--accent);
    margin-bottom: 12px;
  }

  .chapter-title {
    font-family: var(--serif);
    font-size: clamp(32px, 4vw, 48px);
    color: var(--ink);
    line-height: 1.15;
    margin-bottom: 20px;
  }

  .chapter-title em { font-style: italic; }

  .chapter-subtitle {
    font-size: 17px;
    color: var(--secondary);
    line-height: 1.65;
    margin-bottom: 48px;
    max-width: 620px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 32px;
  }

  /* Content blocks */
  .content h2 {
    font-family: var(--serif);
    font-size: 26px;
    color: var(--ink);
    margin: 48px 0 16px;
    line-height: 1.2;
  }

  .content h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--ink);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin: 32px 0 12px;
    font-family: var(--sans);
  }

  .content p {
    font-size: 16px;
    line-height: 1.75;
    color: var(--body);
    margin-bottom: 20px;
  }

  .content ul, .content ol {
    padding-left: 20px;
    margin-bottom: 20px;
  }

  .content li {
    font-size: 16px;
    line-height: 1.7;
    color: var(--body);
    margin-bottom: 6px;
  }

  /* Callout boxes */
  .callout {
    border-left: 3px solid var(--accent);
    background: var(--accent-light);
    padding: 18px 22px;
    border-radius: 0 var(--radius) var(--radius) 0;
    margin: 28px 0;
  }

  .callout-label {
    font-family: var(--mono);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--accent);
    margin-bottom: 8px;
    font-weight: 500;
  }

  .callout p {
    font-size: 15px;
    color: var(--ink);
    margin: 0;
    line-height: 1.65;
  }

  .callout-neutral {
    border-left-color: var(--border);
    background: var(--subtle);
  }

  .callout-neutral .callout-label { color: var(--secondary); }
  .callout-neutral p { color: var(--body); }

  /* Table */
  .table-wrap { overflow-x: auto; margin: 24px 0; }

  table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
  }

  th {
    text-align: left;
    padding: 10px 14px;
    background: var(--subtle);
    font-family: var(--mono);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--secondary);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
  }

  td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    color: var(--body);
    line-height: 1.5;
    vertical-align: top;
  }

  tr:last-child td { border-bottom: none; }

  /* Phase blocks */
  .phases { display: flex; flex-direction: column; gap: 3px; margin: 28px 0; }

  .phase {
    display: flex;
    align-items: stretch;
    gap: 0;
  }

  .phase-label {
    width: 100px;
    padding: 14px 16px;
    background: var(--ink);
    color: white;
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  .phase-label .mode {
    font-size: 9px;
    opacity: 0.5;
    margin-top: 2px;
    letter-spacing: 0.05em;
  }

  .phase:nth-child(1) .phase-label { background: #2A2A2A; }
  .phase:nth-child(2) .phase-label { background: #D4541A; }
  .phase:nth-child(3) .phase-label { background: #2A2A2A; }
  .phase:nth-child(4) .phase-label { background: #B03E0E; }

  .phase-body {
    flex: 1;
    padding: 14px 18px;
    border: 1px solid var(--border);
    border-left: none;
    font-size: 14px;
    line-height: 1.55;
    color: var(--body);
    background: var(--bg);
  }

  /* ── EXERCISE SECTION ── */
  .exercise-block {
    border: 1.5px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    margin: 48px 0 32px;
  }

  .exercise-header {
    background: var(--ink);
    padding: 18px 24px;
    display: flex;
    align-items: center;
    gap: 12px;
  }

  .exercise-badge {
    background: var(--accent);
    color: white;
    font-family: var(--mono);
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    padding: 4px 8px;
    border-radius: 3px;
    font-weight: 500;
    flex-shrink: 0;
  }

  .exercise-title-text {
    font-family: var(--serif);
    font-size: 18px;
    color: white;
  }

  .exercise-body { padding: 24px; }

  .exercise-prompt {
    font-size: 15px;
    color: var(--body);
    line-height: 1.7;
    margin-bottom: 20px;
  }

  .exercise-steps {
    background: var(--subtle);
    border-radius: var(--radius);
    padding: 18px 20px;
    margin-bottom: 24px;
  }

  .exercise-steps p {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--secondary);
    margin-bottom: 12px;
    font-family: var(--mono);
  }

  .exercise-steps ol {
    padding-left: 18px;
    margin: 0;
  }

  .exercise-steps li {
    font-size: 14px;
    color: var(--body);
    margin-bottom: 8px;
    line-height: 1.55;
  }

  .exercise-input-label {
    font-family: var(--mono);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--secondary);
    margin-bottom: 8px;
  }

  .exercise-textarea {
    width: 100%;
    min-height: 140px;
    padding: 14px 16px;
    font-family: var(--sans);
    font-size: 15px;
    color: var(--body);
    background: var(--bg);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    resize: vertical;
    outline: none;
    line-height: 1.6;
    transition: border-color var(--transition);
    margin-bottom: 14px;
  }

  .exercise-textarea:focus { border-color: var(--accent); }

  .exercise-textarea::placeholder { color: var(--secondary); opacity: 0.6; }

  .exercise-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
  }

  /* AI Feedback */
  .ai-feedback {
    margin-top: 20px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    display: none;
  }

  .ai-feedback.visible { display: block; }

  .ai-feedback-header {
    background: var(--subtle);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid var(--border);
  }

  .ai-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    animation: pulse 1.5s ease-in-out infinite;
  }

  @keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.8); }
  }

  .ai-dot.done { animation: none; background: #22C55E; }

  .ai-feedback-label {
    font-family: var(--mono);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--secondary);
  }

  .ai-feedback-body {
    padding: 18px 20px;
    font-size: 15px;
    line-height: 1.7;
    color: var(--body);
    min-height: 60px;
  }

  .ai-feedback-body strong { color: var(--ink); }

  .ai-feedback-body .loading-text {
    color: var(--secondary);
    font-style: italic;
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .spinner {
    width: 14px;
    height: 14px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    flex-shrink: 0;
  }

  @keyframes spin { to { transform: rotate(360deg); } }

  /* Chapter complete */
  .chapter-complete-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: var(--sans);
    font-size: 14px;
    font-weight: 600;
    color: var(--secondary);
    background: none;
    border: 1.5px dashed var(--border);
    border-radius: var(--radius);
    padding: 14px 20px;
    cursor: pointer;
    width: 100%;
    margin-top: 48px;
    transition: all var(--transition);
  }

  .chapter-complete-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-light);
  }

  .chapter-complete-btn.done {
    border-style: solid;
    border-color: #22C55E;
    color: #15803D;
    background: #F0FDF4;
    cursor: default;
  }

  /* Bottom nav */
  .bottom-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 56px;
    padding-top: 32px;
    border-top: 1px solid var(--border);
  }

  .bottom-nav-btn {
    display: flex;
    flex-direction: column;
    gap: 4px;
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;
    text-align: left;
  }

  .bottom-nav-btn.right { text-align: right; align-items: flex-end; }

  .bottom-nav-dir {
    font-family: var(--mono);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--secondary);
    display: flex;
    align-items: center;
    gap: 5px;
  }

  .bottom-nav-title {
    font-family: var(--serif);
    font-size: 18px;
    color: var(--ink);
    cursor: pointer;
    transition: color var(--transition);
  }

  .bottom-nav-btn:hover .bottom-nav-title { color: var(--accent); }

  /* API key modal */
  .modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10,10,10,0.6);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    backdrop-filter: blur(4px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
  }

  .modal-overlay.open {
    opacity: 1;
    pointer-events: all;
  }

  .modal {
    background: var(--bg);
    border-radius: 12px;
    border: 1px solid var(--border);
    padding: 36px;
    max-width: 480px;
    width: 100%;
    transform: translateY(12px);
    transition: transform 0.25s ease;
  }

  .modal-overlay.open .modal { transform: translateY(0); }

  .modal h2 {
    font-family: var(--serif);
    font-size: 24px;
    color: var(--ink);
    margin-bottom: 12px;
  }

  .modal p {
    font-size: 14px;
    color: var(--secondary);
    line-height: 1.65;
    margin-bottom: 20px;
  }

  .modal-input {
    width: 100%;
    padding: 12px 14px;
    font-family: var(--mono);
    font-size: 13px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    outline: none;
    color: var(--body);
    margin-bottom: 16px;
    transition: border-color var(--transition);
  }

  .modal-input:focus { border-color: var(--accent); }

  .modal-note {
    font-size: 12px !important;
    color: var(--secondary);
    margin-bottom: 16px !important;
  }

  .modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

  /* Welcome / Landing */
  .welcome-screen {
    max-width: 760px;
    margin: 0 auto;
    padding: 72px 48px 80px;
  }

  .welcome-eyebrow {
    font-family: var(--mono);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--accent);
    margin-bottom: 20px;
  }

  .welcome-title {
    font-family: var(--serif);
    font-size: clamp(40px, 5vw, 64px);
    color: var(--ink);
    line-height: 1.1;
    margin-bottom: 24px;
  }

  .welcome-title em { font-style: italic; color: var(--accent); }

  .welcome-desc {
    font-size: 18px;
    color: var(--secondary);
    line-height: 1.7;
    max-width: 580px;
    margin-bottom: 48px;
  }

  .welcome-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 48px;
  }

  .welcome-card {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
    background: var(--subtle);
  }

  .welcome-card-num {
    font-family: var(--mono);
    font-size: 10px;
    color: var(--secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
  }

  .welcome-card-title {
    font-weight: 600;
    font-size: 14px;
    color: var(--ink);
    line-height: 1.4;
  }

  .welcome-start {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
  }

  /* Code block */
  .code-block {
    background: var(--ink);
    border-radius: var(--radius);
    padding: 16px 18px;
    margin: 20px 0;
    overflow-x: auto;
  }

  .code-block code {
    font-family: var(--mono);
    font-size: 13px;
    color: #E8E8E8;
    line-height: 1.6;
    white-space: pre;
    display: block;
  }

  .code-block .code-accent { color: #D4541A; }
  .code-block .code-green { color: #86EFAC; }
  .code-block .code-dim { color: #6B7280; }

  /* Mobile sidebar toggle */
  .menu-toggle {
    display: none;
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 50;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--ink);
    color: white;
    border: none;
    font-size: 18px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(0,0,0,0.25);
  }

  @media (max-width: 840px) {
    .sidebar {
      position: fixed;
      left: -280px;
      top: 0;
      height: 100%;
      transition: left 0.3s ease;
      box-shadow: 4px 0 24px rgba(0,0,0,0.1);
    }

    .sidebar.open { left: 0; }

    .menu-toggle { display: flex; }

    .content { padding: 40px 24px 64px; }

    .welcome-screen { padding: 48px 24px 64px; }

    .welcome-grid { grid-template-columns: 1fr; }

    .topbar { padding: 14px 20px; }
  }

  /* Animations */
  .fade-in {
    animation: fadeIn 0.35s ease forwards;
  }

  @keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
  }

  /* Tooltip */
  .tooltip {
    position: relative;
    display: inline-block;
    cursor: help;
    border-bottom: 1px dashed var(--secondary);
    color: var(--body);
  }

  .tooltip::after {
    content: attr(data-tip);
    position: absolute;
    bottom: 130%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--ink);
    color: white;
    font-size: 12px;
    padding: 6px 10px;
    border-radius: 4px;
    width: 200px;
    text-align: center;
    line-height: 1.4;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    font-family: var(--sans);
    font-weight: 400;
    z-index: 20;
  }

  .tooltip:hover::after { opacity: 1; }

  /* API key indicator */
  .api-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: var(--mono);
    font-size: 10px;
    color: var(--secondary);
    cursor: pointer;
    padding: 6px 10px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    transition: all var(--transition);
  }

  .api-status:hover { background: var(--subtle); }

  .api-indicator {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--border);
    transition: background var(--transition);
  }

  .api-indicator.active { background: #22C55E; }

  /* ── ACCESS GATE ── */
  .gate {
    position: fixed;
    inset: 0;
    background: var(--bg);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
  }

  .gate.hidden { display: none; }

  .gate-card {
    width: 100%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  .gate-logo {
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 500;
    color: var(--secondary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 4px;
  }

  .gate-title {
    font-family: var(--serif);
    font-size: 28px;
    font-weight: 400;
    color: var(--ink);
    line-height: 1.25;
  }

  .gate-desc {
    font-size: 15px;
    color: var(--secondary);
    margin-bottom: 4px;
  }

  .gate-input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: var(--mono);
    font-size: 14px;
    color: var(--ink);
    background: var(--bg);
    outline: none;
    transition: border-color var(--transition);
  }

  .gate-input:focus { border-color: var(--accent); }

  .gate-input.shake {
    animation: shake 0.35s ease;
    border-color: var(--accent);
  }

  .gate-error {
    font-size: 13px;
    color: var(--accent);
    min-height: 18px;
  }

  .gate-btn {
    align-self: flex-start;
  }

  @keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%       { transform: translateX(-6px); }
    40%       { transform: translateX(6px); }
    60%       { transform: translateX(-4px); }
    80%       { transform: translateX(4px); }
  }

