/* ---------------------------------------------------------------------------
   Layout and components for the guided-chain calculator.
   --------------------------------------------------------------------------- */

/* ------------------------------------------------------------- top bar ---- */

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 18px;
  padding: 11px clamp(14px, 3vw, 30px);
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: saturate(1.6) blur(12px);
  -webkit-backdrop-filter: saturate(1.6) blur(12px);
}

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
/* The mark is a supplied PNG with a transparent background, so it needs no tile
   and reads on either theme. */
.brand-mark { display: grid; place-items: center; width: 36px; height: 36px; flex: none; }
.brand-mark img { width: 36px; height: 36px; display: block; object-fit: contain; }
.brand-text { min-width: 0; }
.brand-title { display: block; font-size: 15px; font-weight: 680; letter-spacing: -.015em; white-space: nowrap; }
/* CVSS is an initialism and is uppercase everywhere in the spec — including in
   the vector strings this tool emits — so the wordmark matches. The TLD stays
   lowercase and lighter, because ".AE" reads as a file extension. */
.brand-tld { font-weight: 500; color: var(--text-muted); }
.brand-sub { display: block; font-size: 11.5px; color: var(--text-faint); white-space: nowrap; }
.topbar-spacer { flex: 1 1 auto; }

.version-switch {
  position: relative; display: flex; padding: 3px; gap: 2px; flex: none;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
}
.version-switch .glider {
  position: absolute; top: 3px; left: 3px; height: calc(100% - 6px);
  border-radius: 999px; background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow-sm); pointer-events: none;
  transition: transform var(--speed) var(--ease), width var(--speed) var(--ease);
}
.version-tab {
  position: relative; z-index: 1; border: 0; background: none;
  padding: 6px 15px; border-radius: 999px; font-size: 13px; font-weight: 600;
  color: var(--text-muted); cursor: pointer; white-space: nowrap;
  transition: color var(--speed) var(--ease);
}
.version-tab:hover { color: var(--text); }
.version-tab[aria-selected="true"] { color: var(--accent); }

.icon-btn {
  display: grid; place-items: center; width: 33px; height: 33px; flex: none;
  border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-muted); cursor: pointer;
  transition: background var(--speed) var(--ease), color var(--speed) var(--ease),
              border-color var(--speed) var(--ease);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }
.icon-btn svg { width: 17px; height: 17px; }

.theme-toggle .moon { display: none; }
:root[data-theme="dark"] .theme-toggle .sun { display: none; }
:root[data-theme="dark"] .theme-toggle .moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .sun { display: none; }
  :root:not([data-theme="light"]) .theme-toggle .moon { display: block; }
}

/* -------------------------------------------------------------- page ---- */

/*
 * The score bar is the last element on the page. A flex column with a growing
 * main means it sits at the bottom even when the content is shorter than the
 * viewport, while position: sticky keeps it visible on the way down.
 */
body { display: flex; flex-direction: column; min-height: 100vh; }
.page {
  flex: 1 0 auto;
  width: 100%;
  max-width: 1400px; margin: 0 auto;
  padding: clamp(16px, 2.4vw, 26px) clamp(14px, 3vw, 30px) 28px;
}
.page-hint { font-size: 13.5px; color: var(--text-muted); margin-bottom: 16px; }
.page-hint b { color: var(--text); font-weight: 700; }

/* ------------------------------------------------------------- notice ---- */

.notice {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 11px 14px; border-radius: var(--r-md);
  border: 1px solid var(--border); background: var(--surface);
  font-size: 13.5px; margin-bottom: 14px; box-shadow: var(--shadow-sm);
}
.notice[hidden] { display: none; }
.notice.is-warn  { border-color: color-mix(in srgb, var(--warn) 40%, var(--border)); background: color-mix(in srgb, var(--warn) 8%, var(--surface)); }
.notice.is-error { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); background: color-mix(in srgb, var(--danger) 8%, var(--surface)); }
.notice-icon { flex: none; margin-top: 1px; }
.notice-icon svg { width: 16px; height: 16px; }
.notice.is-warn .notice-icon { color: var(--warn); }
.notice.is-error .notice-icon { color: var(--danger); }
.notice-body { min-width: 0; }
.notice-body p { margin: 0 0 3px; }
.notice-body p:last-child { margin-bottom: 0; }
.notice-close { margin-left: auto; }

