/* Shared styling for httpsig interactive diagrams. Palette mirrors the docs
   site (warm, light/dark) plus semantic colours for the signing lifecycle:
   select components, build base, sign, send, verify (ok / fail). */

:root {
  color-scheme: light dark;

  --bg: hsl(30, 20%, 99%);
  --bg-subtle: hsl(30, 15%, 96%);
  --bg-muted: hsl(30, 12%, 93%);
  --panel: hsl(30, 30%, 100%);
  --fg: hsl(20, 10%, 15%);
  --fg-secondary: hsl(20, 5%, 38%);
  --fg-muted: hsl(20, 5%, 52%);
  --fg-faint: hsl(20, 5%, 68%);
  --border: hsl(30, 15%, 86%);
  --border-light: hsl(30, 15%, 92%);
  --accent: hsl(25, 75%, 45%);

  /* signing lifecycle */
  --select: hsl(212, 72%, 52%);     /* component selection — blue */
  --select-soft: hsl(212, 75%, 93%);
  --base: hsl(270, 45%, 55%);       /* signature base — purple */
  --base-soft: hsl(270, 45%, 93%);
  --sign: hsl(25, 80%, 52%);        /* signing — amber */
  --sign-soft: hsl(25, 85%, 92%);
  --ok: hsl(150, 55%, 40%);         /* verified */
  --ok-soft: hsl(150, 50%, 91%);
  --fail: hsl(2, 72%, 54%);         /* rejected */
  --fail-soft: hsl(2, 75%, 93%);
  --digest: hsl(190, 70%, 42%);     /* content-digest — teal */
  --grid: hsl(30, 12%, 88%);

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, "Helvetica Neue", Arial, sans-serif;
  --display: "Charter", "Iowan Old Style", "Source Serif Pro", Cambria, Georgia, serif;
  --mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, "Roboto Mono", monospace;

  --shadow-sm: 0 1px 2px hsl(30 20% 20% / 0.05);
  --shadow: 0 2px 4px hsl(30 20% 20% / 0.06), 0 8px 24px hsl(30 20% 20% / 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: hsl(20, 8%, 9%);
    --bg-subtle: hsl(20, 6%, 12%);
    --bg-muted: hsl(20, 6%, 16%);
    --panel: hsl(20, 7%, 13%);
    --fg: hsl(30, 18%, 92%);
    --fg-secondary: hsl(20, 8%, 70%);
    --fg-muted: hsl(20, 8%, 56%);
    --fg-faint: hsl(20, 8%, 40%);
    --border: hsl(20, 6%, 24%);
    --border-light: hsl(20, 6%, 19%);
    --accent: hsl(25, 80%, 62%);
    --select: hsl(212, 80%, 62%);
    --select-soft: hsl(212, 45%, 24%);
    --base: hsl(270, 60%, 70%);
    --base-soft: hsl(270, 35%, 24%);
    --sign: hsl(28, 85%, 58%);
    --sign-soft: hsl(28, 40%, 22%);
    --ok: hsl(150, 55%, 52%);
    --ok-soft: hsl(150, 30%, 20%);
    --fail: hsl(2, 75%, 62%);
    --fail-soft: hsl(2, 40%, 24%);
    --digest: hsl(190, 70%, 56%);
    --grid: hsl(20, 6%, 20%);
    --shadow-sm: 0 1px 2px hsl(0 0% 0% / 0.3);
    --shadow: 0 2px 4px hsl(0 0% 0% / 0.3), 0 8px 24px hsl(0 0% 0% / 0.25);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--fg);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.viz-wrap { max-width: 1040px; margin: 0 auto; padding: 1.5rem 1.5rem 5rem; }

.viz-nav {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  font-family: var(--mono); font-size: 0.78rem; margin-bottom: 2rem;
  padding-bottom: 0.9rem; border-bottom: 1px solid var(--border-light);
}
.viz-nav a { color: var(--fg-muted); text-decoration: none; }
.viz-nav a:hover { color: var(--accent); }
.viz-nav .brand { color: var(--fg); font-weight: 600; letter-spacing: 0.01em; }

h1.viz-title {
  font-family: var(--display); font-weight: 600; letter-spacing: -0.02em;
  font-size: 2rem; line-height: 1.15; margin: 0 0 0.5rem;
}
.viz-lede { color: var(--fg-secondary); font-size: 1.02rem; margin: 0 0 1.5rem; max-width: 46rem; }
.viz-lede code, .note code { font-family: var(--mono); font-size: 0.85em; background: var(--bg-muted); padding: 0.08em 0.35em; border-radius: 4px; }
.viz-lede b { color: var(--fg); }

.stage {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 0.5rem;
  overflow: hidden;
}
canvas { display: block; width: 100%; height: auto; border-radius: 8px; }

/* control bar */
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; margin: 1rem 0 0.4rem; }
.btn {
  font-family: var(--mono); font-size: 0.8rem; font-weight: 600;
  color: var(--fg); background: var(--bg-subtle);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 0.45rem 0.8rem; cursor: pointer; user-select: none;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.05s ease;
}
.btn:hover { background: var(--bg-muted); border-color: var(--fg-faint); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: #fff; border-color: transparent; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.toggle.on { background: var(--select); color: #fff; border-color: transparent; }
.btn.danger { color: var(--fail); }
.btn.danger.on { background: var(--fail); color: #fff; border-color: transparent; }
.btn[disabled] { opacity: 0.4; cursor: not-allowed; }

.ctl-group { display: flex; align-items: center; gap: 0.5rem; font-family: var(--mono); font-size: 0.76rem; color: var(--fg-muted); }
.ctl-group label { white-space: nowrap; }
input[type="range"] {
  -webkit-appearance: none; appearance: none; height: 4px; width: 130px;
  background: var(--border); border-radius: 999px; outline: none; cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 15px; height: 15px;
  border-radius: 50%; background: var(--accent); border: 2px solid var(--panel); box-shadow: var(--shadow-sm);
}
input[type="range"]::-moz-range-thumb { width: 15px; height: 15px; border-radius: 50%; background: var(--accent); border: 2px solid var(--panel); }
.ctl-val { color: var(--fg); font-weight: 600; min-width: 2.4em; text-align: right; }

/* stat readouts */
.stats { display: flex; flex-wrap: wrap; gap: 0.75rem; margin: 1rem 0; }
.stat { flex: 1 1 0; min-width: 120px; background: var(--bg-subtle); border: 1px solid var(--border-light); border-radius: 10px; padding: 0.6rem 0.8rem; }
.stat .k { font-family: var(--mono); font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--fg-faint); margin-bottom: 0.2rem; }
.stat .v { font-family: var(--mono); font-size: 1.35rem; font-weight: 600; color: var(--fg); line-height: 1.1; }
.stat.ok .v { color: var(--ok); }
.stat.fail .v { color: var(--fail); }
.stat.sign .v { color: var(--sign); }

/* legend */
.legend { display: flex; flex-wrap: wrap; gap: 1rem 1.25rem; margin: 0.6rem 0 0; font-family: var(--mono); font-size: 0.74rem; color: var(--fg-secondary); }
.legend span { display: inline-flex; align-items: center; gap: 0.4rem; }
.dot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; flex: none; }

