:root {
  --bg: #121417;
  --panel: #1b1f24;
  --panel-2: #232932;
  --accent: #e69200;
  --accent-dim: #8a5800;
  --text: #e6e8ec;
  --text-dim: #98a0ac;
  --ok: #3ec27a;
  --bad: #e14b4b;
  --warn: #f0b429;
  --border: #2a3039;
  --mono: 'JetBrains Mono', Consolas, 'Courier New', monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  height: 100%;
}

.hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.hud-left, .hud-right { display: flex; gap: 10px; align-items: center; }

.brand { font-size: 15px; font-weight: 600; letter-spacing: .3px; }

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border);
  user-select: none;
}
.badge-dim { color: var(--text-dim); }
.badge-link { text-decoration: none; cursor: pointer; }
.badge-link:hover { background: var(--accent-dim); color: #fff; }
/* Wallet badge — a little warmer than the neutrals so the coin count reads
   as "currency" without shouting. */
.badge-coin {
  background: linear-gradient(180deg, #3a2f18 0%, #2a2215 100%);
  color: #f5c65b;
  border-color: #5a4418;
  font-variant-numeric: tabular-nums;
}
.badge-coin.flash { animation: coin-flash 500ms ease-out; }
@keyframes coin-flash {
  0%   { background: #e69200; color: #1a1203; transform: scale(1.08); }
  100% { background: linear-gradient(180deg, #3a2f18 0%, #2a2215 100%); color: #f5c65b; transform: scale(1); }
}
button.badge { font: inherit; cursor: pointer; }
.badge-select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-dim) 50%),
                    linear-gradient(-45deg, transparent 50%, var(--text-dim) 50%);
  background-position: calc(100% - 12px) 50%, calc(100% - 7px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 22px;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}
.badge-select:hover { border-color: var(--accent); }
.badge-select:focus { outline: none; border-color: var(--accent); }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
}
.btn-ghost:hover { background: var(--panel-2); }

.btn-primary {
  background: var(--accent);
  color: #0a0a0a;
  border: none;
  padding: 10px 18px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  font-size: 14px;
}
.btn-primary:hover { background: #ffa60b; }
.btn-primary:disabled { background: #555; color: #999; cursor: not-allowed; }

.btn-secondary {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 6px;
  font-weight: 500;
  cursor: pointer;
  font-size: 14px;
}
.btn-secondary:hover { background: #2d333d; border-color: var(--accent-dim); }

.result-actions { display: flex; gap: 10px; align-items: center; margin-top: 12px; }
.result-solution-wrap { margin-top: 10px; }
.result-solution {
  margin: 8px 0 0 0;
  padding: 10px 12px;
  background: var(--panel-2);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text);
  white-space: pre-wrap;
}
.hidden { display: none !important; }

/* Calculation tree input */
.tree-input {
  display: block;
  padding: 14px;
  background: #161a1f;
  border: 1px solid var(--border);
  border-radius: 6px;
  max-height: 420px;
  overflow: auto;
}

/* Tree toolbar — visible on every viewport. Desktop users get the same buttons
   as mobile (Branch / + / # / ⌫) in addition to the keyboard shortcuts
   (Tab / type +/# / Backspace). The mobile media query below bumps the
   button sizing + makes the bar sticky while the tree scrolls horizontally. */
.tree-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.tt-btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  font-family: var(--mono);
  cursor: pointer;
  /* Desktop: compact so the bar doesn't dominate; mobile overrides to 44/40 below. */
  min-height: 30px;
  transition: border-color 80ms, background 80ms;
}
.tt-btn:hover { border-color: var(--accent-dim); background: #2a2f38; }
.tt-btn:active { background: var(--accent-dim); }
.tt-sym { font-weight: 700; font-size: 15px; color: var(--accent); }
.tt-del { color: var(--bad); }
.tree-canvas {
  position: relative;
  min-width: 72px;
  min-height: 30px;
}
.tree-connectors {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: visible;
}
.tree-connectors .conn {
  stroke: #4a5360;
  fill: #4a5360;
}
.tree-connectors .conn.path {
  stroke: var(--accent);
  fill: var(--accent);
}
.tree-grid {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
}
.tree-cell {
  position: absolute;
  box-sizing: border-box;
}
.tree-cell .ply {
  display: block;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 8px;
  font-family: var(--mono);
  font-size: 14px;
  outline: none;
  text-align: center;
  transition: border-color 80ms, background 80ms;
}
.tree-cell .ply:hover { border-color: var(--accent-dim); }
.tree-cell .ply:focus,
.tree-cell .ply.focused {
  border-color: var(--accent);
  background: #2a2f38;
  box-shadow: 0 0 0 2px rgba(230, 146, 0, 0.15);
}
.tree-cell .ply.on-path {
  border-color: var(--accent-dim);
  background: #2a2620;
}
.tree-cell .ply.on-path.focused {
  background: #3a301c;
  border-color: var(--accent);
}
.tree-cell .ply::placeholder { color: #6a7280; }

.path-preview {
  flex: 1;
  color: var(--text-dim);
  font-size: 12px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  padding: 0 12px;
}
.path-preview.mono { font-family: var(--mono); }

kbd {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text);
}

.layout {
  display: grid;
  grid-template-columns: minmax(360px, 560px) 1fr;
  gap: 18px;
  padding: 18px;
  max-width: 1300px;
  margin: 0 auto;
}

.board-wrap { display: flex; flex-direction: column; gap: 10px; position: relative; }
.cg-wrap {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--panel);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  /* Container query context so coord font-size can scale with the board width
     instead of the viewport — fixes tiny/misaligned labels on small phones and
     when the board is resized mid-session. */
  container-type: inline-size;
}

/* Board coordinate labels (ranks 1-8, files a-h). Chessground's base CSS hard-
   codes 9px font and positions them OUTSIDE the board — which gets clipped by
   our overflow:hidden (needed for the rounded corners). Push them inside the
   board edges; keep them light & transparent the way lichess/chess.com render
   them (no heavy shadow, no bold). */
.cg-wrap coords {
  font-size: clamp(10px, 2.4cqw, 14px) !important;
  font-weight: 400;
  opacity: 0.55;
  color: #e6e8ec;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
}
/* Ranks 1-8: stick to LEFT edge, inside the board. Override the default
   left:-15px / top:-20px which sits outside. */
.cg-wrap coords.ranks,
.cg-wrap coords.ranks.left {
  left: 2px !important;
  top: 0 !important;
  width: auto !important;
  align-items: flex-start !important;
  padding: 1px 0;
}
/* Files a-h: stick to BOTTOM edge, inside the board. */
.cg-wrap coords.files {
  bottom: 0 !important;
  left: 0 !important;
  height: auto !important;
  padding: 1px 0;
}
.cg-wrap coords.squares coord {
  padding: 2% 3%;
}

/* Thin toolbar row that sits ABOVE the board (outside the cg-wrap) and holds
   the "label all 64 squares" toggle. Kept visually light so it doesn't compete
   with the board. */
.board-tools {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
  min-height: 22px;
}
.coord-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.3px;
  cursor: pointer;
  opacity: 0.75;
  transition: opacity 120ms, color 120ms, border-color 120ms;
}
.coord-toggle:hover { opacity: 1; color: var(--text); }
.coord-toggle.active {
  color: var(--accent);
  border-color: var(--accent-dim);
  opacity: 1;
}

/* Blindfold mode: opaque overlay covering the whole board. The old
   approach (toggle a class that tried to hide cg-board via visibility:hidden
   + an ::after caption) didn't actually blacken the board in every theme.
   A real overlay div is foolproof — no matter how chessground paints the
   squares + pieces underneath, the user sees a solid panel until they peek. */
.blind-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  background: #0a0a0c;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  transition: background 160ms;
}
.blind-overlay.revealed {
  /* Go transparent so the board shows through, but keep the button clickable
     to flip back. pointer-events:none on the overlay would block the button
     itself, so we only disable pointer events outside the button. */
  background: transparent;
}
.blind-overlay.revealed .blind-caption { visibility: hidden; }
.blind-caption {
  color: var(--text-dim);
  letter-spacing: 3px;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  line-height: 1.6;
  user-select: none;
}
.blind-flip-btn {
  padding: 10px 20px;
  background: rgba(35, 41, 50, 0.95);
  color: var(--text);
  border: 1px solid var(--accent-dim);
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 140ms, border-color 140ms, color 140ms;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
}
.blind-flip-btn:hover {
  background: var(--accent-dim);
  color: #fff;
  border-color: var(--accent);
}
/* When the board is peeked, keep the flip button visible + compact over it. */
.blind-overlay.revealed .blind-flip-btn {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 12px;
  font-size: 12px;
  background: rgba(10, 10, 12, 0.75);
}

.position-info {
  display: flex; gap: 10px; align-items: center;
  font-size: 13px; color: var(--text-dim);
  padding: 6px 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  flex-wrap: wrap;
}
.themes { font-family: var(--mono); font-size: 11px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 480px;
}

.mode-title { font-size: 14px; font-weight: 600; color: var(--accent); margin: 0 0 6px 0; }
.mode-subtitle { font-size: 12px; color: var(--text-dim); margin-bottom: 10px; }

textarea.san-input {
  width: 100%;
  min-height: 100px;
  font-family: var(--mono);
  font-size: 14px;
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  resize: vertical;
  line-height: 1.5;
}
textarea.san-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(230, 146, 0, 0.15);
}

