/* Wordbranch — neon (2026-09-26). Flat 2D: dark tiles with coloured rings, one cyan accent,
   glow only on the pair being read. Tokens shared with Math Connect's neon direction. */
:root {
  color-scheme: dark;
  --bg: #050810; --cell: #0a1120; --panel: #0c1526; --panel-2: #111c30;
  --line: #5b6b87; --line-soft: #1f2c44; --text: #e8eef9; --muted: #9aa8bf; --faint: #64748b;
  --cyan: #67e8f9; --cyan-hot: #22d3ee;
  --good: #4ade80; --amber: #fbbf24; --bad: #fb7185; --bad-hot: #f43f5e; --ink: #050810;
  --r: 12px; --tile-w: 100px; --tile-h: 56px; --node: 34px;
  --ease-out: cubic-bezier(.2, .8, .2, 1); --ease-pop: cubic-bezier(.3, 1.6, .5, 1);
  font-family: "Baloo 2", system-ui, -apple-system, "Segoe UI", sans-serif; font-weight: 700;
  color: var(--text); background: var(--bg);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  display: flex; flex-direction: column; height: 100dvh; overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button { color: inherit; font: inherit; cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; opacity: .38; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--cyan-hot); outline-offset: 3px; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }

/* ---- Topbar (site contract: ← Games + wordmark h1) ---- */
.topbar {
  flex: none; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  width: 100%; max-width: 1180px; margin: 0 auto; padding: 8px 16px 0; min-height: 48px;
}
.hub-back {
  justify-self: start; display: inline-flex; align-items: center; min-height: 40px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 999px; color: #dfe7f5; background: var(--panel);
  font-size: 13px; font-weight: 800; white-space: nowrap;
}
.hub-back:hover { border-color: var(--cyan-hot); }
.wordmark {
  margin: 0; font-weight: 400; font-family: "Press Start 2P", monospace; font-size: 11px;
  color: var(--cyan); letter-spacing: 1px; white-space: nowrap; text-align: center;
}
.topbar .icon-btn { justify-self: end; }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; padding: 0;
  border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text);
  font-size: 20px; font-weight: 800; line-height: 1;
}
.icon-btn:hover:not(:disabled) { border-color: var(--cyan); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 48px; padding: 0 20px; border: 2px solid var(--line); border-radius: var(--r);
  background: var(--panel); color: var(--text); font-size: 18px; font-weight: 800;
}
.btn:hover:not(:disabled) { border-color: var(--cyan); }
.btn-primary { border-color: var(--cyan); background: var(--cyan); color: var(--ink); }
.btn-primary:hover:not(:disabled) { background: var(--cyan-hot); border-color: var(--cyan-hot); }

