:root {
  --bg-deep: #05070f;
  --bg-lift: #0b1020;
  --ink: #eaf0ff;
  --ink-dim: #8f9ec4;
  --ink-faint: #5c6b90;
  --line: rgba(140, 170, 255, 0.14);

  --c-any: #5eead4;
  --c-pre: #fbbf24;
  --c-intra: #4ade80;
  --c-post: #c084fc;
  --c-sleep: #7dd3fc;

  --font-display: "Space Grotesk", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
}

/* At least a screenful, but free to grow past it. The stage holds a workable
   minimum height rather than shrinking to whatever the site chrome leaves, so
   on a short window the page scrolls instead of squashing the map. */
body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-deep);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* An open sheet is modal, so the page behind it should stay put. */
body.sheet-open { overflow: hidden; }

/* The global site chrome takes its space first; script measures what is left
   and sizes the app to it, so neither one claims a viewport of its own. */
#site-header,
.site-footer {
  flex: 0 0 auto;
}

/* Ambient light behind everything */
body::before {
  content: "";
  position: fixed;
  inset: -20%;
  background:
    radial-gradient(38% 44% at 22% 18%, rgba(56, 189, 248, 0.16), transparent 70%),
    radial-gradient(42% 48% at 82% 74%, rgba(168, 85, 247, 0.15), transparent 70%),
    radial-gradient(60% 60% at 50% 50%, rgba(20, 184, 166, 0.08), transparent 75%);
  filter: blur(20px);
  pointer-events: none;
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  width: 100%;
  min-height: 0;
  flex: 1 1 auto;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  padding: 26px 34px 16px;
  gap: 14px;
}

/* ---------- Masthead ---------- */

.eyebrow {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--c-any);
}

.masthead h1 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.05;
}

.lede {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--ink-dim);
}

/* ---------- Filters & view toggle ---------- */

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px 18px;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  flex: 1 1 auto;
}

.viewtoggle {
  display: inline-flex;
  flex: 0 0 auto;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.035);
}

.vt {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 6px 15px;
  background: transparent;
  color: var(--ink-faint);
  font-family: var(--font-display);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: color .18s, background .18s;
}

.vt:hover { color: var(--ink); }

.vt.is-on {
  background: rgba(255, 255, 255, 0.12);
  color: var(--ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.chip {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 15px 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.035);
  color: var(--ink-dim);
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: color .18s, border-color .18s, background .18s, transform .18s;
}

.chip:hover {
  color: var(--ink);
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.07);
}

.chip .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 0 transparent;
  transition: box-shadow .18s;
}

.chip.is-on {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.3);
}

.chip.is-on .dot { box-shadow: 0 0 10px 1px currentColor; }

.chip--all { padding-left: 15px; }

/* ---------- Stage ---------- */

.stage {
  position: relative;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 20px;
  overflow: hidden;
  background:
    radial-gradient(120% 120% at 50% 0%, rgba(24, 34, 66, 0.7), rgba(5, 7, 15, 0.9) 70%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 30px 80px -40px rgba(0, 0, 0, 0.9);
}

#map {
  display: block;
  width: 100%;
  height: 100%;
  cursor: default;
}

#map.is-hot { cursor: pointer; }
#map.is-dragging { cursor: grabbing; }

.stage-error {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 6px;
  padding: 40px;
  text-align: center;
  color: var(--ink-dim);
  font-size: 13px;
}

.stage-error h2 {
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--ink);
  margin: 0 0 6px;
}

.stage-error pre {
  margin: 6px 0;
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.4);
  color: var(--c-any);
  font-size: 12.5px;
}

.stage-error code {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.07);
  padding: 1px 5px;
  border-radius: 4px;
}

/* ---------- Popup ---------- */

.popup {
  position: absolute;
  z-index: 5;
  width: 330px;
  padding: 20px 22px 18px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: linear-gradient(165deg, rgba(20, 27, 50, 0.94), rgba(8, 11, 22, 0.96));
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.5),
    0 26px 60px -18px rgba(0, 0, 0, 0.85),
    0 0 60px -14px var(--accent, rgba(94, 234, 212, 0.5));
  opacity: 0;
  transform: translateY(8px) scale(0.97);
  transition: opacity .22s ease, transform .22s cubic-bezier(.2, .9, .3, 1.2);
  pointer-events: none;
}

