/* ------------------------------------------------------------------ tokens */
:root {
  color-scheme: light dark;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #eef1f8;
  --border: #d9dee9;
  --text: #16213a;
  --muted: #5b6478;
  --accent: #1f4fd8;
  --accent-strong: #163fb0;
  --accent-soft: #e4ebff;
  --on-accent: #ffffff;
  --danger: #c2372f;
  --danger-soft: #fdecea;
  --weak: #d64545;
  --fair: #e08a1e;
  --good: #a59b00;
  --strong: #2f9e44;
  --excellent: #0f8a6a;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 10px 30px -14px rgba(16, 24, 40, .18);
  --logo-dot: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020;
    --surface: #141a2e;
    --surface-2: #1b2340;
    --border: #2a3354;
    --text: #e6e9f2;
    --muted: #a0a9c3;
    --accent: #7aa2ff;
    --accent-strong: #9db8ff;
    --accent-soft: #1d2a52;
    --on-accent: #0b1020;
    --danger: #ff7b72;
    --danger-soft: #3a1d1f;
    --weak: #ff6b6b;
    --fair: #f2a33a;
    --good: #d6c93a;
    --strong: #4cd964;
    --excellent: #3ddc97;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px -14px rgba(0, 0, 0, .6);
    --logo-dot: #0b1020;
  }
}

/* ------------------------------------------------------------------ base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--accent-strong); }
code, pre { font-family: var(--mono); font-size: .92em; }
code { background: var(--surface-2); padding: .1em .35em; border-radius: 5px; overflow-wrap: anywhere; }
h1, h2, h3 { line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: clamp(1.7rem, 2.6vw + 1rem, 2.4rem); margin: 0 0 .5rem; }
h2 { font-size: 1.35rem; margin: 2.2rem 0 .7rem; }
p { margin: 0 0 1rem; }
small { color: var(--muted); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }
.wrap { width: 100%; max-width: 960px; margin: 0 auto; padding: 0 16px; }
.skip-link { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: .5rem 1rem; z-index: 10; }
.skip-link:focus { left: 8px; }

/* ------------------------------------------------------------------ header / footer */
.site-header { border-bottom: 1px solid var(--border); background: var(--surface); }
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 60px; flex-wrap: wrap; }
.brand { display: inline-flex; align-items: center; gap: .55rem; font-weight: 700; font-size: 1.15rem; color: var(--text); text-decoration: none; }
.brand .logo { color: var(--accent); }
.site-nav { display: flex; gap: .25rem 1.1rem; flex-wrap: wrap; align-items: center; }
.site-nav a { color: var(--muted); text-decoration: none; padding: .35rem 0; font-weight: 500; }
.site-nav a:hover, .site-nav a[aria-current="page"] { color: var(--text); }
.site-nav a[aria-current="page"] { box-shadow: inset 0 -2px 0 var(--accent); }
.site-nav .lang-switch { border: 1px solid var(--border); border-radius: 999px; padding: .25rem .8rem; color: var(--text); }
.site-footer { border-top: 1px solid var(--border); margin-top: 3rem; padding: 1.5rem 0 2rem; color: var(--muted); font-size: .92rem; }
.site-footer p { margin: 0 0 .4rem; }
.footer-links { display: flex; flex-wrap: wrap; gap: .5rem; }
.build { font-family: var(--mono); font-size: .8rem; }

