/* ==========================================================================
   TOPOGRAPH — Broadsheet Studio Design System (Light & Dark Mode)
   Matches Oulipo & Archipelago editorial typography, newsprint surfaces,
   pill controls, and crisp Alpine Summit Green elevation cues.
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --font-display: "Literata", Georgia, serif;
  --font-ui: "Libre Franklin", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-serif: var(--font-display);
  --font-sans: var(--font-ui);
  --font-mono: "JetBrains Mono", "Cascadia Code", "Consolas", monospace;

  --transition-fast: 0.14s cubic-bezier(0.2, 0.8, 0.2, 1);
  --transition-normal: 0.22s ease;

  /* Light Mode (Newsprint Default — matches Oulipo & Archipelago) */
  --bg-deep: #ffffff;
  --bg-surface: #f4f4f1;
  --bg-card: #ffffff;
  --bg-elevated: #eae9e4;
  --border-subtle: #e2e2dd;
  --border-strong: #c8c8c0;
  --text-primary: #121212;
  --text-secondary: #4a4a48;
  --text-muted: #5c5c58;

  /* Topograph Signature Brand: Alpine Summit Green */
  --brand-primary: #059669;
  --brand-glow: #059669;
  --brand-btn-bg: #047857;
  --brand-btn-border: #065f46;
  --brand-btn-text: #ffffff;
  --brand-soft: rgba(5, 150, 105, 0.13);
  --brand-border: rgba(5, 150, 105, 0.42);

  --accent-mist: #0284c7;
  --accent-mist-soft: rgba(2, 132, 199, 0.12);
  --accent-slope: #047857;
  --accent-cliff: #b91c1c;
  --accent-danger: #dc2626;

  /* Board Cell Tokens (Light) */
  --cell-bg: #ffffff;
  --cell-hover: #f7f7f4;
  --cell-border: #d4d4cc;
  --cell-bevel: rgba(0, 0, 0, 0.1);
  --cell-fixed-bg: #e8f1ec;
  --cell-fixed-border: #9ecbb4;
  --cell-fixed-text: #065f46;

  --cell-same-bg: #e0f2fe;
  --cell-same-border: #0284c7;
  --cell-same-text: #0369a1;

  --vp-bg: #ffffff;
  --vp-border: #cfcfc7;
  --vp-text: #121212;
  --vp-satisfied-bg: #ecfdf5;
  --vp-satisfied-border: #10b981;
  --vp-satisfied-text: #047857;
  --vp-violated-bg: #fef2f2;
  --vp-violated-border: #ef4444;
  --vp-violated-text: #b91c1c;

  --slope-bg: #ecfdf5;
  --slope-border: #10b981;
  --cliff-bg: #fef2f2;
  --cliff-border: #ef4444;

  --shadow-elevation: 0 2px 12px rgba(0, 0, 0, 0.06);
}

html {
  background-color: var(--bg-deep);
  color-scheme: light;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg-deep: #121213;
  --bg-surface: #1d1d20;
  --bg-card: #26262a;
  --bg-elevated: #313137;
  --border-subtle: #35353c;
  --border-strong: #50505a;
  --text-primary: #f5f5f2;
  --text-secondary: #c2c2bc;
  --text-muted: #989892;

  --brand-primary: #10b981;
  --brand-glow: #34d399;
  --brand-btn-bg: #34d399;
  --brand-btn-border: #10b981;
  --brand-btn-text: #052e16;
  --brand-soft: rgba(52, 211, 153, 0.18);
  --brand-border: rgba(52, 211, 153, 0.48);

  --accent-mist: #38bdf8;
  --accent-mist-soft: rgba(56, 189, 248, 0.16);
  --accent-slope: #34d399;
  --accent-cliff: #f87171;
  --accent-danger: #f87171;

  /* Board Cell Tokens (Dark) */
  --cell-bg: #26262a;
  --cell-hover: #303036;
  --cell-border: #44444e;
  --cell-bevel: rgba(0, 0, 0, 0.36);
  --cell-fixed-bg: #162820;
  --cell-fixed-border: #2a5943;
  --cell-fixed-text: #34d399;

  --cell-same-bg: #172b3a;
  --cell-same-border: #38bdf8;
  --cell-same-text: #7dd3fc;

  --vp-bg: #26262a;
  --vp-border: #44444e;
  --vp-text: #f5f5f2;
  --vp-satisfied-bg: rgba(16, 185, 129, 0.15);
  --vp-satisfied-border: rgba(52, 211, 153, 0.65);
  --vp-satisfied-text: #34d399;
  --vp-violated-bg: rgba(239, 68, 68, 0.16);
  --vp-violated-border: rgba(248, 113, 113, 0.72);
  --vp-violated-text: #fca5a5;

  --slope-bg: #0c261d;
  --slope-border: rgba(52, 211, 153, 0.6);
  --cliff-bg: #2b1316;
  --cliff-border: rgba(248, 113, 113, 0.68);

  --shadow-elevation: 0 4px 16px rgba(0, 0, 0, 0.35);
}

