:root {
  --steel-0: #101518;
  --steel-1: #1a2226;
  --steel-2: #243036;
  --ivory: #f4efe4;
  --ivory-dim: #ddd4c4;
  --brass: #e4c88a;
  --brass-deep: #8a7044;
  --ink: #1c1814;
  --green: #1f7a45;
  --amber: #c4841a;
  --red: #a33a32;
  --g: 34.5%;
  --y: 66.5%;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: var(--steel-0);
  scroll-padding-top: 72px;
}

body {
  margin: 0;
  min-height: 100vh;
  padding: calc(62px + env(safe-area-inset-top)) 16px calc(36px + env(safe-area-inset-bottom));
  color: var(--ivory);
  background:
    radial-gradient(circle at 86% -8%, rgba(228, 200, 138, 0.14), transparent 34%),
    radial-gradient(circle at 6% 100%, rgba(48, 82, 90, 0.28), transparent 32%),
    linear-gradient(180deg, #1b2428 0%, #0e1316 48%, #0c1013 100%);
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 1.05rem;
  line-height: 1.45;
}

.wrap {
  width: min(1100px, 100%);
  margin: 0 auto;
}

.skip {
  position: absolute;
  left: 12px;
  top: -48px;
  z-index: 2147483646;
  padding: 8px 12px;
  background: var(--ivory);
  color: var(--ink);
  font-weight: 700;
}

.skip:focus { top: 12px; }

h1, h2, .nameplate, .roman, .annunciator-kicker {
  font-family: Palatino, "Palatino Linotype", Georgia, serif;
}

h1, h2, p { overflow-wrap: anywhere; }

.mast { margin-bottom: 18px; }

.eyebrow, .annunciator-kicker {
  margin: 0 0 6px;
  color: var(--brass);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1 {
  margin: 0 0 10px;
  font-size: clamp(2.1rem, 5vw, 3.35rem);
  font-weight: 700;
  line-height: 1.02;
}

h1::after {
  content: "";
  display: block;
  width: 72px;
  height: 2px;
  margin-top: 12px;
  background: linear-gradient(90deg, var(--brass), transparent);
}

.lede, .sheet p, .direction, .frame {
  margin: 0 0 10px;
}

.lede { max-width: 68ch; font-size: 1.08rem; }

.notice, .sheet, .annunciator, .instrument {
  border: 1px solid var(--brass-deep);
  border-radius: 14px;
}

.notice {
  margin: 0 0 16px;
  padding: 12px 14px 4px;
  background: rgba(12, 16, 18, 0.55);
}

.notice p { margin: 0 0 8px; }

h1, h2, .annunciator, .instrument { scroll-margin-top: 72px; }

.notice strong { font-weight: 750; }

.notice b { color: var(--ivory); }

.disclaimer {
  margin: 16px;
  color: var(--ivory);
}

.annunciator, .sheet {
  margin: 0 0 16px;
  padding: 16px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), transparent 30%),
    var(--steel-1);
  box-shadow: inset 0 1px 0 rgba(243, 224, 186, 0.18);
}

.annunciator[data-state="stop"] {
  background: #3c1d1c;
  border-color: #e7c1b8;
}

.annunciator[data-state="watch"] {
  background: #3a2c14;
  border-color: #e6c98a;
}

.annunciator[data-state="clear"] {
  background: #153027;
  border-color: #8dcfab;
}

.annunciator h2 {
  margin: 0 0 8px;
  font-size: clamp(1.85rem, 4vw, 2.7rem);
  line-height: 1.05;
}

#master-text { margin: 0 0 14px; max-width: 78ch; }