input.text-input, select.text-input {
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  width: 100%;
}

.form-row { display: flex; flex-direction: column; gap: 6px; }
.form-row label { font-size: 12px; color: var(--text-dim); }

.hint-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.hint-chip {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 2px 8px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 11px;
  cursor: pointer;
}
.hint-chip:hover { color: var(--accent); border-color: var(--accent); }

.submit-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.submit-row .timer { font-family: var(--mono); color: var(--text-dim); font-size: 12px; }

.result { padding: 12px; border-radius: 6px; border: 1px solid var(--border); background: var(--panel-2); }
.result.hidden { display: none; }
.result-status { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.result-status.ok { color: var(--ok); }
.result-status.bad { color: var(--bad); }
.result-status.warn { color: var(--warn); }
.result-detail { font-size: 13px; color: var(--text); margin-bottom: 10px; }
.result-divergence {
  font-family: var(--mono); font-size: 12px;
  background: var(--bg); padding: 10px; border-radius: 4px;
  max-height: 220px; overflow: auto; white-space: pre-wrap;
}
.result-continuation { font-family: var(--mono); font-size: 12px; color: var(--text-dim); margin-top: 8px; }

.voice-widget {
  display: flex; gap: 10px; align-items: center;
  padding: 8px 10px;
  border: 1px dashed var(--border);
  border-radius: 6px;
}
.voice-widget.recording { border-color: var(--bad); background: rgba(225, 75, 75, 0.08); }
.voice-transcript { font-size: 12px; color: var(--text-dim); font-style: italic; }

/* Candidate Tournament */
.candidate-list { display: flex; flex-direction: column; gap: 8px; }
.candidate-row {
  display: grid; grid-template-columns: 40px 1fr 1fr; gap: 8px; align-items: center;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--panel-2);
}
.candidate-rank {
  font-family: var(--mono); font-weight: 700; color: var(--accent);
  text-align: center;
}
.candidate-move { font-family: var(--mono); font-size: 15px; }
.candidate-just { font-size: 12px; }
.candidate-row input { width: 100%; }
.candidate-row select { width: 60px; }

