:root {
  /* GraphSketball editorial palette: warm cream + ink, slab serif zine
     (token block mirrored from assist-network/styles/index.css). */
  --bg: #f5f1e8;
  --bg-elev: #ece5d4;
  --bg-elev-2: #e2dcc6;
  --fg: #1a1a1a;
  --fg-soft: #3a3a3a;
  --muted: #6e6a60;
  --rule: rgba(26, 26, 26, 0.18);
  --accent: #860038; /* LeBron wine (CLE) */
  --accent-glow: rgba(134, 0, 56, 0.35);

  --font-display: "Rockwell", "Rockwell Nova", "Rokkitt", "Roboto Slab", Georgia, serif;
  --font-body: "Rockwell", "Rockwell Nova", "Rokkitt", "Roboto Slab", Georgia, serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", ui-monospace, monospace;

  --shadow-soft: 0 14px 32px -16px rgba(26, 26, 26, 0.22);
  --shadow-card: 0 18px 60px -18px rgba(26, 26, 26, 0.28);
}

* {
  box-sizing: border-box;
}

/* the hidden attribute must always win — author display rules (flex on
   the hover card, the dropdowns) silently override the UA's [hidden]
   display:none, which kept "hidden" elements rendering */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-feature-settings: "kern" 1, "liga" 1;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
  /* the page itself never pans or zooms — all gestures belong to the
     figure (canvas) or to a scroll panel that opts back in with pan-y.
     Stops "pinch on the wrong place" zooming the whole document. */
  touch-action: none;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

/* position:fixed fully removes iOS document scroll-bounce that
   overscroll-behavior alone misses on older Safari */
body {
  position: fixed;
  inset: 0;
}

/* long-press on the canvas shouldn't select text or pop the iOS callout,
   and taps shouldn't flash the grey highlight */
.canvas {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button {
  -webkit-tap-highlight-color: transparent;
}

/* scroll panels opt back into vertical touch scrolling */
.panel,
.game-list,
.finder-results,
.game-results {
  touch-action: pan-y;
}

/* taps on controls have no 300ms delay and never trigger zoom */
button,
input,
.mate-row,
.chain-row {
  touch-action: manipulation;
}

::selection {
  background: var(--accent);
  color: var(--bg);
}

/* ── Canvas + atmosphere stack (grid → vignette → grain) ─────────── */

.canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  z-index: 0;
  cursor: grab;
  touch-action: none;
}

.canvas:active {
  cursor: grabbing;
}

.canvas.is-hovering {
  cursor: pointer;
}

.labels {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  overflow: hidden;
}

/* Atmosphere layer 1 — faint line grid */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background-image:
    linear-gradient(to right, rgba(26, 26, 26, 0.045) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(26, 26, 26, 0.045) 1px, transparent 1px);
  background-size: 38px 38px;
}

/* Atmosphere layer 2 — radial vignette */
.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background: radial-gradient(
    ellipse at center,
    transparent 35%,
    rgba(26, 26, 26, 0.18) 110%
  );
  opacity: 0.85;
}

/* Atmosphere layer 3 — film grain (multiply on cream = paper) */
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  opacity: 0.11;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.6 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}

/* ── Masthead (top-left) ─────────────────────────────────────────── */

.masthead {
  position: fixed;
  top: max(1.8rem, env(safe-area-inset-top));
  left: max(2rem, env(safe-area-inset-left));
  z-index: 4;
  max-width: min(21rem, 60vw);
  pointer-events: none;
}

.brand {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.6rem;
  text-decoration: none;
  color: var(--fg);
}

.brand-logo {
  display: block;
  width: 1.35rem;
  height: 1.35rem;
}

.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.01em;
  /* Align the CAP-HEIGHT band (cap top -> baseline) to the mark's ink
     center — measured from rendered pixels, not eyeballed. The y
     descender hangs below and doesn't count toward visual alignment. */
  transform: translateY(0.207em);
}

.masthead-title {
  margin: 0.55rem 0 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.5rem, 3.2vw, 2.1rem);
  line-height: 1.05;
  letter-spacing: -0.01em;
}

/* ── Finder (player search under the masthead) ───────────────────── */

.finder {
  position: relative;
  margin-top: 0.85rem;
  width: min(19rem, 100%);
  pointer-events: auto;
}

