:root {
  --bg: #0a0e14;
  --bg-card: #111722;
  --bg-card-hover: #162030;
  --bg-elevated: #192434;
  --bg-subtle: #0d131d;
  --ink: #e2e8f0;
  --ink-heading: #f8fafc;
  --ink-muted: #94a3b8;
  --ink-faint: #64748b;
  --border: #1e2d40;
  --border-active: #334760;
  --border-highlight: #00a3a6;
  
  --petrol: #00a3a6;
  --petrol-dim: rgba(0, 163, 166, 0.14);
  --cyan: #06b6d4;
  --cyan-dim: rgba(6, 182, 212, 0.12);
  --amber: #f59e0b;
  --amber-dim: rgba(245, 158, 11, 0.12);
  --green: #10b981;
  --green-dim: rgba(16, 185, 129, 0.12);
  --alarm: #ef4444;
  --alarm-dim: rgba(239, 68, 68, 0.12);
  
  --font-sans: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-serif: "Literata", Georgia, "Times New Roman", serif;
  --font-mono: "Spline Sans Mono", "JetBrains Mono", SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow: 0 4px 20px -2px rgba(0, 0, 0, 0.5);
  --shell-width: 48rem;
  --shell-wide-width: 66rem;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  background-color: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  line-height: 1.65;
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}

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

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow-x: hidden;
  background-image: 
    radial-gradient(ellipse 60% 40% at 50% 0%, rgba(0, 163, 166, 0.05) 0%, transparent 80%),
    linear-gradient(to bottom, transparent 95%, rgba(6, 182, 212, 0.02) 100%);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.shell {
  width: 100%;
  max-width: var(--shell-width);
  margin-left: auto;
  margin-right: auto;
  padding-left: 1.5rem;
  padding-right: 1.5rem;
}

.shell-wide {
  width: 100%;
  max-width: var(--shell-wide-width);
  margin-left: auto;
  margin-right: auto;
  padding-left: 1.5rem;
  padding-right: 1.5rem;
}

/* Topbar */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 14, 20, 0.85);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-heading);
  text-decoration: none;
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.brand::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--petrol);
  box-shadow: 0 0 10px var(--petrol);
}

.langsw {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--ink-muted);
}

.langsw a {
  color: var(--ink-muted);
  text-decoration: none;
  padding: 0.25rem 0.4rem;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
}

.langsw a:hover {
  color: var(--ink-heading);
  background: var(--bg-card);
}

.langsw a[aria-current="page"] {
  color: var(--petrol);
  background: var(--petrol-dim);
  font-weight: 600;
}

/* Hero Section */
.hero {
  padding: 4.5rem 0 3rem;
  border-bottom: 1px solid var(--border);
  position: relative;
}

.kicker {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--petrol);
  margin-bottom: 1rem;
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--petrol-dim);
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  border: 1px solid rgba(0, 163, 166, 0.3);
}

.kicker-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--petrol);
}

h1 {
  font-family: var(--font-sans);
  font-size: clamp(2.2rem, 5vw, 3.4rem);
  font-weight: 800;
  line-height: 1.12;
  letter-spacing: -0.03em;
  color: var(--ink-heading);
  margin-bottom: 1.5rem;
}

.standfirst {
  font-family: var(--font-serif);
  font-size: clamp(1.15rem, 2.2vw, 1.35rem);
  line-height: 1.55;
  color: #cbd5e1;
  margin-bottom: 2.5rem;
}

/* Ledger line numbers */
.ledgerline {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 1rem;
  margin-top: 2rem;
}

.ledger-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 1.25rem;
  border-radius: var(--radius-md);
  position: relative;
  transition: transform 0.2s, border-color 0.2s;
}

.ledger-item:hover {
  border-color: var(--border-active);
  transform: translateY(-2px);
}

.ledger-item .num {
  display: block;
  font-family: var(--font-mono);
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--ink-heading);
  line-height: 1.1;
  margin-bottom: 0.4rem;
}

