/* ===== RESET & PROTECTION ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
  overscroll-behavior-y: none;
  -webkit-overflow-scrolling: none;
  position: fixed;
  top: 0;
  left: 0;
}

html {
  overflow: hidden;
}

button, .btn, .btn-icon, .btn-tool, .num-btn, .cell, .stats-tab {
  touch-action: manipulation;
}

.scrollable-container {
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

/* ===== THEME ===== */
:root {
  --bg-primary: #0a0e27;
  --bg-secondary: #111640;
  --surface: rgba(255, 255, 255, 0.04);
  --surface-hover: rgba(255, 255, 255, 0.08);
  --surface-glass: rgba(255, 255, 255, 0.06);
  --border: rgba(255, 255, 255, 0.08);
  --border-light: rgba(255, 255, 255, 0.12);

  --primary: #7c6cf0;
  --primary-light: #9d8ff8;
  --primary-dark: #5a4bd4;
  --primary-glow: rgba(124, 108, 240, 0.3);

  --accent: #00d4aa;
  --accent-light: #33e0be;
  --accent-glow: rgba(0, 212, 170, 0.25);

  --danger: #ff6074;
  --danger-glow: rgba(255, 96, 116, 0.25);

  --warning: #ffb347;

  --text: #f0f0ff;
  --text-secondary: #8888aa;
  --text-dim: #555577;

  --given-color: #e8e8ff;
  --filled-color: #7c6cf0;
  --error-color: #ff6074;

  --board-bg: rgba(255, 255, 255, 0.03);
  --cell-bg: rgba(255, 255, 255, 0.02);
  --cell-selected: rgba(124, 108, 240, 0.2);
  --cell-related: rgba(124, 108, 240, 0.07);
  --cell-same-value: rgba(124, 108, 240, 0.15);
  --cell-opponent: rgba(0, 212, 170, 0.12);

  --grid-thin: rgba(255, 255, 255, 0.08);
  --grid-thick: rgba(255, 255, 255, 0.35);

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;

  --shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 30px var(--primary-glow);

  --vh: 1vh;
}

html {
  background: var(--bg-primary);
  background: linear-gradient(145deg, var(--bg-primary) 0%, var(--bg-secondary) 50%, #0d1235 100%);
  background-attachment: fixed;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: transparent;
  color: var(--text);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  min-height: calc(var(--vh, 1vh) * 100);
  min-height: 100dvh;
}

/* ===== BACKGROUND DECORATION ===== */
#bg-decoration {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}

.bg-circle {
  position: absolute;
  border-radius: 50%;
  -webkit-filter: blur(80px);
  filter: blur(80px);
  opacity: 0.15;
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  will-change: transform;
}
.bg-circle.c1 {
  width: 400px; height: 400px;
  background: var(--primary);
  top: -100px; right: -100px;
  animation: floatBg 20s ease-in-out infinite;
}
.bg-circle.c2 {
  width: 300px; height: 300px;
  background: var(--accent);
  bottom: -50px; left: -80px;
  animation: floatBg 25s ease-in-out infinite reverse;
}
.bg-circle.c3 {
  width: 250px; height: 250px;
  background: var(--primary-light);
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  animation: floatBg 18s ease-in-out infinite 5s;
}

@keyframes floatBg {
  0%, 100% { transform: translate(0, 0); }
  33% { transform: translate(30px, -20px); }
  66% { transform: translate(-20px, 30px); }
}

/* ===== UI ROOT ===== */
#ui-root {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 500px;
  z-index: 1;
}

/* ===== SCREENS ===== */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.35s ease, visibility 0.35s, transform 0.35s ease;
  transform: scale(0.97);
  padding: 16px;
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  padding-left: calc(16px + env(safe-area-inset-left, 0px));
  padding-right: calc(16px + env(safe-area-inset-right, 0px));
  overflow: hidden;
}

.screen.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: scale(1);
}

.screen.leaving {
  opacity: 0;
  transform: scale(1.02);
}

/* ===== MENU SCREEN ===== */
.menu-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
  width: 100%;
  max-width: 380px;
  max-height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior-y: contain;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding: 16px 0;
}

.menu-content::-webkit-scrollbar {
  display: none;
}

.logo-section {
  text-align: center;
}

