:root {
  color-scheme: light;
  --ink: #151515;
  --ink-2: #26201d;
  --muted: #665f58;
  --paper: #ffffff;
  --wash: #f7f4ef;
  --line: #ded6c8;
  --line-strong: #b9aa92;
  --red: #a51422;
  --red-ink: #7d0f1a;
  --gold: #c99a2e;
  --gold-soft: #f2dfaf;
  --green: #22744c;
  --amber: #926a10;
  --blue: #315f86;
  --shadow: 0 16px 40px rgba(21, 21, 21, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--wash);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(180deg, #ffffff 0, var(--wash) 360px),
    var(--wash);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

.skip-link {
  position: absolute;
  left: 16px;
  top: 12px;
  z-index: 20;
  transform: translateY(-160%);
  border: 2px solid var(--gold);
  background: var(--ink);
  color: var(--paper);
  padding: 8px 12px;
  font-size: 0.85rem;
  font-weight: 800;
}

.skip-link:focus {
  transform: translateY(0);
}

.app-shell {
  width: min(1440px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0 40px;
}

.topbar {
  display: flex;
  min-height: 72px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 3px solid var(--red);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  place-items: center;
  border: 2px solid var(--gold);
  background: var(--ink);
  color: var(--paper);
  font-size: 1.45rem;
  font-weight: 900;
  line-height: 1;
}

.brand-name,
.brand-subtitle {
  display: block;
}

.brand-name {
  font-size: 1rem;
  font-weight: 900;
  line-height: 1.1;
}

.brand-subtitle {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.3;
}

.topbar-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  border: 1px solid var(--line);
  background: var(--paper);
  padding: 8px 12px;
  color: var(--ink-2);
  font-size: 0.82rem;
  font-weight: 800;
  white-space: nowrap;
}

.status-dot {
  width: 10px;
  height: 10px;
  border: 2px solid var(--red);
  background: var(--gold);
}

.intro-band {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(420px, 0.9fr);
  gap: 28px;
  align-items: end;
  padding: 30px 0 26px;
}

.intro-copy {
  max-width: 760px;
}

.section-kicker,
.control-label,
.panel-kicker {
  margin: 0 0 8px;
  color: var(--red);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  max-width: 760px;
  margin-bottom: 12px;
  font-size: 2.9rem;
  line-height: 0.98;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 10px;
  font-size: 1.35rem;
  line-height: 1.15;
  letter-spacing: 0;
}

h3 {
  margin-bottom: 0;
  font-size: 1.02rem;
  line-height: 1.2;
  letter-spacing: 0;
}

.intro-copy p:last-child,
.preview-drawer p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.55;
}

.safety-ledger {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.safety-ledger div {
  min-height: 94px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--gold);
  background: var(--paper);
  padding: 14px;
}

.safety-ledger dt {
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 900;
  text-transform: uppercase;
}

.safety-ledger dd {
  margin: 0;
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 800;
  line-height: 1.3;
}

.control-strip,
.preview-drawer,
.state-section {
  border: 1px solid var(--line);
  background: var(--paper);
}

.control-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
  padding: 14px;
}

.control-label {
  margin-bottom: 6px;
}

.segmented {
  display: inline-grid;
  grid-template-columns: repeat(4, minmax(74px, 1fr));
  border: 1px solid var(--line-strong);
}

.segmented button {
  min-height: 38px;
  border: 0;
  border-right: 1px solid var(--line-strong);
  background: var(--paper);
  color: var(--ink);
  padding: 0 12px;
  font-size: 0.84rem;
  font-weight: 900;
  cursor: pointer;
}

.segmented button:last-child {
  border-right: 0;
}

.segmented button:hover,
.segmented button:focus-visible {
  outline: 3px solid rgba(201, 154, 46, 0.35);
  outline-offset: -3px;
}

.segmented button.is-selected {
  background: var(--ink);
  color: var(--paper);
}

.mode-output {
  max-width: 420px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
  line-height: 1.35;
  text-align: right;
}

.pulse-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.pulse-card {
  min-height: 112px;
  border: 1px solid var(--line);
  background: var(--paper);
  padding: 14px;
  box-shadow: var(--shadow);
}

.pulse-label {
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 900;
  text-transform: uppercase;
}