.finder input[type="text"] {
  width: 100%;
  font-family: var(--font-body);
  font-size: 0.85rem;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 7px;
  padding: 0.42rem 0.6rem;
  outline: none;
}

.finder input[type="text"]:focus {
  border-color: var(--fg-soft);
}

/* .game-results (game dock, later in the file) anchors dropdowns ABOVE
   the input; the finder needs it BELOW — outrank it on specificity */
.finder .finder-results {
  bottom: auto;
  top: calc(100% + 6px);
  z-index: 5;
  /* results may be wider than the input so full names fit */
  min-width: min(19rem, calc(100vw - 2.2rem));
  width: max-content;
  max-width: calc(100vw - 2.2rem);
}

/* ── Info popover (masthead "i") ─────────────────────────────────── */

.info-btn {
  appearance: none;
  pointer-events: auto;
  width: 1.15rem;
  height: 1.15rem;
  border: 1px solid var(--rule);
  border-radius: 50%;
  background: var(--bg);
  color: var(--muted);
  font-family: var(--font-display);
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  vertical-align: 0.35em;
  padding: 0;
}

.info-btn:hover {
  color: var(--fg);
  border-color: var(--fg-soft);
}

.info-pop {
  pointer-events: auto;
  margin-top: 0.6rem;
  max-width: 19rem;
  background: var(--bg);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 0.7rem 0.85rem;
  box-shadow: var(--shadow-card);
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--fg-soft);
}

.info-credit {
  display: block;
  margin-top: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.66rem;
  color: var(--muted);
}

/* ── Ring chips — degree numbers pinned to each ring (JS-positioned) */

.ring-chip {
  position: absolute;
  transform: translate(-50%, -50%);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 0.1rem 0.42rem;
  white-space: nowrap;
}

/* ── Root label + hover card (JS-positioned) ─────────────────────── */

.root-label {
  position: absolute;
  transform: translate(-50%, 0);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 0.18rem 0.6rem;
  box-shadow: var(--shadow-soft);
  white-space: nowrap;
}

/* hub labels — the always-on name budget (Labels.js) */
.hub-label {
  position: absolute;
  transform: translate(-50%, 0);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.66rem;
  line-height: 1.1;
  color: var(--fg-soft);
  white-space: nowrap;
  /* paper knockout so ink text survives dense disc fields */
  text-shadow:
    0 0 3px var(--bg), 0 0 3px var(--bg),
    0 0 3px var(--bg), 0 0 3px var(--bg);
}

/* the ringed player (searched/selected/frontier) reads first */
.hub-label.is-primary {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent);
}

.hover-card {
  position: absolute;
  transform: translate(-50%, calc(-100% - 14px));
  /* springy pop on show (scale composes with the transform above) */
  scale: 0.92;
  opacity: 0;
  transform-origin: bottom center;
  transition:
    scale 0.22s cubic-bezier(0.34, 1.56, 0.64, 1),
    opacity 0.14s ease;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  background: var(--bg);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--accent-dynamic, var(--accent));
  border-radius: 6px;
  padding: 0.45rem 0.65rem;
  box-shadow: var(--shadow-card);
  white-space: nowrap;
  max-width: 70vw;
}

.hover-card.is-on {
  scale: 1;
  opacity: 1;
}

.hover-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.92rem;
  line-height: 1.1;
}

.hover-meta {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--fg-soft);
}

.hover-degree {
  font-family: var(--font-mono);
  font-size: 0.64rem;
  color: var(--muted);
}

/* ── Daily entry (masthead card; the game is a mode, not a tab) ──── */

.daily-entry {
  appearance: none;
  position: fixed;
  top: max(1.8rem, env(safe-area-inset-top));
  right: max(2rem, env(safe-area-inset-right));
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.12rem;
  width: 14.5rem;
  pointer-events: auto;
  background: var(--bg);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--accent);
  border-radius: 7px;
  padding: 0.5rem 0.7rem;
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  text-align: left;
}

.daily-entry:hover {
  background: var(--bg-elev);
}

.daily-entry:active {
  transform: translateY(1px);
}

.daily-entry-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--fg);
}

.daily-entry-sub {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  color: var(--muted);
}

/* ── Player detail panel (right) ─────────────────────────────────── */

