:root, [data-theme="dark"] {
  --bg: #070709;
  --bg-gradient: radial-gradient(circle at 50% 30%, rgba(255, 30, 80, 0.07), transparent 70%),
                 radial-gradient(circle at 80% 90%, rgba(255, 80, 0, 0.03), transparent 60%);
  --card: rgba(18, 18, 24, 0.85);
  --card-solid: #121218;
  --card-2: rgba(28, 28, 38, 0.85);
  --border: rgba(255, 255, 255, 0.08);
  --border-bright: rgba(255, 255, 255, 0.16);
  --border-active: #ff1e50;
  --white: #f8fafc;
  --grey: #94a3b8;
  --grey-dark: #475569;
  --red: #ff1e50;
  --red-glow: rgba(255, 30, 80, 0.35);
  --accent: #ff3b68;

  /* Surfaces (inset panels, inputs, chips) */
  --surface-inset: rgba(10, 10, 15, 0.9);
  --surface-soft: rgba(28, 28, 38, 0.6);
  --surface-elevated: rgba(22, 22, 30, 0.96);
  --input-bg: rgba(10, 10, 15, 0.8);
  --modal-overlay: rgba(0, 0, 0, 0.88);
  --title-grad-1: #ffffff;
  --title-grad-2: #d1d5db;

  /* Sudoku grid lines */
  --sudoku-grid-line: rgba(255, 255, 255, 0.15);
  --sudoku-grid-border: rgba(255, 255, 255, 0.4);
  --sudoku-given-bg: rgba(30, 30, 42, 0.9);

  /* Canvas games (read into JS via getComputedStyle) */
  --canvas-bg: #0e0e14;
  --canvas-grid: rgba(255, 255, 255, 0.03);
  --canvas-fg: #ffffff;
  --canvas-fg-dim: rgba(240, 240, 255, 0.85);

  color-scheme: dark;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --app-max-w: 420px;
  --ctrl-scale: 1;
}

[data-theme="light"] {
  --bg: #eef0f4;
  --bg-gradient: radial-gradient(circle at 50% 30%, rgba(255, 30, 80, 0.05), transparent 70%),
                 radial-gradient(circle at 80% 90%, rgba(255, 80, 0, 0.03), transparent 60%);
  --card: rgba(255, 255, 255, 0.85);
  --card-solid: #ffffff;
  --card-2: rgba(255, 255, 255, 0.97);
  --border: rgba(15, 15, 25, 0.1);
  --border-bright: rgba(15, 15, 25, 0.22);
  --border-active: #e0114a;
  --white: #16161d;
  --grey: #5b6473;
  --grey-dark: #94a0b3;
  --red: #e0114a;
  --red-glow: rgba(224, 17, 74, 0.25);
  --accent: #e0114a;

  --surface-inset: rgba(15, 15, 25, 0.05);
  --surface-soft: rgba(15, 15, 25, 0.04);
  --surface-elevated: rgba(255, 255, 255, 0.98);
  --input-bg: #ffffff;
  --modal-overlay: rgba(20, 20, 30, 0.5);
  --title-grad-1: #16161d;
  --title-grad-2: #454b58;

  --sudoku-grid-line: rgba(15, 15, 25, 0.15);
  --sudoku-grid-border: rgba(15, 15, 25, 0.35);
  --sudoku-given-bg: rgba(15, 15, 25, 0.05);

  --canvas-bg: #e2e5eb;
  --canvas-grid: rgba(15, 15, 25, 0.06);
  --canvas-fg: #16161d;
  --canvas-fg-dim: rgba(22, 22, 29, 0.75);

  color-scheme: light;
}
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
html, body {
  height: 100%;
  height: 100dvh;
  width: 100%;
  overscroll-behavior: none;
  overflow: hidden;
}
body {
  background: var(--bg);
  background-image: var(--bg-gradient);
  color: var(--white);
  font-family: 'JetBrains Mono', monospace;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(10px + var(--safe-t)) calc(12px + var(--safe-r)) calc(10px + var(--safe-b)) calc(12px + var(--safe-l));
  touch-action: manipulation;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.35s ease, color 0.35s ease;
}
.box, .modal-overlay-fade, .avatar-badge, .profile-card, .record-row, .game-tile,
.diff-tile, .avatar-item, #sudoku-grid, .modal, canvas, .tetris-side, #tetris-next,
.records-dd .dropdown-trigger, input[type="text"] {
  transition: background-color 0.25s ease, border-color 0.25s ease, color 0.25s ease, box-shadow 0.25s ease;
}

