:root {
  --snake: #4caf50;
  --snake-head: #2e7d32;
  --food: #f65e3b;
  --grid: #cdc1b4;
}

body.dark {
  --snake: #66bb6a;
  --snake-head: #a5d6a7;
  --food: #ff7043;
  --grid: #50443c;
}

/* ── Widescreen layout ── */
.app {
  padding: 0;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 100%;
}

.game-row {
  display: flex;
  flex-direction: row;
  gap: 0;
  overflow: hidden;
  align-items: stretch;
  min-height: 200px;
}

.sidebar {
  width: 110px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 16px 8px;
  background: var(--surface);
}

.sidebar-left  { border-right: 1px solid var(--border); }
.sidebar-right { border-left:  1px solid var(--border); }

.sidebar-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.hud-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.hud-value {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-strong);
  font-variant-numeric: tabular-nums;
  letter-spacing: 1px;
  min-width: 3ch;
  text-align: center;
}

.sidebar-btns {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 90%;
}

.sidebar-btns .btn {
  width: 100%;
  font-size: 0.72rem;
  padding: 6px 4px;
}

/* ── Board ── */
.board-wrapper {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.board {
  position: relative;
  aspect-ratio: 1 / 1;
  height: 100%;
  max-width: 100%;
  background: var(--grid);
  border-radius: 8px;
  touch-action: none;
  user-select: none;
  overflow: hidden;
}

#canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.overlay {
  position: absolute;
  inset: 0;
  background: var(--overlay-bg);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 10;
  animation: fadein .3s ease-in-out;
}
.overlay[hidden] { display: none; }
.overlay-text {
  font-size: clamp(28px, 6vmin, 48px);
  font-weight: 800;
  color: var(--text);
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

/* ── Leaderboard modal ── */
.lb-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  animation: fadein .2s ease;
}
.lb-modal[hidden] { display: none; }
.lb-modal-inner {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 24px 20px 16px;
  min-width: 280px;
  max-width: 420px;
  width: 90%;
  box-shadow: var(--shadow-lg);
}
.lb-modal-close {
  position: absolute;
  top: 10px; right: 12px;
  background: none; border: none;
  font-size: 18px; cursor: pointer;
  color: var(--text-muted); line-height: 1;
}
.lb-modal-close:hover { color: var(--text); }
.lb-title { font-size: 13px; font-weight: 800; letter-spacing: 1px; text-transform: uppercase; color: var(--text-muted); margin: 0 0 12px; }
.lb-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.lb-table th, .lb-table td { padding: 6px 10px; text-align: left; border-bottom: 1px solid var(--border); }
.lb-table th { font-size: 10px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: var(--text-muted); }
.lb-table tbody tr:first-child td { color: var(--accent); font-weight: 700; }
.lb-table tbody tr.lb-new td { color: var(--accent); font-weight: 700; background: color-mix(in srgb, var(--accent) 10%, transparent); }
.lb-table tbody tr.lb-new td:first-child::before { content: "★ "; }

/* ── Mobile: stack vertically ── */
@media (max-width: 540px) {
  .game-row {
    flex-direction: column;
    height: auto !important;
  }
  .sidebar {
    flex-direction: row;
    width: 100%;
    height: auto;
    padding: 6px 16px;
    justify-content: space-around;
    gap: 12px;
  }
  .sidebar-left  { border-right: none; border-bottom: 1px solid var(--border); order: 1; }
  .sidebar-right { border-left:  none; border-top:    1px solid var(--border); order: 3; }
  .board-wrapper { order: 2; min-height: 60vw; }
  .sidebar-item  { flex-direction: row; align-items: baseline; gap: 6px; }
  .hud-value     { font-size: 1.2rem; }
  .sidebar-btns  { flex-direction: row; width: auto; }
  .board         { height: auto; width: min(90vw, 80vmin); aspect-ratio: 1/1; }
}