.pulse-value {
  display: block;
  margin-bottom: 8px;
  color: var(--ink);
  font-size: 1.95rem;
  font-weight: 900;
  line-height: 1;
}

.pulse-note {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
  line-height: 1.35;
}

.cockpit-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.panel {
  display: flex;
  min-height: 292px;
  flex-direction: column;
  border: 1px solid var(--line);
  background: var(--paper);
  box-shadow: var(--shadow);
}

.panel.is-muted {
  display: none;
}

.panel-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  border-bottom: 1px solid var(--line);
  padding: 14px 14px 12px;
}

.panel-meta {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  background: var(--wash);
  padding: 0 9px;
  color: var(--ink);
  font-size: 0.75rem;
  font-weight: 900;
  white-space: nowrap;
}

.panel-body {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px 14px;
}

.panel-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  border-left: 4px solid var(--line-strong);
  background: var(--wash);
  padding: 10px;
}

.panel-row[data-tone="good"] {
  border-left-color: var(--green);
}

.panel-row[data-tone="watch"] {
  border-left-color: var(--amber);
}

.panel-row[data-tone="risk"] {
  border-left-color: var(--red);
}

.panel-row[data-tone="info"] {
  border-left-color: var(--blue);
}

.row-title {
  display: block;
  margin-bottom: 5px;
  font-size: 0.9rem;
  font-weight: 900;
  line-height: 1.25;
}

.row-detail {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.35;
}

.row-status {
  display: inline-flex;
  min-height: 26px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-strong);
  background: var(--paper);
  padding: 0 8px;
  color: var(--ink);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
  white-space: nowrap;
}

.panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: auto;
}

.panel-actions button {
  min-height: 34px;
  border: 1px solid var(--red);
  background: var(--paper);
  color: var(--red-ink);
  padding: 0 10px;
  font-size: 0.78rem;
  font-weight: 900;
  cursor: pointer;
}

.panel-actions button:hover,
.panel-actions button:focus-visible {
  outline: 3px solid rgba(165, 20, 34, 0.22);
  outline-offset: 1px;
}

.state-section,
.preview-drawer {
  margin-top: 14px;
  padding: 16px;
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.state-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
}

.state-card {
  min-height: 132px;
  border: 1px solid var(--line);
  border-top: 4px solid var(--gold);
  background: var(--wash);
  padding: 12px;
}

.state-card strong {
  display: block;
  margin-bottom: 8px;
  font-size: 0.9rem;
}

.state-card span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.35;
}

.preview-drawer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.7fr);
  gap: 20px;
  align-items: center;
  border-left: 6px solid var(--red);
}

.preview-output {
  min-height: 112px;
  border: 1px solid var(--line-strong);
  background: var(--ink);
  color: var(--paper);
  padding: 14px;
  font-size: 0.9rem;
  font-weight: 800;
  line-height: 1.45;
}

noscript {
  display: block;
  margin: 0 auto 24px;
  width: min(1440px, calc(100% - 32px));
  border: 1px solid var(--red);
  background: var(--paper);
  padding: 12px;
  color: var(--red-ink);
  font-weight: 900;
}

@media (max-width: 1180px) {
  .intro-band,
  .preview-drawer {
    grid-template-columns: 1fr;
  }

  .cockpit-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .state-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100% - 24px, 1440px);
    padding-top: 12px;
  }

  .topbar,
  .control-strip {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-status,
  .mode-output {
    width: 100%;
    justify-content: flex-start;
    text-align: left;
    white-space: normal;
  }

  h1 {
    font-size: 2.15rem;
  }

  .safety-ledger,
  .pulse-grid,
  .cockpit-grid,
  .state-grid {
    grid-template-columns: 1fr;
  }

  .segmented {
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .segmented button:nth-child(2) {
    border-right: 0;
  }

  .segmented button:nth-child(-n + 2) {
    border-bottom: 1px solid var(--line-strong);
  }
}

@media (max-width: 520px) {
  .brand-lockup {
    align-items: flex-start;
  }

  .brand-subtitle {
    max-width: 220px;
  }

  .panel-header,
  .panel-row {
    grid-template-columns: 1fr;
  }

  .panel-meta,
  .row-status {
    width: max-content;
    max-width: 100%;
    white-space: normal;
  }
}
