/* ==========================================================================
   Google Snake Arcade - Theme & Style System (Google Exact Style)
   ========================================================================== */

:root {
  /* Google Snake Core Colors */
  --header-bg: #4a752c;
  --header-dark: #385922;
  --board-dark: #578a34;
  --grid-light: #aad751;
  --grid-dark: #a2d149;
  --page-bg: #4a752c;

  /* Google Brand Colors */
  --g-blue: #4285f4;
  --g-red: #ea4335;
  --g-yellow: #fbbc05;
  --g-green: #34a853;

  /* UI Tokens */
  --text-main: #ffffff;
  --text-dark: #202124;
  --text-muted: #5f6368;
  --card-bg: #ffffff;
  --card-shadow: 0 12px 32px rgba(0, 0, 0, 0.28), 0 0 0 1px rgba(255, 255, 255, 0.1);
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-pill: 9999px;
  --font-family: 'Fredoka', 'Nunito', 'Product Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-bounce: 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-family);
  background: #3c5d23;
  background: radial-gradient(circle at 50% 40%, #4a752c, #334f1e);
  color: var(--text-main);
  display: flex;
  justify-content: center;
  align-items: center;
}

/* ==========================================================================
   Game Wrapper Container
   ========================================================================== */

.game-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 620px;
  height: 100vh;
  max-height: 850px;
  padding: 8px;
  position: relative;
}

/* Header Bar */
.game-header {
  width: 100%;
  max-width: 600px;
  background-color: var(--header-bg);
  border-top-left-radius: var(--radius-lg);
  border-top-right-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
  z-index: 10;
  border-bottom: 2px solid rgba(0, 0, 0, 0.12);
}

/* Logo */
.brand-logo {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  display: flex;
  align-items: center;
  gap: 3px;
}
.brand-title {
  color: #ffffff;
  margin-left: 2px;
  font-weight: 600;
}
.g-blue { color: #8ab4f8; }
.g-red { color: #f28b82; }
.g-yellow { color: #fdd663; }
.g-green { color: #81c995; }

/* Scoreboard */
.scoreboard {
  display: flex;
  align-items: center;
  gap: 12px;
}

.score-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  background: rgba(0, 0, 0, 0.22);
  padding: 5px 12px;
  border-radius: var(--radius-pill);
  font-size: 1.25rem;
  font-weight: 700;
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.18);
  transition: transform var(--transition-bounce);
}
.score-pill.pop {
  transform: scale(1.18);
}

.pill-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}

.svg-apple {
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.25));
}
.svg-trophy {
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.25));
}

.score-value {
  min-width: 22px;
  text-align: left;
  font-variant-numeric: tabular-nums;
}

/* Header Action Buttons */
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.14);
  border: none;
  color: #ffffff;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  outline: none;
  transition: background var(--transition-fast), transform var(--transition-fast), box-shadow var(--transition-fast);
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.26);
  transform: scale(1.08);
}

.icon-btn:active {
  transform: scale(0.94);
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Bot Auto Play Button */
.bot-btn.active {
  background: linear-gradient(135deg, #00c6ff, #0072ff);
  box-shadow: 0 0 12px rgba(0, 198, 255, 0.75);
  animation: botPulse 1.5s infinite alternate;
}

@keyframes botPulse {
  0% { transform: scale(1); box-shadow: 0 0 8px rgba(0, 198, 255, 0.5); }
  100% { transform: scale(1.08); box-shadow: 0 0 16px rgba(0, 198, 255, 0.9); }
}

/* ==========================================
   Canvas & Game Area
   ========================================== */

.canvas-container {
  position: relative;
  width: 100%;
  max-width: 600px;
  aspect-ratio: 17 / 15;
  background-color: var(--board-dark);
  border-bottom-left-radius: var(--radius-lg);
  border-bottom-right-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
}

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

/* ==========================================
   Screens & Overlay Cards
   ========================================== */

.overlay-screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
  z-index: 20;
  padding: 16px;
}

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

.modal-card {
  background: var(--card-bg);
  color: var(--text-dark);
  border-radius: var(--radius-lg);
  padding: 26px 22px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--card-shadow);
  text-align: center;
  animation: modalPop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes modalPop {
  0% { transform: scale(0.88); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* Start Card Hero */
.snake-hero-animation {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 14px;
}

.hero-snake {
  width: 52px;
  height: 52px;
  background: #4a752c;
  border-radius: 50%;
  position: relative;
  box-shadow: 0 6px 14px rgba(74, 117, 44, 0.4);
  animation: snakeBob 2s infinite ease-in-out;
}

@keyframes snakeBob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-7px); }
}

