/* ─── Dark Theme: Cenarion Grove ─── */
:root {
  --bg: #0e1716;
  --surface: #15231f;
  --border: #20302d;
  --text: #e0e6e1;
  --text-dim: #879a95;
  --text-bright: #f3eee4;

  --classic: #6fb3a3;
  --new-text: #e8a0ab;
  --cursor: #f2d48a;
  --cursor-ink: #1d1604;

  --seg: #24362f;
  --rule: #1e2d29;
}

/* ─── Light Theme: Birch & Sage ─── */
[data-theme="light"] {
  --bg: #f3f5f0;
  --surface: #e6ece4;
  --border: #d3dcd4;
  --text: #23312e;
  --text-dim: #56695f;
  --text-bright: #14211e;

  --classic: #2f7466;
  --new-text: #9e4454;
  --cursor: #1d2b27;
  --cursor-ink: #f6e7bd;

  --seg: #d3dcd2;
  --rule: #dbe2d9;
}

/* ─── Skyborne: Zenith ─── */
[data-palette="skyborne"] {
  --bg: #0c3566;
  --surface: #12417a;
  --border: #26578f;
  --text: #eef2f5;
  --text-dim: #b2cbe6;
  --text-bright: #ffffff;

  --classic: #7fc3ea;
  --new-text: #f5c75a;
  --cursor: #ffffff;
  --cursor-ink: #0c3566;

  --seg: #1d5091;
  --rule: #1a4677;
}

[data-palette="skyborne"][data-theme="light"] {
  --bg: #c4e2fb;
  --surface: #e6f3fd;
  --border: #9cc6ea;
  --text: #0f2a4a;
  --text-dim: #34506f;
  --text-bright: #06182e;

  --classic: #1d5fa4;
  --new-text: #5e4500;
  --cursor: #06182e;
  --cursor-ink: #fff3cf;

  --seg: #9cc6ea;
  --rule: #b0d3f1;
}

/* ─── Dalaran: Arcane Dome ─── */
[data-palette="dalaran"] {
  --bg: #1c0a28;
  --surface: #28113a;
  --border: #5a2f7a;
  --text: #e6dcf0;
  --text-dim: #ab9cc0;
  --text-bright: #f0fbff;

  --classic: #b48ae6;
  --new-text: #8fdcf7;
  --cursor: #e3c77c;
  --cursor-ink: #1f1504;

  --seg: #3f1c58;
  --rule: #2e1442;
}

[data-palette="dalaran"][data-theme="light"] {
  --bg: #f0e4f5;
  --surface: #e5d3ee;
  --border: #b395c8;
  --text: #2a1838;
  --text-dim: #574465;
  --text-bright: #170a22;

  --classic: #6a3d9a;
  --new-text: #0b5f78;
  --cursor: #2a1838;
  --cursor-ink: #f3dfa6;

  --seg: #cfb6de;
  --rule: #dccbe6;
}

/* ─── Page ─── */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
html {
  font-size: 16px;
  scrollbar-color: var(--seg) var(--bg);
}

body {
  position: relative;
  background: var(--bg);
  color: var(--text);
  font-family: "JetBrains Mono", monospace;
  font-size: 1rem;
  container-type: inline-size;
  min-height: 100vh;
  padding: 1.667rem;
  transition:
    background 0.3s,
    color 0.3s;
}

.signature {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.75rem;
  margin-top: 1.333rem;
  letter-spacing: 0.042rem;
}
::selection {
  background: var(--cursor);
  color: var(--cursor-ink);
}

:focus-visible {
  outline: 2px solid var(--cursor);
  outline-offset: 2px;
}

h1,
.subtitle,
.layout {
  max-width: 95rem;
  margin-inline: auto;
}

h1 {
  font-family: "Chakra Petch", sans-serif;
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-bright);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.subtitle {
  color: var(--text-dim);
  font-size: 0.875rem;
  margin-top: 0.25rem;
  margin-bottom: 0.5rem;
}

