/* style.css — Starward Belt page.
 *
 * The map fills the viewport: #field (WebGPU) under #overlay (SVG), both in
 * #stage. The title, the legend, the toolbar, the help card, the scrubber,
 * the zoom buttons, the card, the plate and the hint float on top. Only the
 * buttons, the cards and the scrubber take pointer input, so every other
 * pixel sends drag, wheel and click to the map.
 *
 * grep: :root  .stage  .swapping  .title  .legend  .sw  .tb  .toolbar  .help  .scrub  .zoom
 *       .card  .plate  .seed  .hint  .fallback  @media
 */

:root {
  --bg: #0b0b0b;
  --ink: #f2f2f2;
  --grey: #7a7a7a;
  --line: #3a3a3a;
  --red: #e8365d;
  --pad: 40px;
  --font: 'Chakra Petch', 'Eurostile', 'Bank Gothic', ui-sans-serif, system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

/* ─── map layers ─────────────────────────────────────────────────────────── */

.stage {
  position: fixed;
  inset: 0;
  background: var(--bg);
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}
.stage.dragging { cursor: grabbing; }

/* Map swap: the map and the names fade out, change, and fade in. */
.stage,
.title h1, .title h2,
.plate span, .plate strong, .seed { transition: opacity 250ms ease; }
.swapping .stage,
.swapping .title h1, .swapping .title h2,
.swapping .plate span, .swapping .plate strong, .swapping .seed { opacity: 0; transition-duration: 180ms; }

.stage > canvas,
.stage > svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}
.stage > svg { z-index: 1; overflow: hidden; }

.fallback {
  position: absolute;
  right: var(--pad);
  top: calc(var(--pad) + 110px);
  z-index: 2;
  max-width: 300px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  background: rgba(11, 11, 11, 0.9);
  color: var(--grey);
  font-size: 10px;
  line-height: 1.7;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  text-align: right;
  pointer-events: none;
}
.fallback[hidden] { display: none; }

/* ─── title ──────────────────────────────────────────────────────────────── */

.title {
  position: fixed;
  left: var(--pad);
  top: calc(var(--pad) - 4px);
  z-index: 3;
  pointer-events: none;
  text-transform: uppercase;
}
.title h1 {
  margin: 0;
  font-size: 30px;
  font-weight: 500;
  line-height: 1.1;
  letter-spacing: 0.55em;
  color: #fff;
}
.title h2 {
  margin: 10px 0 0;
  font-size: 20px;
  font-weight: 400;
  line-height: 1.1;
  letter-spacing: 0.55em;
  color: var(--grey);
}

/* ─── legend ─────────────────────────────────────────────────────────────── */

.legend {
  position: fixed;
  left: var(--pad);
  top: calc(var(--pad) + 108px);
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: none;
}

