:root {
  color-scheme: light dark;
  forced-color-adjust: none;
  --bg: #b8c4d0;
  --bg-glow-1: rgba(3, 105, 161, 0.08);
  --bg-glow-2: rgba(79, 70, 229, 0.06);
  --surface: #cad4df;
  --surface-alt: #b0bcc9;
  --input-bg: #9fb0c0;
  --arena-bg: #a5b4c4;
  --border: rgba(15, 23, 42, 0.28);
  --row-border: rgba(15, 23, 42, 0.14);
  --text: #0f172a;
  --muted: #334155;
  --primary: #0369a1;
  --accent-ink: #075985;
  --primary-glow: rgba(3, 105, 161, 0.25);
  --pill-active-bg: rgba(3, 105, 161, 0.18);
  --pill-active-text: #082f49;
  --badge-bg: rgba(3, 105, 161, 0.16);
  --badge-text: #0369a1;
  --panel-shadow: 0 10px 28px rgba(15, 23, 42, 0.1);
  --emerald: #047857;
  --amber: #b45309;
  --rose: #be123c;
}

html[data-theme="slate"],
html[data-theme="light"] {
  color-scheme: only light;
  forced-color-adjust: none;
  --bg: #b8c4d0;
  --bg-glow-1: rgba(3, 105, 161, 0.08);
  --bg-glow-2: rgba(79, 70, 229, 0.06);
  --surface: #cad4df;
  --surface-alt: #b0bcc9;
  --input-bg: #9fb0c0;
  --arena-bg: #a5b4c4;
  --border: rgba(15, 23, 42, 0.28);
  --row-border: rgba(15, 23, 42, 0.14);
  --text: #0f172a;
  --muted: #334155;
  --primary: #0369a1;
  --accent-ink: #075985;
  --primary-glow: rgba(3, 105, 161, 0.25);
  --pill-active-bg: rgba(3, 105, 161, 0.18);
  --pill-active-text: #082f49;
  --badge-bg: rgba(3, 105, 161, 0.16);
  --badge-text: #0369a1;
  --panel-shadow: 0 10px 28px rgba(15, 23, 42, 0.1);
  --emerald: #047857;
  --amber: #b45309;
  --rose: #be123c;
}

html[data-theme="sage"] {
  color-scheme: only light;
  forced-color-adjust: none;
  --bg: #b5c4b9;
  --bg-glow-1: rgba(4, 120, 87, 0.08);
  --bg-glow-2: rgba(15, 118, 110, 0.06);
  --surface: #c7d4ca;
  --surface-alt: #aebfb3;
  --input-bg: #9eb1a4;
  --arena-bg: #a3b5a8;
  --border: rgba(15, 31, 23, 0.28);
  --row-border: rgba(15, 31, 23, 0.14);
  --text: #0f1f17;
  --muted: #2d4a3b;
  --primary: #047857;
  --accent-ink: #065f46;
  --primary-glow: rgba(4, 120, 87, 0.25);
  --pill-active-bg: rgba(4, 120, 87, 0.18);
  --pill-active-text: #022c22;
  --badge-bg: rgba(4, 120, 87, 0.16);
  --badge-text: #047857;
  --panel-shadow: 0 10px 28px rgba(15, 31, 23, 0.1);
  --emerald: #047857;
  --amber: #b45309;
  --rose: #be123c;
}

html[data-theme="clay"] {
  color-scheme: only light;
  forced-color-adjust: none;
  --bg: #c8b8a6;
  --bg-glow-1: rgba(180, 83, 9, 0.08);
  --bg-glow-2: rgba(194, 65, 12, 0.06);
  --surface: #d6c8b8;
  --surface-alt: #bfb09c;
  --input-bg: #b09e8b;
  --arena-bg: #b8a693;
  --border: rgba(28, 20, 13, 0.28);
  --row-border: rgba(28, 20, 13, 0.14);
  --text: #1c140d;
  --muted: #4a3828;
  --primary: #b45309;
  --accent-ink: #7c2d12;
  --primary-glow: rgba(180, 83, 9, 0.25);
  --pill-active-bg: rgba(180, 83, 9, 0.18);
  --pill-active-text: #451a03;
  --badge-bg: rgba(180, 83, 9, 0.16);
  --badge-text: #b45309;
  --panel-shadow: 0 10px 28px rgba(28, 20, 13, 0.1);
  --emerald: #047857;
  --amber: #b45309;
  --rose: #be123c;
}

html[data-theme="twilight"] {
  color-scheme: only light;
  forced-color-adjust: none;
  --bg: #b9b8cc;
  --bg-glow-1: rgba(79, 70, 229, 0.08);
  --bg-glow-2: rgba(147, 51, 234, 0.06);
  --surface: #cac9db;
  --surface-alt: #b0afc4;
  --input-bg: #a2a0b9;
  --arena-bg: #a7a5bd;
  --border: rgba(19, 17, 36, 0.28);
  --row-border: rgba(19, 17, 36, 0.14);
  --text: #131124;
  --muted: #3d3b59;
  --primary: #4f46e5;
  --accent-ink: #3730a3;
  --primary-glow: rgba(79, 70, 229, 0.25);
  --pill-active-bg: rgba(79, 70, 229, 0.18);
  --pill-active-text: #1e1b4b;
  --badge-bg: rgba(79, 70, 229, 0.16);
  --badge-text: #4f46e5;
  --panel-shadow: 0 10px 28px rgba(19, 17, 36, 0.1);
  --emerald: #047857;
  --amber: #b45309;
  --rose: #be123c;
}