.note {
  color: var(--text-dim);
  font-size: 0.75rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ─── Palette picker + theme toggle ─── */
.page-controls {
  position: absolute;
  top: 1.833rem;
  right: calc(1.667rem + max(0rem, (100% - 98.333rem) / 2));
  z-index: 100;
  display: flex;
  gap: 0.5rem;
}
.palette-picker {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1.25rem;
  overflow: hidden;
}
.palette-picker button {
  background: none;
  border: none;
  padding: 0.5rem 0.75rem;
  color: var(--text-dim);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.833rem;
  letter-spacing: 0.042rem;
  text-transform: uppercase;
  cursor: pointer;
}
.palette-picker button:hover {
  color: var(--text-bright);
}
.palette-picker button[aria-pressed="true"] {
  background: var(--cursor);
  color: var(--cursor-ink);
}
.palette-picker button:focus-visible {
  outline-offset: -3px;
}
.theme-toggle {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1.25rem;
  padding: 0.5rem 1rem;
  color: var(--text-dim);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.833rem;
  cursor: pointer;
  letter-spacing: 0.042rem;
  transition:
    background 0.3s,
    border-color 0.3s,
    color 0.3s;
}
.theme-toggle:hover {
  color: var(--text-bright);
  border-color: var(--text-dim);
}

/* The controls clear the left-aligned title only on wide pages */
@container (max-width: 60rem) {
  .page-controls {
    position: static;
    flex-wrap: wrap;
    max-width: 95rem;
    margin: 0 auto 1.25rem;
  }
}

/* ─── Board: skills wired to the families that learn them ─── */
.beta {
  max-width: 95rem;
  margin: 0 auto 1rem;
}

/* Pinned like the Forever level ruler; a fixed height, so hovering never moves the board under the pointer */
.readout-bar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  align-content: center;
  height: 5rem;
  margin-bottom: 0.75rem;
  background: var(--bg);
  transition: background 0.3s;
}
.readout-bar[hidden] {
  display: none;
}
.readout {
  display: flex;
  align-items: baseline;
  gap: 0.625rem;
  color: var(--text-bright);
  font-size: 0.875rem;
  font-weight: 600;
}
.count {
  color: var(--cursor);
  font-family: "Chakra Petch", sans-serif;
  font-size: 2.25rem;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.count:empty {
  display: none;
}
.detail {
  height: 1.25rem;
  margin-top: 0.375rem;
  color: var(--text-dim);
  font-size: 0.8125rem;
  line-height: 1.25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.detail a {
  color: var(--classic);
  text-underline-offset: 0.2em;
}
.detail a:hover {
  color: var(--text-bright);
}

.board {
  --row: 1.5rem;
  display: grid;
  grid-template-columns: 17rem minmax(5rem, 1fr) 35rem;
  align-items: start;
}

.skills,
.skills ul,
.families {
  list-style: none;
}
.families {
  display: grid;
  grid-template-rows: repeat(var(--families), minmax(0, 1fr));
  height: calc(var(--rows) * var(--row));
}

/* Heading and gap sizes mirror HEADING and GROUP_GAP in Page.jsx */
.group + .group {
  margin-top: calc(var(--row) * 0.5);
}
.group h2 {
  height: calc(var(--row) * 0.75);
  line-height: calc(var(--row) * 0.75);
  font-family: "Chakra Petch", sans-serif;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.skill button {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  height: var(--row);
  padding: 0 0 0 0.5rem;
  background: none;
  border: none;
  color: var(--text);
  font: inherit;
  font-size: 0.875rem;
  text-align: left;
  cursor: pointer;
  transition:
    background 0.12s,
    color 0.12s;
}
.skill button:hover {
  background: var(--surface);
  color: var(--text-bright);
}
.skill button[data-trace] {
  color: var(--classic);
}
.skill button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text-bright);
  font-weight: 600;
}

/* Hollow until picked, like a socket waiting for its plug */
.mark {
  flex: none;
  width: 0.625rem;
  height: 0.625rem;
  border: 1px solid var(--classic);
  transition:
    background 0.12s,
    border-color 0.12s;
}
.skill button[aria-pressed="true"] .mark {
  background: var(--cursor);
  border-color: var(--cursor);
}

.skill {
  position: relative;
}

/* Opens over the wire gutter, beside the skill it explains */
.tip {
  position: absolute;
  top: 50%;
  left: calc(100% + 1rem);
  z-index: 3;
  width: 20rem;
  padding: 0.625rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.8125rem;
  line-height: 1.45;
  transform: translateY(-50%);
  visibility: hidden;
  opacity: 0;
  transition:
    opacity 0.12s,
    visibility 0.12s;
}
/* Bridges the gap, so the pointer can move onto the tooltip without closing it */
.tip::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: -1rem;
  width: 1rem;
}
@media (hover: hover) {
  .skill:hover .tip {
    visibility: visible;
    opacity: 1;
  }
}
.skill:has(:focus-visible) .tip {
  visibility: visible;
  opacity: 1;
}
.board[data-tips-hidden] .skill .tip {
  visibility: hidden;
  opacity: 0;
}
.tip-name {
  margin-bottom: 0.25rem;
  color: var(--text-bright);
  font-weight: 600;
}
.tip-meta {
  margin-top: 0.25rem;
  color: var(--text-dim);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}

