
:root {
  color-scheme: light;
  --ink: #f0ece5;
  --panel: #fffdfa;
  --panel-2: #f7f3ec;
  --fg: #1a1714;
  --muted: #6f665d;
  --line: #e3ded6;
  --line-bright: #d2ccc3;
  --accent: #1a1714;
  --state-pass: #177044;
  --state-caution: #9c5500;
  --state-fail: #b02020;
  --meter-track: #e7e3db;
  --fail-tint: rgba(176, 32, 32, 0.07);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", YuGothic, Meiryo, Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, "Cascadia Code", "JetBrains Mono", Menlo, Consolas, "Courier New", monospace;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #0d0b09;
  --panel: #171410;
  --panel-2: #1e1a15;
  --fg: #f2f0ec;
  --muted: #8a8278;
  --line: #252118;
  --line-bright: #342f25;
  --accent: #ffffff;
  --state-pass: #4ec994;
  --state-caution: #d4883a;
  --state-fail: #e86a5a;
  --meter-track: #342f25;
  --fail-tint: rgba(232, 106, 90, 0.05);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  background: var(--ink);
  color: var(--fg);
  font-family: var(--sans);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}

/* Home state: #app grows to fill the viewport so the hero centers vertically
   instead of clinging to the top (which read as a tall mobile screen). */
#app {
  position: relative;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: clamp(2.5rem, 7vh, 4.5rem) 1.5rem 6rem;
  flex: 1;
  display: flex;
  flex-direction: column;
}
/* Once a scan runs, top-anchor the content and widen for the data-dense report. */
#app.has-results { flex: none; display: block; max-width: 1040px; }
#home { flex: 1; display: flex; flex-direction: column; justify-content: center; }
.view { animation: fade 0.35s ease both; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ── Home ─────────────────────────────────────────────────────────────── */
.brand-lockup { display: flex; align-items: baseline; }
.brand {
  font-family: var(--mono);
  font-size: clamp(2.1rem, 6vw, 2.9rem);
  font-weight: 700;
  letter-spacing: -0.045em;
  color: var(--fg);
}
.theme-toggle {
  position: absolute; top: 1.25rem; right: 1.25rem; z-index: 1;
  background: transparent; border: 1px solid var(--line-bright);
  color: var(--muted); border-radius: 8px;
  width: 2rem; height: 2rem; line-height: 1; font-size: 1rem;
  cursor: pointer; transition: color 0.15s, border-color 0.15s;
}
.theme-toggle:hover { color: var(--fg); border-color: var(--muted); }
.theme-toggle:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
.tagline { color: var(--muted); margin: 0.65rem 0 2.25rem; font-size: 0.95rem; }

/* Command-bar style form: input + button share one framed control. */
#scan-form {
  display: flex;
  background: var(--panel);
  border: 1px solid var(--line-bright);
  border-radius: 10px;
  overflow: hidden;
  transition: border-color 0.18s, box-shadow 0.18s;
}
#scan-form:focus-within {
  border-color: var(--muted);
  box-shadow: 0 0 0 1px var(--muted);
}
#target {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  color: var(--fg);
  padding: 0.85rem 1rem;
  font: inherit;
  /* The value is a URL — mono reads it more clearly than the sans body. */
  font-family: var(--mono);
  letter-spacing: -0.01em;
}
#target::placeholder { color: var(--muted); }
#target:focus { outline: none; }
#target[readonly] { color: var(--muted); }

button { font: inherit; cursor: pointer; touch-action: manipulation; }
.btn-analyze {
  background: var(--accent);
  color: var(--ink);
  border: none;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 0.85rem 1.4rem;
  white-space: nowrap;
  transition: filter 0.15s;
}
.btn-analyze:hover { filter: brightness(0.9); }
.btn-analyze:disabled { opacity: 0.4; cursor: default; }
.btn-analyze:focus-visible { outline: 2px solid var(--fg); outline-offset: -4px; }

/* Keep the button width stable across the "Analyze" <-> "Scanning…" label swap;
   ch is an approximation in the sans body and padding is included explicitly.
   Final value is tuned on device — the requirement is "no width jump". */