/* Dojo quiz */
.dojo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dojo-grid textarea { min-height: 60px; }

@keyframes flash {
  0% { opacity: 1; }
  100% { opacity: 1; }
}

/* ─────────────────────────────────────────────────────────────
   Preview / Attempt gate (monetization)
   Shown in the mode-area when the user hasn't yet unlocked the puzzle.
   Blocks typing/branching/submitting until they spend 1 coin.
   ───────────────────────────────────────────────────────────── */
.preview-pane {
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: flex-start;
  padding: 18px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(230,146,0,0.04) 0%, transparent 100%);
}
.preview-pane h3 {
  margin: 0;
  font-size: 15px;
  color: var(--accent);
}
.preview-pane p {
  margin: 0;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.55;
}
.preview-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  width: 100%;
}
.btn-attempt {
  background: var(--accent);
  color: #0a0a0a;
  border: none;
  padding: 10px 18px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.btn-attempt:hover { filter: brightness(1.05); }
.btn-attempt:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  filter: grayscale(0.4);
}
.btn-attempt .coin { font-size: 15px; }
.preview-insufficient {
  color: var(--bad);
  font-size: 12px;
  margin-top: 6px;
}

/* ─────────────────────────────────────────────────────────────
   Saved-puzzles drawer
   Overlay panel listing every puzzle the user has paid to unlock.
   Persisted client-side in localStorage for now.
   ───────────────────────────────────────────────────────────── */