/* -------------------------------------------------------------- chain ---- */

.chain { display: grid; align-items: center; gap: 0; }

.pillar {
  background: var(--surface); border: 1px solid var(--border); border-radius: 13px;
  padding: 14px 11px; text-align: center; box-shadow: var(--shadow-sm);
}
.pillar-ico {
  width: 36px; height: 36px; margin: 0 auto 8px; display: grid; place-items: center;
  border-radius: 10px; background: var(--accent-soft); color: var(--accent);
}
.pillar-ico svg { width: 19px; height: 19px; }
.pillar-title { font-size: 12.5px; font-weight: 650; }
.pillar-sub { display: block; margin-top: 3px; font-size: 11px; color: var(--text-faint); line-height: 1.4; }
.pillar.is-threat .pillar-ico { background: var(--sev-critical-bg); color: var(--sev-critical); }

.pillar.is-outcome { transition: background var(--speed) var(--ease), border-color var(--speed) var(--ease); }
.pillar.is-outcome[data-tone="crit"] {
  border-color: color-mix(in srgb, var(--sev-critical) 35%, var(--border));
  background: linear-gradient(180deg, var(--surface), var(--sev-critical-bg));
}
.pillar.is-outcome[data-tone="crit"] .pillar-ico { background: var(--sev-critical); color: #fff; }
.pillar.is-outcome[data-tone="warm"] {
  border-color: color-mix(in srgb, var(--sev-medium) 35%, var(--border));
  background: linear-gradient(180deg, var(--surface), var(--sev-medium-bg));
}
.pillar.is-outcome[data-tone="warm"] .pillar-ico { background: var(--sev-medium); color: #fff; }
.pillar.is-outcome[data-tone="idle"] .pillar-ico { background: var(--surface-3); color: var(--text-faint); }

.chain-col { display: flex; flex-direction: column; gap: 8px; }

.link { display: flex; align-items: center; justify-content: center; }
.link svg { overflow: visible; }
.link:not(.is-fan) svg { width: 30px; height: 16px; }

/* --------------------------------------------------------------- step ---- */

.step {
  position: relative; background: var(--surface);
  border: 1px solid var(--border); border-radius: 11px;
  padding: 9px 11px 10px 15px; box-shadow: var(--shadow-sm);
  transition: border-color var(--speed) var(--ease), box-shadow var(--speed) var(--ease);
}
.step::before {
  content: ""; position: absolute; left: 0; top: 9px; bottom: 9px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--step-accent, transparent);
}
.step[data-accent="hot"]  { --step-accent: var(--sev-critical); }
.step[data-accent="warm"] { --step-accent: var(--sev-medium); }
.step[data-accent="cool"] { --step-accent: var(--sev-low); }
.step[data-accent="none"] { --step-accent: var(--border-strong); }
.step.is-unset { border-style: dashed; }
.step.is-focused {
  border-color: var(--accent); border-style: solid;
  box-shadow: 0 0 0 3px var(--accent-ring), var(--shadow-md);
}

/* Every part of the card is clickable, including the gaps between the pills. */
.step { cursor: pointer; }
.step:hover { border-color: var(--border-strong); }
.step.is-focused:hover { border-color: var(--accent); }

.step-head { display: flex; align-items: center; gap: 6px; }
.step-q {
  font-size: 11.5px; color: var(--text-muted); font-weight: 550;
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.step-id {
  font-family: var(--mono); font-size: 9.5px; font-weight: 600;
  color: var(--text-faint); background: var(--surface-3);
  padding: 1px 5px; border-radius: 4px;
}
.why {
  margin-left: auto; flex: none; width: 18px; height: 18px; padding: 0;
  border-radius: 50%; border: 1px solid var(--border-strong);
  background: none; color: var(--text-faint); cursor: pointer;
  font-size: 10px; font-weight: 700; line-height: 1;
  transition: background var(--speed) var(--ease), border-color var(--speed) var(--ease), color var(--speed) var(--ease);
}
.why:hover { border-color: var(--accent); color: var(--accent); }
.step.is-focused .why { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* Stretches the full width of the card so the gaps around the pills are live too. */
.picks { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; width: 100%; }
.pick-input {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}
.pick {
  font-size: 11px; padding: 3px 9px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border-strong); color: var(--text-muted);
  background: var(--surface); white-space: nowrap; user-select: none;
  /* Short and linear: this only smooths hover. Selection skips it entirely below,
     so clicking a value lands on the very next frame. */
  transition: background 90ms linear, color 90ms linear, border-color 90ms linear;
}
.pick:hover { border-color: var(--accent); color: var(--accent); }
.pick-input:checked + .pick {
  background: var(--accent); border-color: var(--accent); color: var(--on-accent);
  transition: none;
}
.pick-input:checked + .pick.is-undefined {
  background: var(--surface-3); border-color: var(--border-strong); color: var(--text-muted);
}
.pick-input:focus-visible + .pick { outline: 2px solid var(--accent); outline-offset: 2px; }

.step.in-pillar {
  margin-top: 8px; text-align: left; box-shadow: none;
  background: var(--surface-sunk); padding: 8px 10px 9px 13px;
}
.step.in-pillar .step-q { font-size: 11px; }

/* --------------------------------------------------------------- dock ---- */

.dock {
  margin-top: 18px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow-md); padding: 20px clamp(15px, 2.4vw, 26px);
  min-height: 300px;
}
.dock-hint {
  display: flex; align-items: center; gap: 8px; margin-bottom: 13px;
  font-size: 11px; font-weight: 700; letter-spacing: .13em; text-transform: uppercase;
  color: var(--text-faint);
}
.dock-hint::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }

.dock-grid { display: grid; grid-template-columns: minmax(0, 330px) minmax(0, 1fr); gap: clamp(16px, 2.8vw, 38px); }
.dock-eyebrow {
  font-size: 11px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
  color: var(--accent); margin-bottom: 8px;
}
.dock-q { font-size: clamp(18px, 2.1vw, 24px); line-height: 1.2; letter-spacing: -.022em; font-weight: 700; margin-bottom: 9px; }
.dock-p { font-size: 14px; line-height: 1.6; color: var(--text-muted); }

.choices { display: grid; gap: 8px; align-content: start; }
.choice {
  display: flex; align-items: flex-start; gap: 13px; width: 100%; text-align: left;
  padding: 12px 14px; background: var(--surface);
  border: 1.5px solid var(--border); border-radius: 12px; cursor: pointer;
  transition: border-color var(--speed) var(--ease), box-shadow var(--speed) var(--ease);
}
.choice:hover { border-color: var(--border-strong); }
.choice.is-selected {
  border-color: var(--accent);
  /* A soft lift from the accent tint up into the surface, as in the concept. */
  background: linear-gradient(0deg, var(--accent-soft), var(--surface));
  box-shadow: 0 0 0 3px var(--accent-ring);
  transition: none;
}

/* The icon says something about the answer — see ICONS_BY_METRIC in explain.js. */
.choice-glyph {
  flex: none; width: 34px; height: 34px; border-radius: 9px;
  background: var(--surface-2); color: var(--text-muted);
  display: grid; place-items: center;
  transition: background var(--speed) var(--ease), color var(--speed) var(--ease);
}
.choice-glyph svg { width: 17px; height: 17px; }
.choice:hover .choice-glyph { background: var(--surface-3); color: var(--text); }
.choice.is-selected .choice-glyph { background: var(--accent); color: var(--on-accent); transition: none; }