/* ------------------------------------------------------------------ generator page */
.hero { padding: 2.2rem 0 1.2rem; }
.lead { font-size: 1.08rem; color: var(--muted); max-width: 70ch; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; }
.generator { display: grid; gap: 1.25rem; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { font-weight: 600; margin-bottom: .5rem; padding: 0; }
.modes legend { margin-bottom: .6rem; }
.segmented { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 4px; position: relative; max-width: 100%; }
.segmented input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.segmented label { padding: .5rem 1.1rem; border-radius: 999px; cursor: pointer; color: var(--muted); font-weight: 600; white-space: nowrap; }
.segmented input:checked + label { background: var(--surface); color: var(--accent); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.segmented input:focus-visible + label { outline: 3px solid var(--accent); outline-offset: 2px; }

.output-block { display: grid; gap: .6rem; }
.output-label { font-weight: 600; }
.output-row { display: grid; gap: .75rem; }
.output {
  display: block;
  font-family: var(--mono);
  font-size: clamp(1.1rem, 1.2vw + .9rem, 1.5rem);
  line-height: 1.45;
  padding: .9rem 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 3.6rem;
  overflow-wrap: anywhere;   /* random strings break where needed, passphrases at their separators */
  user-select: all;
  -webkit-user-select: all;
}
.output:empty::before { content: attr(data-placeholder); color: var(--muted); font-family: var(--sans); font-size: 1rem; }
.ch-digit { color: var(--accent); }
.ch-symbol { color: var(--danger); }
.output-actions { display: flex; gap: .6rem; flex-wrap: wrap; }
.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border-radius: 10px; padding: .65rem 1.2rem; border: 1px solid transparent;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  transition: background-color .15s, color .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--on-accent); flex: 1; }
.btn-primary:hover { background: var(--accent-strong); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); flex: 1; }
.btn-secondary:hover { background: var(--surface-2); }
.btn-secondary.is-copied { border-color: var(--strong); color: var(--strong); }
.btn-link { background: none; border: 0; color: var(--accent); padding: .25rem 0; font-weight: 500; }
.btn-link:hover { text-decoration: underline; }
.btn-copy-small { padding: .35rem .7rem; font-size: .85rem; }
.status { min-height: 1.2em; margin: 0; font-size: .9rem; color: var(--muted); }
.error { color: var(--danger); background: var(--danger-soft); padding: .6rem .9rem; border-radius: 8px; margin: 0; }
.notice { background: var(--accent-soft); border-radius: 8px; padding: .8rem 1rem; }