html[data-theme="warmwhite"] {
  color-scheme: only light;
  forced-color-adjust: none;
  --bg: #f6f3ed;
  --fullscreen-bg: #ffffff;
  --bg-glow-1: rgba(2, 132, 199, 0.05);
  --bg-glow-2: rgba(15, 118, 110, 0.04);
  --surface: #ffffff;
  --surface-alt: #eee9df;
  --input-bg: #faf7f2;
  --arena-bg: #fbf9f5;
  --border: rgba(30, 20, 10, 0.12);
  --row-border: rgba(30, 20, 10, 0.07);
  --text: #18181b;
  --muted: #57534e;
  --primary: #0369a1;
  --accent-ink: #075985;
  --primary-glow: rgba(2, 132, 199, 0.2);
  --pill-active-bg: rgba(2, 132, 199, 0.14);
  --pill-active-text: #0369a1;
  --badge-bg: rgba(15, 118, 110, 0.12);
  --badge-text: #0f766e;
  --panel-shadow: 0 10px 28px rgba(30, 20, 10, 0.06);
  --emerald: #059669;
  --amber: #d97706;
  --rose: #e11d48;
}

html[data-theme="stone"] {
  color-scheme: only light;
  forced-color-adjust: none;
  --bg: #d5cfc2;
  --fullscreen-bg: #e4ded2;
  --bg-glow-1: rgba(15, 118, 110, 0.07);
  --bg-glow-2: rgba(180, 83, 9, 0.05);
  --surface: #e4ded2;
  --surface-alt: #d5cfc1;
  --input-bg: #c8c1b2;
  --arena-bg: #dbd4c7;
  --border: rgba(30, 36, 43, 0.25);
  --row-border: rgba(30, 36, 43, 0.14);
  --text: #1e242b;
  --muted: #525b66;
  --primary: #0f766e;
  --accent-ink: #115e59;
  --primary-glow: rgba(15, 118, 110, 0.22);
  --pill-active-bg: rgba(15, 118, 110, 0.16);
  --pill-active-text: #0f766e;
  --badge-bg: rgba(15, 118, 110, 0.16);
  --badge-text: #0f766e;
  --panel-shadow: 0 10px 28px rgba(30, 36, 43, 0.09);
  --emerald: #0f766e;
  --amber: #b45309;
  --rose: #be123c;
}

html[data-theme="dark"] {
  color-scheme: only dark;
  forced-color-adjust: none;
  --bg: #070b14;
  --bg-glow-1: rgba(56, 189, 248, 0.12);
  --bg-glow-2: rgba(168, 85, 247, 0.12);
  --surface: rgba(15, 23, 42, 0.85);
  --surface-alt: rgba(30, 41, 59, 0.65);
  --input-bg: rgba(15, 23, 42, 0.95);
  --arena-bg: rgba(2, 6, 23, 0.65);
  --border: rgba(148, 163, 184, 0.22);
  --row-border: rgba(148, 163, 184, 0.12);
  --text: #f8fafc;
  --muted: #94a3b8;
  --primary: #38bdf8;
  --accent-ink: #38bdf8;
  --primary-glow: rgba(56, 189, 248, 0.25);
  --pill-active-bg: rgba(56, 189, 248, 0.16);
  --pill-active-text: #7dd3fc;
  --badge-bg: rgba(16, 185, 129, 0.14);
  --badge-text: #34d399;
  --panel-shadow: 0 20px 45px rgba(0, 0, 0, 0.4);
  --emerald: #10b981;
  --amber: #f59e0b;
  --rose: #f43f5e;
}

html {
  box-sizing: border-box;
  overflow-x: hidden;
  width: 100%;
  -webkit-text-size-adjust: 100%;
  forced-color-adjust: none;
}

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

body {
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  overflow-x: hidden;
  forced-color-adjust: none;
  background: radial-gradient(circle at 15% 15%, var(--bg-glow-1), transparent 40%),
              radial-gradient(circle at 85% 80%, var(--bg-glow-2), transparent 40%),
              var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
  padding: 1.5rem 1rem 3rem;
  transition: background-color 0.2s ease, color 0.2s ease;
}

/* Accessibility: High-contrast focus-visible rings for keyboard users */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.pill-btn:focus-visible,
.btn-secondary:focus-visible,
.btn-secondary:focus,
.btn-secondary.wheel-active,
.num-btn:focus-visible,
.input-field:focus-visible,
.answer-input:focus-visible,
.filter-select:focus-visible,
.theme-select:focus-visible {
  outline: 2px solid var(--primary) !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 10px var(--primary-glow) !important;
}

:focus:not(:focus-visible) {
  outline: none;
}

.layout {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  box-sizing: border-box;
  min-width: 0;
}

