/* Moderne Snake-spel med forbetra design */
:root {
  /* Fargepalett */
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --secondary: #10b981;
  --accent: #f59e0b;
  --danger: #ef4444;
  --success: #22c55e;
  
  /* Bakgrunner */
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-tertiary: #f1f5f9;
  --bg-dark: #1e293b;
  --bg-darker: #0f172a;
  
  /* Tekst */
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-light: #94a3b8;
  --text-white: #ffffff;
  
  /* Spill */
  --game-bg: #0f172a;
  --game-frame: #334155;
  --game-accent: #10b981;
  
  /* Skygger */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1);
  
  /* Dark mode */
  --is-dark: 0;
}

[data-theme="dark"] {
  --is-dark: 1;
  --bg-primary: #1e293b;
  --bg-secondary: #334155;
  --bg-tertiary: #475569;
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-light: #94a3b8;
}

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

html, body { 
  height: 100%; 
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
  color: var(--text-primary);
  transition: all 0.3s ease;
}

body {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 1rem;
  min-height: 100vh;
}
/* Header/HUD */
.hud {
  padding: 1rem 1.5rem;
  max-width: 1200px;
  margin: 0 auto;
  width: 95%;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(10px);
  border-radius: 1rem;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 2rem;
  flex-wrap: wrap;
  justify-content: space-between;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

[data-theme="dark"] .hud {
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.hud-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.9rem;
}

.hud-item span {
  background: var(--primary);
  color: white;
  padding: 0.25rem 0.75rem;
  border-radius: 0.5rem;
  font-weight: 700;
  min-width: 2rem;
  text-align: center;
}

.hud-item:last-child {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 500;
}

/* Dark mode toggle */
.theme-toggle {
  background: var(--bg-tertiary);
  border: none;
  border-radius: 0.5rem;
  padding: 0.5rem;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
}

.theme-toggle:hover {
  background: var(--primary);
  color: white;
  transform: scale(1.1);
}

.theme-toggle:active {
  transform: scale(0.95);
}

/* Main content */
.wrap { 
  display: flex; 
  flex-direction: column;
  align-items: center; 
  gap: 2rem;
  padding: 1rem;
  min-height: 100vh;
  justify-content: flex-start;
}

/* Game container */
.game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

/* Fullskjerm knapp */
.fullscreen-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  padding: 0.75rem 1.5rem;
  background: linear-gradient(135deg, var(--secondary) 0%, #059669 100%);
  border: none;
  border-radius: 0.75rem;
  color: white;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: var(--shadow-md);
}

.fullscreen-btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  background: linear-gradient(135deg, #059669 0%, var(--secondary) 100%);
}

.fullscreen-btn:active {
  transform: translateY(0);
}

.fullscreen-btn:focus {
  outline: 2px solid var(--secondary);
  outline-offset: 2px;
}

/* Fullskjerm modus */
.canvas-frame:fullscreen {
  width: 100vw !important;
  height: 100vh !important;
  max-width: none !important;
  max-height: none !important;
  border-radius: 0 !important;
  border: none !important;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--game-bg);
}

.canvas-frame:-webkit-full-screen {
  width: 100vw !important;
  height: 100vh !important;
  max-width: none !important;
  max-height: none !important;
  border-radius: 0 !important;
  border: none !important;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--game-bg);
}

.canvas-frame:-moz-full-screen {
  width: 100vw !important;
  height: 100vh !important;
  max-width: none !important;
  max-height: none !important;
  border-radius: 0 !important;
  border: none !important;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--game-bg);
}

.canvas-frame:-ms-fullscreen {
  width: 100vw !important;
  height: 100vh !important;
  max-width: none !important;
  max-height: none !important;
  border-radius: 0 !important;
  border: none !important;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--game-bg);
}

/* Spill-område - Fast størrelse som alltid har prioritet */
.canvas-frame {
  width: 600px;
  height: 600px;
  background: var(--game-bg);
  border: 3px solid var(--game-frame);
  border-radius: 1.5rem;
  box-shadow: 
    0 25px 50px -12px rgba(0, 0, 0, 0.25),
    inset 0 0 0 1px rgba(255, 255, 255, 0.1),
    0 0 0 1px rgba(255, 255, 255, 0.05);
  position: relative;
  overflow: hidden;
  transition: all 0.3s ease;
  flex-shrink: 0; /* Ikke krymp spillet */
}

.canvas-frame:hover {
  transform: translateY(-2px);
  box-shadow: 
    0 32px 64px -12px rgba(0, 0, 0, 0.35),
    inset 0 0 0 1px rgba(255, 255, 255, 0.15),
    0 0 0 1px rgba(255, 255, 255, 0.1);
}

#game {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 1.25rem;
  /* Sikre at canvas er kvadratisk */
  aspect-ratio: 1 / 1;
  object-fit: contain;
}