.panel {
  position: fixed;
  top: max(6.2rem, calc(env(safe-area-inset-top) + 4.4rem));
  right: max(2rem, env(safe-area-inset-right));
  bottom: max(1.4rem, env(safe-area-inset-bottom));
  z-index: 4;
  width: min(19.5rem, calc(100vw - 2.2rem));
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 1rem 1.1rem 1.1rem;
  box-shadow: var(--shadow-card);
}

.panel-close {
  position: absolute;
  top: 0.55rem;
  right: 0.65rem;
  appearance: none;
  border: 0;
  background: transparent;
  font-size: 1.1rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 0.2rem 0.35rem;
}

.panel-close:hover {
  color: var(--fg);
}

.panel-head {
  border-left: 3px solid var(--accent-dynamic, var(--accent));
  padding-left: 0.7rem;
}

.panel-name {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.25rem;
  line-height: 1.1;
  padding-right: 1.2rem;
}

.panel-meta {
  margin: 0.28rem 0 0;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--fg-soft);
}

.panel-degree {
  margin: 0.45rem 0 0;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--accent);
}

.panel-section {
  margin: 1.15rem 0 0.45rem;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--fg);
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.3rem;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.panel-count {
  font-family: var(--font-mono);
  font-weight: 400;
  font-size: 0.68rem;
  color: var(--muted);
}

.panel-chain,
.panel-mates {
  list-style: none;
  margin: 0;
  padding: 0;
}

.chain-row,
.mate-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.26rem 0.3rem;
  border-radius: 5px;
  font-size: 0.82rem;
  cursor: pointer;
}

.chain-row:hover,
.mate-row:hover {
  background: var(--bg-elev);
}

.chain-dot {
  flex: 0 0 auto;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--accent-dynamic, var(--accent));
  border: 1px solid rgba(26, 26, 26, 0.55);
}

.chain-link {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--muted);
  padding: 0.05rem 0 0.05rem 1.05rem;
  border-left: 1px solid var(--rule);
  margin-left: 0.55rem;
}

.mate-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mate-games {
  font-family: var(--font-mono);
  font-size: 0.64rem;
  color: var(--muted);
}

/* ── Daily game dock (bottom-center) ─────────────────────────────── */

.game {
  position: fixed;
  bottom: max(1.2rem, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  width: min(30rem, calc(100vw - 1.6rem));
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 0.85rem 1rem 0.95rem;
  box-shadow: var(--shadow-card);
}

.game-head {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
}

.game-par {
  margin-left: auto;
}

.game-close {
  appearance: none;
  border: 0;
  background: transparent;
  font-size: 1.05rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 0 0.1rem;
  align-self: center;
}

.game-help {
  appearance: none;
  align-self: center;
  width: 1.15rem;
  height: 1.15rem;
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 50%;
  background: var(--bg);
  color: var(--muted);
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
}

.game-help:hover {
  color: var(--fg);
  border-color: var(--fg-soft);
}

.game-howto {
  margin: 0.5rem 0 0;
  padding: 0.55rem 0.65rem;
  background: var(--bg-elev);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--fg-soft);
}

.game-start-line {
  margin: 0.55rem 0 0.4rem;
  font-size: 0.9rem;
  line-height: 1.4;
}

.game-close:hover {
  color: var(--fg);
}

.game-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
}

.game-par {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--muted);
}

.game-brief {
  margin: 0.55rem 0 0.75rem;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--fg-soft);
}

.game-start-name {
  color: var(--fg);
  border-bottom: 2px solid var(--accent-dynamic, var(--accent));
}

.game-chain {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem;
  margin: 0.6rem 0 0.65rem;
}

.game-chip {
  appearance: none;
  font-family: var(--font-body);
  font-size: 0.78rem;
  color: var(--fg);
  background: var(--bg-elev);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--accent-dynamic, var(--accent));
  border-radius: 5px;
  padding: 0.16rem 0.5rem;
  white-space: nowrap;
}

button.game-chip {
  cursor: pointer;
}

button.game-chip:hover {
  background: var(--bg-elev-2);
}

button.game-chip.is-frontier:hover {
  background: var(--fg-soft);
}

.game-chip.is-frontier {
  background: var(--fg);
  color: var(--bg);
}

.game-chip.is-goal {
  border-left-color: var(--accent);
  border-style: dashed;
  color: var(--muted);
  background: transparent;
}

.game-arrow {
  color: var(--muted);
  font-size: 0.75rem;
}

.game-input-row {
  position: relative;
}