.topbar {
  position: relative;
  z-index: 100;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1rem 1.5rem;
  box-shadow: var(--panel-shadow);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.28rem 0.75rem;
  border-radius: 9999px;
  background: var(--badge-bg);
  color: var(--badge-text);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.brand h1 {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.brand p {
  font-size: 0.82rem;
  color: var(--muted);
}

.topbar-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1.25rem;
}

.global-kpis {
  display: flex;
  flex-wrap: wrap;
  gap: 1.15rem;
}

.kpi {
  text-align: right;
}

.kpi-label {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.kpi-val {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--accent-ink);
  font-variant-numeric: tabular-nums;
}

.grid-main {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 1.5rem;
  align-items: stretch;
  width: 100%;
  min-width: 0;
}

.grid-main > * {
  min-width: 0;
  max-width: 100%;
}

@media (max-width: 920px) {
  .grid-main {
    grid-template-columns: 1fr;
  }

  #lb-panel,
  aside.panel {
    height: auto !important;
    max-height: none !important;
  }

  .lb-table-wrap {
    max-height: 500px;
  }

  .filter-bar {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.45rem;
  }

  .filter-bar .custom-select-wrap {
    flex: none;
    min-width: 0;
    width: 100%;
  }
}

.panel, .card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1.25rem;
  padding: 1.5rem;
  box-shadow: var(--panel-shadow);
  backdrop-filter: blur(12px);
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  min-width: 0;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1.15rem;
}

.panel-title {
  font-size: 1.1rem;
  font-weight: 700;
}

.selector-group {
  margin-bottom: 1rem;
}

.selector-label {
  display: block;
  font-size: 0.76rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 0.45rem;
}

.settle-label-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.45rem;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.settle-hint {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--muted);
}

.settle-pill-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 0.5rem;
  align-items: stretch;
}

.custom-settle-wrap {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 44px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 0 0.65rem;
  gap: 0.25rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.custom-settle-wrap:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.custom-settle-wrap .settle-custom-input {
  width: 100%;
  min-height: 44px;
  padding: 0;
  border: none !important;
  outline: none !important;
  box-shadow: none !important;
  background: transparent;
  font-weight: 600;
  font-size: 0.84rem;
  text-align: right;
  -moz-appearance: textfield;
}

.custom-settle-wrap .settle-custom-input::-webkit-outer-spin-button,
.custom-settle-wrap .settle-custom-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.custom-settle-wrap .custom-settle-unit {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
  pointer-events: none;
  flex-shrink: 0;
}

.pill-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
  gap: 0.5rem;
  align-items: stretch;
}

.pill-btn {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  min-height: 44px;
  padding: 0.55rem 0.75rem;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1.2;
}

.pill-btn:hover {
  border-color: var(--primary);
}

.pill-btn.active {
  background: var(--primary) !important;
  color: #ffffff !important;
  border-color: var(--primary) !important;
  font-weight: 700 !important;
  box-shadow: 0 0 16px var(--primary-glow), 0 2px 6px rgba(0, 0, 0, 0.15) !important;
}

html[data-theme="dark"] .pill-btn.active {
  color: #0b1120 !important;
}

.pill-btn:disabled,
.pill-btn[aria-disabled="true"] {
  opacity: 0.52;
  cursor: not-allowed;
}

.retry-banner {
  margin-top: 0.65rem;
  padding: 0.6rem 0.8rem;
  border-radius: 0.65rem;
  border: 1px solid var(--rose);
  background: rgba(244, 63, 94, 0.12);
  color: var(--text);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.82rem;
}

.player-bar {
  display: grid;
  grid-template-columns: 1fr 90px 130px;
  gap: 0.6rem;
  margin-bottom: 1.15rem;
}

.handle-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.handle-input-wrap .input-field {
  width: 100%;
  padding-right: 3rem;
}

.regen-handle-btn {
  position: absolute;
  right: 0;
  min-width: 44px;
  min-height: 44px;
  background: transparent;
  border: none;
  font-size: 1.15rem;
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 0.4rem;
  transition: transform 0.15s ease, opacity 0.15s ease;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}

.regen-handle-btn:hover {
  transform: rotate(25deg) scale(1.15);
}

.regen-handle-btn:active {
  transform: rotate(90deg) scale(0.95);
}

.regen-handle-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.input-field {
  background: var(--input-bg);
  border: 1.5px solid var(--border);
  border-radius: 0.7rem;
  color: var(--text);
  padding: 0.6rem 0.8rem;
  font-size: 0.88rem;
  outline: none;
}

.input-field:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-glow);
}

.player-hint {
  font-size: 0.78rem;
  font-weight: 600;
  margin-top: -0.65rem;
  margin-bottom: 0.85rem;
  min-height: 1.1rem;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

.player-hint.ok {
  color: var(--emerald);
}

.player-hint.warn {
  color: var(--amber);
}

.player-hint.err {
  color: var(--rose);
}

.player-hint .suggestion-chip {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  padding: 0.35rem 0.7rem;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  font-size: 0.78rem;
  color: var(--accent-ink);
  cursor: pointer;
}

.player-hint .suggestion-chip:hover {
  border-color: var(--primary);
}

.arena-box {
  background: var(--arena-bg);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1.5rem;
  text-align: center;
  position: relative;
  transition: all 0.2s ease;
}

.arena-box:fullscreen,
.arena-box.arena-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  width: 100vw;
  height: 100vh;
  max-width: none;
  border-radius: 0;
  border: none;
  background: radial-gradient(circle at 15% 15%, var(--bg-glow-1), transparent 40%),
              radial-gradient(circle at 85% 80%, var(--bg-glow-2), transparent 40%),
              var(--fullscreen-bg, var(--bg));
  color: var(--text);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 2rem 1.5rem;
  overflow-y: auto;
}

.arena-box:fullscreen .hud-row,
.arena-box.arena-fullscreen .hud-row {
  width: 100%;
  max-width: 720px;
}

.arena-box:fullscreen .answer-row,
.arena-box.arena-fullscreen .answer-row {
  width: 100%;
  max-width: 440px;
}

