:root {
  --ink: #18221f;
  --muted: #66746e;
  --paper: #f6f0e7;
  --panel: #fffaf2;
  --panel-2: #eef6ed;
  --graph: #9ba9a2;
  --deleted: #d05845;
  --candidate: #f6c35b;
  --leader: #e84e47;
  --wave: #2678c7;
  --wave-2: #7b5cc9;
  --wave-3: #18946f;
  --wave-4: #c56a2a;
  --shadow: 0 22px 70px rgba(39, 32, 20, 0.14);
  font-family: "Avenir Next", "Trebuchet MS", Verdana, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 8%, rgba(236, 194, 92, 0.22), transparent 28rem),
    radial-gradient(circle at 88% 4%, rgba(35, 120, 108, 0.16), transparent 24rem),
    linear-gradient(145deg, #f8f1e6 0%, #edf4ea 100%);
}

.hero,
.controls,
.layout,
.details {
  width: min(1600px, calc(100vw - 48px));
  margin: 0 auto;
}

.hero {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 28px;
  padding: 34px 0 18px;
}

.eyebrow {
  margin: 0 0 8px;
  color: #9c6a22;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 8px;
  font-size: clamp(2.4rem, 5vw, 5.6rem);
  line-height: 0.92;
  letter-spacing: -0.06em;
}

h2 {
  margin-bottom: 10px;
  font-size: 1.1rem;
}

.subtitle {
  max-width: 760px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1.15rem;
  line-height: 1.45;
}

.verdict {
  max-width: 360px;
  padding: 18px 20px;
  border: 2px solid rgba(208, 88, 69, 0.38);
  border-radius: 22px;
  background: rgba(255, 250, 242, 0.78);
  box-shadow: var(--shadow);
  color: #5d4038;
  line-height: 1.4;
}

.controls {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid rgba(53, 61, 55, 0.16);
  border-radius: 22px;
  background: rgba(255, 250, 242, 0.88);
  box-shadow: 0 12px 44px rgba(30, 28, 22, 0.1);
  backdrop-filter: blur(16px);
}

button {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  background: #20322d;
  color: #fffaf2;
  font-weight: 800;
  cursor: pointer;
}

button:hover {
  background: #335147;
}

.slider-label {
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr);
  align-items: center;
  gap: 10px;
  flex: 1;
  color: var(--muted);
  font-weight: 800;
}

.slider-label.compact {
  flex: 0.6;
}

input[type="range"] {
  width: 100%;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 18px;
  padding-top: 18px;
}

.board-card,
.note-card,
.legend-card,
.zoom-card,
.details {
  border: 1px solid rgba(53, 61, 55, 0.14);
  border-radius: 30px;
  background: rgba(255, 250, 242, 0.86);
  box-shadow: var(--shadow);
}

.board-card {
  padding: 18px;
}

.board-title {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 12px;
}

.board-title h2 {
  margin-bottom: 0;
  font-size: clamp(1.6rem, 2vw, 2.4rem);
  letter-spacing: -0.04em;
}

