@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&family=Google+Sans:wght@400;500;700&display=swap');

:root {
  --bg: #202124;
  --panel: #292a2d;
  --line: #3c4043;
  --text: #e8eaed;
  --text-dim: #9aa0a6;
  --gold: #fbbc04;
  --btn-bg: #8ab4f8;
  --btn-text: #202124;
  --btn-hover: #aecbfa;
  --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
  height: 100vh;
  width: 100vw;
  margin: 0;
  overflow: hidden;
  position: fixed;
  top: 0;
  left: 0;
  background-color: var(--bg);
  color: var(--text);
  font-family: 'Google Sans', 'Roboto', system-ui, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
}

.game-container {
  width: 100%;
  max-width: 900px;
  height: 100vh;
  max-height: 800px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 20px;
  padding: 16px;
  align-items: center;
}

@media (max-width: 860px) {
  .game-container { 
    grid-template-columns: 1fr; 
    max-width: 600px; 
    padding: 10px;
    align-items: start;
    overflow-y: auto;
  }
  .side-panel { display: none; }
}

/* ---------- Google Snake Style HUD ---------- */
.viewport-card {
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.top-bar {
  width: min(65vh, 560px);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  margin-bottom: 12px;
  background: var(--panel);
  border-radius: var(--radius);
  border: 1px solid var(--line);
}

.score-wrap {
  display: flex;
  align-items: center;
  gap: 16px;
}

.score-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 24px;
  font-weight: 700;
  font-family: 'Roboto', sans-serif;
}
.score-pill span.icon { font-size: 22px; }

.controls-wrap {
  display: flex;
  gap: 8px;
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.1s;
}
.icon-btn:hover { background: rgba(255,255,255,0.1); }
.icon-btn:active { transform: scale(0.92); }

/* ---------- Canvas Area ---------- */
.stage-frame {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
  width: min(65vh, 560px);
  height: min(65vh, 560px);
  margin: auto;
  box-shadow: 0 10px 30px rgba(0,0,0,0.6);
  touch-action: none;
}
canvas { display: block; width: 100%; height: 100%; }