.arena-box:fullscreen .equation-text,
.arena-box.arena-fullscreen .equation-text {
  font-size: 4.25rem;
}

.arena-box:fullscreen .result-banner,
.arena-box.arena-fullscreen .result-banner {
  width: 100%;
  max-width: 680px;
}

/* Responsive Numpad scaling in Full Screen */
.arena-box:fullscreen .numpad,
.arena-box.arena-fullscreen .numpad {
  width: 100%;
  max-width: min(520px, 92vw);
  gap: clamp(0.5rem, 1.3vh, 1rem);
  margin: clamp(0.75rem, 2vh, 1.6rem) auto 0;
}

.arena-box:fullscreen .num-btn,
.arena-box.arena-fullscreen .num-btn {
  min-height: clamp(54px, 8.5vh, 88px);
  font-size: clamp(1.4rem, 2.2vw + 1.2vh, 2.4rem);
  border-radius: clamp(0.75rem, 1.2vh, 1.2rem);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.arena-box:fullscreen .num-btn[data-num="clear"],
.arena-box.arena-fullscreen .num-btn[data-num="clear"],
.arena-box:fullscreen .num-btn[data-num="enter"],
.arena-box.arena-fullscreen .num-btn[data-num="enter"] {
  font-size: clamp(1.05rem, 1.5vw + 0.9vh, 1.7rem);
}

/* Full Screen Screen-Size Adaptive Height Breakpoints */
@media (max-height: 760px) {
  .arena-box:fullscreen,
  .arena-box.arena-fullscreen {
    padding: 1rem 1rem;
    justify-content: flex-start;
  }

  .arena-box:fullscreen .equation-text,
  .arena-box.arena-fullscreen .equation-text {
    font-size: clamp(2.4rem, 6.5vh, 3.4rem);
    margin: 0.2rem 0;
  }

  .arena-box:fullscreen .answer-row,
  .arena-box.arena-fullscreen .answer-row {
    margin-bottom: 0.25rem;
  }

  .arena-box:fullscreen .answer-input,
  .arena-box.arena-fullscreen .answer-input {
    font-size: 1.5rem;
    padding: 0.5rem 1rem;
  }

  .arena-box:fullscreen .numpad,
  .arena-box.arena-fullscreen .numpad {
    max-width: min(440px, 85vw);
    gap: 0.45rem;
    margin-top: 0.4rem;
  }

  .arena-box:fullscreen .num-btn,
  .arena-box.arena-fullscreen .num-btn {
    min-height: clamp(42px, 6.5vh, 52px);
    font-size: 1.25rem;
    padding: 0.4rem;
  }
}

@media (max-height: 520px) {
  .arena-box:fullscreen,
  .arena-box.arena-fullscreen {
    padding: 0.5rem;
  }

  .arena-box:fullscreen .hud-row,
  .arena-box.arena-fullscreen .hud-row {
    font-size: 0.8rem;
    margin-bottom: 0.25rem;
  }

  .arena-box:fullscreen .equation-text,
  .arena-box.arena-fullscreen .equation-text {
    font-size: 2rem;
  }

  .arena-box:fullscreen .numpad,
  .arena-box.arena-fullscreen .numpad {
    max-width: min(380px, 90vw);
    gap: 0.3rem;
    margin-top: 0.25rem;
  }

  .arena-box:fullscreen .num-btn,
  .arena-box.arena-fullscreen .num-btn {
    min-height: 36px;
    font-size: 1.1rem;
    padding: 0.25rem;
  }
}

@media (min-height: 950px) and (min-width: 1024px) {
  .arena-box:fullscreen .numpad,
  .arena-box.arena-fullscreen .numpad {
    max-width: 540px;
    gap: 1rem;
    margin-top: 2rem;
  }

  .arena-box:fullscreen .num-btn,
  .arena-box.arena-fullscreen .num-btn {
    min-height: 86px;
    font-size: 2.4rem;
    border-radius: 1.25rem;
  }
}

.equation-text.countdown {
  font-size: 4.2rem;
  color: var(--primary);
}

.numpad-toggle-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.numpad-toggle-row .btn-secondary {
  min-height: 44px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.profile-dial-drawer {
  margin-top: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 0.85rem;
  background: var(--surface-alt);
  padding: 0.4rem 0.85rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.profile-dial-drawer:has(.drawer-summary:focus-visible) {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.drawer-summary {
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text);
  min-height: 44px;
  display: flex;
  align-items: center;
  list-style: none;
  outline: none !important;
  box-shadow: none !important;
  border-radius: 0.65rem;
}

.drawer-body {
  padding-top: 0.75rem;
}

.lb-meta {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.15rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.num-btn-enter {
  grid-column: 1 / -1;
}

.input-field,
.custom-select-trigger,
.btn-secondary,
.theme-menu-btn {
  min-height: 44px;
}

.hud-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.hud-card {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 0.7rem;
  padding: 0.5rem;
}

.hud-label {
  display: block;
  font-size: 0.68rem;
  text-transform: uppercase;
  color: var(--muted);
}

.hud-value {
  font-size: 1.05rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.hud-value.penalty {
  color: var(--rose);
}

.hud-value.progress {
  color: var(--emerald);
}

.equation-stage {
  min-height: 110px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 0.5rem 0 1rem;
}

.equation-text {
  font-size: 3rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.equation-sub {
  font-size: 0.86rem;
  color: var(--muted);
  margin-top: 0.35rem;
}

.answer-row {
  display: flex;
  justify-content: center;
  max-width: 380px;
  margin: 0 auto 0.65rem;
}

.answer-input {
  width: 100%;
  background: var(--input-bg);
  border: 2px solid var(--border);
  border-radius: 0.85rem;
  color: var(--text);
  font-size: 1.55rem;
  font-weight: 800;
  text-align: center;
  padding: 0.65rem 0.9rem;
  outline: none;
  font-variant-numeric: tabular-nums;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.answer-input[readonly] {
  cursor: pointer;
  border-color: var(--primary);
  box-shadow: 0 0 16px var(--primary-glow);
}

.answer-input[readonly]::placeholder {
  color: var(--pill-active-text);
  opacity: 0.9;
  font-weight: 800;
}

.answer-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 22px var(--primary-glow);
}

.answer-input.flash-ok {
  border-color: var(--emerald);
  background: rgba(16, 185, 129, 0.14);
}

.answer-input.flash-err {
  border-color: var(--rose);
  background: rgba(244, 63, 94, 0.16);
}

.answer-input.input-paused {
  border-color: var(--amber) !important;
  background: rgba(180, 83, 9, 0.12) !important;
  box-shadow: 0 0 14px rgba(180, 83, 9, 0.35) !important;
}

.btn-secondary {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 0.5rem 0.95rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.btn-secondary:hover {
  border-color: var(--primary);
}

.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.65rem;
  width: 100%;
  max-width: 380px;
  margin: 1rem auto 0;
}

.numpad.hidden {
  display: none;
}

.num-btn {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 0.8rem;
  padding: 0.85rem 0.6rem;
  min-height: 56px;
  font-size: 1.35rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transition: transform 0.08s ease, background-color 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
}

.num-btn:hover {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.08);
}

.num-btn:active {
  background: var(--pill-active-bg);
  transform: scale(0.96);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.num-btn[data-num="clear"] {
  color: var(--muted);
  font-size: 1.05rem;
  letter-spacing: 0.04em;
  font-weight: 700;
}

.num-btn[data-num="enter"] {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
  font-size: 1.15rem;
  font-weight: 800;
  box-shadow: 0 2px 6px rgba(3, 105, 161, 0.25);
}

html[data-theme="dark"] .num-btn[data-num="enter"] {
  color: #0b1120;
}

.num-btn[data-num="enter"]:hover {
  filter: brightness(0.92);
  box-shadow: 0 4px 10px rgba(3, 105, 161, 0.35);
}

.num-btn[data-num="enter"]:active {
  transform: scale(0.96);
}

.result-banner {
  margin-top: 1.15rem;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.35);
  border-radius: 0.9rem;
  padding: 1rem;
  text-align: left;
}

.result-banner.hidden {
  display: none;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
  margin-top: 0.75rem;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.9rem;
}

.filter-select {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  padding: 0.45rem 0.65rem;
  font-size: 0.8rem;
}

/* Custom Accessible Dropdowns (Theme-Matched, Zero OS Native Popups) */
.custom-select-wrap {
  position: relative;
  display: inline-flex;
  min-width: 0;
  width: 100%;
}

.filter-bar .custom-select-wrap {
  flex: 1 1 calc(25% - 0.5rem);
  min-width: 110px;
}

.player-bar .custom-select-wrap {
  width: 100%;
}

.player-bar .custom-select-trigger {
  background: var(--input-bg);
  border: 1.5px solid var(--border);
  border-radius: 0.7rem;
  padding: 0.6rem 0.75rem;
  font-size: 0.88rem;
  height: 100%;
}

.custom-select-trigger {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  padding: 0.45rem 0.65rem;
  font-size: 0.8rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  box-sizing: border-box;
  text-align: left;
  transition: border-color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
  white-space: nowrap;
  user-select: none;
}

.custom-select-trigger:hover {
  border-color: var(--primary);
  background: var(--surface);
}

.custom-select-trigger:focus-visible {
  outline: 2px solid var(--primary) !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 10px var(--primary-glow) !important;
}

.custom-select-trigger[aria-expanded="true"] {
  border-color: var(--primary);
  box-shadow: 0 0 8px var(--primary-glow);
}

.custom-select-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1 1 auto;
}

.custom-select-caret {
  font-size: 0.7rem;
  color: var(--muted);
  transition: transform 0.2s ease;
  flex: 0 0 auto;
}

.custom-select-trigger[aria-expanded="true"] .custom-select-caret {
  transform: rotate(180deg);
}

.custom-select-menu {
  position: absolute;
  top: calc(100% + 0.35rem);
  left: 0;
  z-index: 9999;
  min-width: 100%;
  max-width: 280px;
  box-sizing: border-box;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 0.35rem;
  box-shadow: 0 12px 32px -4px rgba(0, 0, 0, 0.4), 0 0 20px var(--primary-glow);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  max-height: none;
  overflow-y: visible;
  overscroll-behavior: contain;
}

.filter-bar .custom-select-menu {
  max-height: none;
  overflow-y: visible;
  min-width: max(100%, 195px);
  padding: 0.42rem;
  gap: 0.25rem;
}

.filter-bar .custom-select-option {
  padding: 0.5rem 0.72rem;
  font-size: 0.84rem;
}

.custom-select-menu::before,
.theme-dropdown-menu::before {
  content: '';
  position: absolute;
  top: -10px;
  left: 0;
  right: 0;
  height: 10px;
}

.custom-select-menu.hidden {
  display: none !important;
}

.custom-select-menu.align-right {
  left: auto;
  right: 0;
}

.custom-select-option {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.5rem 0.65rem;
  min-height: 44px;
  border-radius: 0.45rem;
  border: 1px solid transparent;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  box-sizing: border-box;
  transition: all 0.12s ease;
  outline: none;
}

.custom-select-option:hover,
.custom-select-option:focus-visible,
.custom-select-option.focused {
  background: var(--surface-alt);
  color: var(--text);
  border-color: var(--primary) !important;
  outline: 2px solid var(--primary) !important;
  outline-offset: 1px !important;
  box-shadow: 0 0 8px var(--primary-glow) !important;
}

.custom-select-option.active {
  background: var(--primary) !important;
  color: #ffffff !important;
  border-color: var(--primary) !important;
  font-weight: 700;
  box-shadow: 0 0 10px var(--primary-glow) !important;
}

html[data-theme="dark"] .custom-select-option.active {
  color: #0b1120 !important;
}

.custom-select-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  font-size: 0.75rem;
  color: var(--primary);
  flex: 0 0 auto;
}

.custom-select-option.active .custom-select-check {
  color: #ffffff !important;
}

html[data-theme="dark"] .custom-select-option.active .custom-select-check {
  color: #0b1120 !important;
}

#lb-panel,
aside.panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  box-sizing: border-box;
  min-height: 0;
}

.lb-table-wrap {
  width: 100%;
  max-width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.lb-table-wrap::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.lb-table-wrap::-webkit-scrollbar-track {
  background: transparent;
}

.lb-table-wrap::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.lb-table-wrap::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

.lb-table {
  width: 100%;
  min-width: 0;
  border-collapse: collapse;
  font-size: 0.83rem;
}

.lb-table th {
  text-align: left;
  color: var(--muted);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.55rem 0.45rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 2;
}

.lb-table th.score-header,
.lb-table td.score-cell {
  text-align: right;
  padding-right: 0.75rem;
}

.lb-table td {
  padding: 0.6rem 0.45rem;
  border-bottom: 1px solid var(--row-border);
  font-variant-numeric: tabular-nums;
}

.lb-table tbody tr:focus,
.lb-table tbody tr:focus-visible {
  outline: 2px solid var(--primary) !important;
  outline-offset: -2px !important;
  background: var(--surface-alt);
}

.rank-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.65rem;
  height: 1.65rem;
  border-radius: 0.45rem;
  font-weight: 800;
  font-size: 0.76rem;
  background: var(--surface-alt);
}

.rank-1 {
  background: rgba(245, 158, 11, 0.22);
  color: var(--amber);
  border: 1px solid rgba(245, 158, 11, 0.5);
}

.rank-2 {
  background: rgba(148, 163, 184, 0.22);
  color: var(--text);
}

.rank-3 {
  background: rgba(217, 119, 6, 0.2);
  color: var(--amber);
}

.verified-tag {
  display: inline-block;
  margin-left: 0.3rem;
  color: var(--primary);
  font-size: 0.75rem;
}

.score-cell {
  font-weight: 800;
  color: var(--accent-ink);
}

.empty-cell {
  text-align: center;
  color: var(--muted);
}

.country-tag {
  color: var(--muted);
  font-size: 0.74rem;
}

.hidden {
  display: none !important;
}

.status-tag {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.1rem 0.4rem;
  border-radius: 0.35rem;
  font-size: 0.68rem;
  font-weight: 700;
}

.status-tag.completed {
  background: var(--badge-bg);
  color: var(--emerald);
}

.status-tag.incomplete {
  background: rgba(245, 158, 11, 0.16);
  color: var(--amber);
}

.theme-switcher {
  position: relative;
  z-index: 110;
  display: inline-flex;
  align-items: center;
  width: 205px;
  min-width: 205px;
  max-width: 205px;
  flex: 0 0 205px;
  box-sizing: border-box;
  background: transparent;
  border: none;
  padding: 0;
  margin: 0;
}

.theme-select {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 0.65rem;
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  outline: none;
}

.theme-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-glow);
}