/* ==========================================
   SPLASH SCREEN - FADE + ZOOM ONLY
   ========================================== */
#splash-screen {
  position: fixed;
  top: 0; left: 0;
  width: 100vw; height: 100vh; height: 100dvh;
  background: #050507;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  transition: opacity 0.6s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.6s ease;
}
#splash-screen.fade-out { opacity: 0; visibility: hidden; }
.splash-content {
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: scale(0.78);
  animation: splashFadeZoomIn 1s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
.splash-svg-container {
  width: 110px;
  height: 110px;
  filter: drop-shadow(0 0 0px rgba(255, 30, 80, 0));
  animation: splashGlow 1s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
@keyframes splashFadeZoomIn {
  0%   { opacity: 0; transform: scale(0.78); }
  60%  { opacity: 1; }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes splashGlow {
  0%   { filter: drop-shadow(0 0 0px rgba(255, 30, 80, 0)); }
  100% { filter: drop-shadow(0 0 20px rgba(255, 30, 80, 0.45)); }
}

/* ==========================================
   SHARED / GENERIC / CONTAINERS
   ========================================== */
.view {
  display: none;
  width: 100%;
  max-width: var(--app-max-w);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  height: 100%;
  max-height: 100%;
  margin: 0 auto;
  position: relative;
}
.view.active {
  display: flex;
  animation: viewFadeIn 0.22s ease-out forwards;
}
@keyframes viewFadeIn {
  from { opacity: 0; transform: translateY(4px) scale(0.99); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.box {
  background: var(--card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 22px 18px;
  width: 100%;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,0.65), inset 0 1px 0 rgba(255,255,255,0.06);
}

.title {
  font-size: 1.35rem;
  font-weight: 800;
  margin-bottom: 4px;
  letter-spacing: 0.08em;
  background: linear-gradient(180deg, var(--title-grad-1), var(--title-grad-2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.subtitle {
  font-size: 0.7rem;
  color: var(--grey);
  margin-bottom: 14px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

input[type="text"] {
  width: 100%;
  padding: 12px 14px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--white);
  font-family: 'JetBrains Mono', monospace;
  font-size: 15px;
  border-radius: 10px;
  margin-bottom: 12px;
  text-align: center;
  outline: none;
  letter-spacing: 0.05em;
  transition: border-color 0.2s, box-shadow 0.2s;
}
input[type="text"]:focus {
  border-color: var(--red);
  box-shadow: 0 0 12px var(--red-glow);
}

.btn {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  background: var(--card-2);
  border: 1px solid var(--border);
  color: var(--white);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
  border-radius: 10px;
  margin-top: 6px;
  transition: border-color 0.18s, transform 0.12s, background 0.18s, box-shadow 0.18s;
  touch-action: manipulation;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn:hover {
  border-color: var(--border-bright);
  background: rgba(38, 38, 52, 0.9);
}
.btn:active {
  transform: scale(0.97);
  border-color: var(--red);
}
.btn.primary {
  border-color: var(--red);
  color: var(--white);
  background: linear-gradient(135deg, rgba(255, 30, 80, 0.25), rgba(255, 30, 80, 0.08));
  box-shadow: 0 0 14px rgba(255, 30, 80, 0.15);
}
.btn.primary:hover {
  background: linear-gradient(135deg, rgba(255, 30, 80, 0.4), rgba(255, 30, 80, 0.15));
  box-shadow: 0 0 20px rgba(255, 30, 80, 0.3);
}

.avatar-grid {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.avatar-item {
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  cursor: pointer;
  background: var(--surface-inset);
  font-size: 0.95rem;
  transition: all 0.15s ease;
  touch-action: manipulation;
}
.avatar-item:hover {
  border-color: var(--border-bright);
}
.avatar-item.active {
  border-color: var(--red);
  color: var(--red);
  box-shadow: 0 0 14px var(--red-glow), inset 0 0 10px rgba(255,30,80,0.15);
  background: rgba(255,30,80,0.08);
}

.modal {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 100vw; height: 100vh; height: 100dvh;
  background: var(--modal-overlay);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: calc(16px + var(--safe-t)) calc(16px + var(--safe-r)) calc(16px + var(--safe-b)) calc(16px + var(--safe-l));
}
.modal.active { display: flex; animation: viewFadeIn 0.2s ease-out forwards; }
.row-flex { display: flex; gap: 8px; width: 100%; }

.icon-btn {
  flex-shrink: 0;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  color: var(--grey);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 8px 14px;
  min-height: 40px;
  min-width: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, transform 0.1s, background 0.15s;
  touch-action: manipulation;
}
#theme-toggle-btn { font-size: 1rem; padding: 8px 12px; }
.icon-btn:hover {
  border-color: var(--border-bright);
  color: var(--white);
  background: rgba(38, 38, 52, 0.8);
}
.icon-btn:active { transform: scale(0.95); border-color: var(--red); color: var(--red); }

.custom-dropdown { position: relative; display: inline-block; }
.dropdown-trigger {
  background: var(--card-2);
  border: 1px solid var(--border);
  color: var(--white);
  padding: 7px 16px;
  min-height: 44px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.74rem;
  font-weight: 700;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: border-color 0.15s;
}
.dropdown-trigger:hover, .dropdown-trigger:active { border-color: var(--red); }
.dropdown-menu {
  display: none;
  position: absolute;
  top: 100%; right: 0;
  margin-top: 6px;
  background: var(--surface-elevated);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  z-index: 50;
  box-shadow: 0 8px 24px rgba(0,0,0,0.6);
  min-width: 110px;
}
.dropdown-menu.show { display: block; }
.dropdown-opt {
  padding: 9px 14px;
  font-size: 0.72rem;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  color: var(--grey);
  cursor: pointer;
  text-align: right;
  transition: background 0.15s, color 0.15s;
}
.dropdown-opt:hover, .dropdown-opt.active { background: rgba(255,30,80,0.12); color: var(--red); }
.dd-arrow { font-size: 0.55rem; color: var(--red); }

/* ==========================================
   MAIN MENU (minimal home)
   ========================================== */
.menu-wrap {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  justify-content: center;
}
.profile-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(135deg, var(--card-2), var(--card));
  backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px 18px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.06);
  margin-bottom: 4px;
}
.profile-left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.avatar-badge {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-inset);
  border: 1px solid rgba(255, 30, 80, 0.4);
  box-shadow: 0 0 16px rgba(255, 30, 80, 0.2), inset 0 0 12px rgba(255, 30, 80, 0.08);
  color: var(--red);
  font-size: 1.2rem;
  font-weight: 800;
}
.profile-text { display: flex; flex-direction: column; min-width: 0; text-align: left; }
.profile-label { font-size: 0.58rem; color: var(--grey); letter-spacing: 0.16em; margin-bottom: 2px; }
.profile-name { font-size: 0.95rem; font-weight: 800; letter-spacing: 0.03em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.menu-option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
  background: var(--card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px 20px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: border-color 0.2s, transform 0.15s, background 0.2s, box-shadow 0.2s;
  touch-action: manipulation;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}
.menu-option:hover {
  border-color: var(--border-bright);
  background: var(--card-2);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.menu-option:active {
  transform: scale(0.98);
  border-color: var(--red);
}
.menu-option-title { font-size: 1.05rem; font-weight: 800; letter-spacing: 0.08em; color: var(--white); }
.menu-option-sub { font-size: 0.63rem; color: var(--grey); letter-spacing: 0.05em; }

/* ==========================================
   LIST VIEWS (Games / Records shell)
   ========================================== */
.list-wrap {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  height: 100%;
  justify-content: center;
}
.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}
.list-title { font-size: 0.9rem; font-weight: 800; letter-spacing: 0.1em; }
.back-btn {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  color: var(--grey);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 8px 16px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  border-radius: 10px;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 0.15s, color 0.15s, background 0.15s, transform 0.1s;
}
.back-btn:active { transform: scale(0.95); }
.back-btn:hover {
  border-color: var(--border-bright);
  color: var(--white);
}
.back-btn:active { border-color: var(--red); color: var(--red); }

/* --- Game tiles --- */
.game-tiles { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.game-tile {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  transition: border-color 0.2s, transform 0.15s, background 0.2s;
}
.game-tile:hover {
  border-color: var(--border-bright);
  background: var(--card-2);
}
.game-tile-main {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 1;
  min-width: 0;
  cursor: pointer;
  touch-action: manipulation;
}
.game-tile-glyph {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-inset);
  border: 1px solid var(--border);
  color: var(--red);
  font-size: 1.05rem;
  font-weight: 800;
}
.game-tile-text { display: flex; flex-direction: column; min-width: 0; text-align: left; }
.game-tile-name { font-size: 0.86rem; font-weight: 800; letter-spacing: 0.06em; }
.game-tile-sub { font-size: 0.62rem; color: var(--grey); letter-spacing: 0.04em; margin-top: 2px; }
.pill-btn {
  flex-shrink: 0;
  background: rgba(255, 30, 80, 0.1);
  border: 1px solid var(--red);
  color: var(--red);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  padding: 9px 14px;
  min-height: 38px;
  border-radius: 20px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.12s, background 0.15s;
}
.pill-btn:hover { background: rgba(255, 30, 80, 0.25); }
.pill-btn:active { transform: scale(0.94); }

/* --- Difficulty picker (used inside modal) --- */
.diff-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 8px 0; }
.diff-tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  background: var(--surface-inset);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  min-height: 68px;
  cursor: pointer;
  font-family: 'JetBrains Mono', monospace;
  transition: border-color 0.18s, transform 0.12s, background 0.18s, box-shadow 0.18s;
  touch-action: manipulation;
}
.diff-tile:hover {
  border-color: var(--red);
  background: rgba(255, 30, 80, 0.08);
}
.diff-tile:active { transform: scale(0.97); }
.diff-name { font-size: 0.82rem; font-weight: 800; color: var(--white); letter-spacing: 0.06em; }
.diff-dots { display: flex; gap: 4px; }
.diff-dots i { width: 14px; height: 3px; border-radius: 2px; background: rgba(255,255,255,0.12); display: block; }
.diff-dots i.on { background: var(--red); box-shadow: 0 0 8px var(--red-glow); }

/* --- Records --- */
.records-dd { align-self: flex-end; }
.records-list { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.record-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
}
.record-glyph {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-inset);
  border: 1px solid var(--border);
  color: var(--red);
  font-size: 0.9rem;
  font-weight: 800;
}
.record-name { flex: 1; font-size: 0.78rem; font-weight: 700; letter-spacing: 0.05em; text-align: left; }
.record-value { font-size: 0.88rem; font-weight: 800; color: var(--red); letter-spacing: 0.03em; }

/* ==========================================
   GAMEPLAY SHELL & PERFECT CENTERING
   ========================================== */
#view-play {
  justify-content: center;
  padding: 4px 0;
  height: 100%;
}
.play-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: var(--card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 14px;
  margin-bottom: 12px;
}
.play-game-name { font-size: 0.85rem; font-weight: 800; letter-spacing: 0.08em; }
.play-meta { font-size: 0.74rem; color: var(--red); font-weight: 700; letter-spacing: 0.05em; }

.play-area {
  width: 100%;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  max-height: calc(100vh - 100px);
}

/* Desktop keyboard helper hint badge */
.kb-hint {
  font-size: 0.58rem;
  color: var(--grey-dark);
  letter-spacing: 0.08em;
  margin-top: 6px;
  text-transform: uppercase;
}

/* --- Sudoku --- */
#play-sudoku {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
#sudoku-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 1px;
  background: var(--sudoku-grid-line);
  border: 2px solid var(--sudoku-grid-border);
  width: 100%;
  max-width: 340px;
  margin: 0 auto;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
.s-cell {
  background: var(--surface-inset);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1rem, 4.2vw, 1.35rem);
  font-weight: 700;
  color: var(--white);
  cursor: pointer;
  font-family: 'JetBrains Mono', monospace;
  touch-action: manipulation;
  transition: background 0.12s, box-shadow 0.12s, color 0.12s;
}
.s-cell:nth-child(3n) { border-right: 2px solid var(--sudoku-grid-border); }
.s-cell:nth-child(9n) { border-right: none; }
.s-row-thick { border-bottom: 2px solid var(--sudoku-grid-border); }
.s-cell.given { background: var(--sudoku-given-bg); color: var(--grey); cursor: default; }
.s-cell.selected {
  background: rgba(255, 30, 80, 0.2);
  box-shadow: inset 0 0 0 2px var(--red);
  color: #ffffff;
}
.s-cell.error { color: var(--red); font-weight: 800; background: rgba(255, 0, 50, 0.15); }

.numpad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 340px;
  margin: 14px auto 0 auto;
}
.numpad .btn { margin-top: 0; min-height: 50px; border-radius: 10px; font-size: 1.05rem; font-weight: 800; }

/* --- Snake --- */
.canvas-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}
#snake-canvas {
  background: var(--canvas-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 320px;
  aspect-ratio: 1;
  touch-action: none;
  box-shadow: 0 10px 30px rgba(0,0,0,0.6);
}
.d-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 204px;
  margin-top: 14px;
}
.d-pad .btn { min-height: 52px; margin-top: 0; border-radius: 12px; font-size: 1.15rem; }
.swipe-hint { font-size: 0.62rem; color: var(--grey); margin-top: 10px; letter-spacing: 0.05em; }