.logo-title {
  font-size: 52px;
  font-weight: 900;
  letter-spacing: 10px;
  text-indent: 10px;
  background: linear-gradient(135deg, #fff 0%, var(--primary-light) 40%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 0 20px var(--primary-glow));
  line-height: 1.1;
  animation: titlePulse 4s ease-in-out infinite;
}

@keyframes titlePulse {
  0%, 100% { filter: drop-shadow(0 0 20px var(--primary-glow)); }
  50% { filter: drop-shadow(0 0 35px var(--primary-glow)) drop-shadow(0 0 10px var(--accent-glow)); }
}

.logo-subtitle {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 12px;
  text-transform: uppercase;
  text-align: center;
  margin: 4px auto 16px;
  color: var(--accent);
  text-indent: 12px;
  position: relative;
  opacity: 0.85;
}

.logo-subtitle::before,
.logo-subtitle::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 32px;
  height: 1px;
}

.logo-subtitle::before {
  right: 100%;
  margin-right: 6px;
  background: linear-gradient(90deg, transparent, var(--accent));
}

.logo-subtitle::after {
  left: calc(100% - 12px);
  margin-left: 6px;
  background: linear-gradient(90deg, var(--accent), transparent);
}

.elo-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 16px;
  background: rgba(15, 19, 50, 0.85);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 16px;
  font-weight: 600;
  color: var(--warning);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.elo-badge svg {
  color: var(--warning);
  fill: var(--warning);
  width: 14px;
  height: 14px;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

/* ===== BUTTONS ===== */
.btn {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--text);
  text-align: left;
  width: 100%;
  min-height: 48px;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  box-shadow: 0 4px 20px var(--primary-glow);
}

.btn-primary:active {
  box-shadow: 0 2px 10px var(--primary-glow);
}

.btn-accent {
  background: linear-gradient(135deg, #00b89c 0%, #008f7a 100%);
  box-shadow: 0 4px 20px var(--accent-glow);
}

.btn-accent:active {
  box-shadow: 0 2px 10px var(--accent-glow);
}

.btn-warning {
  background: linear-gradient(135deg, #e6a020 0%, #c48510 100%);
  box-shadow: 0 4px 20px rgba(255, 179, 71, 0.25);
  color: #fff;
}

.btn-warning:active {
  box-shadow: 0 2px 10px rgba(255, 179, 71, 0.25);
}

.btn-secondary {
  background: var(--surface);
  border: 1px solid var(--border);
  justify-content: center;
}

.btn-large {
  padding: 18px 22px;
}

.btn-large svg {
  flex-shrink: 0;
  opacity: 0.8;
}

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

.btn-title {
  font-size: 17px;
  font-weight: 700;
}

.btn-desc {
  font-size: 12px;
  opacity: 0.6;
  font-weight: 400;
}

.btn-icon {
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  border: 1px solid var(--border);
}

.btn-icon:active {
  transform: scale(0.92);
}

.btn-icon.active {
  border-color: var(--primary);
  box-shadow: 0 0 10px var(--primary-glow);
}

.menu-top-btns {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top, 0px));
  right: calc(16px + env(safe-area-inset-right, 0px));
  display: flex;
  gap: 8px;
  z-index: 10;
  transition: opacity 0.2s;
}

.menu-top-btns.hidden {
  opacity: 0;
  pointer-events: none;
}

.menu-row {
  display: flex;
  gap: 10px;
  width: 100%;
}

.menu-row .btn-leaderboard {
  flex: 1;
}

/* ===== DIFFICULTY ===== */
.panel {
  background: rgba(15, 19, 50, 0.92);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 32px 24px;
  width: 100%;
  max-width: 380px;
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
}

@supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  .panel {
    background: var(--surface-glass);
  }
}

.panel-title {
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 24px;
  color: var(--text);
}

.difficulty-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.btn-diff {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 54px;
}

.btn-diff:active {
  transform: scale(0.97);
}

.btn-diff.easy { border-left: 3px solid var(--accent); }
.btn-diff.medium { border-left: 3px solid var(--warning); }
.btn-diff.hard { border-left: 3px solid var(--danger); }

.btn-diff.easy:active { background: rgba(0, 212, 170, 0.1); }
.btn-diff.medium:active { background: rgba(255, 179, 71, 0.1); }
.btn-diff.hard:active { background: rgba(255, 96, 116, 0.1); }