.hero-eye {
  width: 11px;
  height: 11px;
  background: white;
  border-radius: 50%;
  position: absolute;
  top: 13px;
}
.hero-eye.left { left: 11px; }
.hero-eye.right { right: 11px; }

.hero-eye .pupil {
  width: 6px;
  height: 6px;
  background: #202124;
  border-radius: 50%;
  position: absolute;
  top: 3px;
  right: 2px;
  animation: lookAround 3s infinite ease-in-out;
}

@keyframes lookAround {
  0%, 100% { transform: translate(0, 0); }
  35% { transform: translate(2px, 0); }
  70% { transform: translate(-2px, 1px); }
}

.hero-tongue {
  width: 6px;
  height: 12px;
  background: #ea4335;
  position: absolute;
  bottom: -6px;
  left: 23px;
  border-radius: 0 0 3px 3px;
  animation: tongueFlick 1.5s infinite ease-in-out;
}

@keyframes tongueFlick {
  0%, 100% { height: 0; opacity: 0; }
  50% { height: 12px; opacity: 1; }
}

.hero-apple {
  animation: appleBounce 1.8s infinite ease-in-out;
  display: flex;
  align-items: center;
  justify-content: center;
}

@keyframes appleBounce {
  0%, 100% { transform: scale(1) translateY(0); }
  50% { transform: scale(1.1) translateY(-6px); }
}

.game-title {
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--header-bg);
  margin-bottom: 4px;
  letter-spacing: -0.5px;
}

.game-subtitle {
  font-size: 0.92rem;
  color: var(--text-muted);
  margin-bottom: 16px;
  font-weight: 500;
}

.control-hints {
  background: #f1f3f4;
  border-radius: var(--radius-md);
  padding: 10px 12px;
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: #3c4043;
  text-align: left;
}

.key-tag {
  background: #ffffff;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 700;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
  border: 1px solid #dadce0;
  color: #1a73e8;
}

/* Common Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 22px;
  font-family: inherit;
  font-size: 1.02rem;
  font-weight: 700;
  border-radius: var(--radius-pill);
  border: none;
  cursor: pointer;
  outline: none;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
}

.btn-primary {
  background: linear-gradient(180deg, #4285f4, #1a73e8);
  color: white;
  box-shadow: 0 4px 12px rgba(66, 133, 244, 0.38);
  width: 100%;
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(66, 133, 244, 0.48);
}
.btn-primary:active {
  transform: translateY(1px);
}

.btn-secondary {
  background: #f1f3f4;
  color: #3c4043;
  width: 100%;
}
.btn-secondary:hover {
  background: #e8eaed;
}

.modal-btn-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}

/* Game Over Face */
.gameover-snake-face {
  width: 48px;
  height: 48px;
  background: #ea4335;
  border-radius: 50%;
  margin: 0 auto 8px auto;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-shadow: 0 4px 12px rgba(234, 67, 53, 0.4);
}

.dead-eye {
  color: white;
  font-size: 1rem;
  font-weight: 900;
  line-height: 1;
}

.gameover-card h2 {
  font-size: 1.6rem;
  color: var(--g-red);
  font-weight: 800;
  margin-bottom: 14px;
}

.gameover-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.stat-box {
  background: #f8f9fa;
  border-radius: var(--radius-md);
  padding: 10px 8px;
  border: 1px solid #e8eaed;
}
.stat-box.highlight-box {
  background: #fff8e1;
  border-color: #ffe082;
}

.stat-label {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.stat-num-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 1.35rem;
  font-weight: 800;
  color: #202124;
}

