/* Fair Block Puzzle — dark theme, responsive (REQ-WEB-1/2). */

:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1c232c;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #2f81f7;
  --accent-2: #3fb950;
  --danger: #f05252;
  --board-max: 520px;
  --gap: clamp(6px, 1.6vw, 12px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  /* iOS: 100vh includes browser chrome; svh is the stable viewport (REQ-WEB-3) */
  min-height: 100vh;
  min-height: 100svh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.hidden { display: none !important; }

/* ---------- theme decor layer (REQ-THM-6 / D-TH-3) ----------
 * Fixed, pointer-events:none, low-opacity scatter behind every screen.
 * Screens sit above it (position:relative; z-index:1 below). */
#decor {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}
#decor .decor-item {
  position: absolute;
  display: block;
  line-height: 1;
  transform: translate(-50%, -50%) rotate(var(--rot, 0deg));
  user-select: none;
}
#decor img.decor-item { object-fit: contain; }

.screen {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--gap);
  padding: var(--gap);
  overscroll-behavior: contain; /* no pull-to-refresh inside scrollable screens */
  position: relative;
  z-index: 1; /* above the decor layer */
}

/* keyboard a11y: visible focus ring only for keyboard users */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- menu ---------- */
.menu-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(92vw, 380px);
  background: var(--panel);
  border-radius: 16px;
  padding: clamp(16px, 4vw, 28px);
  text-align: center;
}
.menu-card h1 { font-size: clamp(1.2rem, 5vw, 1.6rem); margin: 0 0 8px; }

/* middle-menu play buttons: vertical column, full width, equal size (REQ-UI-2) */
.menu-play {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}
.menu-play .btn { width: 100%; min-height: 48px; }

.btn {
  appearance: none;
  border: 1px solid #30363d;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  padding: 0.7em 1em;
  border-radius: 10px;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.small { font-size: 0.8rem; padding: 0.4em 0.7em; border-radius: 8px; min-height: 44px; min-width: 44px; }
.btn.icon-btn { font-size: 1rem; line-height: 1; padding: 0.3em 0.5em; }

.note { color: var(--muted); font-size: 0.8rem; margin: 4px 0 0; }

/* ---------- game screen ---------- */
/* center the hud+board+tray group vertically so tall phones have no dead
   bottom third (REQ-WEB-3) */
/* REQ-MOB-1 (T-1305): the game screen NEVER scrolls — overflow:hidden beats
   the generic .screen overflow-y:auto (ID specificity) so no touch position
   inside it (HUD, gaps, tray) can scroll the view. The daily challenge has
   no separate playfield: daily attempts run on this same #screen-game
   (startServerGame -> showScreen('game')), so this covers classic + daily.
   Other screens (Settings) keep their page scroll. */
#screen-game { justify-content: center; overflow: hidden; }

#hud {
  width: min(92vw, var(--board-max));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: 4px 2px;
}
.hud-left, .hud-right { display: flex; align-items: center; gap: 8px; }
.mode-label { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; }
.stat { font-variant-numeric: tabular-nums; font-size: 0.9rem; }
.stat.score { font-size: 1.25rem; font-weight: 700; min-width: 3ch; text-align: right; }
.stat.combo { color: #e3b341; font-weight: 700; }

#board-wrap {
  position: relative;
  /* REQ-MOB-2 (T-1305): flex-fit sizing replaces the fixed
     `calc(100svh - 260px)` reservation that ignored the bottom nav and
     safe-area insets. In the game column the wrap grows into exactly the
     space left between HUD and tray (basis 0 so content never inflates it,
     min-height:0 so it may shrink), and aspect-ratio:1 transfers that
     clamped height to the width; max-height caps the square at the old
     width budget (92vw / --board-max) on tall desktop screens. */
  flex: 1 1 0%;
  min-height: 0;
  max-height: min(92vw, var(--board-max));
  aspect-ratio: 1;
  border-radius: 14px;
  background: radial-gradient(120% 120% at 50% 0%, #1a212b 0%, #10151c 70%);
  box-shadow: 0 14px 34px rgba(1, 4, 9, 0.65), 0 0 0 1px #21262d,
              inset 0 1px 0 rgba(255, 255, 255, 0.04);
}
#board {
  display: block;
  border-radius: 12px;
  touch-action: none; /* we drive dragging ourselves */
}

