:root {
  --paper: #f3efe6;
  --ink: #1e1a16;
  --muted: #5e574c;
  --rule: #d4ccbe;
  --card: #fffdf8;
  --green: #1f6b4a;
  --green-ink: #f4fff8;
  --amber: #8a5a12;
  --red: #8d2f2f;
  --focus: #1f6b4a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font: 15px/1.45 "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
}

header, footer {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  background: #ebe4d6;
  border-bottom: 1px solid var(--rule);
}

header { flex-wrap: wrap; min-width: 0; max-width: 100%; }

footer {
  border-bottom: 0;
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font-size: 13px;
}

.brand {
  font-weight: 700;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: 0.01em;
}

nav { display: flex; gap: 14px; flex-wrap: wrap; align-items: baseline; }

nav a, a.action {
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}

nav a[aria-current="page"] { border-bottom-color: var(--ink); font-weight: 700; }

.nav-disabled {
  color: var(--muted);
  cursor: not-allowed;
}

.soon { font-size: 12px; font-style: italic; }

nav.places,
nav.subnav {
  min-width: 0;
  max-width: 100%;
}

nav.subnav {
  padding: 8px 22px;
  background: #f7f3ea;
  border-bottom: 1px solid var(--rule);
}

nav.subnav[hidden] { display: none !important; }

.place-note {
  color: var(--muted);
  font-size: 13px;
  margin-right: 4px;
}

.card a { color: inherit; }

#app { padding: 18px 22px 40px; max-width: 1180px; }

h1 { font-size: 28px; font-weight: 650; margin: 0 0 8px; }

h2 { font-size: 18px; margin: 0 0 10px; }

p.lead, .note { color: var(--muted); margin: 0 0 14px; max-width: 70ch; }

.row, .toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; margin: 0 0 14px; }

label.field, label.check { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }

label.check { flex-direction: row; align-items: center; gap: 6px; color: var(--ink); font-size: 14px; }

input, select, textarea, button {
  font: 14px/1.3 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color: var(--ink);
  background: white;
  border: 1px solid #b7ad9d;
  border-radius: 2px;
  padding: 6px 8px;
}

textarea { width: 100%; min-height: 9em; }

button, .btn {
  background: var(--green);
  color: var(--green-ink);
  border-color: var(--green);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}

button.ghost, a.ghost {
  background: transparent;
  color: var(--ink);
  border-color: #b7ad9d;
}

button.warn { background: var(--red); border-color: var(--red); }

button:disabled { opacity: 0.55; cursor: not-allowed; }

input:focus, select:focus, textarea:focus, button:focus, a:focus {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.cards { display: flex; flex-direction: column; gap: 8px; }

.card, .block, .gauge, .diff-row {
  background: var(--card);
  border: 1px solid var(--rule);
  padding: 12px;
}

.card header, .card .meta { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: baseline; justify-content: space-between; }

.card h2 { margin: 0; font-size: 20px; }

.id, .tag, .badge {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 12px;
}

.tag, .badge {
  border: 1px solid var(--rule);
  padding: 1px 6px;
  background: #f7f1e4;
}

.badge.preset { border-color: var(--amber); color: var(--amber); }

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

.tabs { display: flex; gap: 0; margin-bottom: 12px; }

.tabs button { background: transparent; color: var(--ink); border-radius: 0; }

.tabs button[aria-selected="true"] { background: var(--ink); color: var(--paper); }

.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px 12px; }

.block { margin-bottom: 12px; }

.block + .block { margin-top: 0; }

