:root {
  --bg: #080c16;
  --bg-radial: radial-gradient(circle at 65% 42%, #131c33 0%, #0a0f1c 58%, #060911 100%);
  --panel: rgba(14, 20, 36, 0.90);
  --panel-solid: #101729;
  --surface: rgba(24, 34, 58, 0.85);
  --surface-hover: rgba(34, 48, 80, 0.95);
  --border: rgba(148, 163, 184, 0.22);
  --border-bright: rgba(125, 211, 252, 0.45);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --dim: #64748b;
  --accent: #38bdf8;
  --accent-glow: rgba(56, 189, 248, 0.35);
  --gold: #fbbf24;
  --green: #22c55e;
  --danger: #ef4444;
  --p1-color: #3b82f6;
  --p2-color: #ef4444;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "Courier New", ui-monospace, Menlo, Consolas, monospace;
  --target-size: 36px;
}

@media (pointer: coarse) {
  :root {
    --target-size: 44px;
  }
}

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-radial);
  color: var(--text);
  font-family: var(--sans);
  overscroll-behavior: none;
}

button, input, select {
  font-family: inherit;
}

.hidden {
  display: none !important;
}

#app {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  position: relative;
}

/* =========================================================
   TOP PERSISTENT HUD & STF ARCADE HOME BUTTON
   ========================================================= */
#hud {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  padding-top: max(8px, env(safe-area-inset-top));
  background: rgba(9, 13, 24, 0.92);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  z-index: 30;
}

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

.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(79, 195, 247, 0.55);
  background: rgba(24, 34, 58, 0.85);
  color: #e0f2fe;
  text-decoration: none;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.4px;
  white-space: nowrap;
  transition: transform 0.14s ease, border-color 0.14s ease, box-shadow 0.14s ease, background 0.14s ease;
}

.btn-back:hover, .btn-back:focus-visible {
  background: #38bdf8;
  color: #06101f;
  border-color: #7dd3fc;
  box-shadow: 0 0 14px rgba(56, 189, 248, 0.5);
  transform: translateY(-1px);
  outline: none;
}

.brand-badge {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 800;
  letter-spacing: 1px;
  font-size: 13px;
  color: #cbd5e1;
}

.brand-cube {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 2px solid var(--accent);
  background: rgba(56, 189, 248, 0.25);
  box-shadow: 0 0 8px var(--accent-glow);
}

.hud-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.chip {
  min-height: 34px;
  min-width: 36px;
  padding: 5px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: #e2e8f0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.14s ease, border-color 0.14s ease;
}

.chip:hover, .chip:focus-visible {
  background: var(--surface-hover);
  border-color: var(--border-bright);
  outline: none;
}

/* =========================================================
   IN-GAME SCOREBOARD
   ========================================================= */
.scoreboard {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex: 1 1 auto;
  min-width: 0;
}

.score-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 11px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.78);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.score-pill.is-active {
  border-color: rgba(255, 255, 255, 0.6);
  box-shadow: 0 0 16px rgba(56, 189, 248, 0.25);
  transform: translateY(-1px);
}

.swatch-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex: 0 0 auto;
  box-shadow: 0 0 8px currentColor;
}

.score-meta {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.score-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
}

.score-val {
  font-size: 18px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #ffffff;
}

.turn-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.15;
  min-width: 132px;
}

.turn-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  color: #f8fafc;
}

.turn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.remaining-line {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.sep {
  opacity: 0.45;
}

/* =========================================================
   3D STAGE & CANVAS
   ========================================================= */
#stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  overflow: hidden;
}

.canvas-host {
  position: absolute;
  inset: 0;
  touch-action: none;
}

.board-canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  touch-action: none;
}

.webgl-fallback {
  position: absolute;
  inset: 24px;
  margin: auto;
  max-width: 440px;
  max-height: 220px;
  padding: 24px;
  border-radius: 16px;
  border: 1px solid rgba(239, 68, 68, 0.5);
  background: rgba(15, 23, 42, 0.96);
  text-align: center;
  z-index: 40;
}