/* floating +N score popups */
#popups { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.popup {
  position: absolute;
  transform: translate(-50%, -50%);
  font-weight: 800;
  font-size: clamp(1rem, 4vw, 1.4rem);
  color: #fff;
  padding: 2px 10px;
  border-radius: 999px;
  background: rgba(13, 17, 23, 0.55);
  text-shadow: 0 0 8px rgba(63, 185, 80, 0.9), 0 2px 4px rgba(0,0,0,0.6);
  animation: float-up 0.8s ease-out forwards;
}
@keyframes float-up {
  0%   { opacity: 1; translate: 0 0; scale: 0.7; }
  25%  { scale: 1.12; }
  60%  { scale: 1; }
  100% { opacity: 0; translate: 0 -46px; scale: 1; }
}

/* ---------- tray ---------- */
#tray {
  width: min(92vw, var(--board-max));
  min-height: clamp(76px, 16svh, 130px);
  display: flex;
  align-items: center;
  justify-content: space-around;
  gap: var(--gap);
  background: var(--panel);
  border-radius: 14px;
  padding: 8px;
  touch-action: none;
}
.tray-slot {
  flex: 1;
  display: grid;
  place-items: center;
  min-height: 64px;
  padding: 4px;
  cursor: grab;
  touch-action: none;
}
.tray-slot.used { opacity: 0.22; pointer-events: none; cursor: default; }
.tray-slot.dragging { opacity: 0.35; }
.piece-grid { display: grid; gap: 2px; }
.piece-grid .blk {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 22%;
  background: var(--c, #444);
  box-shadow: inset 0 2px 0 rgba(255,255,255,0.18);
}
/* theme glyph / sprite overlay on tray blocks (D-TH-2) */
.piece-grid .blk .blk-glyph {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  line-height: 1;
  pointer-events: none;
  /* contrast halo: tight outline matching the canvas glyph shadow */
  text-shadow: 0 0 1px rgba(0, 0, 0, 0.85), 0 0 3px rgba(0, 0, 0, 0.55);
}
.piece-grid .blk .blk-sprite {
  position: absolute;
  inset: 12%;
  width: 76%;
  height: 76%;
  object-fit: contain;
  pointer-events: none;
}
.piece-grid .empty { width: 100%; aspect-ratio: 1; }

/* ---------- account menu (top-right) ---------- */
.account-wrap { position: fixed; top: 10px; right: 12px; z-index: 45; }
.account-btn {
  background: var(--panel);
  border: 1px solid #30363d;
  color: var(--text);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.9rem;
  cursor: pointer;
}
.account-caret { margin-left: 6px; color: var(--muted); }
.account-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 264px;
  background: var(--panel);
  border: 1px solid #30363d;
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}
.account-menu h4 { margin: 4px 0 0; }
.account-name { margin: 0; font-weight: 700; color: var(--accent-2); }
/* REQ-AVA-6 (T-1303): every avatar surface is a FIXED square box with
 * object-fit: contain and identical border/padding, so the same sprite
 * renders at one visual size regardless of source PNG dimensions (Twemoji
 * 72px vs Pokemon 96px canvases). One size per context, consistent 1:2:4
 * ratio: menu + leaderboard 24px, picker tile 48px, preview modal 96px. */
.account-avatar {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 50%;
  object-fit: contain;
  margin-right: 6px;
  vertical-align: middle;
}
.points-line { margin: 0; font-weight: 700; color: var(--accent-2); font-variant-numeric: tabular-nums; }

/* theme picker: compact auto-fit tiles, full grouped list under the section
 * tab (REQ-SET-2, T-1203): category headers span the grid row; the Settings
 * screen scrolls, the picker never does (REQ-UI-7). */