/* ---------- Combos & HUD Extras ---------- */
.hud-extra {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  display: flex;
  justify-content: center;
  pointer-events: none;
  z-index: 5;
}
.combo-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  background: rgba(0,0,0,0.6);
  padding: 6px 12px;
  border-radius: 20px;
  backdrop-filter: blur(4px);
}
.combo-wrap.show { opacity: 1; transform: translateY(0); }
.combo-label { font-size: 11px; color: #f472b6; letter-spacing: 1px; font-weight: 700; font-family: 'Roboto', sans-serif;}
.combo-bar { width: 90px; height: 6px; border-radius: 4px; background: rgba(244,114,182,0.15); overflow: hidden; }
.combo-fill { height: 100%; width: 20%; background: linear-gradient(90deg, #f472b6, var(--gold)); transition: width 0.2s ease; }

.toast {
  position: absolute; top: 16px; left: 50%; transform: translate(-50%, -10px);
  background: var(--panel); border: 1px solid var(--line);
  padding: 8px 16px; border-radius: 24px; font-size: 13px; font-weight: 500;
  opacity: 0; transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none; white-space: nowrap; z-index: 10;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(32, 33, 36, 0.85);
  backdrop-filter: blur(4px);
  text-align: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 15;
}
.overlay.show { opacity: 1; pointer-events: auto; }
.overlay h2 { font-size: 32px; margin: 0; font-weight: 700; }
.overlay p { color: var(--text-dim); font-size: 14px; max-width: 300px; line-height: 1.5; margin: 0; }
.score-big { font-size: 48px; font-weight: 700; color: #fff; }
.badge { font-family: 'Roboto', monospace; font-size: 12px; color: #000; background: var(--gold); padding: 4px 10px; border-radius: 20px; font-weight: 700; }

.btn {
  font-family: 'Google Sans', sans-serif; font-weight: 500; font-size: 15px;
  padding: 10px 24px; border-radius: 24px; border: none; cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: var(--btn-bg); color: var(--btn-text); }
.btn-primary:hover { background: var(--btn-hover); }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
.btn-ghost:hover { background: rgba(255,255,255,0.05); }
.btn-row { display: flex; gap: 12px; margin-top: 10px; }

/* ---------- Side Panel / Settings ---------- */
.side-panel { display: flex; flex-direction: column; gap: 12px; height: 100%; justify-content: center; }
.info-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.info-card h3 { margin: 0 0 12px; font-size: 14px; font-weight: 500; text-transform: uppercase; color: var(--text-dim); letter-spacing: 0.5px; }
.mod-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 13px; border-bottom: 1px solid rgba(255,255,255,0.05); }
.mod-row:last-child { border-bottom: none; }
.mod-row span.val { color: var(--btn-bg); font-weight: 500; }

/* ---------- Settings Drawer ---------- */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,0.6); opacity: 0; pointer-events: none; transition: opacity 0.25s ease; z-index: 40; }
.scrim.show { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed; top: 0; right: 0; height: 100%; width: min(340px, 90vw);
  background: var(--bg); border-left: 1px solid var(--line);
  z-index: 41; transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
  overflow-y: auto; padding: 24px 24px 60px; /* Extra padding bottom for scrolling */
}
.drawer.show { transform: translateX(0); }

.drawer-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.drawer-head h2 { font-size: 20px; margin: 0; font-weight: 500; }
.close-x { background: none; border: none; color: var(--text-dim); font-size: 24px; cursor: pointer; }
.close-x:hover { color: var(--text); }

.section-title { font-size: 12px; font-weight: 500; text-transform: uppercase; color: var(--text-dim); margin: 20px 0 10px; }
.section-title:first-of-type { margin-top: 0; }

.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg-btn {
  flex: 1 1 auto; text-align: center; border: 1px solid var(--line); border-radius: 6px; padding: 8px;
  font-size: 12px; cursor: pointer; background: transparent; color: var(--text-dim);
  transition: all 0.15s ease; font-weight: 500;
}
.seg-btn.active { border-color: var(--btn-bg); color: var(--btn-bg); background: rgba(138, 180, 248, 0.08); }
.seg-btn:hover { color: var(--text); }

.theme-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.theme-chip {
  border: 1px solid var(--line); border-radius: 6px; padding: 10px;
  cursor: pointer; display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 500;
  transition: all 0.15s ease;
}
.theme-chip .sw { width: 16px; height: 16px; border-radius: 50%; border: 1px solid rgba(0,0,0,0.3); }
.theme-chip.active { border-color: var(--btn-bg); background: rgba(138, 180, 248, 0.08); color: var(--btn-bg); }

input[type=range] { width: 100%; accent-color: var(--btn-bg); cursor: pointer; margin: 10px 0; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; font-size: 14px; }
.switch { position: relative; width: 40px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider-tog { position: absolute; cursor: pointer; inset: 0; background: var(--line); border-radius: 22px; transition: .2s; }
.slider-tog:before { content: ""; position: absolute; height: 16px; width: 16px; left: 3px; bottom: 3px; background: #fff; border-radius: 50%; transition: .2s; }
input:checked + .slider-tog { background: var(--btn-bg); }
input:checked + .slider-tog:before { transform: translateX(18px); }

/* Mobile D-Pad */
.dpad {
  display: none; grid-template-columns: repeat(3, 50px); grid-template-rows: repeat(3, 50px);
  gap: 6px; justify-content: center; margin-top: 16px;
}
.dpad button { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; color: var(--text); font-size: 20px; cursor: pointer; }
.dpad button:active { background: rgba(255,255,255,0.1); }
@media (pointer: coarse) { .dpad { display: grid; } }