/* --- Cloud Jump --- */
#cloud-canvas {
  background: var(--canvas-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 300px;
  height: auto;
  aspect-ratio: 300/400;
  touch-action: none;
  box-shadow: 0 10px 30px rgba(0,0,0,0.6);
}
.flap-btn { max-width: 300px; margin-top: 14px; min-height: 56px; font-size: 0.95rem; }

/* --- Tetris --- */
.tetris-wrap {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  justify-content: center;
  width: 100%;
  max-width: 320px;
  margin: 0 auto;
}
#tetris-canvas {
  background: var(--canvas-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  touch-action: none;
  box-shadow: 0 10px 30px rgba(0,0,0,0.6);
  width: 100%;
  max-width: 180px;
  height: auto;
  aspect-ratio: 1 / 2;
  flex-shrink: 1;
  min-width: 0;
}
.tetris-side {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding-top: 4px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 10px;
  flex-shrink: 0;
  min-width: 82px;
}
#tetris-next {
  background: var(--canvas-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 100%;
  max-width: 72px;
  height: auto;
  aspect-ratio: 1;
}
.tetris-controls {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  width: 100%;
  max-width: 320px;
  margin-top: 14px;
}
.tetris-controls .btn { min-height: 50px; margin-top: 0; padding: 8px 2px; font-size: 0.82rem; border-radius: 10px; }