.diff-stars {
  font-size: 14px;
  min-width: 44px;
}
.btn-diff.easy .diff-stars { color: var(--accent); }
.btn-diff.medium .diff-stars { color: var(--warning); }
.btn-diff.hard .diff-stars { color: var(--danger); }

.diff-name {
  flex: 1;
}

/* ===== MATCHMAKING ===== */
.matchmaking-panel {
  text-align: center;
}

.search-animation {
  position: relative;
  width: 100px;
  height: 100px;
  margin: 0 auto 24px;
}

.search-ring {
  position: absolute;
  inset: 0;
  border: 2px solid var(--primary);
  border-radius: 50%;
  animation: searchPulse 2s ease-out infinite;
}

.search-ring.r2 {
  animation-delay: 1s;
}

@keyframes searchPulse {
  0% { transform: scale(0.5); opacity: 1; }
  100% { transform: scale(1.5); opacity: 0; }
}

.search-icon {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  color: var(--primary-light);
}

.match-text {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
}

.match-range {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

/* ===== GAME SCREEN ===== */
#game-screen {
  justify-content: flex-start;
  padding: 0;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

.game-layout {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  max-width: 500px;
  padding: 8px 0;
  gap: 8px;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px;
  flex-shrink: 0;
}

.game-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.game-mode {
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.game-timer {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.game-score {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
}

.score-label {
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.score-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--primary-light);
  font-variant-numeric: tabular-nums;
}

/* ===== DUEL PANEL ===== */
.duel-panel {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px;
  background: rgba(15, 19, 50, 0.85);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  flex-shrink: 0;
}

.duel-panel.active {
  display: flex;
}

.opponent-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  width: 100%;
}

.opp-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  object-fit: cover;
  flex-shrink: 0;
}

.opp-avatar[src=""], .opp-avatar:not([src]) {
  display: none;
}

.opp-name {
  font-weight: 600;
  color: var(--accent-light);
}

.opp-elo {
  color: var(--warning);
  font-size: 12px;
}

.opp-score {
  margin-left: auto;
  color: var(--text-secondary);
}

.opp-score b {
  color: var(--accent-light);
}

.opponent-board-wrap {
  width: 100%;
  max-width: 160px;
}

/* ===== SUDOKU BOARD ===== */
.board-area {
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 1;
  min-height: 0;
  padding: 0 8px;
  overflow: hidden;
}

.sudoku-board {
  width: 100%;
  max-width: min(400px, 100%);
  max-height: 100%;
  aspect-ratio: 1;
}

.sudoku-board.small {
  max-width: 180px;
}

.board-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  width: 100%;
  height: 100%;
  background: var(--board-bg);
  border: 2px solid var(--grid-thick);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow), 0 0 60px rgba(124, 108, 240, 0.08);
  touch-action: none;
}

.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--cell-bg);
  border-right: 1px solid var(--grid-thin);
  border-bottom: 1px solid var(--grid-thin);
  cursor: pointer;
  transition: background 0.15s ease;
}

.cell:nth-child(9n) { border-right: none; }
.cell:nth-child(n+73) { border-bottom: none; }

.cell.box-left {
  border-left: 2.5px solid var(--grid-thick);
}
.cell.box-top {
  border-top: 2.5px solid var(--grid-thick);
}

.cell.selected {
  background: var(--cell-selected) !important;
  box-shadow: inset 0 0 0 2px var(--primary);
}

.cell.same-row {
  background: var(--cell-related);
}

.cell.same-value {
  background: var(--cell-same-value);
}

.cell.opponent-filled {
  background: var(--cell-opponent);
}

.cell-value {
  font-size: clamp(16px, 5vw, 28px);
  font-weight: 700;
  line-height: 1;
  transition: transform 0.15s ease, color 0.15s ease;
}

.cell.given .cell-value {
  color: var(--given-color);
}

.cell.filled .cell-value {
  color: var(--filled-color);
}

.cell.error .cell-value {
  color: var(--error-color) !important;
}

.small .cell-value {
  font-size: clamp(8px, 2vw, 13px);
}

/* Notes */
.cell-notes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  position: absolute;
  inset: 0;
  padding: 1px;
  overflow: hidden;
}