.strength { display: grid; gap: .35rem; margin-top: .2rem; }
.strength-head { display: flex; justify-content: space-between; font-size: .95rem; }
.strength-label { color: var(--muted); }
.strength-level { font-weight: 700; color: var(--level-color, var(--muted)); }
.meter { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.meter-fill { height: 100%; width: var(--fill, 0%); background: var(--level-color, var(--accent)); border-radius: 999px; transition: width .25s ease, background-color .25s; }
.strength-details { margin: 0; font-size: .92rem; color: var(--muted); }
.strength.level-weak { --level-color: var(--weak); }
.strength.level-fair { --level-color: var(--fair); }
.strength.level-good { --level-color: var(--good); }
.strength.level-strong { --level-color: var(--strong); }
.strength.level-excellent { --level-color: var(--excellent); }

.options { display: grid; gap: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.field { display: grid; gap: .35rem; }
.field > label, .checks legend { font-weight: 600; }
.range-row { display: flex; align-items: center; gap: .75rem; }
input[type="range"] { flex: 1; accent-color: var(--accent); min-width: 0; }
input[type="number"], select {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: .45rem .6rem; min-width: 0;
}
input[type="number"] { width: 5.2rem; text-align: center; }
select { max-width: 100%; }
.unit { color: var(--muted); font-size: .92rem; }
.checks { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: .45rem 1rem; }
.checks label { display: flex; align-items: flex-start; gap: .5rem; cursor: pointer; }
.checks input[type="checkbox"] { accent-color: var(--accent); width: 1.1rem; height: 1.1rem; margin-top: .2rem; flex: none; }

.more { border-top: 1px solid var(--border); padding-top: .75rem; }
.more-list { margin: .5rem 0 0; padding-left: 1.4rem; display: grid; gap: .5rem; }
.more-list li { font-family: var(--mono); overflow-wrap: anywhere; }
.more-list .alt-row { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.more-list .btn { flex: none; }
.more-list .alt-value { user-select: all; -webkit-user-select: all; }

.tip { margin-top: 1.25rem; background: var(--accent-soft); border-color: transparent; box-shadow: none; }
.tip p { margin: 0; }
.trust { margin-top: 2.5rem; max-width: 72ch; }
.ticks { list-style: none; padding: 0; margin: 0 0 1rem; display: grid; gap: .5rem; }
.ticks li { padding-left: 1.7rem; position: relative; }
.ticks li::before { content: "✓"; position: absolute; left: 0; top: 0; color: var(--strong); font-weight: 700; }

/* ------------------------------------------------------------------ prose pages */
.prose { max-width: 76ch; padding-top: 2rem; }
.prose .meta { color: var(--muted); font-size: .9rem; }
.prose ul, .prose ol { padding-left: 1.4rem; }
.prose li { margin-bottom: .45rem; }
.legend { counter-reset: none; }
.legend li { margin-bottom: .8rem; }
.table { border-collapse: collapse; width: 100%; margin: 1rem 0 1.5rem; font-size: .95rem; }
.table caption { text-align: left; color: var(--muted); font-size: .9rem; margin-bottom: .4rem; }
.table th, .table td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { color: var(--muted); font-weight: 600; }
.headers dt { font-weight: 600; margin-top: .9rem; }
.headers dd { margin: .2rem 0 0; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1.2rem; }
.kv dt { font-weight: 600; color: var(--muted); }
.kv dd { margin: 0; }
@media (max-width: 480px) { .kv { grid-template-columns: 1fr; } .kv dd { margin-bottom: .5rem; } }

/* ------------------------------------------------------------------ diagram */
.diagram-figure { margin: 1rem 0 1.5rem; }
.diagram-figure figcaption { color: var(--muted); font-size: .9rem; margin-top: .5rem; text-align: center; }
.diagram { width: 100%; height: auto; display: block; font-family: var(--sans); }
.dg-panel { fill: var(--surface-2); stroke: var(--border); }
.dg-window { fill: var(--surface); stroke: var(--border); }
.dg-chrome-line { stroke: var(--border); stroke-width: 1; }
.dg-dot { fill: var(--border); }
.dg-box { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 1.5; }
.dg-box-final { fill: var(--surface); stroke: var(--strong); }
.dg-file { fill: var(--surface); stroke: var(--border); }
.dg-num { fill: var(--accent); }
.dg-num-text { fill: var(--on-accent); font-size: 13px; font-weight: 700; text-anchor: middle; }
.dg-title { font-size: 15px; font-weight: 700; fill: var(--text); }
.dg-label { font-size: 14px; font-weight: 600; fill: var(--text); }
.dg-sub, .dg-small { font-size: 12px; fill: var(--muted); }
.dg-center { text-anchor: middle; }
.dg-mono { font-family: var(--mono); }
.dg-flow { stroke: var(--accent); stroke-width: 2; fill: none; }
.dg-arrowhead { fill: var(--accent); }
.dg-arrowhead-red { fill: var(--danger); }
.dg-flow-blocked { stroke: var(--danger); stroke-dasharray: 6 5; }
.dg-blocked { fill: var(--surface); stroke: var(--danger); stroke-width: 2.5; }
.dg-blocked-line { stroke: var(--danger); stroke-width: 2.5; }

/* ------------------------------------------------------------------ misc */
@media (max-width: 560px) {
  .segmented { display: flex; }
  .segmented label { flex: 1; text-align: center; padding: .5rem .4rem; white-space: normal; font-size: .95rem; }
}
@media (min-width: 640px) {
  .output-row { grid-template-columns: 1fr auto; align-items: stretch; }
  .output-actions { flex-direction: column; }
  .btn-primary, .btn-secondary { flex: 1; min-width: 8.5rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
@media print {
  .site-header, .site-footer, .output-actions, .more { display: none; }
}

/* ------------------------------------------------------------------ theme toggle (header) */
.theme-toggle {
  font: inherit; font-size: .9rem; font-weight: 600; cursor: pointer;
  color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: .25rem .8rem;
}
.theme-toggle:hover { background: var(--surface-2); }

/* ------------------------------------------------------------------ terminal look
   Activated by data-theme="terminal" on <html> (set from #theme=terminal in the URL by
   theme.js). Same layout, different tokens: phosphor green on black, monospace,
   a digital-rain canvas behind the content, faint scanlines. */
html[data-theme="terminal"] {
  color-scheme: dark;
  background: #000;
  --bg: #000;
  --surface: rgba(0, 12, 3, .84);
  --surface-2: rgba(0, 38, 10, .62);
  --border: #0e6b28;
  --text: #a9f5b6;
  --muted: #4fd06f;
  --accent: #00ff41;
  --accent-strong: #7dffa0;
  --accent-soft: rgba(0, 255, 65, .12);
  --on-accent: #000;
  --danger: #ff5c5c;
  --danger-soft: rgba(255, 60, 60, .16);
  --weak: #ff4d4d;
  --fair: #ffb020;
  --good: #c8ff3d;
  --strong: #00ff41;
  --excellent: #00ffa8;
  --logo-dot: #000;
  --shadow: 0 0 0 1px rgba(0, 255, 65, .18), 0 0 28px rgba(0, 255, 65, .10);
  --term-glow: 0 0 8px rgba(0, 255, 65, .55);
}
html[data-theme="terminal"] body { background: transparent; font-family: var(--mono); }
html[data-theme="terminal"] body::after {                 /* scanlines */
  content: ""; position: fixed; inset: 0; z-index: 3; pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(0, 0, 0, .16) 0 2px, transparent 2px 4px);
}
#rain { position: fixed; inset: 0; z-index: -1; opacity: .30; pointer-events: none; }
html[data-theme="terminal"] ::selection { background: #00ff41; color: #000; }
html[data-theme="terminal"] h1, html[data-theme="terminal"] h2 { color: var(--accent); text-shadow: var(--term-glow); letter-spacing: 0; }
html[data-theme="terminal"] h1::before { content: "> "; opacity: .7; }
html[data-theme="terminal"] .site-header { background: rgba(0, 0, 0, .86); border-color: var(--border); }
html[data-theme="terminal"] .brand { color: var(--accent); text-shadow: var(--term-glow); }
html[data-theme="terminal"] .site-nav a[aria-current="page"] { box-shadow: inset 0 -2px 0 var(--accent); }
html[data-theme="terminal"] .theme-toggle { color: var(--accent); border-color: var(--accent); background: #000; box-shadow: var(--term-glow); }
html[data-theme="terminal"] .card, html[data-theme="terminal"] .tip { background: var(--surface); border-color: var(--border); }
html[data-theme="terminal"] .segmented { background: #000; border: 1px solid var(--border); }
html[data-theme="terminal"] .segmented input:checked + label { background: var(--accent); color: #000; box-shadow: var(--term-glow); }
html[data-theme="terminal"] .output {
  background: rgba(0, 18, 5, .8); border-color: var(--accent); color: var(--accent);
  text-shadow: var(--term-glow); position: relative;
}
html[data-theme="terminal"] .output:empty::before { font-family: var(--mono); }
html[data-theme="terminal"] .ch-digit { color: #d2ffdc; }
html[data-theme="terminal"] .ch-symbol { color: #ffffff; }
html[data-theme="terminal"] .btn-primary { background: var(--accent); color: #000; box-shadow: var(--term-glow); }
html[data-theme="terminal"] .btn-primary:hover { background: var(--accent-strong); }
html[data-theme="terminal"] .btn-secondary { background: #000; color: var(--accent); border-color: var(--accent); }
html[data-theme="terminal"] .btn-secondary:hover { background: var(--accent-soft); }
html[data-theme="terminal"] .btn-secondary.is-copied { color: #d2ffdc; border-color: #d2ffdc; }
html[data-theme="terminal"] input[type="number"], html[data-theme="terminal"] select { background: #000; color: var(--text); border-color: var(--border); }
html[data-theme="terminal"] input[type="range"], html[data-theme="terminal"] .checks input[type="checkbox"] { accent-color: var(--accent); }
html[data-theme="terminal"] .meter { background: rgba(0, 255, 65, .12); }
html[data-theme="terminal"] .meter-fill { box-shadow: var(--term-glow); }
html[data-theme="terminal"] code { background: rgba(0, 255, 65, .10); color: var(--accent-strong); }
html[data-theme="terminal"] .ticks li::before { color: var(--accent); text-shadow: var(--term-glow); }
html[data-theme="terminal"] .table th, html[data-theme="terminal"] .table td { border-color: var(--border); }
html[data-theme="terminal"] .site-footer { border-color: var(--border); background: rgba(0, 0, 0, .7); }
html[data-theme="terminal"] .dg-box { fill: rgba(0, 255, 65, .10); }
html[data-theme="terminal"] .dg-window, html[data-theme="terminal"] .dg-file, html[data-theme="terminal"] .dg-panel, html[data-theme="terminal"] .dg-blocked { fill: rgba(0, 0, 0, .75); }
html[data-theme="terminal"] .dg-box-final { fill: rgba(0, 0, 0, .75); }

/* decode overlay (terminal look only, see app.js) */
.output .decode {
  position: absolute; inset: 0; padding: .9rem 1rem; white-space: pre-wrap; overflow-wrap: anywhere;
  color: var(--accent); pointer-events: none; user-select: none; -webkit-user-select: none;
}
.output.is-decoding > span:not(.decode) { visibility: hidden; }
html[data-theme="terminal"] main.wrap { background: rgba(0, 0, 0, .66); border-radius: 12px; }