.ledger-item .num.highlight-petrol { color: var(--petrol); }
.ledger-item .num.highlight-cyan { color: var(--cyan); }
.ledger-item .num.highlight-amber { color: var(--amber); }
.ledger-item .num.highlight-alarm { color: var(--alarm); }

.ledger-item .label {
  font-size: 0.82rem;
  color: var(--ink-muted);
  line-height: 1.4;
}

/* Prose and editorial blocks */
.block {
  padding: 4rem 0;
  border-bottom: 1px solid var(--border);
}

.prose h2 {
  font-family: var(--font-sans);
  font-size: clamp(1.6rem, 3.2vw, 2.1rem);
  font-weight: 700;
  color: var(--ink-heading);
  letter-spacing: -0.02em;
  margin-bottom: 1.25rem;
  line-height: 1.2;
}

.prose h3 {
  font-family: var(--font-sans);
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--ink-heading);
  margin-top: 2rem;
  margin-bottom: 0.75rem;
}

.prose p {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  line-height: 1.75;
  color: #cbd5e1;
  margin-bottom: 1.4rem;
}

.prose p:last-child {
  margin-bottom: 0;
}

.prose strong {
  color: var(--ink-heading);
  font-weight: 600;
}

/* Attack Lifecycle Flow */
.lifecycle-flow {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin: 2.5rem 0 1.5rem;
}

.flow-step {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  position: relative;
  display: flex;
  flex-direction: column;
}

.flow-step.is-stealth {
  border-color: rgba(245, 158, 11, 0.4);
  background: linear-gradient(180deg, rgba(245, 158, 11, 0.06) 0%, var(--bg-card) 100%);
}

.flow-step.is-write {
  border-color: rgba(239, 68, 68, 0.4);
  background: linear-gradient(180deg, rgba(239, 68, 68, 0.06) 0%, var(--bg-card) 100%);
}

.step-num-tag {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--petrol);
  margin-bottom: 0.5rem;
}

.flow-step.is-stealth .step-num-tag { color: var(--amber); }
.flow-step.is-write .step-num-tag { color: var(--alarm); }

.step-title {
  font-family: var(--font-sans);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink-heading);
  margin-bottom: 0.5rem;
}

.step-text {
  font-size: 0.85rem;
  color: var(--ink-muted);
  line-height: 1.5;
}

/* Interactive Workbench */
.instrument {
  padding: 4.5rem 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg-subtle);
  position: relative;
}

.console-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
  margin-top: 2rem;
}

.console-header {
  background: var(--bg-elevated);
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.console-title {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-heading);
  letter-spacing: 0.08em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.live-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--petrol);
  animation: pulse-petrol 2s infinite;
}

@keyframes pulse-petrol {
  0% { transform: scale(0.95); opacity: 0.6; }
  50% { transform: scale(1.15); opacity: 1; box-shadow: 0 0 8px var(--petrol); }
  100% { transform: scale(0.95); opacity: 0.6; }
}

.console-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
}

@media (max-width: 900px) {
  .console-grid {
    grid-template-columns: 1fr;
  }
}

/* Left panel: PLC Memory & Ladder Logic Inspector */
.plc-panel {
  padding: 1.5rem;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: #080c12;
  position: relative;
  gap: 1.25rem;
}

@media (max-width: 900px) {
  .plc-panel {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
}

.panel-subhead {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Data Block Table */
.db-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.db-table th {
  background: var(--bg-elevated);
  color: var(--ink-muted);
  padding: 0.5rem 0.75rem;
  text-align: left;
  font-size: 0.7rem;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}

.db-table td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  color: var(--ink);
}

.db-table tr:last-child td {
  border-bottom: none;
}

.db-table .val-normal { color: var(--green); }
.db-table .val-read { color: var(--amber); }
.db-table .val-tampered { color: var(--alarm); font-weight: bold; }

/* Ladder Logic Visual Display */
.ladder-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  position: relative;
}

.ladder-svg {
  width: 100%;
  height: auto;
  display: block;
}