/* ==========================================================================
   BASE & CHROME
   ========================================================================== */
::selection {
  background: rgba(5, 150, 105, 0.25);
  color: var(--text-primary);
}

:focus-visible {
  outline: 2px solid var(--brand-glow);
  outline-offset: 2px;
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-deep);
}

::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

body {
  background-color: var(--bg-deep);
  color: var(--text-primary);
  font-family: var(--font-ui);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
}

html.theme-transitions body {
  transition: background-color 0.22s ease, color 0.22s ease;
}

.ui-svg {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
}

#theme-btn .icon-theme-light {
  display: none;
}

html[data-theme="dark"] #theme-btn .icon-theme-dark {
  display: none;
}

html[data-theme="dark"] #theme-btn .icon-theme-light {
  display: block;
}

#mute-btn .icon-sound-off {
  display: none;
}

#mute-btn.is-muted .icon-sound-on {
  display: none;
}

#mute-btn.is-muted .icon-sound-off {
  display: block;
}

/* ==========================================================================
   HEADER BAR (Matches Oulipo & Archipelago)
   ========================================================================== */
.header-bar {
  width: 100%;
  max-width: 900px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
}

.hub-link {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  color: var(--text-primary);
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 0.42rem 0.85rem;
  border-radius: 9999px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-card);
  transition: all var(--transition-fast);
}

.hub-link:hover {
  background: var(--bg-surface);
  border-color: var(--border-strong);
}

.title-group {
  text-align: center;
}

.game-title {
  font-family: var(--font-display);
  font-size: 1.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--text-primary);
}

.puzzle-subtitle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.15rem;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.diff-badge {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0.12rem 0.5rem;
  border-radius: 4px;
  background: var(--brand-btn-bg);
  color: var(--brand-btn-text);
}

.diff-badge.daily-badge {
  background: var(--accent-mist-soft);
  color: var(--accent-mist);
  border: 1px solid rgba(2, 132, 199, 0.35);
}

html[data-theme="dark"] .diff-badge.daily-badge {
  border-color: rgba(56, 189, 248, 0.45);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.38rem;
}

.icon-btn {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 9999px;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.icon-btn:hover {
  background: var(--bg-surface);
  border-color: var(--border-strong);
}

.icon-btn:active {
  transform: translateY(1px);
}

.icon-btn.active-mode {
  background: var(--accent-mist-soft);
  border-color: var(--accent-mist);
  color: var(--accent-mist);
}

/* ==========================================================================
   MAIN STAGE & STATUS PILL
   ========================================================================== */
.main-stage {
  width: 100%;
  max-width: 720px;
  padding: 0.85rem 1rem 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.8rem;
}

.status-bar {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.65rem;
  padding: 0.36rem 0.42rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 9999px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.status-seg {
  display: inline-flex;
  align-items: center;
  gap: 0.42rem;
  padding: 0.28rem 0.82rem;
  border-radius: 9999px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
}

.status-stat strong {
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.scorecard-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--brand-btn-bg);
  color: var(--brand-btn-text);
  border: 1px solid var(--brand-btn-border);
  padding: 0.45rem 1.1rem;
  border-radius: 9999px;
  font-family: var(--font-ui);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.scorecard-pill-btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.03);
}