.drawer { position: fixed; inset: 0; z-index: 40; }
.drawer.hidden { display: none; }
.drawer-backdrop {
  position: absolute; inset: 0;
  background: rgba(8, 10, 12, 0.6);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.drawer-panel {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: min(420px, 100%);
  background: var(--panel);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 20px rgba(0,0,0,0.4);
  display: flex;
  flex-direction: column;
  padding: 16px 18px;
  gap: 12px;
}
.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.drawer-head h3 {
  margin: 0;
  font-size: 15px;
}
.drawer-list {
  flex: 1 1 auto;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.drawer-hint {
  font-size: 11px;
  color: var(--text-dim);
  margin: 0;
  line-height: 1.5;
}
.saved-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}
.saved-section-head {
  margin: 4px 0 2px 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}
.saved-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color 120ms, background 120ms;
}
.saved-item:hover { border-color: var(--accent-dim); background: #252a33; }
.saved-item-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.saved-item-rating { font-weight: 600; font-size: 13px; }
.saved-item-themes {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 250px;
}
.saved-item-date { font-size: 10px; color: var(--text-dim); }
.saved-empty { color: var(--text-dim); font-size: 13px; padding: 20px 6px; text-align: center; }

/* ─────────────────────────────────────────────────────────────
   Mobile: stack board on top, answer panel below (chess.com style).
   Triggers below 800px wide so landscape phones + portrait tablets get
   the stacked layout. HUD chips wrap onto multiple rows.
   ───────────────────────────────────────────────────────────── */
@media (max-width: 800px) {
  .layout {
    grid-template-columns: 1fr;
    padding: 10px;
    gap: 12px;
    max-width: 100%;
  }

  .hud {
    padding: 8px 10px;
    flex-wrap: wrap;
    row-gap: 6px;
  }
  .hud-left, .hud-right {
    flex-wrap: wrap;
    gap: 6px;
  }
  .brand { font-size: 14px; }
  .badge { font-size: 11px; padding: 3px 8px; }

  .board-wrap {
    /* Cap board at a sensible phone size so 3" devices get a full board
       and tablets don't get a ridiculous 800×800 board. */
    max-width: min(100%, 520px);
    margin: 0 auto;
    width: 100%;
  }

  .panel {
    min-height: auto;
    padding: 12px;
  }

  /* Keep the SAN / calc-tree cells tappable; iOS Safari auto-zooms any
     focused input with font-size < 16px, so bump all text inputs. */
  textarea.san-input,
  input.text-input,
  select.text-input,
  .tree-cell .ply {
    font-size: 16px;
  }

  .btn-primary,
  .btn-secondary {
    padding: 12px 18px;
    font-size: 15px;
  }

  /* Calculation tree on mobile.
     Critical structural change vs desktop: the X-scroll for wide branch trees
     lives on `.tree-canvas`, NOT on `.tree-input`. Reason: setting `overflow-x:
     auto` on .tree-input (with overflow-y:visible) triggers the CSS spec
     coercion to `overflow: auto auto`, which makes .tree-input a vertical
     scroll *context*. That breaks two things at once:
       (a) `position: sticky` on .tree-toolbar then sticks against .tree-input's
           local viewport (which never scrolls vertically), not the page — so
           the toolbar scrolls offscreen with the page when the user dismisses
           the keyboard.
       (b) `scrollIntoView()` on a cell only walks .tree-input (whose Y scroll
           is at 0) and stops, never reaching the body to bring the cell back
           into the visual viewport above/below the keyboard.
     Putting overflow:visible here keeps .tree-input as a normal block and lets
     body be the page scroll context, fixing both. */
  .tree-input {
    max-height: none;
    padding: 10px;
    overflow: visible;
  }
  .tree-canvas {
    /* The wide-branch horizontal scroll lives here now. .tree-canvas has an
       inline `width: ${px}` set in JS to fit content; max-width:100% clamps
       the visible box to the parent so absolute-positioned cells beyond the
       parent's width spill into scrollable overflow. Y stays visible so it
       doesn't fight body scroll. */
    overflow-x: auto;
    overflow-y: visible;
    max-width: 100%;
  }
  .tree-toolbar {
    /* Sticks to top of the page viewport — body is now the scroll context
       (see .tree-input above) so the toolbar actually trails the page scroll
       instead of being pinned to a non-scrolling local viewport. */
    gap: 8px;
    margin-bottom: 12px;
    position: sticky;
    top: 0;
    background: #161a1f;
    z-index: 2;
    padding: 4px 0;
  }
  /* Restore the finger-friendly 44/40 sizing on mobile that desktop compacted. */
  .tt-btn {
    padding: 8px 12px;
    font-size: 15px;
    min-width: 44px;
    min-height: 40px;
  }
  .tt-sym { font-size: 18px; }

  .position-info {
    font-size: 12px;
    padding: 6px 8px;
  }

  .dojo-grid {
    grid-template-columns: 1fr;
  }

  .candidate-row {
    grid-template-columns: 32px 1fr 1fr;
    gap: 6px;
    padding: 6px 8px;
  }
}

/* Very narrow phones (≤380px): further trim HUD so all chips still fit. */
@media (max-width: 380px) {
  .brand { font-size: 13px; }
  .badge { font-size: 10px; padding: 2px 6px; }
  .btn-ghost { padding: 3px 6px; font-size: 11px; }
}

/* -----------------------------------------------------------------------
   Auth slot (Google Sign-In button / signed-in user chip)
   The GIS iframe sets its own internal sizing; we just give it a home.
   ----------------------------------------------------------------------- */
.auth-slot {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
}
.auth-loading, .auth-error {
  font-size: 11px;
  color: var(--text-dim);
  padding: 4px 8px;
  border: 1px dashed var(--border);
  border-radius: 999px;
}
.auth-error { color: var(--bad); border-color: rgba(225,75,75,0.35); }

.auth-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 3px 4px 3px 3px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--text);
}
.auth-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--panel);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.auth-avatar-fallback { font-size: 13px; color: var(--text-dim); }
.auth-name {
  max-width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.auth-signout {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0 6px 0 2px;
  font-size: 14px;
  line-height: 1;
}
.auth-signout:hover { color: var(--accent); }

@media (max-width: 800px) {
  .auth-name { max-width: 60px; }
}

/* =========================================================================
   Signup / Welcome pages — full-viewport centered hero + card
   ========================================================================= */
.signup-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at top, rgba(230, 146, 0, 0.12) 0%, transparent 55%),
    var(--bg);
}
.signup-hero {
  width: 100%;
  max-width: 520px;
  padding: 24px 18px;
}
.signup-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px 28px;
  box-shadow: 0 30px 80px -30px rgba(0, 0, 0, 0.65);
  text-align: center;
}
.signup-brand {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.4px;
  color: var(--text-dim);
  margin-bottom: 8px;
}
.signup-title {
  font-size: 26px;
  font-weight: 700;
  margin: 0 0 12px 0;
  color: var(--text);
  letter-spacing: -0.2px;
}
.signup-sub {
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.55;
  margin: 0 0 22px 0;
}
.signup-auth-slot {
  display: inline-flex;
  justify-content: center;
  margin: 0 auto;
  min-height: 44px;
}
.signup-error {
  margin-top: 14px;
  font-size: 12px;
  color: var(--bad);
  line-height: 1.4;
}