/* =========================================================
   SETUP OVERLAY (FLOATING ROTATING CUBE PREVIEW BEHIND/BESIDE)
   ========================================================= */
.setup-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 18px clamp(16px, 4vw, 48px);
  overflow-y: auto;
  pointer-events: none;
}

.setup-card {
  pointer-events: auto;
  width: 100%;
  max-width: 440px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 20px 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55), 0 0 36px rgba(56, 189, 248, 0.08);
  backdrop-filter: blur(16px);
}

.preview-caption {
  position: fixed;
  right: 22px;
  bottom: 18px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid var(--border);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.9px;
  color: #cbd5e1;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #38bdf8;
  box-shadow: 0 0 10px #38bdf8;
  animation: pulseGlow 1.8s infinite ease-in-out;
}

@keyframes pulseGlow {
  0%, 100% { opacity: 0.45; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1.15); }
}

.eyebrow {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1.5px;
  color: var(--accent);
  text-transform: uppercase;
  margin-bottom: 4px;
}

.game-title {
  margin: 0;
  font-size: 32px;
  font-weight: 900;
  letter-spacing: 1.5px;
  line-height: 1.05;
  background: linear-gradient(135deg, #ffffff 0%, #bae6fd 60%, #38bdf8 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.game-subtitle {
  margin: 6px 0 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted);
}

.setup-section {
  margin-top: 14px;
}

.field-label {
  display: block;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1.2px;
  color: var(--muted);
  margin-bottom: 6px;
}

.seg-grid {
  display: grid;
  gap: 7px;
}
.seg-grid.two {
  grid-template-columns: repeat(2, 1fr);
}
.seg-grid.three {
  grid-template-columns: repeat(3, 1fr);
}

.seg-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 2px;
  padding: 8px 10px;
  min-height: var(--target-size);
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.7);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.14s ease, background 0.14s ease, transform 0.12s ease;
}

.seg-btn:hover {
  background: var(--surface-hover);
  border-color: rgba(148, 163, 184, 0.45);
}

.seg-btn.active {
  background: rgba(56, 189, 248, 0.16);
  border-color: #38bdf8;
  box-shadow: inset 0 0 0 1px rgba(56, 189, 248, 0.35);
}

.seg-title {
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
}

.seg-sub {
  font-size: 10.5px;
  color: var(--muted);
  line-height: 1.2;
}

.colors-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.color-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.color-swatch {
  position: relative;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, opacity 0.12s ease;
}

.color-swatch:hover:not(:disabled) {
  transform: scale(1.1);
}

.color-swatch.selected {
  border-color: #ffffff;
  box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.9), 0 0 12px rgba(255, 255, 255, 0.5);
  transform: scale(1.06);
}

.color-swatch:disabled {
  opacity: 0.25;
  cursor: not-allowed;
}

.color-swatch:disabled::after {
  content: "";
  position: absolute;
  inset: 4px;
  border-top: 2px solid #ffffff;
  transform: rotate(-45deg);
  top: 50%;
}

.toggle-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.65);
  cursor: pointer;
}

.toggle-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  accent-color: #38bdf8;
  cursor: pointer;
  flex: 0 0 auto;
}

.toggle-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.toggle-text strong {
  font-size: 13px;
}

.toggle-text small {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.35;
}

