/*
 * Five Whys. One column, typography first, one accent color.
 * Ported from the design canvas; light tokens on :root, dark under
 * prefers-color-scheme.
 */

:root {
  --bg: #f5f5f2;
  --surface: #ffffff;
  --ink: #1b1d21;
  --muted: #595e65;
  --rule: #d6d7d1;
  --accent: #2448c8;
  --accent-ink: #ffffff;
  --accent-soft: #e8ecfa;
  --error: #a3331f;
  --error-soft: #f8e9e5;
  --serif: "Source Serif 4", Georgia, serif;
  --sans: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131416;
    --surface: #1c1e21;
    --ink: #e8e7e3;
    --muted: #a3a6ab;
    --rule: #34373c;
    --accent: #91a8ff;
    --accent-ink: #0e1325;
    --accent-soft: #1e2542;
    --error: #f2a08d;
    --error-soft: #3a211b;
  }
}

*, *::before, *::after { box-sizing: border-box; }
/* Elements with a display rule (like .btn-link) would otherwise ignore it. */
[hidden] { display: none !important; }

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 640px; margin: 0 auto; padding: 0 20px 64px; }

.honeypot { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }

/* Header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; height: 64px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-family: var(--serif); font-size: 28px; font-weight: 600; color: var(--ink); text-decoration: none; letter-spacing: -0.01em; }
.brand:hover { color: var(--accent); }
/* The mark keeps its own colors so only the wordmark reacts to hover. */
.brand-mark { flex: none; }
.brand-mark-line { fill: none; stroke: var(--ink); stroke-width: 2; }
.brand-mark-root { fill: var(--accent); }
.quiet-link { font-size: 14px; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.quiet-link:hover { color: var(--ink); }

/* Intro (problem entry) */
.intro { padding: 40px 0 32px; }
.intro h1 { margin: 0 0 12px; font-family: var(--serif); font-weight: 600; font-size: 34px; line-height: 1.15; letter-spacing: -0.02em; }
.intro p { margin: 0; font-family: var(--serif); font-size: 19px; line-height: 1.55; color: var(--muted); }

/* Forms */
.field-label { display: block; margin: 0 0 10px; font-family: var(--serif); font-size: 22px; font-weight: 600; line-height: 1.3; }
.textarea {
  display: block; width: 100%; min-height: 148px; padding: 14px 16px;
  border: 1.5px solid var(--rule); border-radius: 10px; background: var(--surface); color: var(--ink);
  font-family: var(--serif); font-size: 19px; line-height: 1.5; resize: vertical;
}
.textarea::placeholder { color: var(--muted); opacity: 0.8; }
.textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.textarea.is-focused { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.textarea[readonly],
form[aria-busy="true"] .textarea { color: var(--muted); }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; margin-top: 14px; }
.actions .meta { display: flex; align-items: center; gap: 16px; margin-right: auto; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 24px; border: 0; border-radius: 10px;
  background: var(--accent); color: var(--accent-ink);
  font-family: var(--sans); font-size: 16px; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.7; cursor: progress; }
.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

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

.turnstile { margin-top: 16px; }

.shared-note { margin: 0 0 24px; font-size: 14px; color: var(--muted); }

/* The chain */
.chain { list-style: none; margin: 0; padding: 0; }
.step { position: relative; display: grid; grid-template-columns: 32px minmax(0, 1fr); column-gap: 16px; padding-bottom: 24px; }
.step::before { content: ""; position: absolute; left: 15px; top: 36px; bottom: 4px; width: 2px; background: var(--rule); }
.chain:not(.open) .step:last-child::before { display: none; }
.chain:not(.open) .step:last-child { padding-bottom: 0; }

.marker {
  display: flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 50%;
  border: 1.5px solid var(--rule); background: var(--bg);
  font-family: var(--mono); font-size: 13px; font-weight: 500; color: var(--muted);
}
.marker.dot::after { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--ink); }
.marker.current, .marker.root { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }

.step-label { margin: 5px 0 4px; font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.step-label.accent { color: var(--accent); }
.step-text { margin: 6px 0 0; font-family: var(--serif); font-size: 16px; line-height: 1.5; }
.step-text.problem { margin-top: 0; font-size: 24px; line-height: 1.35; font-weight: 600; letter-spacing: -0.01em; }
.step.is-root .step-text { font-weight: 600; }
.step.is-root .step-body { margin-top: -2px; padding: 12px 14px; border-radius: 10px; background: var(--accent-soft); }
.step.is-root .step-label { margin-top: 0; }

.ask .ask-label { margin: 0 0 12px; font-family: var(--serif); font-size: 30px; font-weight: 600; line-height: 32px; color: var(--accent); letter-spacing: -0.01em; }

/* Inline error */
.alert {
  display: flex; gap: 10px; align-items: flex-start; margin: 0 0 12px; padding: 12px 14px; border-radius: 10px;
  background: var(--error-soft); color: var(--error); font-size: 15px; font-weight: 500;
}
.alert svg { flex: none; margin-top: 2px; }

/* Result panels */
.panel { margin-top: 32px; padding: 24px 22px; border: 1.5px solid var(--rule); border-radius: 14px; background: var(--surface); }
.panel h2 { margin: 0 0 10px; font-family: var(--serif); font-size: 24px; font-weight: 600; line-height: 1.25; letter-spacing: -0.01em; }
.panel h3 { margin: 24px 0 8px; font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.panel p { margin: 0; font-family: var(--serif); font-size: 18px; line-height: 1.55; }
.panel p + p { margin-top: 12px; }
.panel .lede { color: var(--muted); }
.panel ol { margin: 0; padding: 0; list-style: none; counter-reset: fix; }
.panel ol li { counter-increment: fix; position: relative; padding: 0 0 0 36px; margin: 0 0 14px; font-family: var(--serif); font-size: 18px; line-height: 1.55; }
.panel ol li::before { content: counter(fix); position: absolute; left: 0; top: 2px; width: 24px; height: 24px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); font-family: var(--mono); font-size: 13px; font-weight: 500; display: flex; align-items: center; justify-content: center; }
.panel ol li strong { font-weight: 600; }
.panel code { font-family: var(--mono); font-size: 0.85em; padding: 1px 5px; border-radius: 4px; background: var(--bg); }
.panel-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-top: 20px; padding-top: 18px; border-top: 1.5px solid var(--rule); }
.panel-foot .note { font-size: 14px; color: var(--muted); }
.share-actions { display: flex; flex-wrap: wrap; gap: 0 24px; margin-left: auto; }
.btn-link { display: inline-flex; align-items: center; min-height: 44px; font-weight: 600; color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.btn-link:hover { color: var(--ink); }
button.btn-link { padding: 0; border: 0; background: none; font-family: inherit; font-size: inherit; cursor: pointer; }

.reason { margin-top: 20px; padding: 16px 18px; border-radius: 10px; background: var(--bg); }
.reason .reason-title { margin: 0 0 6px; font-family: var(--sans); font-size: 16px; font-weight: 600; }
.reason p { font-size: 17px; }

/* Call to action under a finished analysis */
.cta { margin-top: 48px; padding: 28px 24px; border-radius: 14px; background: var(--accent-soft); }
.cta h2 { margin: 0 0 8px; font-family: var(--serif); font-size: 26px; font-weight: 600; line-height: 1.25; letter-spacing: -0.01em; }
.cta p { margin: 0 0 20px; font-family: var(--serif); font-size: 18px; line-height: 1.5; color: var(--muted); }

/* Pending summary */
.pending-row { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 15px; }
.pending-row .spinner { color: var(--accent); }
.skeleton { margin-top: 18px; display: flex; flex-direction: column; gap: 10px; }
.skeleton span { display: block; height: 12px; border-radius: 6px; background: var(--rule); opacity: 0.6; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.only-wide { display: none; }

@media (min-width: 720px) {
  .wrap { padding: 0 32px 96px; }
  .top { height: 96px; }
  .brand { font-size: 36px; }
  .intro { padding: 72px 0 40px; }
  .intro h1 { font-size: 44px; }
  .intro p { font-size: 20px; }
  .step { grid-template-columns: 36px minmax(0, 1fr); column-gap: 20px; }
  .marker { width: 36px; height: 36px; }
  .step::before { left: 17px; top: 40px; }
  .step-text { margin-top: 7px; font-size: 17px; }
  .step-text.problem { font-size: 28px; }
  .only-wide { display: inline; }
  .panel { padding: 32px 32px; }
  .cta { padding: 36px 32px; }
  .cta h2 { font-size: 30px; }
}