.note { font-size: 0.85rem; color: var(--fg-muted); margin: 1.5rem 0 0; }

/* signature-base assembly (DOM-based diagram) */
.sb-grid { display: grid; gap: 1rem; }
@media (min-width: 760px) { .sb-grid { grid-template-columns: 1fr 1fr; } }
.sb-panel { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-sm); overflow: hidden; }
.sb-panel h3 { font-family: var(--mono); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--fg-muted); margin: 0; padding: 0.7rem 0.9rem; border-bottom: 1px solid var(--border-light); background: var(--bg-subtle); }
.sb-code { font-family: var(--mono); font-size: 0.82rem; line-height: 1.7; padding: 0.8rem 0.9rem; margin: 0; white-space: pre-wrap; word-break: break-word; min-height: 7rem; }
.sb-line { display: block; padding: 0.05rem 0.35rem; border-radius: 4px; transition: background 0.2s ease; }
.sb-line.lit { background: var(--base-soft); }
.sb-line .cid { color: var(--select); }
.sb-line.params .cid { color: var(--base); }
.req-line { display: block; padding: 0.05rem 0.35rem; border-radius: 4px; transition: background 0.2s ease, opacity 0.2s ease; opacity: 0.55; }
.req-line.lit { background: var(--select-soft); opacity: 1; }
.req-line .hname { color: var(--select); }
.checkbox-row { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; margin: 1rem 0 0; font-family: var(--mono); font-size: 0.78rem; }
.checkbox-row label { display: inline-flex; align-items: center; gap: 0.4rem; color: var(--fg-secondary); cursor: pointer; }

/* diagram index */
.viz-index { list-style: none; padding: 0; margin: 1.5rem 0; display: grid; gap: 0.75rem; }
.viz-index a { display: block; text-decoration: none; color: inherit; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 1rem 1.1rem; transition: border-color 0.12s ease, transform 0.05s ease; }
.viz-index a:hover { border-color: var(--accent); transform: translateY(-1px); }
.viz-index .t { font-weight: 600; font-size: 1.05rem; }
.viz-index .d { color: var(--fg-secondary); font-size: 0.9rem; margin-top: 0.2rem; }

/* Embed mode: rendered inside the landing-page iframe (?embed) — drop chrome. */
body.embed { background: transparent; }
.embed .viz-wrap { max-width: 100%; padding: 0.5rem 0.75rem 1rem; }
.embed .viz-nav, .embed .viz-title, .embed .viz-lede, .embed .note { display: none; }
.embed .stage { box-shadow: none; }