/* ==========================================================================
   TOPOGRAPH BOARD VIEWPORT & GRID CELLS
   ========================================================================== */
.topograph-viewport {
  background: var(--bg-surface);
  border: 1.5px solid var(--border-strong);
  border-radius: 14px;
  padding: 12px;
  width: fit-content;
  margin: 0 auto;
  box-shadow: var(--shadow-elevation);
  touch-action: manipulation;
}

.survey-board {
  display: grid;
  gap: 6px;
  align-items: center;
  justify-items: center;
  position: relative;
  touch-action: manipulation;
}

.board-corner {
  width: var(--vp-size, 40px);
  height: var(--vp-size, 40px);
  visibility: hidden;
  pointer-events: none;
}

/* Perimeter Skyline Viewpoint Badges */
.vp-cell {
  width: var(--vp-size, 40px);
  height: var(--vp-size, 40px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-ui);
  font-size: 1.03rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums lining-nums;
  font-feature-settings: "tnum" 1, "lnum" 1;
  border-radius: 8px;
  transition: all var(--transition-fast);
  color: var(--text-muted);
  user-select: none;
}

.vp-cell.has-clue {
  background: var(--vp-bg);
  border: 1.5px solid var(--vp-border);
  color: var(--vp-text);
  box-shadow: 0 1px 0 var(--cell-bevel);
  cursor: pointer;
}

.vp-cell.has-clue:hover,
.vp-cell.vp-active-ray {
  border-color: var(--brand-primary) !important;
  color: var(--brand-glow) !important;
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(5, 150, 105, 0.2) !important;
}

.vp-cell.satisfied {
  border-color: var(--vp-satisfied-border) !important;
  background: var(--vp-satisfied-bg) !important;
  color: var(--vp-satisfied-text) !important;
}

.vp-cell.violated {
  border-color: var(--vp-violated-border) !important;
  background: var(--vp-violated-bg) !important;
  color: var(--vp-violated-text) !important;
}

.vp-cell.empty {
  visibility: hidden;
  pointer-events: none;
}

.vp-cell.clue-hint-focus {
  border-color: var(--brand-primary) !important;
  background: var(--brand-soft) !important;
  color: var(--brand-glow) !important;
}

/* Interactive Sightline Ray & Occlusion States */
.topo-cell.sightline-path {
  background: var(--accent-mist-soft) !important;
}

.topo-cell.sightline-visible {
  border-color: var(--brand-primary) !important;
  box-shadow: inset 0 0 0 1.5px var(--brand-primary) !important;
  z-index: 5;
}

.sightline-crest-tag {
  position: absolute;
  top: 2px;
  left: 4px;
  font-family: var(--font-ui);
  font-size: 0.62rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums lining-nums;
  color: var(--brand-primary);
  pointer-events: none;
  z-index: 6;
}

.topo-cell.sightline-occluded {
  opacity: 0.42;
  filter: grayscale(0.65);
  box-shadow: none !important;
}

/* Grid Cells */
.topo-cell {
  position: relative;
  width: var(--cell-size, 62px);
  height: var(--cell-size, 62px);
  background: var(--cell-bg);
  border: 1.5px solid var(--cell-border);
  border-radius: 7px;
  box-shadow: 0 1px 0 var(--cell-bevel);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color var(--transition-fast), border-color var(--transition-fast), transform 0.1s ease;
}

.topo-cell:hover:not(.fixed) {
  background: var(--cell-hover);
  border-color: var(--border-strong);
}

.topo-cell.selected {
  outline: 2.5px solid var(--brand-primary);
  outline-offset: 1px;
  z-index: 6;
}

body.pencil-active .topo-cell.selected {
  outline: 2.5px dashed var(--accent-mist) !important;
  outline-offset: 1px;
}

