:root {
  --bg-color: #000000;
  --board-bg: #000000;
  --grid-dot-color: #222222;
  --snake-color: #3d82f7;
  --text-main: #f0f0f0;
  --text-muted: #888888;
  --panel-bg: rgba(18, 18, 18, 0.85);
  --panel-border: rgba(255, 255, 255, 0.08);
  --btn-bg: #141414;
  --btn-hover: #222222;
  --btn-active: #2e2e2e;
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-color);
  color: var(--text-main);
  font-family: var(--font-family);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

body.game-over-state {
  filter: grayscale(1);
}

/* App Container */
.app-container {
  width: 100%;
  height: 100%;
  max-width: 600px;
  max-height: 900px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 24px;
  transition: all 0.3s ease;
}

/* Zen Mode: Pure screen matching exact screenshot */
body.zen-mode .app-container {
  max-width: 100vw;
  max-height: 100vh;
  padding: 0;
  justify-content: center;
}

body.zen-mode header,
body.zen-mode footer.control-bar,
body.zen-mode .dpad-container {
  display: none !important;
}

body.zen-mode .board-wrapper {
  box-shadow: none;
  border-radius: 0;
}

/* Floating exit Zen button */
.zen-exit-btn {
  display: none;
  position: fixed;
  top: 16px;
  right: 16px;
  background: rgba(30, 30, 30, 0.4);
  color: #666;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 100;
  opacity: 0.3;
  transition: opacity 0.2s, background 0.2s, color 0.2s;
}

.zen-exit-btn:hover {
  opacity: 1;
  color: #fff;
  background: rgba(30, 30, 30, 0.9);
}

body.zen-mode .zen-exit-btn {
  display: flex;
}

/* Header & HUD */
header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 12px;
}

.logo-area {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.logo-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--text-main);
}

.logo-tag {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 1.5px;
  color: var(--snake-color);
  text-transform: uppercase;
}

.stats-bar {
  display: flex;
  align-items: center;
  gap: 20px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.stat-label {
  font-size: 0.65rem;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 600;
}

.stat-value {
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-main);
  letter-spacing: 0.5px;
  transition: color 0.3s ease;
}

.stat-value.level-up {
  animation: levelPulse 0.8s ease-out;
}

@keyframes levelPulse {
  0% {
    transform: scale(1.45);
    color: #ffffff;
    text-shadow: 0 0 14px var(--snake-color);
  }
  100% {
    transform: scale(1);
    color: var(--text-main);
    text-shadow: none;
  }
}

/* Board Wrapper */
.board-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--board-bg);
  box-shadow: 0 0 50px rgba(0, 0, 0, 0.9);
  border-radius: 6px;
  overflow: hidden;
  touch-action: none;
}

canvas#gameCanvas {
  display: block;
  background-color: var(--board-bg);
  cursor: pointer;
}

/* Game over overlay */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 10;
  padding: 24px;
  text-align: center;
}

.overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.overlay h2 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: 4px;
  text-transform: uppercase;
  margin-bottom: 8px;
  color: var(--text-main);
}

.overlay.game-over h2 {
  color: #ff4757;
}

.overlay .overlay-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  letter-spacing: 1px;
  margin-bottom: 24px;
}

.score-summary {
  display: flex;
  gap: 32px;
  margin-bottom: 28px;
}

.score-summary .stat-item {
  align-items: center;
}

.score-summary .stat-value {
  font-size: 1.8rem;
  color: var(--snake-color);
}

.btn-primary {
  background-color: var(--snake-color);
  color: #ffffff;
  border: none;
  border-radius: 24px;
  padding: 12px 28px;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 4px 14px rgba(61, 130, 247, 0.4);
}

.btn-primary:hover {
  background-color: #5593f8;
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(61, 130, 247, 0.5);
}

.btn-primary:active {
  transform: translateY(1px);
}

.overlay-hint {
  font-size: 0.72rem;
  color: #666666;
  margin-top: 16px;
  letter-spacing: 0.5px;
}

/* Control Bar */
.control-bar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 14px;
}

.icon-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  background: var(--btn-bg);
  border: 1px solid var(--panel-border);
  color: var(--text-muted);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.icon-btn:hover {
  background: var(--btn-hover);
  color: var(--text-main);
  border-color: rgba(255, 255, 255, 0.18);
}

.icon-btn:active {
  background: var(--btn-active);
  transform: scale(0.95);
}

.icon-btn.active {
  color: var(--snake-color);
  border-color: rgba(61, 130, 247, 0.4);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.helper-text {
  font-size: 0.72rem;
  color: #555555;
  letter-spacing: 0.5px;
}

/* Mobile Virtual D-Pad (Visible on mobile/touch screens) */
.dpad-container {
  display: none;
  margin-top: 12px;
  width: 140px;
  height: 140px;
  position: relative;
}

@media (hover: none) and (pointer: coarse) {
  .dpad-container {
    display: block;
  }
}

.dpad-btn {
  position: absolute;
  width: 44px;
  height: 44px;
  background: rgba(25, 25, 25, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  color: #888888;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  cursor: pointer;
}

.dpad-btn:active {
  background: var(--snake-color);
  color: #ffffff;
}

.dpad-btn.up { top: 0; left: 48px; }
.dpad-btn.down { bottom: 0; left: 48px; }
.dpad-btn.left { top: 48px; left: 0; }
.dpad-btn.right { top: 48px; right: 0; }

.dpad-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

/* Modal Dialog */
dialog.settings-modal {
  background: #141414;
  color: var(--text-main);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 24px 28px;
  max-width: 360px;
  width: 90%;
  margin: auto;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.8);
}

dialog.settings-modal::backdrop {
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
}

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

.modal-header h3 {
  font-size: 1.1rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text-main);
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.setting-label {
  font-size: 0.85rem;
  color: #cccccc;
}

.setting-desc {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.setting-select {
  background: #202020;
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-main);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.8rem;
  outline: none;
  cursor: pointer;
}

/* Switch toggle */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: #2a2a2a;
  transition: 0.2s;
  border-radius: 24px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: #ffffff;
  transition: 0.2s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--snake-color);
}

input:checked + .slider:before {
  transform: translateX(20px);
}

/* A full-screen board with only the settings control visible during play. */
.app-container,
body.zen-mode .app-container {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  padding: 0;
  display: block;
}

.app-container > header,
.dpad-container,
#dpadSettingRow,
.zen-exit-btn,
.control-bar .icon-btn:not(#settingsBtn),
.control-bar .helper-text {
  display: none !important;
}

.board-wrapper {
  position: fixed;
  inset: 0;
  border-radius: 0;
  box-shadow: none;
}

.control-bar,
.control-bar .icon-group,
body.zen-mode footer.control-bar {
  display: contents !important;
}

#settingsBtn {
  position: fixed;
  left: max(16px, env(safe-area-inset-left));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 20;
  display: flex;
}

dialog.settings-modal {
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
}