.skill-name,
.from {
  white-space: nowrap;
}
.from {
  margin-left: auto;
  color: var(--text-dim);
  font-size: 0.75rem;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

.tag {
  color: var(--new-text);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  margin-left: 0.5rem;
}

/* One viewBox unit per row: the SVG stretches to the board and strokes keep their width */
.wires {
  width: 100%;
  height: calc(var(--rows) * var(--row));
  overflow: visible;
}
.wires path {
  fill: none;
  stroke: var(--classic);
  stroke-opacity: 0.35;
  stroke-width: 1px;
  vector-effect: non-scaling-stroke;
  transition:
    stroke 0.12s,
    stroke-opacity 0.12s;
}
.board[data-picking] .wires path {
  stroke: var(--rule);
  stroke-opacity: 1;
}
.board .wires path[data-trace] {
  stroke: var(--classic);
  stroke-opacity: 1;
  stroke-width: 2px;
}
/* A picked skill's wires run out from its socket to every family that learns it.
   A wipe, not a dash: dashes are measured on screen under non-scaling strokes.
   The -1 top and bottom insets are a row of slack, so flat wires keep their stroke. */
.board .wires path[data-lit] {
  stroke: var(--cursor);
  clip-path: inset(-1px 0 -1px 0);
  animation: wire-out 0.4s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.board .wires path[data-lit="near"] {
  stroke-opacity: 0.2;
}
.board .wires path[data-lit="match"] {
  stroke-opacity: 1;
  stroke-width: 2px;
}
@keyframes wire-out {
  from {
    clip-path: inset(-1px 100% -1px 0);
  }
}

.family {
  display: grid;
  grid-template-columns: 0.625rem 9rem 14rem minmax(0, 1fr);
  align-items: center;
  column-gap: 0.75rem;
  padding: 0 0.5rem 0 0;
  font-size: 0.875rem;
  cursor: default;
  transition:
    background 0.12s,
    color 0.12s;
}
.family:hover,
.family:focus-visible,
.family[data-state="match"] {
  background: var(--surface);
}
.family:focus-visible {
  outline-offset: -2px;
}
/* The socket every wire lands in; it fills when the family learns every picked skill */
.family::before {
  content: "";
  width: 0.625rem;
  height: 0.625rem;
  border: 1px solid var(--classic);
  transition:
    background 0.12s,
    border-color 0.12s;
}
.family[data-state="match"]::before {
  background: var(--cursor);
  border-color: var(--cursor);
}
.family-name {
  color: var(--text-bright);
  font-weight: 600;
  white-space: nowrap;
}
.diet,
.lacks {
  color: var(--text-dim);
  font-size: 0.75rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lacks:empty {
  display: none;
}
.family[data-state="near"] .family-name {
  color: var(--text);
  font-weight: 400;
}
.family[data-state="out"] .family-name {
  color: var(--text-dim);
  font-weight: 400;
}

.universal {
  max-width: 95rem;
  margin: 1.25rem auto 0;
}

/* ─── Where to tame: zones for the families your picks narrow to ─── */
.where {
  max-width: 95rem;
  margin: 2.5rem auto 0;
}
.where h2 {
  font-family: "Chakra Petch", sans-serif;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-bright);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.where-status {
  margin-top: 0.5rem;
}
.where-status:empty {
  display: none;
}
.where-list {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.75rem 3rem;
  margin-top: 1rem;
}
.where-family h3 {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.25rem;
  padding-bottom: 0.375rem;
  border-bottom: 1px solid var(--rule);
  color: var(--text-bright);
  font-family: "Chakra Petch", sans-serif;
  font-size: 0.9375rem;
  font-weight: 600;
}
/* The same socket as the family's board row; it fills gold while the picks match it */
.where-family h3::before {
  content: "";
  flex: none;
  width: 0.625rem;
  height: 0.625rem;
  border: 1px solid var(--classic);
}
.where-family[data-state="match"] h3::before {
  background: var(--cursor);
  border-color: var(--cursor);
}
.where-count,
.where-family h3 a {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.75rem;
  font-weight: 400;
}
.where-count {
  color: var(--text-dim);
}
.where-family h3 a {
  margin-left: auto;
  color: var(--classic);
  text-underline-offset: 0.2em;
}
.where-family h3 a:hover {
  color: var(--text-bright);
}
.spots {
  list-style: none;
}
.spots li {
  display: grid;
  grid-template-columns: 8.5rem minmax(12rem, 1fr) 13rem minmax(0, 20rem);
  grid-template-areas: "levels track zone notable";
  align-items: baseline;
  column-gap: 0.75rem;
  font-size: 0.8125rem;
  line-height: 1.4;
}
/* The text cells carry the row spacing, so track cells stack flush and gridlines run unbroken */
.spot-levels,
.spot-zone,
.spot-notable {
  padding-block: 0.1875rem;
}
.spot-levels {
  grid-area: levels;
}
.spot-zone {
  grid-area: zone;
}
.spot-notable {
  grid-area: notable;
}

/* A small copy of the Forever level track: one cell per level, a hairline at every tenth.
   Each cell fills its row's full height, so the hairlines join into one ruler down the list. */
.spot-track {
  /* Where the band sits: level with the row's first line of text, however many lines wrap below */
  --band-top: calc(0.1875rem + 0.7em - 0.25rem);
  grid-area: track;
  position: relative;
  align-self: stretch;
  /* Clear of the zone names, so the 60 end doesn't read as a column rule */
  margin-right: 0.75rem;
  background: linear-gradient(
      to right,
      transparent calc(95% - 0.5px),
      var(--rule) calc(95% - 0.5px) calc(95% + 0.5px),
      transparent calc(95% + 0.5px)
    )
    0 0 / calc(100% / var(--cap) * 10) 100% repeat-x;
}
.band {
  position: absolute;
  top: var(--band-top);
  height: 0.5rem;
  background: var(--classic);
}
.spots-ruler .spot-track {
  height: 1.25rem;
}
/* Numerals knock out the hairline they sit on, with the page's own ground */
.spots-ruler .spot-track span {
  position: absolute;
  top: 0;
  padding: 0 0.125rem;
  background: var(--bg);
  transform: translateX(-50%);
  color: var(--text-dim);
  font-family: "Chakra Petch", sans-serif;
  font-size: 0.6875rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.spot-levels {
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.spot-notable {
  color: var(--text-dim);
  font-size: 0.75rem;
}
.notable {
  display: block;
}
.rank {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
}

@media (prefers-reduced-motion: reduce) {
  body,
  .readout-bar,
  .theme-toggle,
  .tip,
  .skill button,
  .mark,
  .wires path,
  .family,
  .family::before {
    transition: none;
  }
  .board .wires path[data-lit] {
    animation: none;
  }
}

/* Narrower pages: each family folds into a name over its diet, or over what it lacks on a near miss */
@container (max-width: 58rem) {
  .board {
    grid-template-columns: minmax(0, 17rem) minmax(1.75rem, 1fr) minmax(0, 14rem);
  }
  /* The socket and name sit on the row's centre line, where its wires land; the diet hangs below */
  .family {
    grid-template-columns: 0.625rem minmax(0, 1fr);
    grid-template-rows: 1fr auto 1fr;
    column-gap: 0.5rem;
    padding: 0;
  }
  .family::before,
  .family > .family-name {
    grid-row: 2;
  }
  .family > .diet,
  .family > .lacks {
    grid-column: 2;
    grid-row: 3;
    align-self: start;
    font-size: 0.6875rem;
  }
  .family[data-state="near"] > .diet {
    display: none;
  }
  .tip {
    top: 100%;
    left: 0;
    width: 100%;
    transform: none;
  }
  .tip::before {
    display: none;
  }
}

/* Phones: the level column goes to the detail line too */
@media (max-width: 40rem) {
  body {
    padding: 1rem;
  }
}
@container (max-width: 40rem) {
  .readout-bar {
    height: 6.5rem;
  }
  .detail {
    height: 3.75rem;
    white-space: normal;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
  }
  .board {
    --row: 2rem;
    grid-template-columns: minmax(0, 1fr) 1.75rem minmax(0, 8.75rem);
  }
  .family > .diet {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-height: 1.1;
    white-space: normal;
  }
  .skill button {
    font-size: 0.8125rem;
    padding-left: 0;
  }
  .from,
  .tip {
    display: none;
  }
  .mark {
    margin-left: auto;
  }
  .family {
    font-size: 0.8125rem;
  }
  /* The track keeps the first column to itself, as on desktop; the zone, its levels and its
     rare beasts stack beside it, and the band sits on the zone's line */
  .spots li {
    grid-template-columns: 8.5rem minmax(0, 1fr);
    grid-template-areas:
      "track zone"
      "track levels"
      "track notable";
  }
  .spot-zone {
    padding-bottom: 0;
  }
  .spot-levels {
    padding-block: 0;
  }
  .spot-notable {
    padding-top: 0;
  }
  .band {
    min-width: 0.25rem;
  }
  /* A 1.75rem gutter can't hold every wire legibly: the idle board shows sockets, a pick draws its wires */
  .board .wires path:not([data-lit], [data-trace]) {
    stroke-opacity: 0;
  }
}