.setup-actions {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.setup-secondary {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

/* =========================================================
   BUTTONS
   ========================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--target-size);
  padding: 9px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.4px;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.14s ease, border-color 0.14s ease, box-shadow 0.14s ease;
}

.btn:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--border-bright);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

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

.btn-lg {
  min-height: 46px;
  font-size: 14px;
  letter-spacing: 0.8px;
}

.btn-sm {
  min-height: 32px;
  padding: 5px 11px;
  font-size: 12px;
}

.btn-primary {
  background: linear-gradient(135deg, #0284c7 0%, #38bdf8 100%);
  border-color: #7dd3fc;
  color: #04101e;
  box-shadow: 0 6px 20px rgba(56, 189, 248, 0.3);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #0ea5e9 0%, #7dd3fc 100%);
  box-shadow: 0 8px 24px rgba(56, 189, 248, 0.45);
}

.btn-secondary {
  background: rgba(30, 41, 59, 0.85);
}

.btn-ghost {
  background: transparent;
}

.btn-danger-outline {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.45);
  color: #fca5a5;
}

.btn-danger-outline:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.22);
  border-color: #ef4444;
}

/* =========================================================
   IN-GAME FLOATING OVERLAYS & BOTTOM CONTROL DOCK
   ========================================================= */
.game-overlays {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 15;
}

.edge-help-pill {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: calc(100% - 24px);
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(11, 17, 31, 0.86);
  border: 1px solid var(--border);
  backdrop-filter: blur(10px);
  font-size: 12.5px;
  color: var(--text);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.help-idle {
  color: var(--muted);
}

.help-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 700;
}

.help-chip.complete {
  color: #4ade80;
}

.help-chip.vuln {
  color: #fbbf24;
}

.help-chip.safe {
  color: #38bdf8;
}

.status-toast {
  position: absolute;
  top: 56px;
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid rgba(56, 189, 248, 0.5);
  color: #e0f2fe;
  font-size: 12px;
  font-weight: 700;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.45);
}

.status-toast.extra-turn {
  border-color: #4ade80;
  color: #bbf7d0;
  background: rgba(20, 83, 45, 0.88);
}

.spinner-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #38bdf8;
  animation: pulseGlow 0.9s infinite ease-in-out;
}

.status-toast.extra-turn .spinner-dot {
  background: #4ade80;
}

.confirm-pill {
  pointer-events: auto;
  position: absolute;
  bottom: calc(74px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px 8px 16px;
  border-radius: 14px;
  background: rgba(11, 17, 32, 0.94);
  border: 1px solid rgba(56, 189, 248, 0.55);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(12px);
  max-width: calc(100% - 24px);
}

.confirm-msg {
  font-size: 12.5px;
  font-weight: 700;
  color: #e0f2fe;
  white-space: nowrap;
}

.confirm-btns {
  display: flex;
  gap: 6px;
}

.restore-results-btn {
  pointer-events: auto;
  position: absolute;
  bottom: calc(74px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
}

.control-dock {
  pointer-events: auto;
  position: absolute;
  bottom: max(12px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 14px;
  background: rgba(11, 17, 31, 0.9);
  border: 1px solid var(--border);
  backdrop-filter: blur(12px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  max-width: calc(100% - 16px);
  overflow-x: auto;
}

.dock-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 6px 12px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: rgba(30, 41, 59, 0.72);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.14s ease, border-color 0.14s ease, opacity 0.14s ease;
}

.dock-btn:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--border-bright);
}

.dock-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.dock-btn.accent {
  background: rgba(56, 189, 248, 0.16);
  border-color: rgba(56, 189, 248, 0.4);
  color: #bae6fd;
}

.dock-ico {
  font-size: 14px;
  line-height: 1;
}

/* =========================================================
   MODALS
   ========================================================= */
dialog.modal {
  width: min(760px, calc(100% - 24px));
  max-height: calc(100dvh - 32px);
  margin: auto;
  padding: 0;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--panel-solid);
  color: var(--text);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.75);
  overflow: hidden;
  display: none;
  flex-direction: column;
}

dialog.modal[open] {
  display: flex;
}

dialog.modal::backdrop {
  background: rgba(4, 7, 15, 0.72);
  backdrop-filter: blur(5px);
}

dialog.modal.modal-compact {
  width: min(460px, calc(100% - 24px));
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.75);
}

.modal-head h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
}

.modal-close {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
}

.modal-close:hover {
  background: var(--surface-hover);
  border-color: var(--border-bright);
}

.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.6);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal-foot.space-between {
  justify-content: space-between;
}

/* How To Play Grid */
.rules-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
}

.rule-card {
  position: relative;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.65);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rule-num {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(56, 189, 248, 0.16);
  border: 1px solid rgba(56, 189, 248, 0.45);
  color: #7dd3fc;
  font-size: 11px;
  font-weight: 800;
  display: grid;
  place-items: center;
}

.rule-art {
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 13, 25, 0.7);
  border-radius: 8px;
  padding: 4px;
}