.topo-cell.same-value {
  background: var(--cell-same-bg) !important;
  border-color: var(--cell-same-border) !important;
}

.topo-cell.same-value .cell-value {
  color: var(--cell-same-text) !important;
}

.topo-cell.fixed {
  cursor: default;
  background: var(--cell-fixed-bg);
  border-color: var(--cell-fixed-border);
}

.topo-cell.fixed .cell-value {
  color: var(--cell-fixed-text);
  font-weight: 800;
}

.topo-cell.fixed::after {
  content: "";
  position: absolute;
  bottom: 4px;
  right: 4px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--cell-fixed-text);
  opacity: 0.65;
}

.topo-cell.conflict {
  background: var(--vp-violated-bg) !important;
  border: 2px dashed var(--accent-danger) !important;
  animation: shakeCell 0.3s ease;
}

.topo-cell.conflict::after {
  content: "!";
  position: absolute;
  top: 2px;
  left: 4px;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  font-weight: 800;
  color: var(--accent-danger);
  line-height: 1;
  z-index: 6;
}

.topo-cell.cell-mistake {
  background: var(--vp-violated-bg) !important;
  border-color: var(--accent-danger) !important;
  animation: shakeCell 0.3s ease;
}

.topo-cell.cell-mistake .cell-value {
  color: var(--accent-danger) !important;
  font-weight: 800;
}

.topo-cell.cell-mistake::before {
  content: "✕";
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 0.62rem;
  font-weight: 800;
  color: var(--accent-danger);
  line-height: 1;
  z-index: 6;
}

.topo-cell.cell-hint-focus {
  border-color: var(--brand-primary) !important;
  box-shadow: 0 0 0 2px var(--brand-glow) !important;
  background: var(--brand-soft) !important;
}

.topo-cell.cell-hint-peer {
  border-color: var(--accent-mist) !important;
  background: var(--accent-mist-soft) !important;
}

@keyframes shakeCell {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

.cell-value {
  font-family: var(--font-ui);
  font-size: 1.54rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums lining-nums;
  font-feature-settings: "tnum" 1, "lnum" 1;
  color: var(--text-primary);
  z-index: 2;
  pointer-events: none;
  line-height: 1;
}

/* Pencil Candidate Notes Matrix */
.cell-pencil-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  place-items: center;
  width: 100%;
  height: 100%;
  padding: 3px 4px;
  pointer-events: none;
}

.pencil-note {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-ui);
  font-size: 0.72rem;
  line-height: 1;
  color: var(--text-muted);
  font-weight: 800;
  font-variant-numeric: tabular-nums lining-nums;
  font-feature-settings: "tnum" 1, "lnum" 1;
  visibility: hidden;
  border-radius: 3px;
  transition: color 0.14s ease, background-color 0.14s ease;
}

.pencil-note.active {
  visibility: visible;
  color: var(--text-secondary);
}

.pencil-note.active.same-value-note {
  color: var(--cell-same-text) !important;
  background: var(--cell-same-bg);
}

