/* ==========================================================================
   007: Doomsday Protocol — global stylesheet
   Palette: midnight navy + gold leaf, with crimson alarms.
   ========================================================================== */

:root {
  --bg: #0a0f1c;
  --bg-2: #0d1424;
  --panel: #131d33;
  --panel-2: #1a2740;
  --panel-3: #22314f;
  --ink: #eef1f8;
  --muted: #9aa6bf;
  --faint: #6b7690;
  --gold: #d9b45b;
  --gold-strong: #f0cf78;
  --gold-dim: rgba(217, 180, 91, 0.16);
  --crimson: #c0392b;
  --danger: #e0574f;
  --ok: #4fd1a1;
  --blue: #6aa7ff;
  --line: rgba(217, 180, 91, 0.22);
  --line-soft: rgba(154, 166, 191, 0.16);
  --shadow: 0 18px 40px -18px rgba(0, 0, 0, 0.75);
  --radius: 14px;
  --radius-sm: 9px;
  --maxw: 1120px;
  --font-display: "Cinzel", Georgia, "Times New Roman", serif;
  --font-body: "Space Grotesk", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #f6f2e7;
  --bg-2: #efe8d8;
  --panel: #fffefb;
  --panel-2: #fbf7ec;
  --panel-3: #f3ecda;
  --ink: #1b2233;
  --muted: #5d6678;
  --faint: #8a907f;
  --gold: #8f6f16;
  --gold-strong: #a8841c;
  --gold-dim: rgba(143, 111, 22, 0.12);
  --crimson: #9e2b20;
  --danger: #b3312a;
  --ok: #1f7a55;
  --blue: #2f5fb0;
  --line: rgba(27, 34, 51, 0.16);
  --line-soft: rgba(27, 34, 51, 0.1);
  --shadow: 0 16px 34px -20px rgba(30, 30, 40, 0.4);
  color-scheme: light;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font-body);
  background:
    radial-gradient(1200px 600px at 80% -10%, var(--gold-dim), transparent 60%),
    radial-gradient(900px 500px at -10% 0%, rgba(106, 167, 255, 0.06), transparent 55%),
    var(--bg);
  color: var(--ink);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overflow-x: hidden;
}

img, svg { max-width: 100%; display: block; }
a { color: var(--gold-strong); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; line-height: 1.15; margin: 0 0 .5em; letter-spacing: .01em; }
h1 { font-size: clamp(1.9rem, 5vw, 3.2rem); }
h2 { font-size: clamp(1.4rem, 3.4vw, 2.1rem); }
h3 { font-size: 1.15rem; }
p { margin: 0 0 1em; }
strong { color: var(--gold-strong); }

.container { width: min(100% - 2rem, var(--maxw)); margin-inline: auto; }
.narrow { width: min(100% - 2rem, 760px); margin-inline: auto; }

.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 100;
  background: var(--gold); color: #111; padding: .6rem 1rem; border-radius: 0 0 8px 0;
}
.skip-link:focus { left: 0; }