.choice-text { min-width: 0; flex: 1; }
/* spans inside a button — they must be told to stack */
.choice-title { display: block; font-size: 14.5px; font-weight: 650; letter-spacing: -.008em; }
.choice-desc  { display: block; font-size: 13px; color: var(--text-muted); line-height: 1.5; margin-top: 2px; }
.choice-note  { display: block; font-size: 11px; color: var(--text-faint); margin-top: 6px; }
.choice-note code {
  font-family: var(--mono); font-size: 10.5px; background: var(--surface-3);
  padding: 1px 5px; border-radius: 4px; color: var(--text-muted);
}
.choice-tick {
  flex: none; width: 20px; height: 20px; border-radius: 50%; margin-top: 7px;
  border: 1.5px solid var(--border-strong); display: grid; place-items: center;
}
.choice-tick svg { width: 11px; height: 11px; color: #fff; opacity: 0; }
.choice.is-selected .choice-tick { background: var(--accent); border-color: var(--accent); }
.choice.is-selected .choice-tick svg { opacity: 1; }

/* ----------------------------------------------------------- sections ---- */

.section {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-sm);
  margin-top: 14px; overflow: hidden;
}
.section-head {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 14px 17px; background: none; border: 0; text-align: left; cursor: pointer;
}
.section-head:hover { background: var(--surface-2); }
.section-headings { min-width: 0; flex: 1; }
.section-title { display: block; font-size: 14px; font-weight: 650; letter-spacing: -.01em; }
.section-blurb { display: block; font-size: 12.5px; color: var(--text-muted); margin-top: 3px; line-height: 1.45; }
.section-badge {
  flex: none; font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 999px;
  background: var(--surface-3); color: var(--text-muted); font-variant-numeric: tabular-nums;
}
.section-badge.is-set { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.section-chevron { flex: none; color: var(--text-faint); transition: transform var(--speed) var(--ease); }
.section-chevron svg { width: 16px; height: 16px; display: block; }
.section[data-open="false"] .section-chevron { transform: rotate(-90deg); }
.section[data-open="false"] .section-body { display: none; }
.section-body { padding: 4px 17px 17px; border-top: 1px solid var(--border); }

.subgroup-title {
  font-size: 10.5px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
  color: var(--text-faint); margin: 14px 0 9px;
}
.step-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(238px, 1fr)); gap: 8px; }

/* ------------------------------------------------------------ verdict ---- */

.verdict {
  position: sticky; bottom: 0; z-index: 35;
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(14px);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  box-shadow: 0 -6px 24px rgba(0, 0, 0, .07);
}
.verdict-inner {
  max-width: 1400px; margin: 0 auto;
  display: grid; grid-template-columns: auto minmax(0, 1fr) minmax(230px, 300px);
  align-items: center; gap: clamp(14px, 2.2vw, 26px);
  padding: 12px clamp(14px, 3vw, 30px);
}

.verdict-score { display: flex; align-items: center; gap: 11px; }
.score {
  font-size: 40px; font-weight: 800; letter-spacing: -.045em; line-height: 1;
  font-variant-numeric: tabular-nums; color: var(--sev, var(--text-faint));
}
.score.is-empty { font-size: 30px; color: var(--text-faint); }
.sev-chip {
  padding: 4px 11px; border-radius: 999px; font-size: 11px; font-weight: 700;
  letter-spacing: .07em; text-transform: uppercase;
  background: var(--sev-bg, var(--surface-3)); color: var(--sev, var(--text-muted));
}

.verdict-mid { min-width: 0; }
.story { font-size: 13.5px; line-height: 1.55; color: var(--text-muted); }
.story b { color: var(--text); font-weight: 650; }
.story-todo { color: var(--warn); }
.story-todo b { color: var(--warn); font-family: var(--mono); font-size: 12.5px; }

