/* Google Snake Theme & Modern AI Dashboard */

:root {
  --bg-color: #578a34;
  --header-bg: #4a752c;
  --header-border: #385b20;
  --grass-light: #aad751;
  --grass-dark: #a2d149;
  --snake-blue: #467cf0;
  --snake-blue-dark: #3b6fd4;
  --snake-eye: #ffffff;
  --snake-pupil: #2b2b2b;
  --snake-tongue: #e83344;
  --apple-red: #e7473c;
  --apple-shine: #ff8c82;
  --apple-leaf: #388e3c;
  --apple-stem: #6d4c41;
  --panel-bg: #ffffff;
  --card-bg: #f8fafc;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --primary-accent: #22c55e;
  --accent-hover: #16a34a;
  --border-color: #e2e8f0;
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 2px 4px rgba(0,0,0,0.06);
  --shadow-md: 0 6px 16px rgba(0,0,0,0.12);
  --shadow-lg: 0 12px 28px rgba(0,0,0,0.2);
}

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

body {
  font-family: 'Fredoka', 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 16px;
}

.main-container {
  width: 100%;
  max-width: 1140px;
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

/* Header */
.game-header {
  background-color: var(--header-bg);
  color: #ffffff;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 4px solid var(--header-border);
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.stat-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(0, 0, 0, 0.22);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.apple-stat {
  color: #ffdd80;
}

.stat-sub {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.75);
}

.trophy-stat {
  color: #ffd166;
}

.coverage-stat {
  color: #70e000;
}

.header-center .logo-title {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.g-blue { color: #4285f4; }
.g-red { color: #ea4335; }
.g-yellow { color: #fbbc05; }
.g-green { color: #34a853; }

.ai-tag {
  background: #fbbc05;
  color: #1e293b;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.header-btn {
  background: rgba(255, 255, 255, 0.18);
  border: none;
  color: white;
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.header-btn:hover {
  background: rgba(255, 255, 255, 0.28);
  transform: translateY(-1px);
}

.header-btn.primary-btn {
  background: #34a853;
  color: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.header-btn.primary-btn:hover {
  background: #2e9649;
}

/* Game Wrapper: Canvas + Aside Controls */
.game-wrapper {
  display: flex;
  flex-direction: row;
  background-color: #f1f5f9;
}

.canvas-container {
  position: relative;
  background: var(--grass-light);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
  flex: 1;
}

#snake-canvas {
  background-color: var(--grass-light);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  display: block;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
}

/* Control Panel */
.control-panel {
  width: 380px;
  min-width: 350px;
  background: #ffffff;
  border-left: 1px solid var(--border-color);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
  max-height: calc(100vh - 100px);
}

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.section-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #334155;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Radio Group Algorithm Cards */
.radio-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.radio-card {
  display: flex;
  align-items: flex-start;
  padding: 10px 14px;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  background: #ffffff;
  transition: all 0.15s ease;
}

.radio-card input {
  margin-right: 10px;
  margin-top: 4px;
  accent-color: #22c55e;
  cursor: pointer;
}

.radio-content {
  flex: 1;
}

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

.radio-header strong {
  font-size: 0.92rem;
  color: var(--text-main);
}

.radio-content small {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.3;
}

.radio-card:hover {
  border-color: #94a3b8;
  background: #f8fafc;
}

.radio-card.active {
  border-color: #22c55e;
  background: #f0fdf4;
}

.badge {
  font-size: 0.68rem;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
}

.dynamic-badge {
  background: #dbeafe;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
}

.win-guarantee {
  background: #dcfce7;
  color: #15803d;
}

.fast-badge {
  background: #e0f2fe;
  color: #0369a1;
}

.risk-badge {
  background: #fee2e2;
  color: #b91c1c;
}

.user-badge {
  background: #fef3c7;
  color: #b45309;
}

/* Speed Controls */
.speed-buttons {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.speed-btn {
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  color: #334155;
  padding: 8px 4px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
}

.speed-btn:hover {
  background: #e2e8f0;
}

.speed-btn.active {
  background: #3b82f6;
  border-color: #2563eb;
  color: #ffffff;
}

.step-controls {
  margin-top: 4px;
}

.secondary-btn {
  width: 100%;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  color: #1e293b;
  padding: 9px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.secondary-btn:hover {
  background: #e2e8f0;
}

/* Sliders & Grid Size */
.density-slider-container {
  display: flex;
  align-items: center;
  gap: 12px;
}

.density-slider-container input[type="range"] {
  flex: 1;
  accent-color: #e7473c;
  cursor: pointer;
}

.density-readout {
  min-width: 90px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

#density-value {
  font-weight: 800;
  font-size: 1.1rem;
  color: #e7473c;
}

.density-apple-count {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.grid-size-selector {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
}

.grid-size-selector label {
  font-size: 0.88rem;
  font-weight: 600;
  color: #475569;
}

.grid-size-selector select {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid #cbd5e1;
  font-weight: 700;
  font-family: inherit;
  color: #1e293b;
  background: #fff;
  cursor: pointer;
}

/* Toggle Switches */
.toggle-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toggle-switch {
  display: flex;
  align-items: center;
  cursor: pointer;
  gap: 10px;
  position: relative;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-switch .slider {
  width: 38px;
  height: 22px;
  background-color: #cbd5e1;
  border-radius: 34px;
  position: relative;
  transition: 0.2s;
  flex-shrink: 0;
}

.toggle-switch .slider:before {
  content: "";
  position: absolute;
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  border-radius: 50%;
  transition: 0.2s;
}

.toggle-switch input:checked + .slider {
  background-color: #22c55e;
}

.toggle-switch input:checked + .slider:before {
  transform: translateX(16px);
}

.toggle-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #334155;
}

/* Math Explanation Card */
.math-card {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  padding: 14px;
  border-radius: var(--radius-md);
}

.math-header {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #1d4ed8;
  font-size: 0.88rem;
  margin-bottom: 6px;
}

.math-desc {
  font-size: 0.78rem;
  line-height: 1.4;
  color: #1e40af;
}

.live-metrics {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
  background: #ffffff;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid #dbeafe;
}

.metric {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.metric-key {
  font-size: 0.7rem;
  color: #64748b;
  text-transform: uppercase;
}

.metric-val {
  font-size: 0.95rem;
  font-weight: 800;
  color: #0f172a;
}

/* Overlay Card (Win / Game Over) */
.game-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.game-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.overlay-card {
  background: #ffffff;
  border-radius: var(--radius-lg);
  padding: 30px;
  max-width: 420px;
  width: 90%;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: popIn 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.trophy-bounce {
  font-size: 3.5rem;
  margin-bottom: 8px;
  animation: bounce 1.2s infinite alternate ease-in-out;
}

@keyframes bounce {
  from { transform: translateY(0); }
  to { transform: translateY(-8px); }
}

.overlay-card h2 {
  font-size: 1.5rem;
  font-weight: 800;
  color: #15803d;
  margin-bottom: 6px;
}

.overlay-card p {
  font-size: 0.9rem;
  color: #64748b;
  margin-bottom: 20px;
}

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

.overlay-stat-item {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  padding: 10px;
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.overlay-stat-label {
  font-size: 0.72rem;
  color: #64748b;
  text-transform: uppercase;
}

.overlay-stat-value {
  font-size: 1.15rem;
  font-weight: 800;
  color: #0f172a;
}

.overlay-btn {
  background: #22c55e;
  color: #ffffff;
  border: none;
  padding: 12px 24px;
  border-radius: var(--radius-md);
  font-size: 1.05rem;
  font-weight: 800;
  cursor: pointer;
  width: 100%;
  transition: all 0.2s ease;
  box-shadow: 0 4px 12px rgba(34, 197, 94, 0.35);
}

.overlay-btn:hover {
  background: #16a34a;
  transform: translateY(-2px);
}

/* Responsiveness */
@media (max-width: 980px) {
  .game-wrapper {
    flex-direction: column;
  }
  .control-panel {
    width: 100%;
    min-width: unset;
    border-left: none;
    border-top: 1px solid var(--border-color);
  }
}
