:root {
  --bg: #0a0e1a;
  --bg-2: #131a2b;
  --fg: #e8eaf2;
  --muted: #8a90a8;
  --accent: #2563eb;
  --border-blue: #2563eb;
  --border-blue-glow: #3b82f6;
  --danger: #ef4444;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

#app {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.screen {
  width: 100%;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.hidden { display: none !important; }

.title-toltris {
  margin: 0;
  width: 100%;
  max-width: 560px;
  display: flex;
  justify-content: center;
}

.title-toltris svg {
  width: 100%;
  height: auto;
  display: block;
}

h2 {
  margin: 0;
  font-size: 28px;
  font-weight: 600;
}

/* ---- Menu buttons ---- */

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

.menu-buttons.row {
  flex-direction: row;
  width: auto;
}

.menu-btn {
  background: var(--bg-2);
  color: var(--fg);
  border: 2px solid #2a3350;
  border-radius: 8px;
  padding: 12px 20px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease, transform 80ms ease;
}

.menu-btn:hover {
  border-color: var(--border-blue-glow);
  background: #1a2440;
}

.menu-btn:active {
  transform: scale(0.98);
}

/* ---- Color customization ---- */

.color-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 360px;
  background: var(--bg-2);
  padding: 16px;
  border-radius: 8px;
  border: 1px solid #2a3350;
}

.color-row {
  display: grid;
  grid-template-columns: 32px 1fr 56px;
  align-items: center;
  gap: 12px;
}

.color-swatch {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.15);
}

.color-label {
  font-size: 15px;
}

.color-input {
  width: 56px;
  height: 32px;
  border: 1px solid #2a3350;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  padding: 0;
}

/* ---- Alternate Versions ---- */

.alt-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 460px;
}

.alt-card {
  background: var(--bg-2);
  border: 2px solid #2a3350;
  border-radius: 10px;
  padding: 18px 20px;
  text-align: left;
  cursor: pointer;
  color: var(--fg);
  font-family: inherit;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color 120ms ease, background 120ms ease, transform 80ms ease;
}

.alt-card:hover {
  border-color: var(--border-blue-glow);
  background: #1a2440;
}

.alt-card:active {
  transform: scale(0.99);
}

.alt-card-title {
  font-size: 20px;
  font-weight: 600;
}

.alt-card-desc {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
}

/* ---- Controls ---- */

.screen-hint {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.controls-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 420px;
  background: var(--bg-2);
  padding: 16px;
  border-radius: 8px;
  border: 1px solid #2a3350;
}

.binding-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.binding-row {
  display: grid;
  grid-template-columns: 1fr 160px;
  align-items: center;
  gap: 12px;
  padding: 6px 0;
}

.binding-label {
  font-size: 15px;
}

.binding-btn {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid #2a3350;
  border-radius: 6px;
  padding: 8px 12px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease;
  text-align: center;
}

.binding-btn:hover {
  border-color: var(--border-blue-glow);
  background: #1a2440;
}

.binding-btn.capturing {
  border-color: var(--border-blue-glow);
  background: #1a2440;
  color: var(--border-blue-glow);
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.settings-block {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #1f2742;
}

.toggle-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}

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

.toggle-hint {
  font-size: 12px;
  color: var(--muted);
}

.toggle-checkbox {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
  background: #2a3350;
  border-radius: 12px;
  transition: background 150ms ease;
  flex-shrink: 0;
}

.toggle-switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: var(--fg);
  border-radius: 50%;
  transition: transform 150ms ease;
}

.toggle-checkbox:checked + .toggle-switch {
  background: var(--border-blue);
}

.toggle-checkbox:checked + .toggle-switch::after {
  transform: translateX(20px);
}

/* ---- Leaderboard ---- */

.leaderboard-list {
  width: 100%;
  background: var(--bg-2);
  padding: 16px;
  border-radius: 8px;
  border: 1px solid #2a3350;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}

.leaderboard-table th,
.leaderboard-table td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid #1f2742;
}

.leaderboard-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.leaderboard-table tr:last-child td {
  border-bottom: none;
}

.empty-state {
  color: var(--muted);
  text-align: center;
  margin: 0;
  padding: 24px 0;
}

/* ---- Game layout ---- */

#screen-game {
  position: relative;
  max-width: none;
}

.game-layout {
  display: flex;
  gap: 24px;
  align-items: flex-start;
}

/* Blue U-shaped border on left, right, bottom — NO top border. */
.playfield-wrap {
  background: transparent;
  border-left: 4px solid var(--border-blue);
  border-right: 4px solid var(--border-blue);
  border-bottom: 4px solid var(--border-blue);
  border-top: none;
  box-shadow:
    -4px 0 16px -4px var(--border-blue-glow),
    4px 0 16px -4px var(--border-blue-glow),
    0 4px 16px -4px var(--border-blue-glow);
  padding: 0;
  line-height: 0;
}

#board-canvas {
  display: block;
  background: transparent;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 180px;
}

.sidebar-block {
  background: var(--bg-2);
  border: 1px solid #2a3350;
  border-radius: 8px;
  padding: 12px;
}

.sidebar-label {
  font-size: 12px;
  letter-spacing: 2px;
  color: var(--muted);
  margin-bottom: 8px;
  text-align: center;
  font-weight: 600;
}

#next-canvas, #hold-canvas {
  display: block;
  margin: 0 auto;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 4px;
}

.hud {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.hud-row {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
}

.hud-row span:first-child {
  color: var(--muted);
  letter-spacing: 1px;
  font-size: 12px;
}

.hud-row span:last-child {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.controls-help {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
}

/* ---- Overlays (pause, game over) ---- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 16, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.overlay-card {
  background: var(--bg-2);
  border: 1px solid #2a3350;
  border-radius: 12px;
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  align-items: center;
  min-width: 320px;
}

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

.name-entry p {
  margin: 0;
  font-size: 14px;
  text-align: center;
  color: var(--muted);
}

.name-entry input {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid #2a3350;
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 15px;
  width: 100%;
}

.name-entry input:focus {
  outline: none;
  border-color: var(--border-blue-glow);
}