.note-num {
  font-size: clamp(8px, 2vw, 11px);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  visibility: hidden;
  line-height: 1;
  overflow: hidden;
}

/* ===== CELL ANIMATIONS ===== */
.cell.correct-anim .cell-value {
  animation: popIn 0.4s ease;
}

@keyframes popIn {
  0% { transform: scale(0.5); opacity: 0.5; }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); opacity: 1; }
}

.cell.shake {
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

.cell.hint-anim {
  animation: hintGlow 0.7s ease;
}

@keyframes hintGlow {
  0% { background: rgba(0, 212, 170, 0.4); }
  100% { background: var(--cell-bg); }
}

.cell.opponent-pulse {
  animation: oppPulse 0.6s ease;
}

@keyframes oppPulse {
  0% { background: rgba(0, 212, 170, 0.4); }
  100% { background: var(--cell-opponent); }
}

/* ===== CONTROLS ===== */
.controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 8px;
  flex-shrink: 0;
}

.numpad {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 4px;
  touch-action: none;
}

.num-btn {
  aspect-ratio: 1;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: clamp(16px, 4vw, 22px);
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}

.num-btn:active {
  background: var(--primary);
  transform: scale(0.92);
  box-shadow: 0 0 15px var(--primary-glow);
}

.tool-buttons {
  display: flex;
  justify-content: center;
  gap: 12px;
}

.btn-tool {
  width: 48px;
  height: 48px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.btn-tool:active {
  background: var(--surface-hover);
  transform: scale(0.92);
}

.btn-tool.active {
  background: var(--primary-glow);
  color: var(--primary-light);
  border-color: var(--primary);
}

.btn-hint-ad {
  position: relative;
}

.hint-ad-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 18px;
  height: 18px;
  background: var(--accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 2px 6px var(--accent-glow);
}

/* ===== FLOATING SCORE ===== */
.floating-score {
  position: fixed;
  pointer-events: none;
  font-size: 18px;
  font-weight: 800;
  z-index: 100;
  animation: floatUp 1s ease-out forwards;
}

.floating-score.positive { color: var(--accent); }
.floating-score.negative { color: var(--danger); }
.floating-score.bonus-float { color: var(--warning); font-size: 16px; }

@keyframes floatUp {
  0% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-50px) scale(0.8); }
}

/* ===== RESULT ===== */
.result-panel {
  text-align: center;
}

.result-title {
  font-size: 28px;
  font-weight: 800;
  margin-bottom: 24px;
  letter-spacing: 1px;
}

.result-title.win { color: var(--accent); }
.result-title.lose { color: var(--danger); }
.result-title.draw { color: var(--warning); }

.result-stats {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.stat-label {
  color: var(--text-secondary);
  font-size: 14px;
}

.stat-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.result-section {
  display: none;
  margin-bottom: 16px;
}

.result-section.active {
  display: block;
}

.elo-result {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 16px;
  background: var(--surface);
  border-radius: var(--radius-md);
  margin-top: 8px;
}

.elo-change {
  font-size: 32px;
  font-weight: 800;
}

.elo-change.positive { color: var(--accent); }
.elo-change.negative { color: var(--danger); }

.elo-new {
  font-size: 14px;
  color: var(--text-secondary);
}

.elo-new b {
  color: var(--warning);
}

.result-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 20px;
}

.result-buttons .btn {
  justify-content: center;
}

/* ===== LEADERBOARD ===== */
.btn-leaderboard {
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
}

.btn-leaderboard svg {
  flex-shrink: 0;
  opacity: 0.7;
}

.leaderboard-panel {
  display: flex;
  flex-direction: column;
  max-height: 80vh;
  max-height: calc(var(--vh, 1vh) * 80);
}