.btn-analyze { min-width: calc(9ch + 2.8rem); display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; }
/* The button is always :disabled while loading, so the dimming (:disabled {
   opacity: .4 }) would also dim the spinner. Restore full opacity with a
   higher-specificity selector (.loading:disabled beats :disabled regardless of
   source order); :disabled stays responsible only for blocking interaction. */
.btn-analyze.loading:disabled { opacity: 1; }
.spinner {
  width: 0.9rem; height: 0.9rem; flex: none;
  /* currentColor = the button's text color, so the spinner always matches the
     label across themes without naming a specific token. */
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.spinner[hidden] { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Staged wait text under the form. */
.scan-status { margin-top: 1rem; color: var(--muted); font-size: 0.9rem; }
.scan-status[hidden] { display: none; }

/* Error message on the form (failed scan / bad input). */
.error-msg {
  margin-top: 1rem;
  padding: 0.65rem 0.95rem;
  background: var(--fail-tint);
  border-left: 2px solid var(--state-fail);
  border-radius: 0 6px 6px 0;
  color: var(--fg);
  font-size: 0.9rem;
}
.error-msg[hidden] { display: none; }

/* Numbers use tabular figures so count-up + ms columns don't reflow per frame. */
.meter-score, .leg-ms { font-variant-numeric: tabular-nums; }

/* ── Report ───────────────────────────────────────────────────────────── */
/* Results render below the form in-flow, not as a separate view. */
#report { margin-top: 2.5rem; }
/* #report is a programmatic focus target (tabindex=-1) so keyboard/SR users
   land on the results after a scan. It is not an interactive control, so a
   keyboard-modality scan would otherwise make the UA draw a focus-visible
   outline around the entire section. Suppress it — the focus move plus
   scrollIntoView is the cue; the box is not. */
#report:focus { outline: none; }

.section { margin-top: 3rem; }
.section-label {
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  padding-bottom: 0.75rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}

/* Verdict block — the signature meter leads the whole report. */
.verdict-section { margin-top: 1.75rem; }
.verdict {
  display: flex;
  align-items: center;
  gap: 2.5rem;
  flex-wrap: nowrap;
}
.verdict-detail { flex: 1; min-width: 0; }
.verdict-target {
  font-family: var(--mono);
  color: var(--muted);
  word-break: break-all;
  font-size: 0.9rem;
  margin-bottom: 0.6rem;
}
.verdict-summary { color: var(--fg); font-size: 1.05rem; }
.verdict-summary .issues { color: var(--state-fail); }
.verdict-summary .clean { color: var(--state-pass); }
.verdict-summary .no-signal { color: var(--muted); }

/* Analog 270-degree compliance meter. */
.meter { position: relative; flex: none; filter: drop-shadow(0 1px 4px rgba(0,0,0,0.08)); }
.meter svg { display: block; transform: rotate(135deg); }
.meter .track { stroke: var(--meter-track); }
.meter .fill { stroke-linecap: round; }
.meter .tick { stroke: var(--line-bright); stroke-width: 1; }
.meter .tick-major { stroke: var(--muted); stroke-width: 1.5; }
.meter-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 0.25rem;
}
.meter-score {
  font-size: 2.3rem; font-weight: 700; letter-spacing: -0.03em;
  color: var(--fg); line-height: 1;
}
.meter-verdict {
  font-size: 0.64rem; letter-spacing: 0.22em; text-transform: uppercase; font-weight: 700;
}
.meter-verdict.pass { color: var(--state-pass); }
.meter-verdict.partial { color: var(--state-caution); }
.meter-verdict.fail { color: var(--state-fail); }

/* Compliance check cards: border WIDTH = requirement level, border COLOR + tint = result state. */
.checks-list { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin-top: 1.75rem; }
.check {
  border-left: 1px solid var(--line);
  padding: 0.85rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.check:last-child { border-bottom: none; }
/* Requirement level = border WIDTH + name weight, never color. */
.check.must { border-left-width: 3px; }
.check.must .name { font-weight: 700; }
.check.should .name { font-weight: 500; }
.check.may .name { color: var(--muted); }
/* Result state = border COLOR + tint, independent of level. */
.check.fail { border-left-color: var(--state-fail); background: var(--fail-tint); }
.check.indeterminate { border-left-color: var(--muted); background: var(--panel); opacity: 0.7; }
.check .name { display: flex; align-items: center; gap: 0.5rem; line-height: 1.3; }
.check .spec { color: var(--muted); font-size: 0.8rem; margin-top: 0.3rem; line-height: 1.45; }
.mark-pass { color: var(--state-pass); flex: none; }
.mark-fail { color: var(--state-fail); flex: none; }
.mark-indeterminate { color: var(--muted); flex: none; }
.indeterminate-note { color: var(--muted); font-size: 0.85rem; margin-top: 0.4rem; }

.level-badge {
  font-size: 0.62rem; letter-spacing: 0.1em; font-weight: 700;
  padding: 0.1rem 0.4rem; color: var(--muted);
}
/* MUST = square outline. SHOULD = pill outline. No fill color. */
.level-badge.must { border: 1.5px solid var(--fg); border-radius: 3px; color: var(--fg); }
.level-badge.should { border: 1px solid var(--muted); border-radius: 999px; }
.level-badge.may { border: 1px dashed var(--line-bright); border-radius: 999px; }

/* Diff block: expected/actual rows, meaning carried by structure not color. */
.diff { font-family: var(--mono); margin-top: 0.65rem; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; font-size: 0.85rem; background: var(--panel-2); }
.diff-row { display: flex; gap: 0.5rem; padding: 0.3rem 0.65rem; color: var(--fg); }
.diff-row + .diff-row { border-top: 1px solid var(--line); }
.diff-label { color: var(--muted); flex: none; min-width: 4.5rem; }
.diff-val { word-break: break-all; }

/* Instrument panel — Profile + Health, demoted below the verdict. */
.instrument-panel { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
@media (min-width: 900px) {
  .instrument-panel { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 2rem; }
}
.panel-cell .panel-label {
  font-size: 0.72rem; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 0.7rem;
}
.kv-table { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.kv {
  display: flex; justify-content: space-between; align-items: baseline; gap: 1rem;
  padding: 0.55rem 0.85rem; background: var(--panel); border-bottom: 1px solid var(--line);
}
.kv:last-child { border-bottom: none; }
.kv span:first-child { color: var(--muted); flex: none; font-size: 0.85rem; }
.kv span:last-child { color: var(--fg); text-align: right; word-break: break-word; font-size: 0.85rem; }

/* Evidence timeline. */
.evidence-list { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.evidence-leg {
  display: flex; align-items: center; gap: 0.85rem;
  padding: 0.55rem 1rem; background: var(--panel); border-bottom: 1px solid var(--line);
}
.evidence-leg:last-child { border-bottom: none; }
.leg-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--state-pass); flex: none; }
.leg-dot.unobserved { background: transparent; border: 1.5px dashed var(--muted); }
.leg-label { color: var(--fg); flex: 1; }
.leg-ms { margin-left: auto; color: var(--muted); font-size: 0.85rem; }
.badge {
  font-size: 0.68rem; color: var(--muted);
  border: 1px solid var(--line-bright); border-radius: 999px; padding: 0.05rem 0.55rem;
}

/* ── Responsive ───────────────────────────────────────────────────────── */
@media (max-width: 560px) {
  #scan-form { flex-direction: column; }
  #scan-form #target { width: 100%; }
  .btn-analyze { width: 100%; }
  .instrument-panel { grid-template-columns: 1fr; }
  .verdict { flex-wrap: wrap; justify-content: center; text-align: center; }
  /* Short viewports: don't vertically center — it cramps the hero. */
  #home { flex: none; justify-content: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  .view { animation: none; }
  * { transition: none !important; }
  .spinner { animation: none; display: none; }
}