/* --- Shared stat text (used in records / tetris side) --- */
.stat-label { font-size: 0.6rem; color: var(--grey); letter-spacing: 0.1em; }
.stat-value { font-size: 1.15rem; font-weight: 800; color: var(--red); }

/* ==========================================
   DYNAMIC CONTROL SCALING (REAL DIMENSIONS)
   ========================================== */
.numpad {
  gap: calc(10px * var(--ctrl-scale));
}
.numpad .btn {
  min-height: calc(50px * var(--ctrl-scale));
  font-size: calc(1.05rem * var(--ctrl-scale));
}

.d-pad {
  width: calc(204px * var(--ctrl-scale));
  gap: calc(10px * var(--ctrl-scale));
}
.d-pad .btn {
  min-height: calc(52px * var(--ctrl-scale));
  font-size: calc(1.15rem * var(--ctrl-scale));
}

.flap-btn {
  min-height: calc(56px * var(--ctrl-scale));
  font-size: calc(0.95rem * var(--ctrl-scale));
}

.tetris-controls {
  max-width: calc(320px * var(--ctrl-scale));
  gap: calc(8px * var(--ctrl-scale));
}
.tetris-controls .btn {
  min-height: calc(50px * var(--ctrl-scale));
  font-size: calc(0.82rem * var(--ctrl-scale));
}