.lb-list {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-width: none;
  -ms-overflow-style: none;
  min-height: 200px;
  max-height: 50vh;
  max-height: calc(var(--vh, 1vh) * 50);
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.lb-list::-webkit-scrollbar {
  display: none;
}

.lb-loading {
  text-align: center;
  color: var(--text-secondary);
  padding: 40px 0;
  font-size: 14px;
}

.lb-empty {
  text-align: center;
  color: var(--text-dim);
  padding: 40px 0;
  font-size: 14px;
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}

.lb-row.is-self {
  background: rgba(124, 108, 240, 0.12);
  border-color: var(--primary);
}

.lb-row.top-1 .lb-rank { color: #ffd700; }
.lb-row.top-2 .lb-rank { color: #c0c0c0; }
.lb-row.top-3 .lb-rank { color: #cd7f32; }

.lb-rank {
  font-size: 16px;
  font-weight: 800;
  min-width: 28px;
  text-align: center;
  color: var(--text-dim);
}

.lb-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface-hover);
}

.lb-avatar-placeholder {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--surface-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-dim);
  font-size: 14px;
}

.lb-name {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-row.is-self .lb-name {
  color: var(--primary-light);
}

.lb-score {
  font-size: 16px;
  font-weight: 700;
  color: var(--warning);
  font-variant-numeric: tabular-nums;
}

.lb-separator {
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  padding: 4px 0;
  letter-spacing: 4px;
}

/* ===== STATS ===== */
.stats-panel {
  display: flex;
  flex-direction: column;
  max-height: 80vh;
  max-height: calc(var(--vh, 1vh) * 80);
}

.stats-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.stats-tab {
  flex: 1;
  padding: 12px 6px;
  min-height: 44px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s ease;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stats-tab.active {
  background: var(--primary);
  color: var(--text);
}

.stats-content {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-width: none;
  -ms-overflow-style: none;
  margin-bottom: 16px;
}

.stats-content::-webkit-scrollbar {
  display: none;
}

/* ===== RESPONSIVE ===== */

/* Small phones */
@media (max-width: 400px) {
  .logo-title {
    font-size: 40px;
    letter-spacing: 8px;
    text-indent: 8px;
  }
  .menu-content {
    gap: 20px;
  }
  .game-layout {
    gap: 4px;
  }
  .numpad {
    gap: 3px;
  }
}

@media (max-height: 600px) {
  .menu-content {
    gap: 16px;
  }
  .logo-title {
    font-size: 36px;
    letter-spacing: 6px;
    text-indent: 6px;
  }
  .logo-subtitle {
    font-size: 14px;
    letter-spacing: 8px;
    text-indent: 8px;
    margin: 2px auto 8px;
  }
  .btn-large {
    padding: 12px 18px;
  }
}

/* Tall screens — more breathing room */
@media (min-height: 700px) {
  .game-layout {
    gap: 12px;
  }
}

/* Short screens — compact */
@media (max-height: 650px) {
  .game-layout {
    gap: 2px;
    padding: 4px 0;
  }
  .game-header {
    padding: 2px 8px;
  }
  .controls {
    gap: 6px;
    padding: 2px 8px;
  }
  .duel-panel {
    padding: 4px 8px;
  }
  .opponent-board-wrap {
    max-width: 120px;
  }
}

/* Desktop / wide screens — always vertical layout, centered */
@media (min-width: 600px) {
  #ui-root {
    max-width: 480px;
    margin: 0 auto;
  }

  .num-btn {
    min-width: 44px;
    min-height: 44px;
    font-size: 20px;
  }

  .cell-value {
    font-size: 24px;
  }

  .small .cell-value {
    font-size: 11px;
  }
}

/* Landscape on mobile — board + controls side by side */
@media (max-height: 500px) and (orientation: landscape) {
  #ui-root {
    max-width: 100%;
  }

  #game-screen {
    padding: 0 8px;
  }

  .game-layout {
    flex-direction: row;
    flex-wrap: wrap;
    max-width: 100%;
    align-items: flex-start;
  }

  .game-header {
    width: 100%;
    flex-shrink: 0;
  }

  .duel-panel {
    width: 100%;
    flex-direction: row;
    align-items: center;
    gap: 12px;
  }

  .duel-panel .opponent-board-wrap {
    max-width: 120px;
  }

  .board-area {
    flex: none;
    width: 50%;
    max-height: calc(100vh - 80px);
    padding: 0 4px;
  }

  .sudoku-board {
    max-width: 100%;
  }

  .controls {
    flex: 1;
    justify-content: center;
    align-items: center;
    padding: 4px;
  }

  .numpad {
    grid-template-columns: repeat(3, 1fr);
    max-width: 180px;
    gap: 6px;
  }

  .num-btn {
    min-width: 48px;
    min-height: 48px;
  }
}