/* Responsive design - Spill har alltid prioritet */
@media (max-width: 700px) {
  /* Når skjermen blir smalere enn spillet, beholde spillstørrelse */
  .canvas-frame {
    width: 500px;
    height: 500px;
  }
  
  .wrap {
    gap: 1rem;
    padding: 0.5rem;
  }
  
  .info-panel {
    margin: 0.5rem auto;
    padding: 0.75rem;
  }
  
  .controls-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
  }
}

@media (max-width: 550px) {
  /* Enda mindre skjermer - krymp spillet litt */
  .canvas-frame {
    width: 450px;
    height: 450px;
  }
  
  .hud {
    padding: 0.5rem;
    gap: 0.5rem;
  }
  
  .hud-item {
    font-size: 0.8rem;
  }
  
  .hud-item span {
    padding: 0.2rem 0.4rem;
    min-width: 1.2rem;
  }
  
  .info-panel {
    padding: 0.5rem;
    margin: 0.25rem auto;
  }
  
  .controls-grid {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }
  
  .status-indicators {
    flex-direction: column;
    gap: 0.5rem;
  }
}

@media (max-width: 480px) {
  /* Veldig små skjermer - minimum spillstørrelse */
  .canvas-frame {
    width: 400px;
    height: 400px;
  }
}

@media (max-width: 420px) {
  /* Ekstremt små skjermer - spill må krympes */
  .canvas-frame {
    width: 350px;
    height: 350px;
  }
  
  .wrap {
    gap: 0.5rem;
    padding: 0.25rem;
  }
  
  .hud {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
    padding: 0.5rem;
  }
  
  .hud-item {
    justify-content: center;
    font-size: 0.75rem;
  }
  
  .info-panel {
    padding: 0.5rem;
    margin: 0.25rem auto;
    font-size: 0.9rem;
  }
  
  .controls-grid {
    grid-template-columns: 1fr;
    gap: 0.25rem;
  }
  
  .control-item {
    padding: 0.25rem;
  }
  
  .key {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
  }
  
  .status-indicators {
    flex-direction: column;
    gap: 0.25rem;
  }
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  z-index: 1000;
  animation: fadeIn 0.3s ease;
}

.overlay.hidden { 
  display: none; 
}

.overlay-card {
  background: var(--bg-primary);
  border-radius: 1.5rem;
  padding: 2rem 1.5rem;
  width: min(90%, 420px);
  text-align: center;
  box-shadow: var(--shadow-xl);
  border: 1px solid rgba(255, 255, 255, 0.1);
  animation: slideUp 0.4s ease;
}

.overlay-card h2 {
  color: var(--text-primary);
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

.overlay-card p {
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 1.5rem;
}

/* Knapper */
.btn {
  appearance: none;
  border: none;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 0.75rem;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

.btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transition: left 0.5s;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.btn:hover::before {
  left: 100%;
}

.btn:active { 
  transform: translateY(0); 
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* Animasjoner */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { 
    opacity: 0;
    transform: translateY(20px) scale(0.95);
  }
  to { 
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.pulse {
  animation: pulse 2s infinite;
}

/* Footer */
.foot {
  padding: 1rem 1.5rem;
  max-width: 1200px;
  margin: 0 auto;
  width: 95%;
  text-align: center;
  color: var(--text-light);
  font-size: 0.8rem;
}

/* Informasjonspanel */
.info-panel {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border-radius: 1rem;
  padding: 1.5rem;
  margin: 1rem auto;
  max-width: 600px;
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

[data-theme="dark"] .info-panel {
  background: rgba(30, 41, 59, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.info-panel h3 {
  color: var(--text-primary);
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.info-panel p {
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 0.75rem;
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.control-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  background: var(--bg-tertiary);
  border-radius: 0.5rem;
  font-size: 0.9rem;
}

.control-item .key {
  background: var(--primary);
  color: white;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  font-weight: 600;
  font-size: 0.8rem;
  min-width: 2rem;
  text-align: center;
}

/* Combo og status indikatorer */
.status-indicators {
  display: flex;
  gap: 1rem;
  margin: 1rem 0;
  flex-wrap: wrap;
  justify-content: center;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--bg-secondary);
  border-radius: 0.75rem;
  font-size: 0.9rem;
  font-weight: 600;
}

.status-item.active {
  background: var(--success);
  color: white;
}

.status-item.warning {
  background: var(--accent);
  color: white;
}

.status-item.danger {
  background: var(--danger);
  color: white;
}

/* Loading spinner */
.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--bg-tertiary);
  border-top: 4px solid var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 1rem auto;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Confetti effekt */
.confetti {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9999;
}

.confetti-piece {
  position: absolute;
  width: 10px;
  height: 10px;
  background: var(--primary);
  animation: confetti-fall 3s linear infinite;
}

@keyframes confetti-fall {
  0% {
    transform: translateY(-100vh) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(100vh) rotate(720deg);
    opacity: 0;
  }
}