/* ---------- header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 40;
  backdrop-filter: blur(10px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  border-bottom: 1px solid var(--line-soft);
}
.nav {
  display: flex; align-items: center; gap: 1rem;
  padding: .7rem 0;
}
.brand {
  display: flex; align-items: center; gap: .6rem;
  font-family: var(--font-display); font-weight: 700;
  color: var(--ink); letter-spacing: .04em; white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand .mark {
  width: 34px; height: 34px; flex: none;
}
.brand small { display: block; font-family: var(--font-body); font-size: .62rem; letter-spacing: .22em; color: var(--gold); text-transform: uppercase; }
.nav-links { display: flex; gap: .25rem; margin-left: auto; flex-wrap: wrap; }
.nav-links a {
  color: var(--muted); padding: .45rem .7rem; border-radius: 999px; font-size: .92rem;
}
.nav-links a:hover { color: var(--ink); background: var(--gold-dim); text-decoration: none; }
.nav-links a[aria-current="page"] { color: var(--gold-strong); background: var(--gold-dim); }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  cursor: pointer; font-size: 1.05rem; flex: none;
}
.icon-btn:hover { border-color: var(--gold); color: var(--gold-strong); }
.nav-toggle { display: none; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  font-family: var(--font-body); font-size: .95rem; font-weight: 600;
  padding: .7rem 1.15rem; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--ink);
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease, border-color .12s ease;
}
.btn:hover { border-color: var(--gold); transform: translateY(-1px); text-decoration: none; }
.btn:active { transform: translateY(0); }
.btn-primary {
  background: linear-gradient(180deg, var(--gold-strong), var(--gold));
  color: #17130a; border-color: transparent;
  box-shadow: 0 10px 24px -12px var(--gold);
}
.btn-primary:hover { color: #17130a; }
.btn-danger { border-color: var(--danger); color: var(--danger); }
.btn-ghost { background: transparent; }
.btn-sm { padding: .42rem .8rem; font-size: .84rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn[aria-pressed="true"] { border-color: var(--gold); color: var(--gold-strong); background: var(--gold-dim); }

/* ---------- hero ---------- */
.hero { padding: clamp(2rem, 6vw, 4.5rem) 0 2rem; position: relative; overflow: hidden; }
.hero::after {
  content: ""; position: absolute; inset: 0;
  background-image:
    repeating-linear-gradient(90deg, transparent 0 78px, var(--line-soft) 78px 79px);
  opacity: .35; pointer-events: none; z-index: 0;
}
.hero > * { position: relative; z-index: 1; }
.eyebrow {
  display: inline-flex; align-items: center; gap: .5rem;
  font-family: var(--font-mono); font-size: .74rem; letter-spacing: .28em;
  text-transform: uppercase; color: var(--gold-strong);
  border: 1px solid var(--line); border-radius: 999px; padding: .35rem .8rem; margin-bottom: 1rem;
}
.eyebrow .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--danger); box-shadow: 0 0 10px var(--danger); animation: blink 1.6s infinite; }
@keyframes blink { 50% { opacity: .3; } }
.hero h1 .gold { color: var(--gold-strong); }
.hero .lede { font-size: clamp(1.02rem, 2.1vw, 1.22rem); color: var(--muted); max-width: 60ch; }
.hero-actions { display: flex; flex-wrap: wrap; gap: .7rem; margin-top: 1.4rem; }

.hero-grid { display: grid; gap: 1.4rem; align-items: start; }
@media (min-width: 900px) { .hero-grid { grid-template-columns: 1.2fr .8fr; } }

/* ---------- cards / panels ---------- */
.card {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 1.2rem;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 1rem; }
.card-head { display: flex; align-items: center; gap: .7rem; margin-bottom: .6rem; }
.card-head h2, .card-head h3 { margin: 0; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: 1fr; }
.grid-3 { grid-template-columns: 1fr; }
@media (min-width: 700px) { .grid-2 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: repeat(3, 1fr); } }

.pill {
  display: inline-block; font-family: var(--font-mono); font-size: .7rem;
  letter-spacing: .08em; text-transform: uppercase;
  padding: .22rem .55rem; border-radius: 999px;
  border: 1px solid var(--line); color: var(--gold-strong); background: var(--gold-dim);
}
.tag-row { display: flex; flex-wrap: wrap; gap: .4rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: var(--font-mono); }
.center { text-align: center; }
.section { padding: clamp(1.6rem, 4vw, 3rem) 0; }
.section-head { margin-bottom: 1.2rem; }
.divider { height: 1px; background: var(--line-soft); margin: 1.2rem 0; border: 0; }

/* ---------- badge seal ---------- */
.seal {
  width: 120px; height: 120px; margin-inline: auto; opacity: .95;
}

/* ---------- game ---------- */
.game-shell { margin-top: 1rem; }
.hud {
  display: flex; flex-wrap: wrap; align-items: center; gap: .6rem 1.1rem;
  padding: .8rem 1rem; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); box-shadow: var(--shadow);
}
.hud .hud-item { display: flex; flex-direction: column; line-height: 1.1; }
.hud .hud-label { font-family: var(--font-mono); font-size: .62rem; letter-spacing: .18em; text-transform: uppercase; color: var(--faint); }
.hud .hud-value { font-family: var(--font-mono); font-size: 1.05rem; font-weight: 700; }
.hud .hud-value.clock { font-size: 1.4rem; }
.clock.low { color: var(--danger); animation: pulse .9s infinite; }
@keyframes pulse { 50% { opacity: .5; } }
.hud-spacer { flex: 1 1 40px; }