.theme-menu-btn {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.45rem;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 0.65rem;
  padding: 0.38rem 0.65rem;
  font-size: 0.77rem;
  font-weight: 700;
  cursor: pointer;
  outline: none;
  white-space: nowrap;
  overflow: hidden;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#theme-menu-label {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
  flex: 1 1 auto;
}

.theme-menu-btn:focus-visible,
.theme-menu-btn:focus {
  border-color: var(--primary) !important;
  box-shadow: 0 0 8px var(--primary-glow) !important;
  outline: 2px solid var(--primary) !important;
  outline-offset: 2px !important;
}

.theme-caret {
  font-size: 0.72rem;
  color: var(--muted);
  transition: transform 0.2s ease;
}

.theme-menu-btn[aria-expanded="true"] .theme-caret {
  transform: rotate(180deg);
}

.theme-dropdown-menu {
  position: absolute;
  top: calc(100% + 0.35rem);
  right: 0;
  z-index: 9999;
  width: 205px;
  min-width: 205px;
  max-width: 205px;
  box-sizing: border-box;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 0.45rem;
  box-shadow: 0 12px 32px -4px rgba(0, 0, 0, 0.4), 0 0 20px var(--primary-glow);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  max-height: none;
  overflow-y: visible;
  overscroll-behavior: contain;
}