.theme-picker {
  display: grid;
  /* 84px min so long single-word names (Thanksgiving, Patriotic) fit a line
   * instead of breaking mid-word (the old 64px min clipped them). */
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 8px;
}
/* category section header (name + count) with visible separation (REQ-SET-2) */
.picker-group-header {
  grid-column: 1 / -1;
  margin-top: 14px;
  padding: 6px 2px 4px;
  border-top: 1px solid #30363d;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.picker-group-header:first-child { margin-top: 0; border-top: none; padding-top: 0; }
/* REQ-AVA-7 (T-1303): top-level avatar sections ('Standard (n)' / '<Theme>
 * pack') plus the pack unlock subtitle naming the gating theme and cost. */
.picker-section-header { font-size: 0.8rem; color: var(--text); }
.picker-pack-subtitle {
  grid-column: 1 / -1;
  margin: -8px 2px 2px;
  font-size: 0.66rem;
  color: var(--muted);
}
.theme-entry {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  min-width: 0;
}
.theme-opt {
  position: relative;
  text-align: center;
  border: 1px solid #30363d;
  background: var(--panel-2);
  color: var(--text);
  border-radius: 8px;
  padding: 5px 4px;
  font-size: 0.62rem;
  cursor: pointer;
}
/* Long theme names wrap onto at most 2 lines instead of ellipsizing a
 * single line — the old nowrap+ellipsis clipped the lock glyph away. */
.theme-name {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: break-word;
}
/* Always-visible corner lock badge for picker tiles (theme + design),
 * mirroring .avatar-lock. Sits on an opaque chip so it reads over any name. */
.picker-lock {
  position: absolute;
  top: 1px;
  right: 2px;
  font-size: 10px;
  line-height: 1;
  padding: 1px;
  background: var(--panel);
  border-radius: 4px;
  pointer-events: none;
}
.theme-opt.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.theme-opt[disabled] { opacity: 0.55; cursor: not-allowed; }
.theme-opt.locked { opacity: 0.85; border-style: dashed; } /* opens the preview modal (REQ-PRV-2) */
/* Locked tiles reserve room for the corner badge so it never overlaps the
 * name, and dim the name so locked vs owned reads at a glance. */
.theme-opt.locked, .design-opt.locked { padding-right: 14px; }
.theme-opt.locked .theme-name, .design-opt.locked .design-name { color: var(--muted); }
.theme-cost { font-size: 0.6rem; color: var(--muted); text-align: center; white-space: nowrap; font-variant-numeric: tabular-nums; }
.theme-cost.owned, .design-cost.owned { color: var(--accent-2); font-weight: 700; }

/* avatar picker: compact auto-fit grid, full grouped list (REQ-AVA-5) */
.avatar-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  gap: 6px;
}
.avatar-opt {
  position: relative;
  width: 48px;
  height: 48px;
  padding: 2px;
  border: 2px solid #30363d;
  border-radius: 8px;
  background: var(--panel-2);
  cursor: pointer;
}
.avatar-opt img { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
.avatar-opt.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.avatar-opt.locked { border-style: dashed; }
.avatar-opt.locked img { filter: grayscale(0.8); opacity: 0.6; }
.avatar-lock { position: absolute; top: 1px; right: 2px; font-size: 10px; }

/* block-design picker: swatch tiles, full grouped list (REQ-SKN-4, REQ-SET-2) */
.blockdesign-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 8px;
}
.design-entry {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  min-width: 0;
}
.design-opt {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  border: 1px solid #30363d;
  background: var(--panel-2);
  color: var(--text);
  border-radius: 8px;
  padding: 5px 4px;
  font-size: 0.6rem;
  cursor: pointer;
  min-width: 0;
}
.design-opt.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.design-opt.locked { opacity: 0.85; border-style: dashed; }
.design-swatch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: 2px solid #30363d;
  border-radius: 7px;
  background: var(--panel);
  font-size: 0.85rem;
  line-height: 1;
}
.design-name {
  max-width: 100%;
  /* wraps to at most 2 lines (never clips the lock badge — see .picker-lock) */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: break-word;
}
.design-cost { font-size: 0.6rem; color: var(--muted); text-align: center; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* settings toggle row (REQ-SND-2: theme sounds) */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0 0;
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
}
.toggle-row input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