.popup.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.popup::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 2px;
  border-radius: 18px 18px 0 0;
  background: linear-gradient(90deg, transparent, var(--accent, #5eead4), transparent);
  opacity: 0.9;
}

.popup-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink-dim);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  transition: color .15s, background .15s;
}

.popup-close:hover { color: var(--ink); background: rgba(255, 255, 255, 0.12); }

.popup-kicker {
  display: block;
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent, #5eead4);
}

.popup-title {
  margin: 4px 0 10px;
  font-family: var(--font-display);
  font-size: 23px;
  font-weight: 700;
  letter-spacing: -0.01em;
  padding-right: 22px;
}

.popup-windows {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.tag {
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid currentColor;
  font-size: 10.5px;
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  opacity: 0.9;
}

.popup-info {
  margin: 0 0 16px;
  font-size: 13px;
  line-height: 1.62;
  color: #c3cee9;
}

.popup-links-wrap h3 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.popup-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.link-chip {
  appearance: none;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .15s;
}

.link-chip:hover {
  background: rgba(255, 255, 255, 0.13);
  border-color: rgba(255, 255, 255, 0.35);
  transform: translateY(-1px);
}

.link-chip[disabled] {
  cursor: default;
  opacity: 0.42;
  transform: none;
  background: transparent;
}

.popup-score {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.popup-score-label {
  display: block;
  margin-bottom: 8px;
  font-family: var(--font-display);
  font-size: 9.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.popup-score-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.popup-score-pips {
  display: inline-flex;
  gap: 5px;
}

.pip {
  width: 20px;
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.1);
  transform: scaleX(0.2);
  transform-origin: left center;
  transition: transform .32s cubic-bezier(.2, .9, .3, 1.3), background .32s, box-shadow .32s;
}

.pip.is-on {
  background: var(--accent, #5eead4);
  box-shadow: 0 0 10px -1px var(--accent, #5eead4);
}

.popup-score.is-shown .pip { transform: scaleX(1); }

.pip:nth-child(1) { transition-delay: .02s; }
.pip:nth-child(2) { transition-delay: .07s; }
.pip:nth-child(3) { transition-delay: .12s; }
.pip:nth-child(4) { transition-delay: .17s; }
.pip:nth-child(5) { transition-delay: .22s; }

.popup-score-word {
  font-family: var(--font-display);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--accent, #5eead4);
}

/* ---------- List view (mobile) ---------- */

/* The map and the list are alternate presentations of the same data; script
   sets `view-list` on the body for whichever one is on screen. */

.lede--list,
.hint--list { display: none; }

body.view-list .lede--map,
body.view-list .hint--map { display: none; }

body.view-list .lede--list,
body.view-list .hint--list { display: inline; }

.listing {
  --cols: 4px minmax(0, 1fr) 54px 46px;
  --cols-lean: 4px minmax(0, 1fr) 46px;
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(150, 180, 255, 0.24) transparent;
}

.listing::-webkit-scrollbar { width: 11px; }
.listing::-webkit-scrollbar-track { background: transparent; }

.listing::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: 999px;
  background: rgba(150, 180, 255, 0.22);
  background-clip: content-box;
}

.listing::-webkit-scrollbar-thumb:hover {
  background: rgba(150, 180, 255, 0.38);
  background-clip: content-box;
}

.listing-head,
.row {
  display: grid;
  grid-template-columns: var(--cols);
  align-items: center;
  gap: 12px;
}

/* Sources without intake figures drop the column rather than show empty bars. */
.listing.no-intake .listing-head,
.listing.no-intake .row { grid-template-columns: var(--cols-lean); }

.listing.no-intake .listing-head span:nth-child(3) { display: none; }

.listing-head {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 10px 14px;
  background: linear-gradient(180deg, rgba(8, 11, 22, 0.96), rgba(8, 11, 22, 0.82));
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  font-family: var(--font-display);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.listing-head span:nth-child(3),
.listing-head span:nth-child(4) { text-align: right; }

.row {
  width: 100%;
  min-height: 58px;
  padding: 11px 14px;
  border: 0;
  border-bottom: 1px solid rgba(140, 170, 255, 0.08);
  border-radius: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .16s;
}

.row:active { background: rgba(255, 255, 255, 0.06); }

.row.is-active {
  background: rgba(255, 255, 255, 0.07);
  box-shadow: inset 0 0 30px -14px var(--accent, #5eead4);
}

.row-rail {
  height: 34px;
  border-radius: 3px;
  box-shadow: 0 0 12px -4px var(--accent, #5eead4);
}

.row-main {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.row-name {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-windows {
  display: flex;
  gap: 5px;
}

.row-windows i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  opacity: 0.85;
}

.row-intake {
  height: 5px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.row-intake i {
  display: block;
  height: 100%;
  border-radius: 3px;
  background: var(--accent, #5eead4);
  box-shadow: 0 0 8px -2px var(--accent, #5eead4);
}

.row-score {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-end;
}

.row-sparks {
  display: flex;
  gap: 4px;
}

.row-word {
  display: none;
  font-family: var(--font-display);
  font-size: 11.5px;
  font-weight: 600;
  font-style: normal;
  letter-spacing: 0.02em;
  color: var(--accent, #5eead4);
}

.spark {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
}

.spark.is-on {
  background: var(--accent, #5eead4);
  box-shadow: 0 0 7px -1px var(--accent, #5eead4);
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(2, 4, 10, 0.68);
  opacity: 0;
  transition: opacity .24s ease;
}

.sheet-backdrop.is-open { opacity: 1; }

/* In list view the detail card has no bubble to anchor to, so it becomes a
   centred modal here and a bottom sheet on phones. */
.popup.is-sheet {
  position: fixed;
  z-index: 50;
  left: 50%;
  top: 50%;
  width: min(430px, calc(100vw - 40px));
  max-height: min(78vh, 660px);
  overflow-y: auto;
  overscroll-behavior: contain;
  transform: translate(-50%, calc(-50% + 12px)) scale(0.97);
}

.popup.is-sheet.is-open { transform: translate(-50%, -50%) scale(1); }

/* Wider screens have room for a roomier table. */
@media (min-width: 768px) {
  .listing-head,
  .row {
    --cols: 5px minmax(0, 1fr) 200px 150px;
    --cols-lean: 5px minmax(0, 1fr) 150px;
    gap: 20px;
    padding-left: 24px;
    padding-right: 24px;
  }

  .listing-head { padding-top: 13px; padding-bottom: 13px; }
  .row { min-height: 64px; }
  .row-name { font-size: 16px; }
  .row-intake { height: 6px; }
  .row-score { justify-content: space-between; }
  .row-word { display: block; }
  .row:hover { background: rgba(255, 255, 255, 0.05); }
}

/* ---------- Footnote ---------- */

.footnote {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  font-size: 11.5px;
  color: var(--ink-faint);
}

.footnote kbd {
  font-family: var(--font-display);
  font-size: 10px;
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  color: var(--ink-dim);
}

/* ---------- Narrow screens ---------- */

@media (max-width: 767px) {

  /* The stage stops being a fixed pane and the rows simply run down the page. */
  .app {
    display: block;
    height: auto;
    padding: 22px 16px 30px;
  }

  .masthead { margin-bottom: 16px; }
  .masthead h1 { font-size: 29px; }
  .lede { font-size: 13px; }

  .controls { margin-bottom: 14px; }
  .viewtoggle { display: none; }

  .chip {
    padding: 6px 12px 6px 10px;
    font-size: 11.5px;
  }

  /* The list is its own panel, so the map's frame comes off. */
  .stage {
    border: 0;
    border-radius: 0;
    background: none;
    overflow: visible;
    box-shadow: none;
  }

  .listing { height: auto; overflow: visible; }
  .listing-head { border-radius: 14px 14px 0 0; }

  .listing-rows {
    border-radius: 0 0 14px 14px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.022);
  }

  .row:last-child { border-bottom: 0; }

  .footnote {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    margin-top: 16px;
  }

  /* The centred modal drops to a bottom sheet. Inline left/top from the map
     view are cleared in script so these can take over. */
  .popup.is-sheet {
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: auto;
    max-height: 84vh;
    border-radius: 20px 20px 0 0;
    border-bottom: 0;
    padding: 22px 20px calc(24px + env(safe-area-inset-bottom));
    transform: translateY(100%);
    transition: transform .3s cubic-bezier(.2, .9, .3, 1), opacity .2s ease;
  }

  .popup.is-sheet.is-open { transform: translateY(0); }

  .popup::before { border-radius: 20px 20px 0 0; }

  .popup-close {
    top: 14px;
    right: 14px;
    width: 32px;
    height: 32px;
    font-size: 19px;
  }

  .popup-title { font-size: 25px; }
  .popup-info { font-size: 13.5px; }
  .link-chip { padding: 9px 14px; font-size: 13px; }
}