/* Contour Seam Badges: Slope (~ wave) & Cliff (|| upright) */
.indicator {
  justify-self: center;
  align-self: center;
  width: 18px;
  height: 18px;
  padding: 2px;
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 25;
  pointer-events: none;
  line-height: 1;
  user-select: none;
  box-shadow: 0 0 0 2px var(--bg-surface), 0 1px 3px rgba(0, 0, 0, 0.14);
  transition: border-color 0.18s ease, background-color 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.indicator-slope {
  border-radius: 50%;
  background: var(--slope-bg);
  border: 1.5px solid var(--slope-border);
  color: var(--accent-slope);
}

.indicator-cliff {
  border-radius: 4px;
  background: var(--cliff-bg);
  border: 1.5px solid var(--cliff-border);
  color: var(--accent-cliff);
}

.indicator.satisfied {
  background: var(--vp-satisfied-bg) !important;
  border-color: var(--vp-satisfied-border) !important;
  color: var(--vp-satisfied-text) !important;
}

.indicator.violated {
  background: var(--vp-violated-bg) !important;
  border-color: var(--vp-violated-border) !important;
  color: var(--vp-violated-text) !important;
  animation: alertPulse 0.35s ease;
}

@keyframes alertPulse {
  0%, 100% { transform: scale(1); }
  40% { transform: scale(1.2); }
  75% { transform: scale(0.94); }
}

.ind-svg {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ==========================================================================
   VICTORY COMPLETION REACTION: ELEVATION ASCENT
   ========================================================================== */
.survey-board.solved-landscape .topo-cell {
  cursor: default;
  animation: topoElevationRise 540ms cubic-bezier(0.22, 1, 0.36, 1) var(--stagger-elev, 0ms) both;
}

.survey-board.solved-landscape .vp-cell.has-clue {
  animation: topoBadgeSettle 420ms ease var(--stagger-vp, 0ms) both;
}

@keyframes topoElevationRise {
  0% { transform: translateY(0) scale(1); border-color: var(--cell-border); }
  45% { transform: translateY(-4px) scale(1.03); border-color: var(--brand-primary); box-shadow: 0 4px 10px rgba(5, 150, 105, 0.16); }
  100% { transform: translateY(0) scale(1); border-color: var(--brand-border); }
}

@keyframes topoBadgeSettle {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .survey-board.solved-landscape .topo-cell,
  .survey-board.solved-landscape .vp-cell.has-clue {
    animation: none !important;
  }
}

/* ==========================================================================
   CONTROLS PANEL (Tactile Keypad + Pill Deck + Auto-Prune Switch)
   ========================================================================== */
.controls-panel {
  width: 100%;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.7rem;
}

.keypad-row {
  display: flex;
  justify-content: center;
  gap: 0.45rem;
  width: 100%;
}

.keypad-btn {
  flex: 1;
  max-width: 58px;
  min-width: 44px;
  height: 46px;
  background: var(--cell-bg);
  border: 1.5px solid var(--border-strong);
  border-bottom: 3px solid var(--border-strong);
  border-radius: 10px;
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.keypad-btn:hover {
  background: var(--bg-surface);
  border-color: var(--brand-primary);
  transform: translateY(-1px);
}

.keypad-btn:active {
  transform: translateY(1px);
}

.keypad-btn.completed {
  opacity: 0.42;
  background: var(--vp-satisfied-bg);
  border-color: var(--vp-satisfied-border);
  color: var(--vp-satisfied-text);
}

.keypad-num {
  font-family: var(--font-ui);
  font-size: 1.32rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums lining-nums;
  font-feature-settings: "tnum" 1, "lnum" 1;
  line-height: 1;
  transition: font-size var(--transition-fast), color var(--transition-fast);
}

body.pencil-active .keypad-btn {
  border: 1.5px dashed var(--border-strong);
  background: var(--bg-surface);
}

body.pencil-active .keypad-btn:hover {
  background: var(--bg-elevated);
  border-color: var(--text-secondary);
}

body.pencil-active .keypad-num {
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--text-secondary);
}

body.pencil-active .keypad-btn.completed {
  border-color: var(--vp-satisfied-border);
  background: var(--vp-satisfied-bg);
}

body.pencil-active .keypad-btn.completed .keypad-num {
  color: var(--vp-satisfied-text);
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
}

.tool-choice-btn,
.action-btn {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 9999px;
  padding: 0.55rem 1.05rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  font-family: var(--font-ui);
  font-size: 0.82rem;
  font-weight: 500;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.tool-choice-btn:hover:not(.active-mode),
.action-btn:hover:not(:disabled):not(.active-mode) {
  background: var(--bg-surface);
  border-color: var(--border-strong);
}

.action-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.tool-choice-btn.active-mode,
.tool-choice-btn.active-mode:hover {
  background: var(--accent-mist);
  border-color: var(--accent-mist);
  color: #ffffff;
  font-weight: 700;
}

.tool-choice-btn.active-mode:hover {
  filter: brightness(0.92);
}

html[data-theme="dark"] .tool-choice-btn.active-mode,
html[data-theme="dark"] .tool-choice-btn.active-mode:hover {
  color: #0b1620;
}

html[data-theme="dark"] .tool-choice-btn.active-mode:hover {
  filter: brightness(1.08);
}

.assistance-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
}

.assist-btn {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 9999px;
  padding: 0.65rem 1.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.42rem;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.assist-btn:hover {
  background: var(--bg-surface);
  border-color: var(--border-strong);
}

.assist-btn#check-btn:hover {
  border-color: var(--brand-primary);
  color: var(--brand-glow);
}

.assist-btn#hint-btn {
  background: var(--brand-btn-bg);
  color: var(--brand-btn-text);
  border-color: var(--brand-btn-border);
  font-weight: 700;
}

.assist-btn#hint-btn:hover {
  background: var(--brand-btn-bg);
  border-color: var(--brand-btn-border);
  filter: brightness(1.06);
}

