/* ============================================================
   ZillaTrax v6 — Guide (Help modal)
   ============================================================

   Replaces the rescue block that lived in polish.css. Those rules were
   recovered from the deleted style.css to stop the modal rendering as raw
   markup; nothing about them was designed, which is why the guide looked
   unlike the rest of the app.

   This follows docs/visual-spec.md — "studio at night":
     - near-black surfaces, grey chrome, and COLOUR MEANS SOMETHING
     - purple is the AI and only the AI
     - green = free/safe, amber = spends credits, red = replaces work
     - section hues come from --color-section-* and are used ONLY for sections
     - type is caption/body/title/readout; spacing is 4/8/12/16 (20/24/32 in modals)

   Layout is a docs shell — a nav rail on the left, one scrolling pane on the
   right — because the guide now carries six sections and top tabs stop being
   scannable past about four.
   ============================================================ */

/* DELIBERATELY OUTSIDE @layer, the same call settings.css makes.
   `.modal { display: none }` in style-v2.css is UNLAYERED, and an unlayered rule
   beats every layered one no matter how specific — so a layered `.help-modal.open
   { display: flex }` loses and the guide opens invisibly. This is the same @layer
   trap that once zeroed 137 padding rules; the fix is to stay out of the layer,
   not to escalate specificity. */

  /* ── Shell ───────────────────────────────────────────────── */
  body .modal.help-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: var(--z-modal, 4000);
    align-items: center;
    justify-content: center;
    padding: var(--space-4, 16px);
  }
  body .modal.help-modal.open { display: flex; }
  /* [hidden] is how modalGuard knows the guide is closed; never let .open win over it. */
  body .modal.help-modal[hidden] { display: none; }

  body .help-modal .help-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.72);
    backdrop-filter: blur(6px);
  }

  body .help-modal .help-modal-content {
    position: relative;
    display: flex;
    flex-direction: column;
    width: min(1080px, 96vw);
    height: min(860px, 92vh);
    background: var(--surface-200, #141417);
    border: 1px solid var(--v6-border-faint, rgba(255, 255, 255, 0.08));
    border-radius: var(--radius-lg, 12px);
    box-shadow: var(--shadow-4);
    overflow: hidden;
    animation: help-rise var(--duration-slow, 260ms) var(--ease-out-expo, ease);
  }
  @keyframes help-rise {
    from { opacity: 0; transform: translateY(12px) scale(0.99); }
    to   { opacity: 1; transform: none; }
  }
  @media (prefers-reduced-motion: reduce) {
    body .help-modal .help-modal-content { animation: none; }
  }

  /* ── Header ──────────────────────────────────────────────── */
  body .help-modal .help-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3, 12px);
    padding: 14px 20px;
    border-bottom: 1px solid var(--v6-border-faint, rgba(255, 255, 255, 0.08));
    background: linear-gradient(180deg, var(--surface-300, #18181b), var(--surface-200, #141417));
    flex: 0 0 auto;
  }
  body .help-modal .help-modal-title { display: flex; align-items: center; gap: 10px; }
  body .help-modal .help-modal-title h2 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.01em;
    color: var(--text-primary, #fafafa);
  }
  /* The guide is AI-adjacent chrome, not an AI action — a tinted mark, not the
     accent gradient, so the purple stays meaningful on Create. */
  body .help-modal .help-modal-title .help-icon {
    display: grid;
    place-items: center;
    width: 26px; height: 26px;
    border-radius: var(--radius-sm, 6px);
    background: color-mix(in oklab, var(--accent-primary, #8b5cf6) 18%, transparent);
    color: var(--accent-primary, #8b5cf6);
  }
  body .help-modal .help-modal-title .help-icon svg { width: 15px; height: 15px; }

  body .help-modal .help-close-btn {
    display: grid;
    place-items: center;
    width: 30px; height: 30px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm, 6px);
    background: transparent;
    color: var(--text-secondary, #a1a1aa);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    transition: background var(--duration-fast, 120ms), color var(--duration-fast, 120ms);
  }
  body .help-modal .help-close-btn:hover {
    background: var(--surface-400, #1f1f23);
    color: var(--text-primary, #fafafa);
  }
  body .help-modal .help-close-btn:focus-visible { box-shadow: var(--ring-focus); outline: none; }

  /* ── How it works strip ──────────────────────────────────── */
  body .help-modal .help-howto {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-2, 8px);
    padding: 10px 20px 12px;
    border-bottom: 1px solid var(--v6-border-faint, rgba(255, 255, 255, 0.08));
    background: var(--surface-100, #0d0d0f);
    flex: 0 0 auto;
  }
  body .help-modal .help-howto__title {
    grid-column: 1 / -1;
    margin: 0 0 2px;
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted, #71717a);
  }
  body .help-modal .help-howto__line {
    margin: 0;
    padding: 8px 11px;
    font-size: 13px;
    line-height: 1.4;
    color: var(--text-secondary, #a1a1aa);
    background: var(--surface-300, #18181b);
    border: 1px solid var(--v6-border-faint, rgba(255, 255, 255, 0.06));
    border-radius: var(--radius-sm, 6px);
  }
  body .help-modal .help-howto__line b { color: var(--text-primary, #fafafa); font-weight: 600; }
  @media (max-width: 860px) {
    body .help-modal .help-howto { grid-template-columns: 1fr 1fr; }
  }

  /* ── Body: nav rail + pane ───────────────────────────────── */
  body .help-modal .help-body {
    display: flex;
    min-height: 0;
    flex: 1 1 auto;
  }

  body .help-modal .help-tabs {
    display: flex;
    flex-direction: column;
    gap: 2px;
    width: 190px;
    flex: 0 0 190px;
    padding: 12px 8px;
    border-right: 1px solid var(--v6-border-faint, rgba(255, 255, 255, 0.08));
    background: var(--surface-100, #0d0d0f);
    overflow-y: auto;
  }
  body .help-modal .help-tab {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 10px;
    border: 0;
    border-radius: var(--radius-sm, 6px);
    background: transparent;
    color: var(--text-secondary, #a1a1aa);
    font-size: 13px;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    transition: background var(--duration-fast, 120ms), color var(--duration-fast, 120ms);
  }
  body .help-modal .help-tab .tab-icon {
    display: grid; place-items: center;
    width: 16px; height: 16px;
    color: var(--text-muted, #71717a);
    flex: 0 0 auto;
  }
  body .help-modal .help-tab .tab-icon svg { width: 15px; height: 15px; }
  body .help-modal .help-tab:hover { background: var(--surface-300, #18181b); color: var(--text-primary, #fafafa); }
  body .help-modal .help-tab.active {
    background: color-mix(in oklab, var(--accent-primary, #8b5cf6) 14%, transparent);
    color: var(--text-primary, #fafafa);
  }
  body .help-modal .help-tab.active .tab-icon { color: var(--accent-primary, #8b5cf6); }
  body .help-modal .help-tab:focus-visible { box-shadow: var(--ring-focus); outline: none; }

  body .help-modal .help-tab-content {
    flex: 1 1 auto;
    min-width: 0;
    overflow-y: auto;
    padding: 20px 24px 28px;
    scroll-behavior: smooth;
  }
  body .help-modal .help-pane { display: none; }
  body .help-modal .help-pane.active { display: block; animation: help-fade var(--duration-base, 180ms) var(--ease-out-quart, ease); }
  @keyframes help-fade { from { opacity: 0; } to { opacity: 1; } }
  @media (prefers-reduced-motion: reduce) {
    body .help-modal .help-pane.active { animation: none; }
  }

  @media (max-width: 720px) {
    body .help-modal .help-body { flex-direction: column; }
    body .help-modal .help-tabs {
      flex: 0 0 auto; width: auto; flex-direction: row; overflow-x: auto;
      border-right: 0; border-bottom: 1px solid var(--v6-border-faint, rgba(255, 255, 255, 0.08));
    }
    body .help-modal .help-tab { width: auto; white-space: nowrap; }
  }

  /* ── Prose ───────────────────────────────────────────────── */
  body .help-modal .help-lede {
    margin: 0 0 20px;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-secondary, #a1a1aa);
  }
  body .help-modal .help-lede strong { color: var(--text-primary, #fafafa); font-weight: 600; }

  body .help-modal .section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 24px 0 10px;
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted, #71717a);
  }
  body .help-modal .help-pane > .section-title:first-child { margin-top: 0; }
  body .help-modal .section-title::after {
    content: '';
    flex: 1 1 auto;
    height: 1px;
    background: var(--v6-border-faint, rgba(255, 255, 255, 0.08));
  }

  body .help-modal p { font-size: 13px; line-height: 1.5; color: var(--text-secondary, #a1a1aa); }
  body .help-modal strong { color: var(--text-primary, #fafafa); font-weight: 600; }
  body .help-modal code {
    padding: 1px 5px;
    font-family: var(--font-mono, ui-monospace, monospace);
    font-size: 12px;
    color: var(--text-primary, #fafafa);
    background: var(--surface-400, #1f1f23);
    border-radius: 4px;
  }

  /* ── Numbered steps ──────────────────────────────────────── */
  body .help-modal .help-steps { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; list-style: none; counter-reset: hstep; }
  body .help-modal .help-step {
    display: grid;
    grid-template-columns: 26px 1fr;
    gap: 12px;
    align-items: start;
    padding: 12px 14px;
    background: var(--surface-300, #18181b);
    border: 1px solid var(--v6-border-faint, rgba(255, 255, 255, 0.06));
    border-radius: var(--radius-md, 8px);
  }
  body .help-modal .help-step::before {
    counter-increment: hstep;
    content: counter(hstep);
    display: grid; place-items: center;
    width: 26px; height: 26px;
    font-family: var(--font-mono, ui-monospace, monospace);
    font-size: 12px; font-weight: 500;
    color: var(--accent-primary, #8b5cf6);
    background: color-mix(in oklab, var(--accent-primary, #8b5cf6) 15%, transparent);
    border-radius: var(--radius-pill, 999px);
  }
  body .help-modal .help-step__body { min-width: 0; }
  body .help-modal .help-step__title { font-size: 13px; font-weight: 600; color: var(--text-primary, #fafafa); }
  body .help-modal .help-step__sub { margin: 3px 0 0; font-size: 13px; line-height: 1.45; color: var(--text-secondary, #a1a1aa); }

  /* ── Cards ───────────────────────────────────────────────── */
  body .help-modal .help-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 8px; }
  body .help-modal .help-card {
    padding: 12px 14px;
    background: var(--surface-300, #18181b);
    border: 1px solid var(--v6-border-faint, rgba(255, 255, 255, 0.06));
    border-radius: var(--radius-md, 8px);
  }
  body .help-modal .help-card__title {
    display: flex; align-items: center; gap: 7px;
    font-size: 13px; font-weight: 600;
    color: var(--text-primary, #fafafa);
  }
  body .help-modal .help-card__title svg { width: 14px; height: 14px; color: var(--text-muted, #71717a); }
  body .help-modal .help-card p { margin: 5px 0 0; }

  /* A card that carries a verdict. Left edge only — the spec keeps fills neutral. */
  body .help-modal .help-card--good { border-left: 2px solid var(--color-success, #22c55e); }
  body .help-modal .help-card--warn { border-left: 2px solid var(--color-transport-pause, #f59e0b); }
  body .help-modal .help-card--danger { border-left: 2px solid var(--color-danger, #ef4444); }

  /* ── Action reference ────────────────────────────────────── */
  body .help-modal .help-actions { display: flex; flex-direction: column; gap: 6px; }
  body .help-modal .help-action {
    display: grid;
    grid-template-columns: 28px 1fr auto;
    gap: 12px;
    align-items: start;
    padding: 11px 13px;
    background: var(--surface-300, #18181b);
    border: 1px solid var(--v6-border-faint, rgba(255, 255, 255, 0.06));
    border-radius: var(--radius-md, 8px);
  }
  body .help-modal .help-action__icon {
    display: grid; place-items: center;
    width: 28px; height: 28px;
    border-radius: var(--radius-sm, 6px);
    background: var(--surface-400, #1f1f23);
    color: var(--text-secondary, #a1a1aa);
  }
  body .help-modal .help-action__icon svg { width: 15px; height: 15px; }
  body .help-modal .help-action__label { font-size: 13px; font-weight: 600; color: var(--text-primary, #fafafa); }
  body .help-modal .help-action__sub { margin: 3px 0 0; font-size: 12px; line-height: 1.45; color: var(--text-secondary, #a1a1aa); }
  body .help-modal .help-action__meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: 0 0 auto; }

  /* Cost + safety chips. Same vocabulary as the Create menu so the guide and
     the menu can never say different things about the same action. */
  body .help-modal .help-chip {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px 7px;
    font-family: var(--font-mono, ui-monospace, monospace);
    font-size: 11px; font-weight: 500;
    white-space: nowrap;
    border-radius: var(--radius-pill, 999px);
    border: 1px solid transparent;
  }
  body .help-modal .help-chip--free {
    color: var(--color-success, #22c55e);
    background: color-mix(in oklab, var(--color-success, #22c55e) 12%, transparent);
    border-color: color-mix(in oklab, var(--color-success, #22c55e) 30%, transparent);
  }
  body .help-modal .help-chip--credits {
    color: var(--color-transport-pause, #f59e0b);
    background: color-mix(in oklab, var(--color-transport-pause, #f59e0b) 12%, transparent);
    border-color: color-mix(in oklab, var(--color-transport-pause, #f59e0b) 30%, transparent);
  }
  body .help-modal .help-chip--replaces {
    color: var(--color-danger, #ef4444);
    background: color-mix(in oklab, var(--color-danger, #ef4444) 12%, transparent);
    border-color: color-mix(in oklab, var(--color-danger, #ef4444) 30%, transparent);
  }
  body .help-modal .help-chip--undo {
    color: var(--text-muted, #71717a);
    background: var(--surface-400, #1f1f23);
    border-color: var(--v6-border-faint, rgba(255, 255, 255, 0.06));
  }

  body .help-modal .help-legend { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }

  /* ── Anatomy diagram ─────────────────────────────────────── */
  body .help-modal .help-anatomy {
    width: 100%;
    margin: 0 0 4px;
    background: var(--surface-100, #0d0d0f);
    border: 1px solid var(--v6-border-faint, rgba(255, 255, 255, 0.06));
    border-radius: var(--radius-md, 8px);
    padding: 12px;
  }
  /* Capped so the SVG's own 10px type renders near 10px. Unconstrained it
     scaled with the pane and the diagram shouted over the steps beside it. */
  body .help-modal .help-anatomy svg { display: block; width: 100%; max-width: 560px; height: auto; margin: 0 auto; }
  body .help-modal .help-anatomy__caption {
    margin: 8px 2px 0;
    font-size: 12px;
    color: var(--text-muted, #71717a);
  }

  /* ── Shortcuts ───────────────────────────────────────────── */
  body .help-modal .shortcut-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 6px; }
  body .help-modal .shortcut-item {
    display: grid;
    grid-template-columns: minmax(96px, auto) 1fr;
    gap: 12px;
    align-items: baseline;
    padding: 9px 12px;
    background: var(--surface-300, #18181b);
    border: 1px solid var(--v6-border-faint, rgba(255, 255, 255, 0.06));
    border-radius: var(--radius-sm, 6px);
  }
  body .help-modal .shortcut-keys { display: flex; gap: 3px; align-items: center; flex-wrap: wrap; }
  body .help-modal .shortcut-name { font-size: 13px; font-weight: 500; color: var(--text-primary, #fafafa); }
  body .help-modal .shortcut-desc { margin: 2px 0 0; font-size: 12px; line-height: 1.4; color: var(--text-secondary, #a1a1aa); }
  body .help-modal kbd {
    display: inline-block;
    min-width: 20px;
    padding: 2px 6px;
    font-family: var(--font-mono, ui-monospace, monospace);
    font-size: 11px;
    font-weight: 500;
    line-height: 1.4;
    text-align: center;
    color: var(--text-primary, #fafafa);
    background: var(--surface-400, #1f1f23);
    border: 1px solid var(--v6-border-default, rgba(255, 255, 255, 0.12));
    border-bottom-width: 2px;
    border-radius: 5px;
  }
  body .help-modal .shortcut-keys .kbd-plus { color: var(--text-muted, #71717a); font-size: 11px; }

  /* ── Glossary ────────────────────────────────────────────── */
  body .help-modal .glossary-list { display: flex; flex-direction: column; gap: 6px; }
  body .help-modal .glossary-item {
    display: grid;
    grid-template-columns: minmax(120px, 150px) 1fr;
    gap: 14px;
    padding: 10px 13px;
    background: var(--surface-300, #18181b);
    border: 1px solid var(--v6-border-faint, rgba(255, 255, 255, 0.06));
    border-radius: var(--radius-sm, 6px);
  }
  body .help-modal .glossary-term { font-size: 13px; font-weight: 600; color: var(--text-primary, #fafafa); }
  body .help-modal .glossary-def { font-size: 13px; line-height: 1.45; color: var(--text-secondary, #a1a1aa); }
  @media (max-width: 620px) {
    body .help-modal .glossary-item { grid-template-columns: 1fr; gap: 3px; }
  }

  /* ── Section colour key ──────────────────────────────────── */
  body .help-modal .help-sections { display: flex; flex-wrap: wrap; gap: 6px; }
  body .help-modal .help-section-chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px 4px 6px;
    font-size: 12px;
    color: var(--text-primary, #fafafa);
    background: var(--surface-300, #18181b);
    border: 1px solid var(--v6-border-faint, rgba(255, 255, 255, 0.06));
    border-radius: var(--radius-pill, 999px);
  }
  body .help-modal .help-section-chip i {
    width: 10px; height: 10px; border-radius: 3px; display: block;
  }

  /* ── Footer ──────────────────────────────────────────────── */
  body .help-modal .help-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3, 12px);
    padding: 10px 20px;
    border-top: 1px solid var(--v6-border-faint, rgba(255, 255, 255, 0.08));
    background: var(--surface-100, #0d0d0f);
    font-size: 12px;
    color: var(--text-muted, #71717a);
    flex: 0 0 auto;
  }
  body .help-modal .about-version-badge {
    font-family: var(--font-mono, ui-monospace, monospace);
    font-size: 11px;
    color: var(--text-secondary, #a1a1aa);
    padding: 2px 8px;
    background: var(--surface-400, #1f1f23);
    border: 1px solid var(--v6-border-faint, rgba(255, 255, 255, 0.06));
    border-radius: var(--radius-pill, 999px);
  }

  /* ── About pane ──────────────────────────────────────────── */
  body .help-modal .about-content { display: flex; flex-direction: column; gap: 12px; }
  body .help-modal .about-content h3 { margin: 0; font-size: 14px; font-weight: 600; color: var(--text-primary, #fafafa); }
  body .help-modal .about-tagline { margin: 0; font-size: 13px; color: var(--text-secondary, #a1a1aa); }
  body .help-modal .about-section h4 {
    margin: 0 0 4px;
    font-size: 12px; font-weight: 500;
    letter-spacing: 0.06em; text-transform: uppercase;
    color: var(--text-muted, #71717a);
  }
  body .help-modal .feature-list { margin: 0; padding-left: 18px; }
  body .help-modal .feature-list li { font-size: 13px; line-height: 1.55; color: var(--text-secondary, #a1a1aa); }
