:root {
  --bg: #f6f1e7;
  --bg-accent: #efe4cd;
  --panel: rgba(255, 251, 242, 0.88);
  --ink: #1f2b2a;
  --muted: #5f6b68;
  --grid: #cfbf9f;
  --occupied: #14281d;
  --bullet: #8c6d1f;
  --t: #e4572e;
  --u: #2e86ab;
  --w: #b56576;
  --wr: #7b2cbf;
  --v: #ff7b00;
  --vbar: #2a9d8f;
  --ring-even: #dcead2;
  --ring-odd: #dbe5f8;
  --start: #c1121f;
  --stop: #d62828;
  --arrow: #6a994e;
  --corner: #8f2d56;
  --shadow: 0 18px 48px rgba(61, 43, 16, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Gill Sans", "Trebuchet MS", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.85), transparent 35%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-accent) 100%);
}

code {
  font-family: "SFMono-Regular", "Menlo", monospace;
  font-size: 0.95em;
}

.page {
  max-width: 1400px;
  margin: 0 auto;
  padding: 32px 24px 48px;
}

.hero {
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 10px;
  color: #8c5a22;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.78rem;
  font-weight: 700;
}

h1 {
  margin: 0 0 12px;
  font-size: clamp(2rem, 4vw, 3.6rem);
  line-height: 0.98;
}

.lede {
  max-width: 70ch;
  margin: 0;
  color: var(--muted);
  font-size: 1.06rem;
  line-height: 1.55;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(320px, 0.85fr);
  gap: 20px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid rgba(111, 78, 25, 0.15);
  border-radius: 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.stage {
  padding: 18px;
}

.sidebar {
  padding: 24px 22px;
}

.stage-toolbar,
.controls-stack {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
}

.controls-stack .secondary {
  margin-top: 28px;
}

.controls {
  display: flex;
  gap: 10px;
}

button,
select {
  border-radius: 999px;
  border: 1px solid rgba(31, 43, 42, 0.18);
  background: white;
  color: var(--ink);
  padding: 10px 16px;
  font: inherit;
}

button {
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 20px rgba(31, 43, 42, 0.08);
}

button.secondary {
  background: rgba(255, 255, 255, 0.5);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 999px;
  background: #f3e3c6;
  color: #69451a;
  font-weight: 700;
}

.meta {
  color: var(--muted);
  margin-left: 8px;
}

.grid {
  margin-top: 18px;
  display: grid;
  gap: 6px;
}

.cell {
  aspect-ratio: 1;
  border-radius: 12px;
  border: 1px solid rgba(113, 88, 42, 0.18);
  background: rgba(255, 255, 255, 0.72);
  position: relative;
  display: grid;
  place-items: center;
  font-size: 0.78rem;
  font-weight: 700;
  user-select: none;
  transition: transform 120ms ease, background 120ms ease;
}

.cell.editable:hover {
  transform: scale(1.03);
  background: rgba(255, 250, 238, 0.96);
  cursor: pointer;
}

.cell.occupied {
  background: color-mix(in srgb, var(--occupied) 88%, white);
  color: white;
}

.cell.bottom-row {
  box-shadow: inset 0 -4px 0 rgba(140, 109, 31, 0.18);
}

.signal-t {
  box-shadow: inset 0 0 0 3px rgba(228, 87, 46, 0.95);
}

.signal-u {
  box-shadow: inset 0 0 0 3px rgba(46, 134, 171, 0.95);
}

.signal-w {
  box-shadow: inset 0 0 0 3px rgba(181, 101, 118, 0.95);
}

.signal-wr {
  box-shadow: inset 0 0 0 3px rgba(123, 44, 191, 0.95);
}

.signal-v {
  box-shadow: inset 0 0 0 3px rgba(255, 123, 0, 0.95);
}

.signal-vbar {
  box-shadow: inset 0 0 0 3px rgba(42, 157, 143, 0.95);
}

.signal-start {
  box-shadow: inset 0 0 0 3px rgba(193, 18, 31, 0.95);
}

.signal-stop {
  box-shadow: inset 0 0 0 3px rgba(214, 40, 40, 0.98);
  color: #8f1010;
}

.signal-arrow {
  box-shadow: inset 0 0 0 3px rgba(106, 153, 78, 0.95);
}

.bullet {
  background: color-mix(in srgb, var(--bullet) 20%, white);
}

.ring-even {
  background: color-mix(in srgb, var(--ring-even) 70%, white);
}

.ring-odd {
  background: color-mix(in srgb, var(--ring-odd) 70%, white);
}

.corner {
  outline: 2px dashed rgba(143, 45, 86, 0.8);
  outline-offset: -4px;
}

.label {
  opacity: 0.9;
}

.legend {
  margin-top: 18px;
}

.legend-content {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.92rem;
}

.legend-content span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.swatch {
  width: 18px;
  height: 18px;
  border-radius: 6px;
  border: 1px solid rgba(31, 43, 42, 0.15);
  background: white;
}

.swatch.occupied { background: var(--occupied); }
.swatch.bullet { background: color-mix(in srgb, var(--bullet) 35%, white); }
.swatch.t { box-shadow: inset 0 0 0 3px var(--t); }
.swatch.u { box-shadow: inset 0 0 0 3px var(--u); }
.swatch.w { box-shadow: inset 0 0 0 3px var(--w); }
.swatch.wr { box-shadow: inset 0 0 0 3px var(--wr); }
.swatch.v { box-shadow: inset 0 0 0 3px var(--v); }
.swatch.vbar { box-shadow: inset 0 0 0 3px var(--vbar); }
.swatch.ring-even { background: var(--ring-even); }
.swatch.ring-odd { background: var(--ring-odd); }
.swatch.start { box-shadow: inset 0 0 0 3px var(--start); }
.swatch.stop { box-shadow: inset 0 0 0 3px var(--stop); }
.swatch.arrow { box-shadow: inset 0 0 0 3px var(--arrow); }
.swatch.corner {
  background: white;
  outline: 2px dashed var(--corner);
  outline-offset: -3px;
}

.stack-field {
  display: grid;
  gap: 8px;
  flex: 1;
  min-width: 220px;
  color: var(--muted);
}

.copy h2,
.source h2 {
  margin-top: 22px;
  margin-bottom: 12px;
  font-size: 1.05rem;
}

.copy ol {
  margin: 0;
  padding-left: 20px;
  line-height: 1.55;
}

.phase-copy,
.hint,
.source p {
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

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

  .grid {
    gap: 4px;
  }

  .cell {
    border-radius: 10px;
    font-size: 0.72rem;
  }

  .controls-stack .secondary {
    margin-top: 0;
  }
}