.theme-dropdown-menu.hidden {
  display: none !important;
}

.theme-menu-header {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.15rem 0.25rem 0.35rem;
  border-bottom: 1px solid var(--border);
}

.theme-menu-title {
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--text);
}

.theme-menu-hint {
  font-size: 0.63rem;
  color: var(--muted);
}

.theme-options-grid {
  display: flex;
  flex-direction: column;
  gap: 0.22rem;
}

.theme-option-card {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.6rem;
  min-height: 44px;
  border-radius: 0.45rem;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 0.73rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  outline: none;
  transition: all 0.12s ease;
  width: 100%;
  box-sizing: border-box;
}

.theme-option-card:hover,
.theme-option-card:focus-visible,
.theme-option-card.focused {
  border-color: var(--primary) !important;
  outline: 2px solid var(--primary) !important;
  outline-offset: 1px !important;
  box-shadow: 0 0 8px var(--primary-glow) !important;
}

.theme-option-card.active {
  background: var(--primary) !important;
  color: #ffffff !important;
  border-color: var(--primary) !important;
  box-shadow: 0 0 10px var(--primary-glow) !important;
}

html[data-theme="dark"] .theme-option-card.active {
  color: #0b1120 !important;
}

.theme-swatch {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
  box-shadow: 0 0 3px rgba(0, 0, 0, 0.25);
}