.module-dots { display: flex; gap: .4rem; align-items: center; }
.module-dot {
  width: 14px; height: 14px; border-radius: 4px; border: 1px solid var(--line);
  background: var(--panel-2); position: relative;
}
.module-dot.active { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-dim); }
.module-dot.solved { background: var(--ok); border-color: var(--ok); }
.module-dot.failed { background: var(--danger); border-color: var(--danger); }

.device {
  position: relative; margin-top: 1rem; border: 1px solid var(--line);
  border-radius: var(--radius); background:
    linear-gradient(180deg, var(--panel), var(--bg-2));
  box-shadow: var(--shadow); overflow: hidden;
}
.device-top {
  display: flex; align-items: center; gap: .7rem; padding: .7rem 1rem;
  border-bottom: 1px solid var(--line-soft);
  background: linear-gradient(180deg, var(--panel-3), transparent);
}
.device-top .screw { width: 9px; height: 9px; border-radius: 50%; background: var(--faint); opacity: .5; }
.device-title { font-family: var(--font-mono); font-size: .78rem; letter-spacing: .18em; text-transform: uppercase; color: var(--muted); }
.device-body { padding: 1.1rem; min-height: 290px; }
@media (min-width: 700px) { .device-body { padding: 1.6rem; } }

.module-head { display: flex; flex-wrap: wrap; gap: .5rem; align-items: baseline; margin-bottom: .5rem; }
.module-head .module-no { font-family: var(--font-mono); color: var(--gold); font-size: .8rem; letter-spacing: .16em; }
.module-prompt { color: var(--ink); }
.module-prompt .clue { color: var(--muted); }
.module-help { color: var(--muted); font-size: .92rem; }
.module-feedback { min-height: 1.4rem; font-family: var(--font-mono); font-size: .85rem; margin-top: .5rem; }
.module-feedback.ok { color: var(--ok); }
.module-feedback.bad { color: var(--danger); }

.input-row { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .8rem; }
input[type="text"], input[type="search"], select, textarea {
  font-family: var(--font-mono); font-size: 1rem;
  background: var(--bg-2); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: .65rem .8rem; min-width: 0;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--gold-strong); outline-offset: 2px;
}
.cipher-text {
  font-family: var(--font-mono); font-size: clamp(1.05rem, 4vw, 1.5rem);
  letter-spacing: .14em; word-break: break-word;
  color: var(--gold-strong); background: var(--bg-2);
  border: 1px dashed var(--line); border-radius: var(--radius-sm);
  padding: .9rem 1rem; margin: .6rem 0;
}
.morse-line { font-family: var(--font-mono); font-size: clamp(1.05rem, 4.5vw, 1.5rem); letter-spacing: .12em; word-break: break-word; color: var(--gold-strong); }

.chart { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: .35rem; margin-top: .6rem; }
.chart span { font-family: var(--font-mono); font-size: .8rem; background: var(--bg-2); border: 1px solid var(--line-soft); border-radius: 6px; padding: .3rem .4rem; }
.chart span b { color: var(--gold-strong); }
details.disclosure { margin-top: .7rem; border: 1px solid var(--line-soft); border-radius: var(--radius-sm); background: var(--bg-2); }
details.disclosure > summary { cursor: pointer; padding: .6rem .8rem; font-family: var(--font-mono); font-size: .8rem; color: var(--muted); }
details.disclosure[open] > summary { color: var(--gold-strong); }
details.disclosure > div { padding: 0 .8rem .8rem; }