/* ---------- settings screen (REQ-UI-4, REQ-SET-1/2, T-1203) ---------- */
.settings-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.settings-header h2 { margin: 0; }
/* section tabs: Preferences | Themes | Block designs | Avatars (REQ-SET-1) */
.settings-panel { width: min(96vw, 880px); }
.settings-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0 14px;
  border-bottom: 1px solid #30363d;
}
.settings-tab {
  border: 1px solid #30363d;
  border-bottom: none;
  background: var(--panel-2);
  color: var(--muted);
  border-radius: 10px 10px 0 0;
  padding: 7px 14px;
  font-size: 0.8rem;
  cursor: pointer;
}
.settings-tab.active {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--panel);
}
/* panes never scroll themselves — the page scroll is the only scrollbar */
.settings-pane { display: block; }
/* current selection summary on the Preferences tab */
.current-selection { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.current-selection-item {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid #30363d;
  border-radius: 12px;
  background: var(--panel-2);
  padding: 8px 10px;
}
.current-selection-thumb {
  flex: none;
  width: 34px;
  height: 34px;
  border: 1px solid #30363d;
  border-radius: 8px;
  background: var(--panel);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  line-height: 1;
}
.current-selection-thumb img { width: 100%; height: 100%; object-fit: contain; border-radius: 7px; image-rendering: pixelated; }
.current-selection-name { font-size: 0.8rem; max-width: 160px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* REQ-UI-7 (T-1106 fix): the old max-height caps clipped the picker grids
 * (avatar pages overflowed at 360px: 5x48px rows > 240px cap). The section
 * tabs (T-1203) give every picker the full width and the page scroll, so the
 * caps stay forbidden on the base selectors. */
#screen-settings .avatar-picker {
  grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
}

/* ---------- preview modal (REQ-PRV-1/2, T-1203) ---------- */
.preview-modal-card { width: min(92vw, 340px); align-items: center; }
.preview-modal-card h2 { margin: 0; font-size: 1.05rem; text-align: center; }
.preview-modal-board { border-radius: 10px; }
.preview-modal-avatar {
  width: 96px;
  height: 96px;
  padding: 4px;
  border: 1px solid #30363d;
  border-radius: 12px;
  background: var(--panel-2);
  object-fit: contain;
  image-rendering: pixelated;
}
.preview-modal-meta { margin: 0; font-size: 0.8rem; color: var(--muted); text-align: center; }
/* REQ-PVW-1 (T-1302): app-chrome mock. The theme's real CSS vars are set on
 * .preview-chrome-mock's inline style attribute, so every var() below picks
 * up the PREVIEWED theme inside the mock subtree only. */
.preview-modal-chrome { width: 100%; }
.preview-chrome-mock {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  background: var(--bg);
  border: 1px solid var(--panel-2);
  border-radius: 10px;
}
.preview-chrome-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: var(--panel);
  border-radius: 8px;
}
.preview-chrome-title { color: var(--text); font-weight: 700; font-size: 0.8rem; }
.preview-chrome-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: 1px solid var(--accent);
  border-radius: 50%;
  background: var(--panel-2);
  font-size: 12px;
}
.preview-chrome-buttons { display: flex; gap: 6px; }
.preview-chrome-btn {
  padding: 4px 12px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 6px;
  font-size: 0.72rem;
}
.preview-chrome-btn.primary { background: var(--accent); color: var(--bg); border-color: transparent; }
.preview-chrome-score { color: var(--muted); font-size: 0.68rem; }
.preview-chrome-decor { position: absolute; line-height: 1; pointer-events: none; }
.preview-chrome-decor img { width: 100%; height: auto; }
.preview-modal-strip { border-radius: 10px; }
.preview-modal-card .popup-buttons { width: 100%; }
/* REQ-PRV-5 (T-1402): prev/next paging row between the meta line and the
   action buttons; touch-friendly (>=44px targets, .btn already 44px min). */
.preview-modal-nav { display: flex; justify-content: center; gap: 16px; }
.preview-nav-btn { min-width: 48px; min-height: 48px; font-size: 0.9rem; line-height: 1; }