/* Right panel: Controls & Physical Effects */
.control-panel {
  padding: 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.control-group-title {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 0.6rem;
  display: block;
}

.sector-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

@media (max-width: 540px) {
  .sector-buttons {
    grid-template-columns: 1fr;
  }
}

.sector-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--ink);
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: center;
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 500;
  transition: all 0.15s;
}

.sector-btn:hover {
  border-color: var(--border-active);
  background: var(--bg-card-hover);
}

.sector-btn[aria-pressed="true"] {
  border-color: var(--petrol);
  background: var(--petrol-dim);
  color: var(--ink-heading);
  font-weight: 600;
}

/* Phase Toggle (Read vs Write) */
.phase-toggle-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem;
}

.segmented-toggle {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 3px;
}

.segmented-toggle button {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--ink-muted);
  padding: 0.6rem 0.8rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}

.segmented-toggle button[aria-pressed="true"] {
  background: var(--bg-card);
  color: var(--amber);
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.segmented-toggle button[aria-pressed="true"].phase-write {
  color: var(--alarm);
}

/* Defense switch */
.defense-toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
}

.defense-toggle button {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--ink);
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  transition: all 0.15s;
}

.defense-toggle button[aria-pressed="true"] {
  background: var(--petrol-dim);
  border-color: var(--petrol);
  color: var(--petrol);
}

/* Effect Card */
.effect-card {
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  border: 1px solid var(--border);
}

.effect-card.stealth {
  background: rgba(245, 158, 11, 0.08);
  border-color: rgba(245, 158, 11, 0.4);
}

.effect-card.disruptive {
  background: rgba(239, 68, 68, 0.08);
  border-color: rgba(239, 68, 68, 0.4);
}

.effect-card.blocked {
  background: rgba(0, 163, 166, 0.08);
  border-color: rgba(0, 163, 166, 0.4);
}

.effect-card .eff-title {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.effect-card.stealth .eff-title { color: var(--amber); }
.effect-card.disruptive .eff-title { color: var(--alarm); }
.effect-card.blocked .eff-title { color: var(--petrol); }

.effect-card .eff-text {
  font-family: var(--font-serif);
  font-size: 0.95rem;
  line-height: 1.45;
  color: var(--ink);
}

/* Certainty 3-column Matrix */
.certainty-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.25rem;
  margin: 2.5rem 0 1.5rem;
}

.certainty-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
}

.certainty-badge {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
  display: inline-block;
  margin-bottom: 1rem;
  align-self: flex-start;
}

.certainty-badge.green {
  background: var(--green-dim);
  color: var(--green);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.certainty-badge.amber {
  background: var(--amber-dim);
  color: var(--amber);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.certainty-badge.blue {
  background: var(--cyan-dim);
  color: var(--cyan);
  border: 1px solid rgba(6, 182, 212, 0.3);
}

.certainty-title {
  font-family: var(--font-sans);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--ink-heading);
  margin-bottom: 0.75rem;
}

.certainty-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  font-size: 0.88rem;
  color: #cbd5e1;
  line-height: 1.5;
}

.certainty-list li {
  padding-left: 1.1rem;
  position: relative;
}

.certainty-list li::before {
  content: "•";
  position: absolute;
  left: 0;
  color: var(--petrol);
}

/* Method and Sources footer */
.method-footer {
  padding: 3.5rem 0;
  border-top: 1px solid var(--border);
  font-size: 0.88rem;
  color: var(--ink-muted);
  background: #070a0e;
}

.method-footer h3 {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-heading);
  margin-bottom: 0.8rem;
}

.method-footer p {
  line-height: 1.6;
  margin-bottom: 0.8rem;
}

.method-footer a {
  color: var(--cyan);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.method-footer a:hover {
  color: var(--ink-heading);
}

.source-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem 1.2rem;
  margin-top: 1.2rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.source-tag {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius-sm);
  color: var(--ink);
  text-decoration: none;
  transition: border-color 0.15s;
}

.source-tag:hover {
  border-color: var(--cyan);
  color: var(--cyan);
}

/* Focus and accessibility */
a:focus-visible, button:focus-visible, input:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
}