.phase {
  margin-bottom: 4px;
  color: #a46b21;
  font-size: 0.82rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.step-counter {
  min-width: 86px;
  padding: 10px 14px;
  border-radius: 999px;
  background: #20322d;
  color: #fff;
  font-weight: 900;
  text-align: center;
}

.board {
  --cols: 18;
  --rows: 13;
  --cell: min(52px, calc((100vw - 520px) / var(--cols)));
  position: relative;
  width: calc(var(--cols) * var(--cell));
  height: calc(var(--rows) * var(--cell));
  min-width: 0;
  margin: 0 auto;
  border-radius: 24px;
  background:
    linear-gradient(rgba(38, 50, 45, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(38, 50, 45, 0.06) 1px, transparent 1px);
  background-size: var(--cell) var(--cell);
  overflow: hidden;
}

.edges,
.cells {
  position: absolute;
  inset: 0;
}

.edge {
  stroke: var(--graph);
  stroke-width: 5;
  stroke-linecap: round;
  opacity: 0.76;
}

.edge.tree {
  stroke: #536b62;
  stroke-width: 6;
}

.edge.deleted {
  stroke: var(--deleted);
  stroke-width: 4;
  stroke-dasharray: 7 8;
  opacity: 0.65;
}

.edge.signal-edge {
  stroke: #e06a2a;
  stroke-width: 9;
  stroke-dasharray: none;
  opacity: 0.95;
}

.cell {
  position: absolute;
  display: grid;
  place-items: center;
  width: calc(var(--cell) - 8px);
  height: calc(var(--cell) - 8px);
  transform: translate(4px, 4px);
  border: 2px solid #d1c5b4;
  border-radius: 14px;
  background: #fffdf8;
  color: var(--muted);
  font-size: clamp(0.6rem, 1.1vw, 0.82rem);
  font-weight: 900;
  transition: background 180ms ease, border 180ms ease, transform 180ms ease, opacity 180ms ease;
}

.cell.reached {
  border-color: rgba(38, 120, 199, 0.5);
  background: #edf6ff;
}

.cell.front {
  border-color: var(--wave);
  box-shadow: 0 0 0 4px rgba(38, 120, 199, 0.18);
  color: #104a81;
}

.cell.candidate {
  border-color: #c98a24;
  background: #fff3cb;
  color: #6b4200;
}

.cell.loser {
  border-color: #b94c3f;
  background: #f9dbd6;
  color: #79291e;
  text-decoration: line-through;
}

.cell.leader {
  border-color: var(--leader);
  background: #ffe0df;
  color: #9a1711;
  box-shadow: 0 0 0 6px rgba(232, 78, 71, 0.18);
  transform: translate(4px, 4px) scale(1.1);
}

.cell.removed {
  opacity: 0.13;
  filter: grayscale(1);
}

.hole-cell {
  position: absolute;
  z-index: 1;
  width: calc(var(--cell) - 8px);
  height: calc(var(--cell) - 8px);
  transform: translate(4px, 4px);
  border: 2px dashed rgba(18, 34, 31, 0.85);
  border-radius: 10px;
  background:
    repeating-linear-gradient(
      135deg,
      rgba(24, 34, 31, 0.88) 0 7px,
      rgba(24, 34, 31, 0.72) 7px 14px
    );
  box-shadow: inset 0 0 0 3px rgba(255, 250, 242, 0.22);
  pointer-events: none;
}

.wave-dot {
  position: absolute;
  width: calc(var(--cell) * 0.34);
  height: calc(var(--cell) * 0.34);
  border: 3px solid #fff;
  border-radius: 999px;
  box-shadow: 0 3px 10px rgba(14, 29, 26, 0.24);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.wave-dot.c0 { background: var(--wave); }
.wave-dot.c1 { background: var(--wave-2); }
.wave-dot.c2 { background: var(--wave-3); }
.wave-dot.c3 { background: var(--wave-4); }
.wave-dot.c4 { background: #ce4f8f; }
.wave-dot.c5 { background: #536f1f; }

.collision-mark {
  position: absolute;
  display: grid;
  place-items: center;
  width: calc(var(--cell) * 0.52);
  height: calc(var(--cell) * 0.52);
  border-radius: 999px;
  background: #212121;
  color: #fff;
  font-size: calc(var(--cell) * 0.32);
  font-weight: 1000;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.signal-badge {
  position: absolute;
  z-index: 5;
  display: grid;
  place-items: center;
  width: calc(var(--cell) * 0.56);
  height: calc(var(--cell) * 0.56);
  border: 3px solid #fffaf2;
  border-radius: 999px;
  box-shadow: 0 0 0 4px rgba(255, 250, 242, 0.75), 0 8px 20px rgba(21, 24, 20, 0.32);
  color: #fffaf2;
  font-size: calc(var(--cell) * 0.2);
  font-weight: 1000;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.signal-badge.moving::after {
  content: "";
  position: absolute;
  inset: -8px;
  border: 2px solid currentColor;
  border-radius: inherit;
  opacity: 0.38;
  animation: pulse-signal 900ms ease-out infinite;
}

.signal-badge.delete {
  background: #d05845;
}

.signal-badge.winner {
  background: #c94732;
}

.signal-badge.ok {
  background: #18946f;
}

@keyframes pulse-signal {
  from {
    transform: scale(0.75);
    opacity: 0.45;
  }
  to {
    transform: scale(1.35);
    opacity: 0;
  }
}

.side {
  display: grid;
  gap: 18px;
  align-content: start;
}

.note-card,
.legend-card,
.zoom-card {
  padding: 20px;
}

.note-card p,
.zoom-card p,
.details p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.5;
}

#note {
  min-height: 128px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0;
  color: #50605a;
  font-weight: 700;
}

.swatch,
.ring {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 2px solid #d1c5b4;
  background: #fffdf8;
}

.swatch.candidate {
  border-color: #c98a24;
  background: #fff3cb;
}

.swatch.hole {
  border-style: dashed;
  border-color: rgba(18, 34, 31, 0.85);
  background:
    repeating-linear-gradient(
      135deg,
      rgba(24, 34, 31, 0.88) 0 5px,
      rgba(24, 34, 31, 0.72) 5px 10px
    );
}

.swatch.loser {
  border-color: #b94c3f;
  background: #f9dbd6;
}

.swatch.leader {
  border-color: var(--leader);
  background: #ffe0df;
}

.line {
  width: 34px;
  height: 0;
  border-top: 5px solid var(--graph);
}

.line.deleted {
  border-color: var(--deleted);
  border-top-style: dashed;
}

.ring.front {
  border-color: var(--wave);
  background: transparent;
  box-shadow: 0 0 0 4px rgba(38, 120, 199, 0.14);
}

.zoom-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
}

.zoom-title span {
  color: #a46b21;
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.counter-zoom {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 4px;
  margin: 12px 0;
}

.counter-cell {
  display: grid;
  grid-template-rows: 1fr 1fr;
  min-height: 58px;
  border: 1px solid #d7cbbc;
  border-radius: 9px;
  overflow: hidden;
  background: #fffdf8;
}

.counter-cell > div {
  display: grid;
  place-items: center;
  min-height: 28px;
  font-weight: 900;
}

.counter-cell > div:first-child {
  border-bottom: 1px solid #d7cbbc;
  color: #855d2e;
}

.counter-cell.active {
  outline: 3px solid rgba(38, 120, 199, 0.35);
}

.details {
  margin-top: 18px;
  margin-bottom: 34px;
  padding: 22px 26px;
}

@media (max-width: 1080px) {
  .hero,
  .layout {
    display: block;
  }

  .verdict {
    max-width: none;
    margin-top: 18px;
  }

  .layout {
    padding-top: 14px;
  }

  .side {
    margin-top: 18px;
  }

  .board {
    --cell: min(44px, calc((100vw - 80px) / var(--cols)));
  }
}

@media (max-width: 760px) {
  .hero,
  .controls,
  .layout,
  .details {
    width: min(100vw - 24px, 1600px);
  }

  .controls {
    flex-wrap: wrap;
  }

  .slider-label,
  .slider-label.compact {
    flex-basis: 100%;
  }
}