/* ---------- floating drag piece ---------- */
.drag-float {
  position: fixed;
  z-index: 40;
  pointer-events: none;
  opacity: 0.78;
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.5));
}

/* ---------- classic difficulty popup ---------- */
.popup-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(1, 4, 9, 0.72);
  display: grid;
  place-items: center;
  z-index: 30;
  backdrop-filter: blur(2px);
}
.popup-card {
  width: min(88vw, 300px);
  background: var(--panel);
  border: 1px solid #30363d;
  border-radius: 16px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.popup-card h2 { margin: 0; font-size: 1.15rem; text-align: center; }
.popup-buttons { display: flex; flex-direction: column; gap: 8px; }

/* ---------- dashboard breakdown cards ---------- */
.mode-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
.stat-card {
  background: var(--panel-2);
  border: 1px solid #30363d;
  border-radius: 12px;
  padding: 10px 12px;
}
.stat-card h4 { margin: 0 0 8px; font-size: 0.95rem; color: var(--text); }
.stat-card .stat-grid { gap: 6px; }

/* ---------- game over overlay ---------- */
#overlay {
  position: fixed;
  inset: 0;
  background: rgba(1, 4, 9, 0.72);
  display: grid;
  place-items: center;
  z-index: 20;
  backdrop-filter: blur(2px);
}
.overlay-card {
  width: min(88vw, 340px);
  background: var(--panel);
  border: 1px solid #30363d;
  border-radius: 16px;
  padding: 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.overlay-card h2 { margin: 0; }
.overlay-card .final { font-size: 1.1rem; margin: 0; }
.overlay-card .final span { font-size: 1.8rem; font-weight: 800; color: var(--accent-2); }

/* landscape phones: put tray beside the board */
@media (orientation: landscape) and (max-height: 500px) {
  #screen-game {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    align-content: center;
    gap: 8px;
  }
  #hud { width: 100%; padding: 0; }
  /* row layout: the wrap is a main-axis (width) item again — explicit width
     (T-1305 overrides the column flex-fit basis) */
  #board-wrap {
    flex: 0 1 auto;
    width: min(80svh, var(--board-max), calc(100svh - 70px));
    max-height: none;
  }
  #tray {
    width: min(30vw, 220px);
    min-height: 0;
    flex-direction: column;
    height: min(80svh, var(--board-max));
    padding: 6px;
  }
  .tray-slot { min-height: 0; flex: 1; }
}

/* ---------- top nav / bottom tab bar (T-700) ---------- */
body { display: flex; flex-direction: column; }
/* 'safe center': when a screen's content is taller than the viewport (e.g.
 * the Settings panel with the full design category open), plain `center`
 * makes the top overflow unreachable — the Back button hides under the nav
 * with no way to scroll to it. `safe` falls back to start-alignment on
 * overflow (T-1106 QA fix). */
.screen { flex: 1; min-height: 0; overflow-y: auto; justify-content: safe center; }

.main-nav {
  position: relative;
  z-index: 30;
  display: flex;
  gap: 4px;
  background: var(--panel);
  border-bottom: 1px solid #30363d;
  padding: 6px 8px; /* safe-area handled by body padding (no double inset) */
  z-index: 30;
}
.nav-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  padding: 8px 14px;
  min-height: 44px; /* touch target (REQ-WEB-3) */
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
}
.nav-btn.active { color: var(--text); background: var(--panel-2); font-weight: 600; }

/* narrow screens: bottom tab bar (REQ-WEB-1) */
@media (max-width: 640px) {
  .main-nav {
    order: 99;
    position: sticky;
    bottom: 0;
    justify-content: space-around;
    border-bottom: 0;
    border-top: 1px solid #30363d;
    padding-bottom: calc(6px + env(safe-area-inset-bottom));
  }
  .nav-btn { flex: 1; text-align: center; padding: 10px 4px; }
}