.errors { margin: 0 0 12px; padding: 8px 12px; background: #f8ece6; border: 1px solid #e2c2b6; }

.errors.ok { background: #e7f3ec; border-color: #b7d7c6; }

.errors li { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }

.gauges { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin: 12px 0; }

.gauge .v { font-size: 26px; font-variant-numeric: tabular-nums; font-family: ui-monospace, Menlo, Consolas, monospace; }

.track { height: 8px; background: #ece6da; margin-top: 6px; }

.track > i { display: block; height: 100%; background: #333; }

.gauge.hunger i { background: #c36b1a; }
.gauge.fatigue i { background: #2c628a; }
.gauge.exhaustion i { background: var(--red); }
.gauge.stomach i { background: #6b4c2a; }
.gauge.energy i { background: #1f6b4a; }

.lamp.off { color: var(--muted); }
.lamp.on { color: var(--red); font-weight: 700; }

canvas.tape, canvas.grid {
  width: 100%;
  background: #fffdf8;
  border: 1px solid var(--rule);
  display: block;
}

canvas.tape { height: 150px; }

canvas.tape.world2,
canvas.tape.world3 { height: 360px; }

canvas.grid { width: min(100%, 360px); height: 360px; }

canvas.chart {
  width: 100%;
  max-width: 760px;
  height: 260px;
  background: #fffdf8;
  border: 1px solid var(--rule);
  display: block;
}

table.data {
  border-collapse: collapse;
  background: white;
  width: 100%;
  max-width: 760px;
  margin: 8px 0 14px;
}

table.data th, table.data td {
  border: 1px solid var(--rule);
  padding: 4px 8px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

table.data th:first-child, table.data td:first-child { text-align: left; }
table.data td.pass { color: #1b6b3a; }
table.data td.fail { color: #8a2e2e; }

.headline { font-weight: 600; margin: 8px 0; }

#curriculum-timeline { margin: 8px 0 12px; }
#curriculum-timeline[hidden] { display: none; }
.stage-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.stage-mark {
  border: 1px solid var(--rule);
  background: white;
  padding: 2px 6px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px;
}
.stage-mark.done { background: #e7f2eb; }
.stage-mark.current { box-shadow: inset 0 -2px 0 var(--green); font-weight: 600; }

.legend { display: flex; flex-wrap: wrap; gap: 10px 16px; margin: 6px 0 12px; }

.swatch-key { display: inline-block; width: 14px; height: 8px; margin-right: 6px; vertical-align: middle; }

#instruments { margin: 4px 0 16px; }

#instruments h2 span {
  font-weight: 400;
  color: var(--muted);
  font-size: 13px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
}

.instrument-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 0 0 12px;
}

label.check.debug-keys {
  margin: 0 0 6px;
  font-size: 13px;
}

label.check.sync-canvas {
  margin: 0;
  font-size: 13px;
  white-space: nowrap;
}

.reading-list {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px;
  border: 1px solid var(--rule);
  background: white;
  max-height: 320px;
  overflow: auto;
}

.reading-row, .fire-row {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 10px;
  align-items: baseline;
  padding: 4px 8px;
  border-bottom: 1px solid var(--rule);
}

.reading-row b, .fire-row b { min-width: 8.5em; }

.reading-group { color: var(--muted); min-width: 8.2em; }

.reading-lines { flex-basis: 100%; color: var(--muted); padding-left: 1em; }

.fire-row.on, .reading-row.phoneme.on { box-shadow: inset 3px 0 0 var(--green); }

.timeline-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 0 0 8px;
}

.timeline-bar input[type="range"] { flex: 1 1 180px; min-width: 140px; }

a.btn[aria-disabled="true"] {
  opacity: 0.45;
  pointer-events: none;
}

.event-strip {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  min-height: 22px;
  margin: 0 0 8px;
  padding-bottom: 2px;
}

.event-cell {
  flex: 0 0 8px;
  width: 8px;
  height: 18px;
  padding: 0;
  border: 1px solid var(--rule);
  background: #fffdf8;
  cursor: pointer;
}

.event-cell.has-event { background: #e2b100; border-color: #8a5a12; }

.event-cell.current { outline: 2px solid var(--ink); outline-offset: 1px; }

.channel-groups,
.channel-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin: 0 0 8px;
}

.channel-toggles {
  max-height: 132px;
  overflow: auto;
  padding: 4px 0;
  font-size: 12px;
}

.channel-groups label,
.channel-toggles label {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px;
}

.sonogram-wrap { overflow-x: auto; }

canvas.sonogram {
  background: #fffdf8;
  border: 1px solid var(--rule);
  display: block;
}

.diff-row { display: grid; grid-template-columns: 90px minmax(160px, 1.2fr) minmax(120px, 1fr) minmax(120px, 1fr); gap: 8px; margin-bottom: 6px; font-size: 13px; }

.diff-row pre { margin: 0; white-space: pre-wrap; word-break: break-word; font-size: 12px; }

.op-add { color: var(--green); }
.op-remove { color: var(--red); }
.op-replace { color: var(--amber); }

#va-panel[hidden] { display: none; }

.status-line { min-height: 1.3em; color: var(--muted); }

@media (max-width: 800px) {
  .gauges { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .instrument-grid { grid-template-columns: 1fr; }
  .diff-row { grid-template-columns: 1fr; }
  header { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 520px) {
  #app, header, footer { padding-left: 12px; padding-right: 12px; }
  .gauges { grid-template-columns: 1fr; }
}