.swatch-slate { background: #64748b; }
.swatch-sage { background: #10b981; }
.swatch-clay { background: #ea580c; }
.swatch-twilight { background: #8b5cf6; }
.swatch-warmwhite { background: #f59e0b; }
.swatch-stone { background: #78716c; }
.swatch-dark { background: #06b6d4; }
.swatch-auto { background: linear-gradient(135deg, #f59e0b 50%, #06b6d4 50%); }

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border-width: 0 !important;
}

.site-footer {
  margin-top: 1.5rem;
  padding: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.footer-link {
  background: transparent;
  border: none;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: underline;
  padding: 0 4px;
}

.footer-link:hover {
  color: var(--text);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  backdrop-filter: blur(6px);
}

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1.25rem;
  max-width: 580px;
  width: 100%;
  padding: 1.75rem;
  box-shadow: var(--panel-shadow);
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 1.25rem;
  font-weight: 800;
}

.modal-close-icon {
  background: transparent;
  border: none;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  color: var(--muted);
  cursor: pointer;
}

.modal-body {
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.modal-body ul {
  padding-left: 1.25rem;
}

.modal-body li {
  margin-bottom: 0.35rem;
}

.cookie-badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 9999px;
  background: var(--badge-bg);
  color: var(--emerald);
  font-size: 0.72rem;
  font-weight: 800;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
  border: none;
  border-radius: 0.75rem;
  padding: 0.65rem 1.25rem;
  min-height: 44px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  align-self: flex-end;
  transition: opacity 0.15s ease;
}

html[data-theme="dark"] .btn-primary {
  color: #0b1120;
}

.privacy-layout {
  max-width: 860px;
  margin: 0 auto;
  padding: 24px 16px;
}
.privacy-topbar { margin-bottom: 24px; }
.privacy-card { padding: 28px; line-height: 1.65; }
.privacy-card h2 { font-size: 1.4rem; margin: 0 0 12px; }
.privacy-card h3 { font-size: 1.12rem; margin: 20px 0 10px; }
.privacy-card ul { padding-left: 1.25rem; margin: 8px 0 14px; }
.privacy-card li { margin-bottom: 6px; }
.privacy-badge-row { margin-bottom: 18px; }
.privacy-hr { border: 0; border-top: 1px solid var(--border); margin: 22px 0; }
.privacy-link { color: var(--accent-ink); text-decoration: underline; }
.privacy-cta-row { margin-top: 28px; text-align: center; }
.privacy-back-btn {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.privacy-footer {
  margin-top: 28px;
  text-align: center;
  font-size: 0.9rem;
}

.btn-primary:hover {
  opacity: 0.9;
}

/* DevTools Protected View Overlay */
body.devtools-locked > *,
html.devtools-locked > * {
  display: none !important;
}

body.devtools-locked,
html.devtools-locked {
  display: flex !important;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  margin: 0;
  background: var(--bg, #0f172a);
}

body.devtools-locked::after,
html.devtools-locked::after {
  content: "🛡️ Protected View — Developer Tools Disabled";
  display: block;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--muted, #94a3b8);
  background: var(--surface, rgba(30, 41, 59, 0.7));
  border: 1px solid var(--border, rgba(255, 255, 255, 0.1));
  padding: 16px 28px;
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
  text-align: center;
}

/* ==========================================================================
   Mobile Viewport & Device Responsiveness Fixes
   ========================================================================== */
@media (max-width: 640px) {
  body {
    padding: 0.75rem 0.55rem 2.25rem;
  }

  .layout {
    gap: 0.65rem;
  }

  /* Topbar Mobile: Compact single-row brand + theme switch */
  .topbar {
    padding: 0.65rem 0.75rem;
    border-radius: 0.9rem;
    flex-direction: column;
    align-items: stretch;
    gap: 0.55rem;
  }

  .brand {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.45rem;
    width: 100%;
  }

  .brand p {
    font-size: 0.74rem;
    line-height: 1.3;
  }

  .topbar-right {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 0.65rem;
  }

  .global-kpis {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.35rem;
    width: 100%;
  }

  .kpi {
    text-align: center;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 0.55rem;
    padding: 0.4rem 0.2rem;
  }

  .kpi-label {
    font-size: 0.56rem;
    letter-spacing: 0.02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .kpi-val {
    font-size: 0.92rem;
  }

  .theme-switcher {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    flex: 1 1 auto;
    display: flex;
  }

  .theme-menu-btn {
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }

  .theme-dropdown-menu {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    left: 0;
    right: 0;
  }

  /* Panels: Identical width, full viewport fit */
  .panel, .card {
    padding: 1rem 0.85rem;
    border-radius: 0.9rem;
  }

  .panel-header {
    margin-bottom: 0.85rem;
  }

  .panel-title {
    font-size: 1.02rem;
  }

  .selector-group {
    margin-bottom: 0.85rem;
  }

  .selector-label {
    font-size: 0.72rem;
    margin-bottom: 0.35rem;
  }

  /* Challenge & Difficulty Pills: Balanced 2x2 grid with identical sizes */
  .pill-row {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.45rem;
  }

  .settle-pill-row {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.45rem;
  }

  .pill-btn {
    padding: 0.55rem 0.45rem;
    font-size: 0.8rem;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1.25;
    text-align: center;
  }

  /* Player Identity Row: Nickname + Country on top, Claim PIN full width below */
  .player-bar {
    grid-template-columns: 1fr 88px;
    gap: 0.45rem;
    margin-bottom: 0.85rem;
  }

  .handle-input-wrap {
    grid-column: 1 / 2;
    min-width: 0;
  }

  .player-bar .custom-select-wrap {
    grid-column: 2 / 3;
    width: 100%;
  }

  .player-bar .custom-select-trigger {
    padding: 0.55rem 0.35rem;
    font-size: 0.85rem;
  }

  #player-country {
    grid-column: 2 / 3;
    text-align: center;
    padding: 0.55rem 0.35rem;
  }

  #player-pin {
    grid-column: 1 / -1;
    width: 100%;
  }

  /* Arena & HUD: Compact, non-overflowing metrics */
  .arena-box {
    padding: 1rem 0.75rem;
    border-radius: 0.85rem;
  }

  .hud-row {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.3rem;
    margin-bottom: 0.6rem;
  }

  .hud-card {
    padding: 0.35rem 0.25rem;
    text-align: center;
  }

  .hud-label {
    font-size: 0.58rem;
  }

  .hud-value {
    font-size: 0.88rem;
  }

  .equation-stage {
    min-height: 68px;
    margin: 0.15rem 0 0.5rem;
  }

  .equation-text {
    font-size: 2.35rem;
  }

  .equation-sub {
    font-size: 0.78rem;
    line-height: 1.35;
  }

  .answer-input {
    font-size: 1.35rem;
    padding: 0.55rem 0.75rem;
  }

  .numpad-toggle-row {
    flex-wrap: wrap;
    gap: 0.4rem;
  }

  .numpad-toggle-row .btn-secondary {
    flex: 1 1 calc(50% - 0.4rem);
    padding: 0.45rem 0.5rem;
    font-size: 0.78rem;
    text-align: center;
  }

  .numpad {
    max-width: 100%;
    gap: 0.5rem;
    margin-top: 0.75rem;
  }

  .num-btn {
    min-height: 50px;
    font-size: 1.25rem;
    padding: 0.65rem 0.4rem;
  }

  .result-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.45rem;
  }

  /* Leaderboard Filters & Table: Symmetrical 2x2 filter grid & smooth scroll */
  .filter-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.45rem;
    margin-bottom: 0.75rem;
  }

  .filter-select {
    width: 100%;
    font-size: 0.76rem;
    padding: 0.42rem 0.45rem;
    text-overflow: ellipsis;
  }

  .filter-bar .custom-select-wrap {
    width: 100%;
    min-width: 0;
  }

  .custom-select-trigger {
    font-size: 0.76rem;
    padding: 0.42rem 0.45rem;
  }

  .lb-table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 0.55rem;
  }

  .lb-table {
    font-size: 0.76rem;
    min-width: 0;
  }

  .lb-table th {
    padding: 0.45rem 0.3rem;
    font-size: 0.65rem;
  }

  .lb-table td {
    padding: 0.5rem 0.3rem;
  }

  .rank-pill {
    min-width: 1.45rem;
    height: 1.45rem;
    font-size: 0.7rem;
  }

  .status-tag {
    display: block;
    margin-left: 0;
    margin-top: 2px;
    width: fit-content;
    font-size: 0.62rem;
  }

  .country-tag {
    font-size: 0.68rem;
  }

  /* Full Screen Arena Mode on Mobile */
  .arena-box:fullscreen,
  .arena-box.arena-fullscreen {
    padding: 1.25rem 0.85rem;
  }

  .arena-box:fullscreen .equation-text,
  .arena-box.arena-fullscreen .equation-text {
    font-size: 3rem;
  }

  /* Footer */
  .site-footer {
    padding: 1rem 0.85rem;
    border-radius: 0.85rem;
    flex-direction: column;
    text-align: center;
    gap: 0.6rem;
  }
}

@media (max-width: 380px) {
  body {
    padding: 0.5rem 0.35rem 2rem;
  }

  .global-kpis {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.35rem;
  }

  .brand h1 {
    font-size: 1.15rem;
  }

  .equation-text {
    font-size: 2rem;
  }
}