/* Control Size Customization Modal */
.scale-options {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 16px 0;
}
.scale-opt {
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 6px;
  color: var(--white);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.18s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.scale-opt:hover {
  border-color: var(--border-bright);
}
.scale-opt.active {
  border-color: var(--red);
  color: var(--red);
  background: rgba(255, 30, 80, 0.12);
  box-shadow: 0 0 14px var(--red-glow), inset 0 0 10px rgba(255,30,80,0.1);
}
.scale-pct { font-size: 0.92rem; font-weight: 800; }
.theme-options { grid-template-columns: repeat(3, 1fr); }

/* Onboarding */
.onboard-list { display: flex; flex-direction: column; gap: 14px; margin: 6px 0 16px 0; text-align: left; }
.onboard-row { display: flex; align-items: flex-start; gap: 12px; }
.onboard-glyph {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-inset);
  border: 1px solid var(--border);
  color: var(--red);
  font-size: 0.85rem;
  font-weight: 800;
}
.onboard-text { font-size: 0.75rem; line-height: 1.5; color: var(--grey); letter-spacing: 0.01em; }
.onboard-text strong { color: var(--white); }

/* Control Preview Box */
.ctrl-preview-box {
  width: 100%;
  background: var(--surface-inset);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 8px;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100px;
  overflow: hidden;
}