/* wires */
.wire-list { display: flex; flex-direction: column; gap: .5rem; margin-top: .8rem; }
.wire {
  display: flex; align-items: center; gap: .8rem; cursor: pointer;
  background: var(--bg-2); border: 1px solid var(--line-soft); border-radius: 999px;
  padding: .5rem .8rem; color: var(--ink); font-family: var(--font-mono); text-align: left;
  transition: transform .1s ease, border-color .1s ease;
}
.wire:hover { transform: translateX(3px); border-color: var(--gold); }
.wire .swatch { width: 34px; height: 14px; border-radius: 4px; border: 1px solid rgba(0,0,0,.35); flex: none; }
.wire .wire-label { font-size: .9rem; }
.wire.cut-wrong { border-color: var(--danger); opacity: .55; }
.wire.cut-right { border-color: var(--ok); box-shadow: 0 0 0 3px rgba(79,209,161,.18); }

/* memory grid */
.mem-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .7rem; max-width: 380px; margin-top: .8rem; }
.mem-cell {
  aspect-ratio: 1; border-radius: var(--radius-sm); border: 1px solid var(--line-soft);
  background: var(--panel-2); cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-size: 1.4rem;
  color: color-mix(in srgb, var(--flash, var(--gold)) 55%, transparent);
  transition: transform .1s ease, box-shadow .1s ease, background .1s ease;
}
.mem-cell:hover { transform: translateY(-2px); }
.mem-cell.flash { background: var(--flash, var(--gold)); color: #12100a; box-shadow: 0 0 26px var(--flash, var(--gold)); }
.mem-cell[data-c="g"] { --flash: #e3c56e; }
.mem-cell[data-c="r"] { --flash: #e0574f; }
.mem-cell[data-c="b"] { --flash: #6aa7ff; }
.mem-cell[data-c="v"] { --flash: #8bd18b; }

/* keypad */
.keypad-code {
  font-family: var(--font-mono); font-size: 2rem; letter-spacing: .5em;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: .6rem 1rem; color: var(--gold-strong); display: inline-block; min-width: 8ch; text-align: center;
}
.keypad-keys { display: grid; grid-template-columns: repeat(3, 64px); gap: .5rem; margin-top: .8rem; }
.keypad-keys button {
  font-family: var(--font-mono); font-size: 1.1rem; padding: .6rem 0; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--panel-2); color: var(--ink); cursor: pointer;
}
.keypad-keys button:hover { border-color: var(--gold); color: var(--gold-strong); }
.keypad-keys button.wide { grid-column: span 2; }
.fact-line { font-size: .92rem; color: var(--muted); }

/* results */
.result-card { text-align: center; }
.result-rank {
  font-family: var(--font-display); font-size: clamp(1.6rem, 5vw, 2.6rem);
  color: var(--gold-strong); margin: .2rem 0;
}
.result-score { font-family: var(--font-mono); font-size: clamp(2.2rem, 8vw, 3.6rem); font-weight: 700; }
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .7rem; margin: 1rem 0; }
@media (min-width: 620px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--bg-2); border: 1px solid var(--line-soft); border-radius: var(--radius-sm); padding: .6rem; }
.stat b { display: block; font-family: var(--font-mono); font-size: 1.25rem; color: var(--gold-strong); }
.stat span { font-size: .74rem; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); }

/* ---------- academy ---------- */
.tool { border: 1px solid var(--line-soft); border-radius: var(--radius); background: var(--panel); padding: 1.1rem; }
.tool label { display: block; font-family: var(--font-mono); font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; color: var(--faint); margin: .7rem 0 .25rem; }
.tool output { display: block; font-family: var(--font-mono); font-size: 1.15rem; word-break: break-word; color: var(--gold-strong); min-height: 1.5em; }
.tool input[type="text"], .tool select, .tool textarea { width: 100%; }
.tool input[type="range"] { width: 100%; accent-color: var(--gold); }

/* ---------- vault ---------- */
.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-bottom: 1rem; }
.filters input[type="search"] { flex: 1 1 200px; }
.film-grid { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 640px) { .film-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 980px) { .film-grid { grid-template-columns: repeat(3, 1fr); } }
.film-card { border: 1px solid var(--line-soft); border-radius: var(--radius); background: var(--panel); padding: 1rem; display: flex; flex-direction: column; gap: .4rem; }
.film-card .num { font-family: var(--font-mono); font-size: .72rem; color: var(--gold); letter-spacing: .16em; }
.film-card h3 { margin: 0; font-size: 1.1rem; }
.film-card dl { margin: .3rem 0 0; display: grid; grid-template-columns: auto 1fr; gap: .15rem .6rem; font-size: .86rem; }
.film-card dt { color: var(--faint); font-family: var(--font-mono); font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; padding-top: .12rem; }
.film-card dd { margin: 0; }
.film-card .syn { color: var(--muted); font-size: .9rem; }