/* ---- App shell: one screen, no page scroll ---- */
.app {
  flex: 1; min-height: 0; width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 16px 8px; position: relative;
  display: grid; grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  grid-template-areas: "status" "stage" "readout" "actions";
}
.status-row { grid-area: status; display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 4px 0; }
/* The ≡ button keeps its 44 px hit target; a long title is what gives way (it ellipsises). */
.status-row .icon-btn, .status-row .progress { flex: none; }
.board-name {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 4px; min-width: 0;
  border: 0; background: transparent; text-align: left; font-size: 15px; font-weight: 700; border-radius: 10px;
}
.board-name:hover { color: var(--cyan); }
.board-number { color: var(--faint); font-variant-numeric: tabular-nums; }
.board-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.caret { color: var(--faint); font-size: 18px; line-height: 0; }
.progress { margin-left: auto; color: var(--muted); font-size: 14px; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Stage: the tree region. On phone it scrolls (tree then meanings); on desktop it dissolves into the grid. */
.stage { grid-area: stage; display: flex; flex-direction: column; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
.board-viewport { flex: 1 0 auto; display: flex; align-items: center; justify-content: center; max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: thin; padding: 4px 0; transition: min-height .45s var(--ease-out); }
.board { position: relative; flex: none; isolation: isolate; }
.board > svg, .board > #tiles, .board > #link-buttons { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.connection { fill: none; stroke: var(--line); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.connection.correct { stroke: var(--good); }
.connection.amber { stroke: var(--amber); }
.connection.incorrect { stroke: var(--bad); stroke-dasharray: 4 6; }
.connection-hit { fill: none; stroke: transparent; stroke-width: 24px; pointer-events: stroke; cursor: pointer; touch-action: manipulation; }
.arrow { fill: var(--line); }
.arrow.correct { fill: var(--good); }
.arrow.amber { fill: var(--amber); }
.arrow.incorrect { fill: var(--bad); }

.tile {
  position: absolute; transform: translate(-50%, -50%);
  width: var(--tile-w); height: var(--tile-h);
  display: flex; align-items: center; justify-content: center; padding: 2px 4px;
  background: var(--cell); border: 3px solid var(--line); border-radius: var(--r); color: var(--text);
  font-size: var(--tile-font, 22px); line-height: 1.05; font-weight: 800; letter-spacing: -.2px; white-space: nowrap; overflow: hidden;
  pointer-events: auto; touch-action: none; user-select: none; -webkit-user-select: none;
  transition: transform .12s var(--ease-out), background .12s ease-out, color .12s ease-out, border-color .12s ease-out, opacity .12s ease-out;
}
.tile:hover:not(:disabled) { border-color: var(--cyan); }
.tile:active:not(:disabled) { transform: translate(-50%, -50%) scale(.94); transition-duration: .06s; }
.tile.confirmed { border-color: var(--good); }
.tile.group-member { border-color: var(--cyan); }
.tile.selected { background: var(--cyan); border-color: var(--cyan); color: var(--ink); transform: translate(-50%, -50%) scale(1.06); z-index: 2; }
.board.has-selection .tile:not(.selected):not(.group-member) { opacity: .6; }
.tile.drop-target { outline: 3px solid var(--cyan); outline-offset: 3px; opacity: 1 !important; }
.tile.solved { border-color: var(--good); background: color-mix(in srgb, var(--good) 14%, var(--cell)); }
.tile.revealed { border-color: var(--line); background: var(--panel-2); color: var(--muted); }
.tile:disabled { opacity: 1; }
.tile.drag-source { opacity: .35 !important; }
/* Outline (15 words on a phone): full-width rows; a vertical swipe on a tile scrolls the stage. */
.board.outline .tile { justify-content: flex-start; padding-left: 16px; border-radius: 10px; touch-action: pan-y; }
.board.outline .tile.selected { transform: translate(-50%, -50%) scale(1.02); }
.drag-ghost {
  position: fixed; z-index: 5; pointer-events: none; transform: translate(-50%, -50%);
  background: var(--cyan); border-color: var(--cyan); color: var(--ink); opacity: .72;
  filter: drop-shadow(0 0 12px var(--cyan));
  /* Lifted above the pointer so the word under it stays readable. */
  transform: translate(-50%, calc(-50% - 22px));
}

.link-button {
  position: absolute; width: 44px; height: 44px; padding: 0; transform: translate(-50%, -50%);
  border: 0; border-radius: 50%; background: transparent; pointer-events: auto; display: grid; place-items: center; z-index: 1;
}
.link-button span {
  display: grid; place-items: center; width: var(--node); height: var(--node);
  background: var(--cell); border: 3px solid var(--line); border-radius: 50%;
  color: var(--muted); font-size: 16px; font-weight: 800; line-height: 1;
  transition: border-color .12s ease-out, background .12s ease-out, color .12s ease-out, transform .09s var(--ease-pop);
}
.link-button:active:not(:disabled) span { transform: scale(.9); }
.link-button:hover:not(:disabled) span { border-color: var(--cyan); color: var(--cyan); }
.link-button.correct span { border-color: var(--good); background: var(--good); color: var(--ink); }
.link-button.amber span { border-color: var(--amber); color: var(--amber); }
.link-button.incorrect span { border-color: var(--bad); color: var(--bad); }
.link-button:disabled { opacity: 1; }
/* A reveal is shown, not solved: hollow ✓ nodes and softer lines keep it apart from a real win. */
.board.revealed .link-button.correct span { background: var(--cell); color: var(--good); }
.board.revealed .connection, .board.revealed .arrow { opacity: .55; }

/* ---- Readout: the one big line ---- */
.readout-card { grid-area: readout; display: flex; flex-direction: column; justify-content: center; min-height: 72px; padding: 4px 0; }
.readout { margin: 0; font-size: 30px; line-height: 1.1; font-weight: 800; min-height: 33px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transform-origin: left center; transition: color .12s ease-out; }
.readout.idle { color: var(--muted); font-size: 22px; font-weight: 700; }
.readout.live { color: var(--cyan); }
.readout.good { color: var(--good); }
.readout.amber { color: var(--amber); }
.readout.bad { color: var(--bad); }
.readout.won { color: var(--good); }
.meaning-line { margin: 2px 0 0; min-height: 18px; font-size: 14px; line-height: 1.3; color: var(--muted); font-weight: 700; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
/* Stars: earned ones are gold and lit, the rest faint outlines, so ★★☆ reads as two of three. */
.stars { white-space: nowrap; letter-spacing: 1px; }
.star-earned { color: var(--amber); text-shadow: 0 0 8px rgba(251, 191, 36, .45); }
.star-empty { color: var(--faint); }
.meaning-line .stars { font-size: 18px; line-height: 1; vertical-align: -1px; }
.actions { grid-area: actions; display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; padding: 4px 0 0; }
.actions .btn { flex: 1; max-width: 260px; margin-left: auto; }

/* ---- Meanings (after a win or a reveal) ---- */
.meanings { flex: none; padding: 8px 0 12px; }
.meanings.enter { animation: rise .3s var(--ease-out) both; }
@keyframes rise { from { opacity: 0; transform: translateY(16px); } }
.meanings h2 { margin: 0 0 10px; font-size: 16px; font-weight: 800; color: var(--muted); }
#meaning-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.meaning { padding: 8px 10px; border: 1px solid var(--line-soft); border-radius: 10px; background: var(--panel); }
.meaning strong { display: block; font-size: 15px; margin-bottom: 2px; }
.meaning p { margin: 0; font-size: 12px; line-height: 1.4; color: var(--muted); font-weight: 700; }

/* ---- Board chips (desktop side panel) ---- */
.chips { display: none; }

/* ---- Toast (at most two messages use it) ---- */
.toast {
  position: fixed; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: min(360px, calc(100% - 32px)); padding: 8px 14px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--panel-2); color: var(--text); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  opacity: 0; pointer-events: none; z-index: 8; transform: translate(-50%, 6px); transition: opacity .2s ease-out, transform .2s var(--ease-out);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.noscript { color: var(--muted); }

/* ---- Sheet (the ? and ≡ sheets share one dialog) ---- */
dialog.sheet {
  position: fixed; inset: auto 0 0 0; margin: 0 auto; width: min(460px, 100%); max-height: 86dvh;
  border: 1px solid var(--line-soft); border-bottom: 0; border-radius: 22px 22px 0 0;
  background: var(--panel); color: var(--text); padding: 18px 20px calc(18px + env(safe-area-inset-bottom));
  box-shadow: 0 -12px 40px rgba(0, 0, 0, .5); overflow: auto; overscroll-behavior: contain;
}
dialog::backdrop { background: rgba(5, 8, 16, .6); }
.close-modal { position: absolute; right: 8px; top: 8px; width: 44px; height: 44px; border: 0; background: transparent; font-size: 26px; color: var(--muted); }
dialog h2 { margin: 4px 30px 10px 0; font-size: 22px; font-weight: 800; line-height: 1.1; }
dialog p { margin: 0 0 10px; font-size: 15px; line-height: 1.45; color: var(--muted); }
dialog p b { color: var(--text); }
.sheet-list { display: grid; gap: 8px; margin: 6px 0 12px; }
.sheet-list .btn { justify-content: flex-start; font-size: 16px; min-height: 48px; }
.sheet-list .btn small { margin-left: auto; color: var(--muted); font-size: 13px; font-weight: 700; }
.board-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 6px 0 14px; }
.board-chip {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 52px; padding: 6px 4px; border: 2px solid var(--line-soft); border-radius: 12px; background: var(--cell);
  font-size: 15px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums;
}
.board-chip small { font-size: 11px; color: var(--muted); font-weight: 700; }
.board-chip small .stars { font-size: 12px; letter-spacing: 0; }
.board-chip.done { border-color: #2a3a57; color: var(--good); }
.board-chip.current { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(103, 232, 249, .16); color: var(--cyan); }
.board-chip:hover { border-color: var(--cyan); }
.help-steps { margin: 0 0 12px; padding: 0; list-style: none; display: grid; gap: 10px; }
.help-steps li { display: grid; grid-template-columns: 40px 1fr; gap: 10px; align-items: start; font-size: 14px; line-height: 1.4; color: var(--muted); font-weight: 700; }
.help-steps b { color: var(--text); display: block; font-size: 15px; }
.help-steps i { font-style: normal; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; border: 3px solid var(--line); font-size: 16px; color: var(--muted); }
.help-steps i.good { border-color: var(--good); background: var(--good); color: var(--ink); }
.help-steps i.amber { border-color: var(--amber); color: var(--amber); }
.help-steps i.bad { border-color: var(--bad); color: var(--bad); }
.help-demo { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 4px 0 14px; font-size: 18px; font-weight: 800; }
.help-demo b { padding: 6px 12px; border: 3px solid var(--good); border-radius: 10px; background: var(--cell); }
.help-demo span { color: var(--faint); }
.small-note { font-size: 12px !important; color: var(--faint) !important; }
.sheet-extra { position: absolute; top: 8px; right: 52px; display: flex; --feedback-ink: var(--muted); }
dialog[data-sheet="help"] h2 { margin-right: 150px; }
dialog[data-sheet="menu"] .sheet-extra { display: none; }
.sheet-note { font-size: 12px; color: var(--faint); margin: 0; }

/* ---- Desktop: two columns ---- */
@media (min-width: 900px) {
  .topbar { padding-top: 12px; }
  .app {
    column-gap: 28px; padding-bottom: 12px;
    grid-template-columns: minmax(0, 1fr) 320px;
    grid-template-rows: auto auto auto minmax(0, 1fr);
    grid-template-areas: "status status" "stage readout" "stage actions" "stage side";
  }
  .stage { display: contents; }
  .board-viewport { grid-area: stage; align-self: stretch; min-height: 0; padding: 8px 0; }
  .readout-card { align-self: start; padding: 14px 16px 12px; border: 1px solid var(--line-soft); border-radius: 16px; background: var(--panel); margin-top: 4px; min-height: 96px; }
  .readout { font-size: 32px; }
  .actions { padding-top: 12px; }
  /* The side row is bounded and scrolls: the board chips while playing, the meanings once finished. */
  .chips { grid-area: side; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding-top: 14px; align-content: start; min-height: 0; overflow-y: auto; scrollbar-width: thin; }
  .app.finished .chips { display: none; }
  .chips::before { content: "Boards"; grid-column: 1 / -1; font-size: 13px; color: var(--muted); margin-bottom: -2px; }
  .chips .board-chip { min-height: 48px; font-size: 14px; }
  .meanings { grid-area: side; min-height: 0; overflow-y: auto; padding: 14px 2px 0 0; scrollbar-width: thin; }
  #meaning-list { grid-template-columns: 1fr; }
  .toast { bottom: 40px; }
  dialog.sheet { inset: 0; margin: auto; width: min(520px, calc(100% - 32px)); max-height: 84dvh; border-bottom: 1px solid var(--line-soft); border-radius: 22px; padding-bottom: 18px; }
}
@media (min-width: 900px) and (max-width: 1099px) {
  .app { grid-template-columns: minmax(0, 1fr) 264px; column-gap: 20px; }
  /* The narrow panel: let the idle hint wrap instead of truncating. */
  .readout.idle { white-space: normal; font-size: 20px; line-height: 1.15; }
  .chips .board-chip { min-height: 44px; font-size: 13px; padding: 4px 2px; }
  .chips .board-chip small { font-size: 10px; }
}
@media (min-width: 900px) and (max-height: 640px) {
  .readout-card { min-height: 80px; padding: 10px 14px 8px; }
  .readout { font-size: 26px; }
  .chips { padding-top: 8px; gap: 6px; }
  .chips .board-chip { min-height: 44px; }
}
@media (max-width: 380px) {
  .readout { font-size: 26px; }
  .readout.idle { font-size: 19px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
  .tile.selected, .tile:active:not(:disabled) { transform: translate(-50%, -50%); }
}