/* Auto-Prune Notes Pill Toggle */
.options-row {
  display: flex;
  justify-content: center;
  width: 100%;
}

.setting-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.36rem 0.85rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 9999px;
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.setting-toggle-btn:hover {
  background: var(--bg-card);
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.setting-toggle-btn .switch-track {
  width: 30px;
  height: 16px;
  background: var(--border-strong);
  border-radius: 9999px;
  position: relative;
  transition: background-color 0.2s ease;
  display: inline-block;
  flex-shrink: 0;
}

.setting-toggle-btn .switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  background: #ffffff;
  border-radius: 50%;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.setting-toggle-btn.active {
  border-color: var(--brand-border);
  background: var(--brand-soft);
  color: var(--text-primary);
}

.setting-toggle-btn.active .switch-track {
  background: var(--brand-primary);
}

.setting-toggle-btn.active .switch-thumb {
  transform: translateX(14px);
}

.setting-toggle-btn.active strong {
  color: var(--brand-glow);
}

/* ==========================================================================
   FEEDBACK BANNER & HINT CARD
   ========================================================================== */
.feedback-banner {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 0.65rem 0.95rem;
  font-size: 0.83rem;
  line-height: 1.45;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  animation: fadeIn 0.2s ease;
}

.feedback-banner.success {
  background: #dcfce7;
  border-color: #86efac;
  color: #166534;
}

.feedback-banner.warning {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #991b1b;
}

.feedback-banner.info {
  border-color: var(--border-strong);
  background: var(--bg-surface);
  color: var(--text-secondary);
}

html[data-theme="dark"] .feedback-banner.success {
  background: rgba(16, 185, 129, 0.14);
  border-color: rgba(16, 185, 129, 0.45);
  color: #4ade80;
}

html[data-theme="dark"] .feedback-banner.warning {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.45);
  color: #fca5a5;
}

.feedback-content {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex: 1;
}

.feedback-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.feedback-action-btn {
  background: var(--accent-danger);
  color: #ffffff;
  border: none;
  border-radius: 9999px;
  padding: 0.28rem 0.7rem;
  font-family: var(--font-ui);
  font-size: 0.73rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: filter var(--transition-fast);
}

.feedback-action-btn:hover {
  filter: brightness(1.08);
}

.feedback-action-btn.secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
}

.feedback-close-btn {
  background: transparent;
  border: none;
  color: inherit;
  opacity: 0.7;
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.1rem 0.25rem;
}

.feedback-close-btn:hover {
  opacity: 1;
}

.hint-card-panel {
  width: 100%;
  background: var(--bg-card);
  border: 1.5px solid var(--brand-primary);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  font-size: 0.84rem;
  line-height: 1.5;
  box-shadow: var(--shadow-elevation);
  animation: fadeIn 0.2s ease;
}

.hint-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.4rem;
}

.hint-card-title-group {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.hint-card-title {
  font-family: var(--font-display);
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--brand-glow);
}

html[data-theme="dark"] .hint-card-title {
  color: var(--brand-glow);
}

.hint-type-badge {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--bg-surface);
  padding: 0.14rem 0.45rem;
  border-radius: 4px;
}