.game-input-row.is-shake {
  animation: shake 0.35s;
}

@keyframes shake {
  20% { transform: translateX(-5px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}

.game input[type="text"] {
  width: 100%;
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 7px;
  padding: 0.5rem 0.65rem;
  outline: none;
}

.game input[type="text"]:focus {
  border-color: var(--fg-soft);
}

.game-results {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 8px;
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.game-result {
  appearance: none;
  border: 0;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-body);
  font-size: 0.82rem;
  color: var(--fg);
  text-align: left;
  padding: 0.38rem 0.6rem;
  cursor: pointer;
}

.game-result.is-active,
.game-result:hover {
  background: var(--bg-elev);
}

/* the daily move list — always visible, in-flow (the dropdown idiom
   above is for the finder) */
.game-results.game-list {
  position: static;
  margin-top: 0.5rem;
  max-height: 30vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  box-shadow: none;
}

.game-result.is-goal-row .mate-name {
  font-weight: 700;
}

.game-list-empty {
  margin: 0;
  padding: 0.5rem 0.65rem;
}

.game-note {
  margin: 0.5rem 0 0;
  font-family: var(--font-mono);
  font-size: 0.66rem;
  color: var(--muted);
  line-height: 1.5;
}

.game-note strong {
  color: var(--fg);
}

.game-record {
  color: var(--fg-soft);
}

.game-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.6rem;
}

.game-btn {
  appearance: none;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.78rem;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 0.32rem 0.9rem;
  cursor: pointer;
}

.game-btn:hover:not(:disabled) {
  background: var(--bg-elev);
}

.game-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.game-btn-primary {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}

.game-btn-primary:hover:not(:disabled) {
  background: var(--fg-soft);
}

/* ── Hint + loading ──────────────────────────────────────────────── */

.hint {
  position: fixed;
  bottom: 1.1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.66rem;
  color: var(--muted);
  pointer-events: none;
  transition: opacity 0.8s ease;
}

.hint.is-faded {
  opacity: 0;
}

.loading {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  background: var(--bg);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--muted);
  transition: opacity 0.45s ease;
}

.loading.is-done {
  opacity: 0;
  pointer-events: none;
}

/* ── Mobile ──────────────────────────────────────────────────────── */

@media (max-width: 700px) {
  .masthead {
    top: 1rem;
    left: 1.1rem;
    max-width: 52vw;
  }

  .masthead-title {
    font-size: 1.35rem;
  }

  .hint {
    display: none;
  }

  /* panel becomes a bottom sheet under the thumb, clear of the home bar */
  .panel {
    top: auto;
    right: max(0.8rem, env(safe-area-inset-right));
    left: max(0.8rem, env(safe-area-inset-left));
    bottom: max(1rem, env(safe-area-inset-bottom));
    width: auto;
    max-height: 46vh;
  }

  .game {
    bottom: max(1rem, env(safe-area-inset-bottom));
    width: calc(100vw - 1.6rem);
  }

  .daily-entry {
    top: max(1rem, env(safe-area-inset-top));
    right: max(1.1rem, env(safe-area-inset-right));
    width: min(11rem, 34vw);
    padding: 0.4rem 0.6rem;
  }

  /* iOS Safari auto-zooms when focusing an input under 16px — hold both
     text inputs at 16px on touch to stop the zoom-in on tap */
  .finder input[type="text"],
  .game input[type="text"] {
    font-size: 16px;
  }
}

/* Touch pointers: 44px min hit targets (Apple HIG) on the small controls,
   and only apply :hover styling where hovering is real (it sticks on
   touch otherwise). */
@media (pointer: coarse) {
  .panel-close,
  .game-close,
  .game-btn {
    min-width: 44px;
    min-height: 44px;
  }

  /* the inline "i" stays visually small but gets a comfortable tap area */
  .info-btn {
    position: relative;
  }
  .info-btn::after {
    content: "";
    position: absolute;
    inset: -12px;
  }
}

/* :hover sticks on touch until you tap elsewhere — neutralize it back to
   each element's resting background so rows/buttons don't stay lit. */
@media (hover: none) {
  .daily-entry:hover,
  .game-btn:hover {
    background: var(--bg);
  }
  .mate-row:hover,
  .chain-row:hover,
  .game-result:hover {
    background: transparent;
  }
}

/* Respect reduced-motion: snap camera/UI transitions instead of easing. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