/* ---------- auth ---------- */
.auth-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--panel-2);
  border: 1px solid #30363d;
  border-radius: 10px;
  padding: 8px 12px;
}
.auth-user { font-weight: 600; overflow-wrap: anywhere; }
.auth-forms { display: flex; flex-direction: column; gap: 12px; }
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--panel-2);
  border: 1px solid #30363d;
  border-radius: 10px;
  padding: 12px;
}
.auth-form h2 { margin: 0; font-size: 1rem; }
.auth-form input {
  font: inherit;
  padding: 0.6em 0.8em;
  border-radius: 8px;
  border: 1px solid #30363d;
  background: var(--bg);
  color: var(--text);
}
.auth-form input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.error { color: var(--danger); font-size: 0.85rem; margin: 0; }
.btn.danger { background: #5a1e1e; border-color: var(--danger); }
/* disabled: keep text legible instead of ghosting the whole button */
.btn:disabled {
  opacity: 1;
  background: #21262d;
  color: var(--muted);
  border-color: #30363d;
  cursor: not-allowed;
}

/* ---------- generic panel ---------- */
.panel {
  width: min(92vw, 460px);
  background: var(--panel);
  border: 1px solid #30363d;
  border-radius: 16px;
  padding: clamp(14px, 4vw, 24px);
  align-self: center;
}
.panel.wide { width: min(94vw, 640px); }
.panel h2 { margin: 0 0 10px; }
.panel h3 { margin: 18px 0 6px; font-size: 0.95rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }

/* ---------- chips / tabs ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip {
  display: inline-block;
  background: var(--panel-2);
  border: 1px solid #30363d;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.8rem;
  color: var(--text);
}
.chip.selectable { cursor: pointer; font: inherit; min-height: 44px; }
.chip.selectable.active { border-color: var(--accent); background: rgba(47, 129, 247, 0.15); }
.tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.tab {
  appearance: none;
  border: 1px solid #30363d;
  background: var(--panel-2);
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  padding: 6px 16px;
  min-height: 44px; /* touch target */
  border-radius: 999px;
  cursor: pointer;
}
.tab.active { color: #fff; background: var(--accent); border-color: var(--accent); font-weight: 600; }

/* ---------- Boards screen: Global/Personal separation + selectors
   (REQ-LDR-1/2/3) ---------- */
.boards-top-tabs {
  border-bottom: 1px solid #30363d;
  padding-bottom: 10px;
  margin-bottom: 14px;
}
.boards-top-tabs .tab { font-size: 1rem; padding: 8px 22px; }
.lb-filters { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 10px; }
.lb-select {
  appearance: none;
  background: var(--panel-2);
  border: 1px solid #30363d;
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  padding: 6px 10px;
  min-height: 40px;
  cursor: pointer;
}
.lb-select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
#lb-personal-table td:first-child, #lb-personal-table th:first-child { width: auto; }

/* ---------- leaderboard tables ---------- */
.lb-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.lb-table th, .lb-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid #21262d; }
.lb-table th { color: var(--muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; }
.lb-table td:first-child, .lb-table th:first-child { width: 3.5ch; }
.lb-table tr.viewer-row { background: rgba(47, 129, 247, 0.14); font-weight: 700; }
.lb-avatar {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 50%;
  object-fit: contain;
  vertical-align: middle;
  margin-right: 6px;
}

/* ---------- dashboard ---------- */
.points-card {
  background: var(--panel-2);
  border: 1px solid #30363d;
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 10px;
  font-weight: 700;
  color: var(--accent-2);
  font-variant-numeric: tabular-nums;
}
.points-card .note { font-weight: 400; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
.stat-cell {
  background: var(--panel-2);
  border: 1px solid #30363d;
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-cell strong { font-size: 1.2rem; color: var(--accent-2); font-variant-numeric: tabular-nums; }
.stat-cell span { color: var(--muted); font-size: 0.75rem; }

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.list-item {
  background: var(--panel-2);
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.85rem;
}
.list-item.muted { color: var(--muted); }
.list-item.tappable { cursor: pointer; border-color: var(--accent); }
.list-item.tappable:active { transform: scale(0.99); }

.daily-active {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border: 1px solid #e3b341;
  border-radius: 10px;
  padding: 10px;
  margin: 8px 0;
}
.daily-meta { display: flex; flex-wrap: wrap; gap: 6px; }

.daily-practice-past {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 10px 0 0;
}
.daily-practice-past label { font-size: 0.85rem; color: var(--muted); }
.daily-practice-past input[type="date"] {
  background: var(--panel, #fff);
  color: inherit;
  border: 1px solid var(--border, #ccc);
  border-radius: 8px;
  padding: 6px 8px;
  font: inherit;
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #1f2937;
  border: 1px solid #30363d;
  color: var(--text);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 0.9rem;
  max-width: min(88vw, 420px);
  z-index: 40;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}

/* ---------- motion preferences (a11y) ---------- */
@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;
  }
  .btn:active, .list-item.tappable:active { transform: none; }
}

/* ---------- admin screen (REQ-ADM-2/3 UI, T-1105b) ---------- */
.admin-table { width: 100%; border-collapse: collapse; margin: 4px 0 12px; }
.admin-table th, .admin-table td {
  text-align: left;
  padding: 4px 10px 4px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-variant-numeric: tabular-nums;
}
.admin-table th { color: var(--muted); font-size: 0.8rem; font-weight: 600; }
.admin-table-host h4 { margin: 10px 0 2px; font-size: 0.9rem; color: var(--text); }
.admin-backup { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.admin-backup > #admin-import-confirm, .admin-backup > #admin-import-result { flex: 1 1 100%; }
.admin-import-confirm {
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--panel-2);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.admin-import-confirm p { margin: 0 8px 0 0; flex: 1 1 240px; }
.admin-import-result { margin-top: 8px; }
.admin-import-errors {
  border: 1px solid var(--danger);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--danger);
}
.admin-import-errors ul { margin: 4px 0 0; padding-left: 20px; font-size: 0.85rem; }
.admin-import-ok { color: var(--accent-2); }

/* ---- Phase 18: rewards, achievements, coupons ---- */
.reward-card { border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; margin: 10px 0; background: var(--card, rgba(255,255,255,.03)); }
.reward-card h3 { margin: 0 0 4px; font-size: 1rem; }
.reward-card.complete { border-color: var(--accent-2, #4caf7d); }
.reward-done { color: var(--accent-2, #4caf7d); font-weight: 600; }
.reward-line { font-variant-numeric: tabular-nums; }
.progress-bar { height: 8px; border-radius: 6px; background: var(--border); overflow: hidden; margin: 6px 0; }
.progress-fill { height: 100%; background: var(--accent, #6c8cff); border-radius: 6px; transition: width .3s ease; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.achievements h3 { margin: 18px 0 6px; }
.achievements details { margin: 6px 0; }
.achievements summary { cursor: pointer; font-weight: 600; }
.ach-list { display: grid; gap: 8px; margin-top: 8px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.ach-card { display: flex; gap: 10px; border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; align-items: flex-start; }
.ach-card.locked { opacity: .55; }
.ach-card.earned { border-color: var(--accent-2, #4caf7d); }
.ach-icon { font-size: 1.5rem; line-height: 1; }
.ach-body { flex: 1; min-width: 0; }
.ach-body strong { display: block; }
.ach-body p { margin: 2px 0; font-size: .85rem; }
.ach-date { font-size: .75rem; opacity: .7; }
.coupon-inventory { margin: 10px 0; }
.coupon-row { display: flex; justify-content: space-between; gap: 10px; border: 1px dashed var(--border); border-radius: 8px; padding: 6px 10px; margin: 4px 0; }
@media (prefers-reduced-motion: reduce) {
  .progress-fill { transition: none; }
}

/* Admin section menu (phase 18 UX) */
.admin-menu {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 14px;
}
.admin-section { min-height: 120px; }

/* Touch lift slider (preferences) */
.slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0;
}
.slider-row > span { flex: 0 0 auto; }
.slider-row input[type="range"] { flex: 1 1 auto; accent-color: var(--accent, #6c5ce7); }
.slider-row output { flex: 0 0 auto; min-width: 4.5em; text-align: right; opacity: 0.8; }
.slider-row input[type="range"]:disabled { opacity: 0.4; }
