:root {
  --bg: #e6dfd0;
  --paper: #f7f4ec;
  --ink: #1c1915;
  --muted: #5c564c;
  --line: #d4ccbc;
  --pine: #1f4d3a;
  --pine-ink: #f3fbf6;
  --amber: #ffd7a1;
  --signal: #e4570e;
  --focus: #e4570e;
  color-scheme: light;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 "Segoe UI", "Liberation Sans", "Nimbus Sans", sans-serif;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    calc(1.25rem + env(safe-area-inset-bottom))
    env(safe-area-inset-left);
}

button, input { font: inherit; color: inherit; }

button { cursor: pointer; }

button:focus-visible,
input:focus-visible,
summary:focus-visible,
a:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.wrap {
  width: min(44rem, 100%);
  margin: 0 auto;
  padding: 0.75rem;
}

.mast {
  background: var(--pine);
  color: var(--pine-ink);
  border-radius: 10px;
  padding: 1rem;
}

.brand {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.brand > div { min-width: 0; }

.mark {
  width: 2.7rem;
  height: 2.7rem;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  background: var(--signal);
  color: white;
  font-weight: 800;
  letter-spacing: -0.04em;
  border-radius: 6px;
}

.kicker {
  margin: 0;
  color: var(--amber);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}

.mast h1 {
  margin: 0.12rem 0 0;
  font-size: 1.5rem;
  line-height: 1.15;
  font-weight: 750;
}

.lede {
  margin: 0.55rem 0 0;
  color: #d7e7dd;
  font-size: 0.95rem;
}

.paper {
  background: var(--paper);
  border: 1px solid #d9d0c0;
  border-radius: 10px;
  padding: 0.9rem;
  margin-top: 0.75rem;
}

.field { display: flex; flex-direction: column; gap: 0.4rem; }
.field + .field { margin-top: 1rem; }

.label,
.field > label,
.check {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}

.seg button,
.bands button,
.vendors button,
.btn {
  min-height: 48px;
  border: 1px solid #b7ad9c;
  background: white;
  border-radius: 6px;
  padding: 0.35rem 0.7rem;
  font-weight: 650;
}

.seg button[aria-pressed="true"],
.bands button[aria-pressed="true"],
.vendors button[aria-pressed="true"] {
  background: var(--pine);
  border-color: var(--pine);
  color: var(--pine-ink);
}

.bands,
.vendors {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.bands button,
.vendors button {
  flex: 0 0 auto;
  min-height: 40px;
  font-size: 0.92rem;
}

input[type="search"] {
  width: 100%;
  min-height: 48px;
  padding: 0.45rem 0.7rem;
  border: 1px solid #b7ad9c;
  border-radius: 6px;
  background: white;
  font-size: 1rem;
}

input:disabled {
  background: #efeae0;
  color: #8a8175;
}

.check {
  display: flex;
  gap: 0.55rem;
  align-items: flex-start;
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.35;
}

.check input {
  width: 1.15rem;
  height: 1.15rem;
  margin-top: 0.1rem;
  flex: 0 0 auto;
}

.count {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.choices {
  max-height: min(22rem, 48vh);
  overflow: auto;
  background: white;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.choices:empty,
.choices[hidden] { display: none; }

.group {
  padding: 0.35rem 0.75rem 0.15rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  background: #f3ecdf;
  position: sticky;
  top: 0;
}

.choice {
  width: 100%;
  text-align: left;
  background: white;
  border: 0;
  border-bottom: 1px solid var(--line);
  min-height: 48px;
  padding: 0.6rem 0.75rem;
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
  align-items: center;
}

.choice:hover,
.choice:focus-visible { background: #f3ecdf; }

.choice[aria-selected="true"] { background: #e5f2eb; }

.choice-copy { min-width: 0; }

.choice-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.25rem;
}

.choice-title {
  display: block;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.choice-sub {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
}

.pill {
  flex: 0 0 auto;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  border-radius: 99px;
  padding: 0.16rem 0.45rem;
  background: #ece7dc;
  color: #3d4a42;
}

.pill.low { background: #d9e6f5; color: #1d4e89; }
.pill.mid { background: #f8e7cf; color: #8a4b08; }
.pill.c4 { background: #d7efe6; color: #0f5c4c; }
.pill.c8 { background: #f3dcef; color: #6b2d5b; }
.pill.all { background: #e4e7e2; color: #3d4a42; }
.pill.eight { background: #1f4d3a; color: white; }

.picked {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
  background: var(--pine);
  color: var(--pine-ink);
  border-radius: 6px;
  padding: 0.7rem 0.75rem;
}

.picked strong {
  display: block;
  font-size: 1.02rem;
  overflow-wrap: anywhere;
}

.picked span {
  display: block;
  color: #d5e6dc;
  font-size: 0.85rem;
}

.picked button {
  flex: 0 0 auto;
  min-height: 40px;
  background: transparent;
  color: inherit;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 6px;
  padding: 0.25rem 0.65rem;
}

.hint,
.empty {
  margin: 0;
  padding: 0.75rem;
  color: var(--muted);
}

.form-actions { margin-top: 0.9rem; }

.btn {
  background: var(--pine);
  border-color: var(--pine);
  color: white;
}

.btn.ghost {
  background: white;
  color: var(--pine);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0.7rem 0 0.2rem;
}

.actions .btn { flex: 1 1 8rem; }

.pair {
  display: grid;
  gap: 0.35rem;
}

.eyebrow {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.pair h2 {
  margin: 0;
  font-size: 1.28rem;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.pair p { margin: 0.12rem 0 0; }

.family { color: var(--muted); font-size: 0.88rem; }

.pair-arrow {
  color: var(--signal);
  font-size: 1.3rem;
  line-height: 1;
}

.note {
  background: #fff6e8;
  border: 1px solid #e7c48a;
  color: #6a3d07;
  border-radius: 6px;
  padding: 0.6rem 0.7rem;
  margin: 0.45rem 0 0;
  font-size: 0.92rem;
}

.note.bad {
  background: #fff1f2;
  border-color: #fecdd3;
  color: #9f1239;
}

.set-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.75rem 0.75rem 0.4rem;
  margin-top: 0.7rem;
}

.set-card h3 {
  margin: 0;
  font-size: 1.02rem;
}

.set-head {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: baseline;
}

.mode-tag {
  flex: 0 0 auto;
  background: var(--pine);
  color: white;
  border-radius: 4px;
  padding: 0.12rem 0.4rem;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.ret {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: baseline;
  margin: 0.45rem 0 0;
  font-size: 0.92rem;
  overflow-wrap: anywhere;
}

.ret span {
  font-weight: 700;
  letter-spacing: 0.04em;
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--muted);
}

.jumpers { list-style: none; margin: 0.45rem 0 0; padding: 0; }

.jumper {
  display: grid;
  grid-template-columns: 0.42rem 1.3rem 1fr;
  gap: 0.55rem;
  align-items: center;
  padding: 0.48rem 0;
  border-top: 1px solid var(--line);
}

.jumper.red { --rail: #c51616; }
.jumper.green { --rail: #0d7a32; }
.jumper.blue { --rail: #1d4e89; }
.jumper.magenta { --rail: #a21caf; }
.jumper.black { --rail: #1c1915; }

.rail {
  width: 0.42rem;
  align-self: stretch;
  border-radius: 99px;
  background: var(--rail);
}

.jumper.dotted .rail {
  background: repeating-linear-gradient(
    to bottom,
    var(--rail) 0 4px,
    transparent 4px 7px
  );
}

.jumper.dotdot .rail {
  background: repeating-linear-gradient(
    to bottom,
    var(--rail) 0 2px,
    transparent 2px 4px,
    var(--rail) 4px 6px,
    transparent 6px 9px
  );
}

.idx {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  text-align: right;
}

.ends {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 0.35rem;
  align-items: center;
}

.end strong {
  display: block;
  font-size: 1.15rem;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.end .who,
.end .small {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
}

.arrow {
  color: var(--signal);
  font-weight: 700;
}

.wire-canvas {
  position: relative;
  margin: 0.75rem 0 0.2rem;
}

.stage {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2.6rem;
}

.stage figure {
  position: relative;
  margin: 0;
}

.stage figcaption {
  position: absolute;
  z-index: 3;
  top: 0.4rem;
  left: 0.4rem;
  margin: 0;
  padding: 0.12rem 0.4rem;
  border-radius: 4px;
  background: rgba(247, 244, 236, 0.92);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.face-art {
  position: relative;
  width: min(100%, calc(var(--ar) * 16rem));
  aspect-ratio: var(--ar);
  margin-inline: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.face-art img {
  position: absolute;
  object-fit: fill;
}

.no-photo {
  position: absolute;
  z-index: 3;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0;
  padding: 0.35rem 0.5rem;
  background: rgba(247, 244, 236, 0.94);
  text-align: center;
  color: var(--muted);
  font-size: 0.75rem;
}

.port-dot {
  position: absolute;
  z-index: 2;
  transform: translate(-50%, -50%);
  min-width: 1.05rem;
  height: 1.05rem;
  padding: 0 0.18rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 0.62rem;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  background: #fff;
  border: 2px solid #5c564c;
  color: #1c1915;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.9);
}

.port-dot.idle {
  width: 0.45rem;
  height: 0.45rem;
  min-width: 0;
  padding: 0;
  background: rgba(255, 255, 255, 0.92);
  border-width: 1.5px;
  box-shadow: none;
}

.port-dot.hot { color: #fff; border-color: #fff; }
.port-dot.hot.red { background: #c51616; }
.port-dot.hot.green { background: #0d7a32; }
.port-dot.hot.blue { background: #1d4e89; }
.port-dot.hot.magenta { background: #a21caf; }
.port-dot.hot.black { background: #1c1915; }

.wires {
  position: absolute;
  z-index: 1;
  left: 0;
  top: 0;
  overflow: visible;
  pointer-events: none;
}

.face-label {
  margin: 0.8rem 0 0.35rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.port-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(2.7rem, 1fr));
  gap: 0.35rem;
}

.cell {
  min-height: 2.7rem;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: #faf8f3;
  color: #8a8175;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: ui-monospace, "Cascadia Mono", "Liberation Mono", monospace;
  line-height: 1.05;
}

.cell-n { font-size: 0.95rem; font-weight: 700; }
.cell-j { font-size: 0.65rem; }

.cell.red.solid { background: #fde8e4; color: #9f1d1d; border-color: #d20f0f; }
.cell.green.solid { background: #e5f6ea; color: #0d7a32; border-color: #0d7a32; }
.cell.blue.solid { background: #e5eef8; color: #1d4e89; border-color: #1d4e89; }
.cell.magenta.solid { background: #fbe8f8; color: #a21caf; border-color: #a21caf; }
.cell.black.solid { background: #eeeae4; color: #1c1915; border-color: #1c1915; }

.cell.red.dotted,
.cell.red.dotdot { background: white; color: #9f1d1d; border: 2px dashed #d20f0f; }
.cell.green.dotted,
.cell.green.dotdot { background: white; color: #0d7a32; border: 2px dashed #0d7a32; }
.cell.blue.dotted,
.cell.blue.dotdot { background: white; color: #1d4e89; border: 2px dashed #1d4e89; }
.cell.magenta.dotted,
.cell.magenta.dotdot { background: white; color: #a21caf; border: 2px dashed #a21caf; }
.cell.black.dotted,
.cell.black.dotdot { background: white; color: #1c1915; border: 2px dashed #1c1915; }

.set-card.idle {
  background: transparent;
  border: 0;
  border-radius: 0;
  border-bottom: 1px solid var(--line);
  padding: 0.45rem 0.1rem;
  margin-top: 0;
  color: var(--muted);
}

.set-card.idle h3 {
  font-size: 0.92rem;
  font-weight: 650;
}

.set-card.idle p { margin: 0.1rem 0 0; font-size: 0.85rem; }

.notes summary {
  font-weight: 750;
  cursor: pointer;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.notes ul { margin: 0.4rem 0 0.2rem; padding-left: 1.1rem; }
.notes li + li { margin-top: 0.35rem; }
.notes a { color: var(--pine); }

.colophon {
  margin: 0.8rem 0.15rem 0;
  color: var(--muted);
  font-size: 0.8rem;
}

@media print {
  body { background: white; padding: 0; }
  .wrap { max-width: none; }
  .no-print { display: none !important; }
  .mast, .paper, .set-card { break-inside: avoid; }
  .mast { border-radius: 0; }
  a { color: inherit; text-decoration: none; }
}

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