.song-list { list-style: none; padding: 0; margin: 0; }
.song-list li { display: flex; gap: .8rem; padding: .55rem 0; border-bottom: 1px solid var(--line-soft); }
.song-list .yr { font-family: var(--font-mono); color: var(--gold); flex: none; width: 3.4rem; }

.codename-out {
  font-family: var(--font-display); font-size: clamp(1.3rem, 4vw, 2rem); color: var(--gold-strong);
  border: 1px dashed var(--line); border-radius: var(--radius-sm); padding: 1rem; background: var(--bg-2);
}

/* ---------- manual ---------- */
.timeline { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--line); }
.timeline li { position: relative; padding: 0 0 1.1rem 1.3rem; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: .45rem; width: 12px; height: 12px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 0 4px var(--gold-dim); }
.timeline .yr { font-family: var(--font-mono); color: var(--gold-strong); font-weight: 700; }

.fact-cards { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 700px) { .fact-cards { grid-template-columns: repeat(2, 1fr); } }
.fact-cards .card h3 { color: var(--gold-strong); }

/* ---------- footer ---------- */
.site-footer {
  margin-top: 3rem; padding: 2rem 0; border-top: 1px solid var(--line-soft);
  background: var(--bg-2); color: var(--muted); font-size: .9rem;
}
.footer-grid { display: grid; gap: 1.2rem; grid-template-columns: 1fr; }
@media (min-width: 700px) { .footer-grid { grid-template-columns: 2fr 1fr 1fr; } }
.site-footer h4 { color: var(--ink); font-size: .95rem; }
.site-footer ul { list-style: none; padding: 0; margin: 0; }
.site-footer li { margin-bottom: .35rem; }

/* ---------- shared banner / modal ---------- */
.banner {
  display: none; gap: .8rem; align-items: center; flex-wrap: wrap;
  border: 1px solid var(--gold); background: var(--gold-dim); border-radius: var(--radius);
  padding: .8rem 1rem; margin-top: 1rem;
}
.banner.show { display: flex; }

.modal {
  position: fixed; inset: 0; z-index: 60; display: none;
  background: rgba(4, 7, 14, 0.72); padding: 1rem;
  align-items: center; justify-content: center;
}
.modal.open { display: flex; }
.modal-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  max-width: 560px; width: 100%; max-height: 86vh; overflow: auto; padding: 1.3rem;
  box-shadow: var(--shadow);
}
.modal-card .modal-head { display: flex; align-items: center; gap: .8rem; margin-bottom: .6rem; }
.modal-card .modal-head h2 { margin: 0; font-size: 1.25rem; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 1.4rem; transform: translate(-50%, 20px);
  background: var(--gold); color: #17130a; font-weight: 600; padding: .6rem 1.1rem;
  border-radius: 999px; opacity: 0; pointer-events: none; transition: all .25s ease; z-index: 80;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.reveal { opacity: 0; transform: translateY(16px); transition: opacity .5s ease, transform .5s ease; }
.reveal.in { opacity: 1; transform: none; }

/* ---------- responsive nav ---------- */
@media (max-width: 780px) {
  .nav-toggle { display: inline-flex; margin-left: auto; }
  .nav-links {
    display: none; width: 100%; order: 5; flex-direction: column; gap: .1rem;
    padding-top: .4rem; border-top: 1px solid var(--line-soft); margin-top: .3rem;
  }
  .nav-links.open { display: flex; }
  .nav-links a { padding: .6rem .8rem; }
  .nav { flex-wrap: wrap; }
  .brand { margin-right: auto; }
  .mem-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  .reveal { opacity: 1; transform: none; }
}