/* ==========================================
   ANDROID TV / SMART TV FOCUS RINGS
   ========================================== */
:focus-visible, .tv-focused {
  outline: none !important;
  border-color: var(--red) !important;
  box-shadow: 0 0 18px var(--red), inset 0 0 8px rgba(255, 30, 80, 0.4) !important;
  transform: scale(1.03) !important;
  z-index: 20;
}

/* ==========================================
   SHORT / LANDSCAPE VIEWPORT SAFETY NET
   (small phones in landscape, split-screen tablets, short foldables —
   ensures on-screen controls can never end up clipped/unreachable)
   ========================================== */
@media (max-height: 700px) {
  html, body { overflow-y: auto; }
  .view {
    max-height: 100dvh;
    overflow-y: auto;
    justify-content: flex-start;
    padding-top: 8px;
    padding-bottom: 8px;
  }
  .play-area { max-height: none; }
}
@media (max-height: 480px) {
  .swipe-hint, .kb-hint { display: none; }
  .d-pad, .tetris-controls, .numpad { margin-top: 6px; }
  .play-topbar { margin-bottom: 6px; padding: 8px 12px; }
}

/* ==========================================
   LARGE SCREENS (desktop / tablet-landscape / TV)
   Give the app more breathing room instead of staying
   pinned at a tiny fixed-width column.
   ========================================== */
@media (min-width: 860px) {
  :root { --app-max-w: 460px; }
  html { font-size: 104%; }
}
@media (min-width: 1300px) {
  :root { --app-max-w: 520px; }
  html { font-size: 112%; }
}