.new-record-badge {
  display: none;
  background: linear-gradient(90deg, #fbbc05, #ea4335);
  color: white;
  font-weight: 800;
  font-size: 0.88rem;
  padding: 5px 12px;
  border-radius: var(--radius-pill);
  margin-bottom: 12px;
  box-shadow: 0 3px 8px rgba(234, 67, 53, 0.3);
  animation: pulse 1s infinite alternate;
}
.new-record-badge.show {
  display: block;
}

@keyframes pulse {
  0% { transform: scale(0.97); }
  100% { transform: scale(1.03); }
}

/* ==========================================
   Settings Modal System (Google Style)
   ========================================== */

.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
  z-index: 100;
  padding: 16px;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.settings-card {
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  text-align: left;
  padding: 22px;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #e8eaed;
  padding-bottom: 12px;
  margin-bottom: 16px;
}

.settings-header h2 {
  font-size: 1.3rem;
  font-weight: 700;
  color: #202124;
  display: flex;
  align-items: center;
  gap: 8px;
}

.close-btn {
  background: transparent;
  border: none;
  font-size: 1.8rem;
  line-height: 1;
  color: #5f6368;
  cursor: pointer;
  padding: 4px;
  border-radius: 50%;
  transition: background 0.15s;
}
.close-btn:hover {
  background: #f1f3f4;
  color: #202124;
}

.setting-group {
  margin-bottom: 16px;
}

.setting-label {
  display: block;
  font-size: 0.9rem;
  font-weight: 700;
  color: #3c4043;
  margin-bottom: 8px;
}

/* Option Chips */
.option-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(105px, 1fr));
  gap: 8px;
}

.fruit-grid {
  grid-template-columns: repeat(4, 1fr);
}

.option-chip {
  background: #f8f9fa;
  border: 2px solid #e8eaed;
  border-radius: var(--radius-md);
  padding: 7px 8px;
  font-family: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  color: #3c4043;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all var(--transition-fast);
}

.option-chip:hover {
  border-color: #dadce0;
  background: #ffffff;
}

.option-chip.active {
  background: #e8f0fe;
  border-color: #1a73e8;
  color: #1a73e8;
  box-shadow: 0 2px 6px rgba(26, 115, 232, 0.18);
}

.color-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-block;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.15);
}

/* Segmented Control */
.settings-row-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.segmented-control {
  display: flex;
  background: #f1f3f4;
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 2px;
}

.segment-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 7px 4px;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  color: #5f6368;
  border-radius: calc(var(--radius-md) - 3px);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.segment-btn.active {
  background: #ffffff;
  color: #1a73e8;
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.settings-footer {
  margin-top: 18px;
  border-top: 1px solid #e8eaed;
  padding-top: 14px;
}

/* ==========================================
   Mobile Controls (D-pad)
   ========================================== */

.mobile-controls {
  display: none;
  margin-top: 12px;
  z-index: 10;
}

.dpad {
  position: relative;
  width: 140px;
  height: 140px;
}

.dpad-btn {
  position: absolute;
  width: 44px;
  height: 44px;
  background: rgba(255, 255, 255, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.35);
  color: white;
  border-radius: 12px;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
  cursor: pointer;
  outline: none;
  box-shadow: 0 3px 8px rgba(0,0,0,0.22);
  transition: background 0.1s, transform 0.1s;
}

.dpad-btn:active {
  background: rgba(255, 255, 255, 0.45);
  transform: scale(0.92);
}

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

/* Responsive Media Queries */
@media (max-width: 768px) {
  .game-wrapper {
    padding: 6px;
    height: 100vh;
  }
  .game-header {
    padding: 6px 10px;
  }
  .brand-logo {
    font-size: 1.1rem;
  }
  .score-pill {
    padding: 3px 8px;
    font-size: 1.05rem;
  }
  .icon-btn {
    width: 34px;
    height: 34px;
  }
  .settings-row-2col {
    grid-template-columns: 1fr;
  }
  .mobile-controls {
    display: flex;
    justify-content: center;
  }
}

@media (max-height: 650px) {
  .canvas-container {
    max-height: 55vh;
  }
  .mobile-controls {
    display: none;
  }
}