.hint-explanation {
  font-size: 0.83rem;
  line-height: 1.5;
  color: var(--text-secondary);
  margin-bottom: 0.7rem;
}

.hint-card-actions {
  display: flex;
  gap: 0.48rem;
  justify-content: flex-end;
}

.hint-action-btn {
  border-radius: 9999px;
  padding: 0.36rem 0.85rem;
  font-family: var(--font-ui);
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.hint-action-btn.secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
}

.hint-action-btn.secondary:hover {
  background: var(--bg-surface);
}

.hint-action-btn.primary {
  background: var(--brand-btn-bg);
  color: var(--brand-btn-text);
  border: 1px solid var(--brand-btn-border);
}

.hint-action-btn.primary:hover {
  filter: brightness(1.04);
}

.hint-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.15rem;
}

.hint-close-btn:hover {
  color: var(--text-primary);
}

/* ==========================================================================
   LEGEND BAR (Swatches Matching Board Tiles)
   ========================================================================== */
.legend-bar {
  width: 100%;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.75rem 1.15rem;
  padding: 0.8rem 0.5rem 0;
  border-top: 1px solid var(--border-subtle);
  font-size: 0.76rem;
  color: var(--text-muted);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.42rem;
}

.glyph-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  flex-shrink: 0;
  font-weight: 800;
  line-height: 1;
}

.glyph-slope {
  background: var(--slope-bg);
  border: 1.5px solid var(--slope-border);
  border-radius: 50%;
  padding: 3px;
  color: var(--accent-slope);
}

.glyph-cliff {
  background: var(--cliff-bg);
  border: 1.5px solid var(--cliff-border);
  border-radius: 4px;
  padding: 3px;
  color: var(--accent-cliff);
}

.glyph-viewpoint {
  background: var(--vp-bg);
  border: 1.5px solid var(--vp-border);
  color: var(--vp-text);
  font-family: var(--font-ui);
  font-variant-numeric: tabular-nums lining-nums;
  font-feature-settings: "tnum" 1, "lnum" 1;
  font-size: 0.76rem;
}

.glyph-anchor {
  background: var(--cell-fixed-bg);
  border: 1.5px solid var(--cell-fixed-border);
  color: var(--cell-fixed-text);
  font-family: var(--font-ui);
  font-variant-numeric: tabular-nums lining-nums;
  font-feature-settings: "tnum" 1, "lnum" 1;
  font-size: 0.78rem;
}

/* ==========================================================================
   MODALS & ARCHIVE MENU (Matches Oulipo & Archipelago)
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  z-index: 1000;
  animation: fadeIn 0.18s ease;
}

.modal-overlay.open {
  display: flex;
}

.modal-content {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.22);
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.1rem 1.4rem;
  border-bottom: 1px solid var(--border-subtle);
}

.modal-title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--text-primary);
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 9999px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.modal-close:hover {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
}

.modal-body {
  padding: 1.35rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 1.05rem;
}

.modal-helper-copy {
  font-size: 0.84rem;
  line-height: 1.5;
  color: var(--text-secondary);
}

.modal-field-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.45rem;
}

.rule-section {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.rule-section h4 {
  font-family: var(--font-display);
  font-size: 0.96rem;
  color: var(--brand-glow);
}

.rule-section p {
  font-size: 0.84rem;
  line-height: 1.55;
  color: var(--text-secondary);
}

.rule-section code {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  padding: 0.08rem 0.35rem;
  border-radius: 4px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
}

.primary-btn {
  background: var(--brand-btn-bg);
  color: var(--brand-btn-text);
  border: 1px solid var(--brand-btn-border);
  border-radius: 9999px;
  padding: 0.8rem 1.2rem;
  font-family: var(--font-ui);
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: center;
}

.primary-btn:hover {
  filter: brightness(1.04);
  transform: translateY(-1px);
}

/* Segmented Archive Pack Tabs & Pill Puzzle List */
.pack-tabs-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 9999px;
  padding: 4px;
  gap: 4px;
  width: 100%;
}