/* --- Welcome form --- */
.welcome-form {
  text-align: left;
}
.welcome-form .signup-title {
  text-align: center;
}
.welcome-form .signup-sub {
  text-align: center;
}
.profile-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 6px;
}
.form-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.form-field > span {
  font-size: 12px;
  color: var(--text-dim);
  letter-spacing: 0.2px;
}
.text-input {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 80ms;
}
.text-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(230, 146, 0, 0.15);
}
select.text-input {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-dim) 50%),
                    linear-gradient(-45deg, transparent 50%, var(--text-dim) 50%);
  background-position: calc(100% - 14px) 50%, calc(100% - 9px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 28px;
}
.profile-form .btn-primary {
  margin-top: 8px;
  padding: 12px 18px;
  font-size: 15px;
}

/* --- Claim modal (same card, celebratory coat of paint) --- */
.claim-card {
  position: relative;
  overflow: hidden;
  text-align: center;
}
.claim-confetti {
  font-size: 48px;
  line-height: 1;
  margin-bottom: 8px;
  animation: claim-pop 600ms ease-out;
}
@keyframes claim-pop {
  0%   { transform: scale(0.4) rotate(-12deg); opacity: 0; }
  60%  { transform: scale(1.2) rotate(6deg);  opacity: 1; }
  100% { transform: scale(1)   rotate(0);     opacity: 1; }
}
.btn-claim {
  margin-top: 14px;
  padding: 14px 26px;
  font-size: 16px;
  background: linear-gradient(180deg, #f5c65b 0%, #e69200 100%);
  color: #1a1203;
  border: none;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 20px -6px rgba(230, 146, 0, 0.6);
}
.btn-claim:hover { filter: brightness(1.05); }
.btn-claim:disabled { filter: grayscale(0.5); cursor: progress; }

/* =========================================================================
   Dashboard — mode grid + saved problems
   ========================================================================= */
.brand-link {
  color: inherit;
  text-decoration: none;
}
.brand-link:hover { color: var(--accent); }

.dashboard-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 60px;
  display: flex;
  flex-direction: column;
  gap: 36px;
}
.dashboard-section-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.dashboard-heading {
  margin: 0 0 12px 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.1px;
  color: var(--text);
}
.dashboard-count {
  font-size: 12px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.dashboard-sub {
  color: var(--text-dim);
  font-size: 13px;
  margin: -4px 0 14px 0;
  line-height: 1.5;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
}
.mode-tile {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 20px 18px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
  transition: border-color 120ms, transform 120ms, background 120ms;
  min-height: 140px;
}
.mode-tile:hover {
  border-color: var(--accent);
  background: var(--panel-2);
  transform: translateY(-2px);
}
.mode-tile-icon { font-size: 28px; line-height: 1; }
.mode-tile-label { font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.mode-tile-blurb { font-size: 12px; color: var(--text-dim); line-height: 1.45; }

/* Locked tile: greyed out, no hover lift, no link underline. The :hover rule
   above is scoped to .mode-tile (not .mode-tile-locked), so we override here
   to neutralize. */
.mode-tile-locked {
  opacity: 0.55;
  cursor: not-allowed;
  filter: grayscale(0.6);
}
.mode-tile-locked:hover {
  border-color: var(--border);
  background: var(--panel);
  transform: none;
}
.mode-tile-badge {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-dim);
  border: 1px solid var(--border);
}

/* Disabled <option> in the mode-picker dropdown — Chrome/Safari already grey
   them, but make it explicit + dim the text a little more for legibility. */
.badge-select option:disabled { color: #666; }

.saved-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}
.saved-empty-inline {
  color: var(--text-dim);
  font-size: 13px;
  padding: 16px;
  background: var(--panel);
  border: 1px dashed var(--border);
  border-radius: 8px;
  text-align: center;
  grid-column: 1 / -1;
}
.saved-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  transition: border-color 120ms, background 120ms;
}
.saved-card:hover { border-color: var(--accent); background: var(--panel-2); }
.saved-card-row1 {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.saved-card-rating {
  font-weight: 700;
  font-size: 15px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.saved-card-mode {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.saved-card-themes {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.35;
}
.saved-card-foot {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--mono);
  margin-top: 4px;
}

@media (max-width: 600px) {
  .signup-card { padding: 24px 20px; }
  .signup-title { font-size: 22px; }
  .dashboard-main { padding: 18px 14px 50px; gap: 28px; }
  .mode-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .mode-tile { padding: 14px 12px; min-height: 120px; }
  .mode-tile-blurb { display: none; }   /* keep phones dense — label + icon only */
}
@media (max-width: 380px) {
  .mode-grid { grid-template-columns: 1fr; }
}

/* ---------------------------------------------------------------------------
   Shop modal — three-column pricing layout (Phase 5)
   --------------------------------------------------------------------------- */

/* Wallet badge becomes interactive: cursor + hover to advertise the click. */
.badge-coin {
  cursor: pointer;
  transition: filter 120ms, transform 120ms;
}
.badge-coin:hover { filter: brightness(1.15); transform: translateY(-1px); }
/* When subscription is active we render "🪙 ∞" — the same badge, just with
   a slight golden outline so the user notices the unlimited state. */
.badge-coin.badge-coin-unlimited {
  outline: 1px solid rgba(255, 209, 102, 0.6);
  background: linear-gradient(180deg, rgba(255, 209, 102, 0.10), rgba(255, 209, 102, 0.02));
}

.shop-modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.shop-modal.hidden { display: none; }
.shop-backdrop {
  position: absolute; inset: 0;
  background: rgba(8, 10, 14, 0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.shop-panel {
  position: relative;
  z-index: 1;
  width: min(1000px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px 28px 28px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.shop-close {
  position: absolute;
  top: 14px; right: 14px;
  width: 32px; height: 32px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}
.shop-close:hover { background: var(--panel-2); }

.shop-header { text-align: center; margin-bottom: 22px; }
.shop-title { font-size: 24px; margin: 0 0 6px; }
.shop-sub { color: var(--text-dim); margin: 0; font-size: 13px; }

.shop-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}
.shop-loading {
  grid-column: 1 / -1;
  text-align: center;
  padding: 48px 0;
  color: var(--text-dim);
}

.shop-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 22px 20px 20px;
  background: var(--panel-2, #1a1f25);
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: border-color 150ms, transform 150ms;
}
.shop-card:hover { border-color: var(--accent); transform: translateY(-2px); }

.shop-card-highlight {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 8px 24px rgba(255, 209, 102, 0.10);
}
.shop-card-flag {
  position: absolute;
  top: -10px; left: 16px;
  background: var(--accent);
  color: #1a1410;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  padding: 3px 8px;
  border-radius: 999px;
}

.shop-card-disabled { opacity: 0.55; }
.shop-card-disabled:hover { border-color: var(--border); transform: none; }

.shop-card-title { margin: 0; font-size: 17px; font-weight: 700; }
.shop-card-tagline { margin: 0; color: var(--text-dim); font-size: 12px; line-height: 1.4; min-height: 2.8em; }

.shop-card-price {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin: 6px 0 4px;
}
.shop-card-amount { font-size: 32px; font-weight: 700; letter-spacing: -0.02em; }
.shop-card-period { color: var(--text-dim); font-size: 12px; }

.shop-card-features {
  list-style: none;
  margin: 0; padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text);
}
.shop-card-features li {
  position: relative;
  padding-left: 20px;
  line-height: 1.4;
}
.shop-card-features li::before {
  content: "✓";
  position: absolute;
  left: 0; top: 0;
  color: var(--accent);
  font-weight: 700;
}

.shop-card-note {
  font-size: 11px;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.03);
  border-left: 2px solid var(--accent);
  padding: 6px 10px;
  border-radius: 4px;
  line-height: 1.4;
}

.shop-card-buy {
  margin-top: auto;
  width: 100%;
  padding: 11px 12px;
  font-size: 14px;
  font-weight: 600;
}
.shop-card-buy:disabled { cursor: not-allowed; opacity: 0.6; }

/* "Pay in <other currency>" link below the primary Buy button. Plain-text
   feel so it doesn't compete with the primary CTA, but tappable on mobile. */
.shop-card-toggle {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 6px 4px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 11px;
  text-align: center;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  font-family: inherit;
}
.shop-card-toggle:hover { color: var(--text); }
.shop-card-toggle:focus-visible { outline: 1px solid var(--accent); outline-offset: 2px; }

.shop-card-disabled-note,
.shop-card-error {
  font-size: 11px;
  color: var(--text-dim);
  margin: 4px 0 0;
  line-height: 1.4;
}
.shop-card-error { color: #ff8a8a; }

.shop-note { color: var(--text-dim); font-size: 11px; margin: 16px 0 0; text-align: center; }

/* Lock body scroll while modal is open. */
body.shop-open { overflow: hidden; }

@media (max-width: 760px) {
  .shop-panel { padding: 28px 18px 20px; }
  .shop-grid { grid-template-columns: 1fr; gap: 14px; }
  .shop-card-tagline { min-height: 0; }
  .shop-title { font-size: 20px; }
}