.subscores { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.chip {
  display: inline-flex; align-items: baseline; gap: 5px;
  font-size: 11.5px; font-weight: 650; font-variant-numeric: tabular-nums;
  padding: 3px 9px; border-radius: 999px;
  background: var(--sev-bg, var(--surface-3)); color: var(--sev, var(--text-muted));
}
.chip i { font-style: normal; font-weight: 500; opacity: .75; }
.chip.is-quiet { background: var(--surface-3); color: var(--text-faint); font-family: var(--mono); font-size: 10.5px; }

.verdict-vec { min-width: 0; }
.vector-string {
  display: block; font-size: 11.5px; line-height: 1.55; word-break: break-all;
  background: var(--surface-sunk); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 7px 10px; color: var(--text); max-height: 56px; overflow-y: auto;
}
.vector-string .vs-prefix { color: var(--accent); font-weight: 600; }
.vector-string .vs-key { color: var(--text-muted); }
.vector-string .vs-sep { color: var(--text-faint); }

.btn-row { display: flex; gap: 6px; margin-top: 7px; }
.btn {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 10px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface-2); font-size: 12px; font-weight: 600; color: var(--text); cursor: pointer;
  transition: background var(--speed) var(--ease), border-color var(--speed) var(--ease), color var(--speed) var(--ease);
}
.btn:hover:not(:disabled) { background: var(--surface-3); border-color: var(--border-strong); }
.btn svg { width: 13px; height: 13px; flex: none; }
.btn.is-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.is-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.is-done { background: color-mix(in srgb, var(--ok) 16%, var(--surface-2)); border-color: var(--ok); color: var(--ok); }
.btn.is-ghost { flex: 0 0 auto; background: none; border-color: transparent; color: var(--text-muted); }
.btn.is-ghost:hover { background: var(--surface-2); color: var(--text); }

/* --------------------------------------------------------- responsive ---- */

/*
 * When the diagram will not fit at a readable width, js/ui.js measures that and
 * adds .is-stacked — the chain becomes a plain vertical list and the connectors
 * disappear. Measured rather than guessed, because v3.1 and v4.0 need very
 * different amounts of room.
 */
.chain.is-stacked { grid-template-columns: minmax(0, 1fr) !important; gap: 12px; }
.chain.is-stacked .link { display: none; }
.chain.is-stacked .pillar { text-align: left; }
.chain.is-stacked .pillar-ico { margin-left: 0; }
.chain.is-stacked .step-grid,
.chain.is-stacked .chain-col { gap: 8px; }

@media (max-width: 1180px) {
  .dock-grid { grid-template-columns: 1fr; gap: 15px; }
  .dock { min-height: 0; }
}

@media (max-width: 900px) {
  .verdict-inner { grid-template-columns: auto minmax(0, 1fr); row-gap: 10px; }
  .verdict-vec { grid-column: 1 / -1; }
  .btn { flex: 1; }
  .btn.is-ghost { flex: 0 0 auto; }
}

@media (max-width: 640px) {
  .brand-text { display: none; }
  .version-tab { padding: 6px 11px; font-size: 12.5px; }
  .page-hint { display: none; }
  .verdict-inner { grid-template-columns: 1fr; row-gap: 8px; padding: 10px 14px; }
  .verdict-score { gap: 9px; }
  .score { font-size: 30px; }
  .section-blurb { display: none; }
  .step-grid { grid-template-columns: 1fr; }

  /*
   * The narrative is the best part of this design, but a sticky bar that eats
   * half a phone screen is not. Clamp it here; the full sentence is still read
   * out to screen readers, and there is room for it again the moment the
   * viewport grows.
   */
  .story {
    font-size: 12.5px; line-height: 1.45;
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3;
    overflow: hidden;
  }
  .subscores { margin-top: 5px; }
  .vector-string { max-height: 40px; font-size: 11px; }
  .btn-row { margin-top: 6px; }
  .btn .btn-label { font-size: 11.5px; }
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}