.tier {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--c);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.55;
  letter-spacing: 0.45em;
  text-transform: uppercase;
  text-align: left;
  cursor: pointer;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
}
.tier[data-tier="none"] { color: #fff; }
.tier:focus { outline: none; }
.tier:focus-visible .sw { outline: 1px solid var(--grey); outline-offset: 4px; }

/* The swatch: a square in the tier color with one diagonal, lower left to upper right. */
.sw {
  flex: none;
  width: 44px;
  height: 44px;
  border: 1.5px solid var(--c);
  background: linear-gradient(to top right,
    transparent calc(50% - 0.8px), var(--c) calc(50% - 0.6px),
    var(--c) calc(50% + 0.6px), transparent calc(50% + 0.8px));
  transition: opacity 0.15s, transform 0.15s;
}
.tier .lab { max-width: 16em; transition: opacity 0.15s; }
.tier .short { display: none; }
.tier:hover .sw { transform: scale(1.06); }

.tier[aria-pressed="false"] .sw { opacity: 0.25; }
.tier[aria-pressed="false"] .lab {
  opacity: 0.35;
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

/* ─── toolbar and zoom buttons ───────────────────────────────────────────── */

.tb {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  height: 30px;
  min-width: 30px;
  padding: 0 12px;
  border: 1px solid var(--line);
  background: rgba(11, 11, 11, 0.9);
  color: #cfcfcf;
  font: inherit;
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  cursor: pointer;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s, color 0.15s;
}
.tb[hidden] { display: none; }
.tb span { margin-right: -0.3em; }
.tb svg {
  flex: none;
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.2;
  stroke-linecap: square;
}
.tb svg circle { fill: currentColor; stroke: none; }
@media (hover: hover) { .tb:hover { border-color: var(--grey); color: #fff; } }
.tb:focus { outline: none; }
.tb:focus-visible { outline: 1px solid var(--grey); outline-offset: 3px; }
.tb[aria-pressed="true"],
.tb[aria-expanded="true"] { border-color: var(--ink); color: #fff; }
.tb-help { padding: 0; width: 30px; font-size: 13px; }
.tb-help span { margin: 0; }

.toolbar {
  position: fixed;
  right: var(--pad);
  top: calc(var(--pad) - 4px);
  z-index: 5;
  display: flex;
  gap: 8px;
  pointer-events: none;
}

.zoom {
  position: fixed;
  right: var(--pad);
  bottom: calc(var(--pad) + 100px);
  z-index: 3;
  display: flex;
  gap: 6px;
  pointer-events: none;
}
.zoom .tb { padding: 0; width: 30px; }

/* ─── help card ──────────────────────────────────────────────────────────── */

.help {
  position: fixed;
  right: var(--pad);
  top: calc(var(--pad) + 40px);
  z-index: 6;
  width: 372px;
  max-height: calc(100% - 2 * var(--pad) - 50px);
  overflow-y: auto;
  padding: 14px 18px 12px;
  border: 1px solid var(--line);
  background: rgba(11, 11, 11, 0.94);
  font-size: 10.5px;
  line-height: 1.5;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  pointer-events: auto;
}
.help[hidden] { display: none; }
.help-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #fff;
  font-size: 12px;
  letter-spacing: 0.4em;
}
.help-head button {
  padding: 0 2px;
  border: 0;
  background: none;
  color: var(--grey);
  font: inherit;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.help-head button:hover { color: #fff; }
.help-sec { margin: 12px 0 6px; padding-top: 8px; border-top: 1px solid var(--line); color: var(--grey); letter-spacing: 0.4em; }
.help dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; }
.help dt { color: #fff; white-space: nowrap; }
.help dd { margin: 0; color: #a8a8a8; }

/* ─── rail scrubber ──────────────────────────────────────────────────────── */

/* The track is the belt from end to end. Ticks mark the stations. The
 * thumb spans the part of the belt on the screen. */
.scrub {
  position: fixed;
  right: 11px;
  top: calc(var(--pad) + 100px);
  bottom: calc(var(--pad) + 150px);
  z-index: 3;
  width: 18px;
  cursor: pointer;
  touch-action: none;
}
.scrub::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--line);
  transition: background 0.15s;
}
.scrub:hover::before, .scrub.active::before { background: var(--grey); }
.scrub-ticks { position: absolute; inset: 0; pointer-events: none; }
.tick {
  position: absolute;
  left: 50%;
  width: 7px;
  height: 1px;
  margin-left: -3.5px;
  background: var(--grey);
}
.tick.hub { width: 11px; margin-left: -5.5px; background: #cfcfcf; }
.tick.hot { width: 13px; margin-left: -6.5px; background: #fff; }
.scrub-thumb {
  position: absolute;
  left: 50%;
  width: 9px;
  min-height: 8px;
  margin-left: -4.5px;
  border: 1px solid #cfcfcf;
  background: rgba(242, 242, 242, 0.06);
  cursor: grab;
}
.scrub.active .scrub-thumb { border-color: #fff; cursor: grabbing; }
.scrub-tip {
  position: absolute;
  right: 22px;
  transform: translateY(-50%);
  padding: 3px 8px;
  border: 1px solid var(--line);
  background: rgba(11, 11, 11, 0.92);
  color: #fff;
  font-size: 10px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  white-space: nowrap;
  pointer-events: none;
}
.scrub-tip[hidden] { display: none; }

/* ─── card ───────────────────────────────────────────────────────────────── */

.card {
  position: fixed;
  left: var(--pad);
  bottom: var(--pad);
  z-index: 4;
  width: 330px;
  max-height: calc(100% - 2 * var(--pad) - 340px);
  min-height: 0;
  overflow-y: auto;
  padding: 16px 18px 14px;
  border: 1px solid var(--line);
  background: rgba(11, 11, 11, 0.9);
  font-size: 11px;
  line-height: 1.5;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  pointer-events: auto;
}
.card[hidden] { display: none; }
.card.passive { pointer-events: none; }

.card .kind { color: var(--grey); letter-spacing: 0.4em; }
.card .name {
  margin: 4px 0 12px;
  font-size: 17px;
  font-weight: 500;
  letter-spacing: 0.42em;
  color: #fff;
}
.card .rows { display: grid; gap: 3px; }
.card .row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: baseline;
}
.card .row .to { color: #cfcfcf; }
.card .row.off { opacity: 0.32; }
.card .cost { color: var(--c); font-variant-numeric: tabular-nums; letter-spacing: 0.12em; }
.card .cost::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 8px;
  border: 1px solid var(--c);
  vertical-align: 0;
}
.card .chain { margin: 4px 0 12px; font-size: 13px; font-weight: 500; letter-spacing: 0.34em; color: #fff; }
.card .chain span { white-space: nowrap; }
.card .chain i { font-style: normal; color: var(--grey); padding: 0 0.2em; }
.card .total {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  color: var(--grey);
}
.card .total b { font-size: 16px; font-weight: 500; color: #fff; letter-spacing: 0.15em; }
.card .used { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; }
.card .used span { color: var(--c); }
.card .used span[data-tier="none"] { color: #fff; }
.card .note { margin-top: 10px; color: var(--grey); }
.card .none { margin-top: 4px; color: var(--red); letter-spacing: 0.34em; }

/* ─── plate ──────────────────────────────────────────────────────────────── */

.plate {
  position: fixed;
  right: var(--pad);
  bottom: calc(var(--pad) - 6px);
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  text-align: right;
  text-transform: uppercase;
  pointer-events: none;
}
.plate span {
  font-size: 18px;
  letter-spacing: 0.55em;
  margin-right: -0.55em;
  color: var(--grey);
}
.plate strong {
  font-size: 32px;
  font-weight: 500;
  letter-spacing: 0.55em;
  margin-right: -0.55em;
  color: #fff;
}

/* The seed of a random map. A click copies the link. */
.seed {
  padding: 0;
  border: 0;
  background: none;
  color: var(--grey);
  font: inherit;
  font-size: 10px;
  letter-spacing: 0.3em;
  margin-right: -0.3em;
  text-transform: uppercase;
  cursor: pointer;
  pointer-events: auto;
}
.seed[hidden] { display: none; }
.seed b { font-weight: 500; color: #cfcfcf; }
.seed i { font-style: normal; }
.seed:hover i, .seed.copied i { color: #fff; }
.seed:focus { outline: none; }
.seed:focus-visible { outline: 1px solid var(--grey); outline-offset: 3px; }

/* ─── hint ───────────────────────────────────────────────────────────────── */

.hint {
  position: fixed;
  right: var(--pad);
  top: calc(var(--pad) + 46px);
  z-index: 3;
  max-width: 300px;
  color: var(--grey);
  font-size: 10px;
  line-height: 1.8;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  text-align: right;
  opacity: 0.85;
  pointer-events: none;
  transition: opacity 1.2s ease;
}
.hint.gone { opacity: 0; }

/* ─── mid width: keep the plate clear of the card ────────────────────────── */

@media (max-width: 1100px) {
  :root { --pad: 28px; }
  .title h1 { font-size: 24px; }
  .title h2 { font-size: 16px; }
  .legend { top: calc(var(--pad) + 86px); }
  .plate span { font-size: 14px; }
  .plate strong { font-size: 24px; }
  /* The belt reaches the top right here. Put the hint above the plate. */
  .hint { max-width: 220px; top: auto; bottom: calc(var(--pad) + 120px); }
  .fallback { top: calc(var(--pad) + 44px); max-width: 220px; }
  .zoom { bottom: calc(var(--pad) + 76px); }
  .scrub { top: calc(var(--pad) + 60px); bottom: calc(var(--pad) + 124px); }
}

/* ─── touch: no scrubber, no help card (no mouse, no keys) ───────────────── */

@media (max-width: 600px), (pointer: coarse) {
  .scrub, .tb-help, .help { display: none; }
}

/* ─── phone width ────────────────────────────────────────────────────────── */

@media (max-width: 600px) {
  :root { --pad: 16px; }
  .title { top: 14px; }
  .title h1 { font-size: 15px; letter-spacing: 0.42em; }
  .title h2 { margin-top: 5px; font-size: 11px; letter-spacing: 0.42em; }

  .legend {
    top: 62px;
    right: var(--pad);
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px 14px;
  }
  .tier { gap: 7px; font-size: 10px; letter-spacing: 0.22em; line-height: 1; }
  .sw { width: 22px; height: 22px; border-width: 1px; }
  .tier .full { display: none; }
  .tier .short { display: inline; }

  .card {
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: 42%;
    padding: 12px var(--pad) 14px;
    border-width: 1px 0 0;
    letter-spacing: 0.22em;
  }
  .card .name { font-size: 15px; margin-bottom: 8px; }

  .plate { bottom: 14px; gap: 4px; }
  .plate span { font-size: 10px; letter-spacing: 0.45em; margin-right: -0.45em; }
  .plate strong { font-size: 16px; letter-spacing: 0.45em; margin-right: -0.45em; }

  .fallback { top: 104px; left: var(--pad); right: var(--pad); max-width: none; text-align: center; font-size: 9px; letter-spacing: 0.2em; }
  /* Icons only. The Original button shows only on a random map, where the
   * title is shorter. */
  .toolbar { top: 10px; right: var(--pad); gap: 6px; }
  .toolbar .tb { width: 28px; height: 28px; min-width: 28px; padding: 0; }
  .toolbar .tb span { display: none; }
  .zoom { display: none; }
  .seed { font-size: 9px; letter-spacing: 0.24em; margin-right: -0.24em; }

  .hint { top: auto; bottom: 84px; left: var(--pad); right: var(--pad); max-width: none; text-align: center; font-size: 9px; letter-spacing: 0.2em; }
}