.rule-art svg {
  height: 100%;
  width: auto;
}

.rule-card h3 {
  margin: 2px 0 0;
  font-size: 14px;
  font-weight: 700;
}

.rule-card p {
  margin: 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--muted);
}

.how-tips-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
}

.tip-box {
  padding: 11px 13px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.55);
  font-size: 12px;
  line-height: 1.45;
  color: var(--muted);
}

.tip-box strong {
  display: block;
  color: var(--text);
  margin-bottom: 3px;
}

/* Stats Modal */
.stats-kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.kpi-card {
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.72);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kpi-lbl {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
}

.kpi-val {
  font-size: 18px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #ffffff;
}

.subhead {
  margin: 4px 0 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}

.color-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.color-stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.6);
  font-size: 12px;
}

.color-stat-left {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 700;
}

.color-stat-right {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 11.5px;
}

/* End Game Modal */
.end-body {
  align-items: center;
  text-align: center;
}

.end-score-hero {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.end-score-line {
  font-size: 26px;
  font-weight: 900;
  letter-spacing: 0.4px;
}

.end-control-line {
  font-size: 15px;
  font-weight: 700;
  color: #7dd3fc;
}

.control-bar-wrap {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.control-bar {
  width: 100%;
  height: 14px;
  border-radius: 999px;
  overflow: hidden;
  display: flex;
  background: rgba(30, 41, 59, 0.9);
  border: 1px solid var(--border);
}

.bar-seg {
  height: 100%;
  transition: width 0.4s ease;
}

.control-legend {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.end-meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--muted);
}

.end-actions {
  flex-direction: column;
  align-items: stretch;
}

.end-sub-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

/* =========================================================
   RESPONSIVE BREAKPOINTS (MOBILE & COMPACT SCREENS)
   ========================================================= */
@media (max-width: 899px) {
  .setup-overlay {
    justify-content: center;
    align-items: flex-end;
    padding: 10px 12px max(10px, env(safe-area-inset-bottom));
  }

  .setup-card {
    max-width: 500px;
    padding: 14px 15px;
    max-height: 78%;
    overflow-x: hidden;
    overflow-y: auto;
    background: rgba(14, 20, 36, 0.88);
  }

  .preview-caption {
    display: none;
  }
}

@media (max-width: 720px) {
  .brand-badge {
    display: none;
  }

  #hud {
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px 10px;
    padding-top: max(6px, env(safe-area-inset-top));
  }

  .hud-left {
    order: 1;
  }

  .hud-right {
    order: 2;
  }

  .scoreboard {
    order: 3;
    width: 100%;
    justify-content: space-between;
    padding-top: 2px;
    border-top: 1px solid rgba(148, 163, 184, 0.12);
  }

  .score-pill {
    padding: 3px 8px;
    gap: 6px;
  }

  .score-val {
    font-size: 15px;
  }

  .turn-center {
    min-width: 0;
  }

  .turn-badge {
    font-size: 11px;
  }

  .remaining-line {
    font-size: 10px;
  }

  .game-title {
    font-size: 24px;
  }

  .game-subtitle {
    font-size: 12px;
  }

  .setup-section {
    margin-top: 9px;
  }

  .seg-grid.size-grid {
    grid-template-columns: 1fr;
  }

  .seg-grid.size-grid .seg-btn {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    min-height: 36px;
    padding: 6px 11px;
  }

  .colors-row {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .color-swatch {
    width: 26px;
    height: 26px;
  }

  .stats-kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .color-stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .control-dock {
    width: calc(100% - 16px);
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
    padding: 5px;
    overflow: hidden;
  }

  .dock-btn {
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    min-height: 44px;
    padding: 4px 3px;
    font-size: 10px;
    line-height: 1.1;
    text-align: center;
    white-space: normal;
  }

  .dock-ico {
    font-size: 15px;
  }

  .edge-help-pill {
    font-size: 11.5px;
    padding: 6px 11px;
  }

  .confirm-pill {
    flex-direction: column;
    gap: 6px;
    padding: 8px 12px;
    bottom: calc(68px + env(safe-area-inset-bottom));
  }
}