.pack-tab-btn {
  background: transparent;
  border: none;
  border-radius: 9999px;
  padding: 0.48rem 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.16rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.pack-tab-btn.active {
  background: var(--bg-card);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.pack-tab-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-primary);
}

.pack-tab-meta {
  font-size: 0.68rem;
  color: var(--text-muted);
}

.puzzle-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  max-height: 320px;
  overflow-y: auto;
  padding-right: 0.2rem;
}

.puzzle-card-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 9999px;
  padding: 0.65rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: left;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.puzzle-card-btn:hover {
  background: var(--bg-surface);
  border-color: var(--border-strong);
}

.puzzle-card-btn.active {
  background: var(--brand-soft);
  border-color: var(--brand-primary);
}

.puzzle-card-btn.daily-card-btn {
  grid-column: 1 / -1;
  border-color: rgba(2, 132, 199, 0.35);
  background: var(--accent-mist-soft);
}

.puzzle-card-btn.daily-card-btn:hover {
  border-color: var(--accent-mist);
}

.puzzle-card-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-primary);
  display: block;
}

.puzzle-card-diff {
  font-size: 0.68rem;
  color: var(--text-muted);
}

.puzzle-card-badge {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 0.16rem 0.5rem;
  border-radius: 9999px;
  color: var(--text-muted);
}

.puzzle-card-badge.is-solved {
  background: var(--brand-btn-bg);
  color: var(--brand-btn-text);
}

/* Endless Mode Pill Selector Group */
.pill-selector-group {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  width: 100%;
}

.pill-choice-btn {
  padding: 0.6rem 0.5rem;
  background: var(--bg-surface);
  border: 1.5px solid var(--border-subtle);
  border-radius: 8px;
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: center;
}

.pill-choice-btn:hover {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.pill-choice-btn.active {
  background: var(--brand-soft);
  border-color: var(--brand-primary);
  color: var(--brand-glow);
  font-weight: 700;
}

/* Victory Modal Hero */
.victory-hero {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding-top: 0.2rem;
}

.victory-title {
  font-family: var(--font-display);
  font-size: 1.5rem;
  letter-spacing: 0.04em;
  color: var(--text-primary);
}

.scorecard-box {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 0.95rem 1rem;
  font-family: var(--font-mono);
  font-size: 0.83rem;
  line-height: 1.55;
  color: var(--text-secondary);
  white-space: pre-line;
}

.victory-actions {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.victory-action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

.secondary-action {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
}

.secondary-action:hover {
  background: var(--bg-elevated);
  border-color: var(--text-primary);
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: scale(0.98);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* ==========================================================================
   MOBILE & COMPACT VIEWPORT ADAPTABILITY
   ========================================================================== */
@media (max-width: 540px) {
  .header-bar {
    padding: 0.72rem 0.85rem;
  }
  .game-title {
    font-size: 1.35rem;
  }
  .icon-btn {
    width: 31px;
    height: 31px;
  }
  .main-stage {
    padding: 0.65rem 0.75rem 1.5rem;
    gap: 0.65rem;
  }
  .topograph-viewport {
    padding: 8px;
  }
  .survey-board {
    gap: 4px !important;
  }
  .vp-cell {
    font-size: 0.9rem;
  }
  .cell-value {
    font-size: 1.32rem;
  }
  .indicator {
    width: 15px;
    height: 15px;
    padding: 1.5px;
  }
  .puzzle-list {
    grid-template-columns: 1fr;
  }
  .tool-choice-btn,
  .action-btn {
    padding: 0.45rem 0.8rem;
    font-size: 0.76rem;
  }
  .assist-btn {
    padding: 0.52rem 1.2rem;
    font-size: 0.8rem;
  }
}

@media (max-width: 400px) {
  .topograph-viewport {
    padding: 6px;
  }
  .survey-board {
    gap: 3px !important;
  }
  .cell-value {
    font-size: 1.18rem;
  }
  .indicator {
    width: 14px;
    height: 14px;
  }
}

/* Motion & Vestibular Safety */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