.lamps {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.lamps li {
  min-width: 0;
  padding: 8px;
  border-radius: 8px;
  border-top: 4px solid #c8c2b4;
  background: rgba(0, 0, 0, 0.22);
}

.lamps li[data-state="green"] { border-top-color: #49c484; }
.lamps li[data-state="yellow"] { border-top-color: #e6b341; }
.lamps li[data-state="red"] {
  border-top-color: #f0a097;
  background: rgba(80, 20, 18, 0.38);
}

.lamp-name, .lamp-state { display: block; }
.lamp-name { font-weight: 750; }
.lamp-state { color: var(--ivory); font-size: 0.92rem; }

.reflections {
  margin: 12px 0 0;
  padding-left: 1.15rem;
}

.reflections li { margin: 6px 0; }
.reflections strong { font-family: Palatino, Georgia, serif; }

.sheet-head h2 {
  margin: 0 0 6px;
  font-size: 1.45rem;
}

.sheet-head p, .fine, #note-count, #save-status, #band-summary {
  color: var(--ivory-dim);
}

.field-label, .number-block label, .threshold-grid label, .check {
  display: block;
  margin-bottom: 6px;
  font-weight: 700;
}

textarea, input[type="number"] {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--brass-deep);
  border-radius: 8px;
  padding: 8px 10px;
  background: #10161a;
  color: var(--ivory);
  font: inherit;
  font-size: 16px;
}

textarea { min-height: 88px; resize: vertical; }

input[type="number"] {
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-size: 1.2rem;
}

textarea::placeholder, input::placeholder { color: #d5cbbd; opacity: 1; }

input[aria-invalid="true"] { border-color: #f0a097; }

.instruments {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.instrument {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 16px 14px 14px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), transparent 26%),
    linear-gradient(180deg, #2a3439, #151c20);
  box-shadow:
    inset 0 1px 0 rgba(243, 224, 186, 0.28),
    inset 0 0 0 1px rgba(0, 0, 0, 0.35),
    0 16px 32px rgba(0, 0, 0, 0.24);
}

.instrument[data-state="red"] { border-color: #e7c1b8; }
.instrument[data-state="yellow"] { border-color: #e6c98a; }
.instrument[data-state="green"] { border-color: #7dcea0; }

.roman {
  margin: 0;
  color: var(--brass);
  font-size: 0.95rem;
  letter-spacing: 0.16em;
}

.instrument h2 {
  margin: 2px 0 8px;
  font-size: 1.28rem;
  line-height: 1.25;
}

.direction, .frame { color: var(--ivory); }

.frame {
  padding: 8px 10px;
  border-left: 3px solid var(--brass);
  background: rgba(0, 0, 0, 0.2);
}

.dial svg {
  display: block;
  width: min(100%, 420px);
  height: auto;
  margin: 2px auto 0;
}

.nameplate {
  width: fit-content;
  margin: -6px auto 10px;
  padding: 3px 12px 4px;
  border: 1px solid var(--brass-deep);
  border-radius: 2px;
  background: linear-gradient(#3a3228, #241c16);
  color: #f3e6c8;
  font-size: 0.78rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.reading, .prompt {
  margin: 0 0 10px;
  padding: 8px 10px;
  border-left: 4px solid #c8c2b4;
  background: rgba(0, 0, 0, 0.28);
  font-weight: 650;
}

.instrument[data-state="green"] .reading { border-left-color: #49c484; }
.instrument[data-state="yellow"] .reading,
.instrument[data-state="yellow"] .prompt { border-left-color: #e6b341; }
.instrument[data-state="red"] .reading,
.instrument[data-state="red"] .prompt { border-left-color: #f0a097; }

.prompt { font-weight: 500; }

.ends {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
  margin: 0 0 10px;
  font-size: 0.95rem;
}

.ends p {
  display: flex;
  gap: 6px;
  align-items: flex-start;
  margin: 0;
}

.end-high { text-align: right; justify-content: flex-end; }

.swatch {
  flex: 0 0 auto;
  width: 0.8rem;
  height: 0.8rem;
  margin-top: 0.28rem;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 2px;
}

.swatch-low { background: var(--green); }
.swatch-high { background: var(--red); }

.controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 6.6rem;
  gap: 10px;
  align-items: end;
  margin-bottom: 4px;
}

.slider-wrap { position: relative; border-radius: 10px; }

.slider-wrap:focus-within {
  outline: 3px solid #f0d7a2;
  outline-offset: 4px;
}

.scale {
  --track: linear-gradient(90deg, var(--green) 0 var(--g), var(--amber) var(--g) var(--y), var(--red) var(--y) 100%);
  display: block;
  width: 100%;
  height: 44px;
  margin: 0;
  background: transparent;
  appearance: none;
  -webkit-appearance: none;
}

.scale:focus { outline: none; }

.scale::-webkit-slider-runnable-track {
  height: 12px;
  border: 1px solid rgba(0, 0, 0, 0.5);
  border-radius: 999px;
  background: var(--track);
}

.scale::-webkit-slider-thumb {
  width: 28px;
  height: 28px;
  margin-top: -9px;
  border: 2px solid #241c12;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #f8edd4, #c4a574 46%, #6a512c 80%);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  appearance: none;
  -webkit-appearance: none;
}

.scale.is-unset::-webkit-slider-runnable-track { filter: saturate(0.72); }

.scale.is-unset::-webkit-slider-thumb {
  background: rgba(16, 20, 22, 0.15);
  border: 2px dashed var(--brass);
  box-shadow: none;
}

.scale::-moz-range-track {
  height: 12px;
  border: 1px solid rgba(0, 0, 0, 0.5);
  border-radius: 999px;
  background: var(--track);
}

.scale::-moz-range-thumb {
  width: 28px;
  height: 28px;
  border: 2px solid #241c12;
  border-radius: 50%;
  background: #c4a574;
}

.scale.is-unset::-moz-range-track { filter: saturate(0.72); }

.scale.is-unset::-moz-range-thumb {
  background: transparent;
  border: 2px dashed var(--brass);
}

.unset-flag {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -58%);
  padding: 2px 8px;
  border: 1px dashed var(--brass);
  border-radius: 999px;
  background: rgba(14, 18, 20, 0.92);
  color: var(--ivory);
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  pointer-events: none;
  white-space: nowrap;
}

.field-msg {
  min-height: 1.3em;
  margin: 4px 0 8px;
  color: #ffd4cc;
  font-weight: 650;
}

.field-msg:empty { margin: 0; }

.instrument > button,
.sheet > button,
.dialog-actions button,
.check {
  font: inherit;
}

button {
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid var(--brass);
  border-radius: 8px;
  background: #2a241c;
  color: var(--ivory);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

button:hover { background: #3a3126; }

button.danger {
  border-color: #f0c2ba;
  background: #4a2724;
}

button.danger:hover { background: #5c302c; }

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

.band-bar {
  display: flex;
  min-height: 36px;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.45);
  border-radius: 999px;
  color: #fff8ee;
  font-size: 0.85rem;
  font-weight: 750;
}

.band-bar span {
  display: grid;
  place-items: center;
  min-width: 0;
  padding: 0 6px;
  overflow: hidden;
  white-space: nowrap;
}

.band-bar [data-part="green"] { background: var(--green); }
.band-bar [data-part="yellow"] { background: #8a5d10; color: #fff6e4; }
.band-bar [data-part="red"] { background: #7d2b26; }

#band-summary { margin: 0 0 12px; }

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  margin: 8px 0;
  cursor: pointer;
}

.check input {
  width: 22px;
  height: 22px;
  accent-color: #c4a574;
}

.storage h2 { margin: 0 0 8px; font-size: 1.35rem; }

#save-status, #reset-status { margin: 0 0 10px; }

dialog {
  width: min(460px, calc(100% - 24px));
  padding: 18px;
  border: 1px solid var(--brass);
  border-radius: 12px;
  background: #1a2126;
  color: var(--ivory);
}

dialog::backdrop { background: rgba(0, 0, 0, 0.66); }

dialog h2 { margin: 0 0 8px; font-size: 1.5rem; }

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.dialog-actions button { flex: 1 1 140px; }

:focus-visible {
  outline: 3px solid #f0d7a2;
  outline-offset: 3px;
}

.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;
}

@media (max-width: 860px) {
  .lamps { grid-template-columns: 1fr 1fr; }
  .lamps li:last-child { grid-column: 1 / -1; }
}

@media (max-width: 640px) {
  .threshold-grid, .ends, .controls { grid-template-columns: 1fr; }
  .end-high { text-align: left; justify-content: flex-start; }
  .unset-flag { font-size: 0.68rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}

@media (forced-colors: active) {
  button, input, textarea, .instrument, .annunciator, .sheet {
    border: 1px solid CanvasText;
  }
  :focus-visible { outline-color: Highlight; }
}
