/* ==========================================================================
   FLUXLEFT - Cyberpunk Spanning Tree Energy Grid Design System
   Copyright (C) 2026 Left Gaming / Douglas Knoll
   SPDX-License-Identifier: GPL-3.0-or-later
   Released under the GNU General Public License v3.0 or later.
   ========================================================================== */

:root {
  --bg-main: #070913;
  --bg-gradient: radial-gradient(circle at 50% 35%, #11172e 0%, #070913 75%, #030408 100%);
  --surface-glass: rgba(14, 20, 38, 0.75);
  --surface-glass-hover: rgba(24, 34, 62, 0.88);
  --surface-card: rgba(18, 26, 48, 0.92);
  --border-glass: rgba(255, 255, 255, 0.08);
  --border-glass-glow: rgba(0, 240, 255, 0.35);

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent-cyan: #00f0ff;
  --accent-cyan-glow: rgba(0, 240, 255, 0.5);
  --accent-emerald: #00ff88;
  --accent-emerald-glow: rgba(0, 255, 136, 0.55);
  --accent-amber: #ffb700;
  --accent-amber-glow: rgba(255, 183, 0, 0.55);
  --accent-crimson: #ff0055;
  --accent-crimson-glow: rgba(255, 0, 85, 0.6);

  --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  --shadow-subtle: 0 4px 20px -2px rgba(0, 0, 0, 0.4);
  --shadow-elevated: 0 12px 40px -4px rgba(0, 0, 0, 0.65);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-sans);
  background: var(--bg-main);
  background-image: var(--bg-gradient);
  color: var(--text-primary);
  user-select: none;
  -webkit-user-select: none;
}

/* App Container */
.app-container {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  position: relative;
}

/* Header & HUD */
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--surface-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-glass);
  z-index: 10;
  gap: 16px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: 2px;
  font-size: 1.15rem;
  background: linear-gradient(135deg, #00f0ff 0%, #00ff88 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo-icon {
  width: 26px;
  height: 26px;
  color: var(--accent-cyan);
  filter: drop-shadow(0 0 8px var(--accent-cyan-glow));
}

.grid-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-glass);
  padding: 6px 12px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 0.2s ease;
}

.grid-badge:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--border-glass-glow);
}

.grid-badge .label {
  font-size: 0.72rem;
  letter-spacing: 1px;
  color: var(--text-muted);
  font-weight: 600;
}

.grid-badge .val {
  font-size: 0.95rem;
  font-weight: 700;
  color: #fff;
}

.grid-badge .chevron-icon {
  color: var(--text-muted);
  transition: transform 0.2s;
}

.grid-badge:hover .chevron-icon {
  color: var(--text-primary);
  transform: translateY(1px);
}

/* Stats Badges */
.header-stats {
  display: flex;
  align-items: center;
  gap: 12px;
}

.stat-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-glass);
  padding: 4px 14px;
  border-radius: var(--radius-sm);
  min-width: 82px;
}

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

.stat-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.power-stat {
  border-color: rgba(0, 240, 255, 0.35);
  background: rgba(0, 240, 255, 0.08);
}

.power-stat .stat-value {
  color: var(--accent-cyan);
  text-shadow: 0 0 10px var(--accent-cyan-glow);
}

.power-stat.all-powered {
  border-color: rgba(0, 255, 136, 0.4);
  background: rgba(0, 255, 136, 0.12);
}

.power-stat.all-powered .stat-value {
  color: var(--accent-emerald);
  text-shadow: 0 0 12px var(--accent-emerald-glow);
}

.leak-stat {
  border-color: rgba(255, 183, 0, 0.35);
  background: rgba(255, 183, 0, 0.08);
}

.leak-stat .stat-value {
  color: var(--accent-amber);
  text-shadow: 0 0 10px var(--accent-amber-glow);
}

.leak-stat.zero-leaks .stat-value {
  color: var(--accent-emerald);
  text-shadow: 0 0 10px var(--accent-emerald-glow);
}

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

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-glass);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

.icon-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.icon-btn:active:not(:disabled) {
  transform: translateY(1px);
}

.icon-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* Main Playfield */
.game-board {
  flex: 1;
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#gameCanvas {
  display: block;
  touch-action: none;
  cursor: pointer;
}

/* Footer Instructions */
.canvas-footer-tip {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10, 14, 28, 0.75);
  backdrop-filter: blur(10px);
  padding: 8px 20px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-glass);
  font-size: 0.85rem;
  color: var(--text-secondary);
  pointer-events: none;
  text-align: center;
  white-space: nowrap;
}

.canvas-footer-tip strong {
  color: var(--text-primary);
}

/* Hint Toast */
.hint-toast {
  position: absolute;
  top: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: rgba(0, 240, 255, 0.18);
  border: 1px solid rgba(0, 240, 255, 0.5);
  backdrop-filter: blur(12px);
  padding: 8px 18px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  font-weight: 500;
  color: #cffafe;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 20;
}

.hint-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(3, 5, 12, 0.8);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  opacity: 1;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

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

.modal-card {
  background: var(--surface-card);
  border: 1px solid var(--border-glass-glow);
  box-shadow: var(--shadow-elevated), 0 0 50px rgba(0, 240, 255, 0.15);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 460px;
  padding: 28px;
  position: relative;
  animation: modalScaleUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-large {
  max-width: 580px;
  max-height: 85vh;
  overflow-y: auto;
}

@keyframes modalScaleUp {
  from {
    opacity: 0;
    transform: scale(0.92) translateY(12px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

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

.modal-header h2 {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.btn-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.6rem;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
  transition: color 0.15s ease;
}

.btn-close:hover {
  color: var(--text-primary);
}

/* Grid Presets */
.grid-presets {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  max-height: 420px;
  overflow-y: auto;
  padding-right: 4px;
}

.preset-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s ease;
}

.preset-btn:hover {
  background: rgba(0, 240, 255, 0.12);
  border-color: var(--border-glass-glow);
  transform: translateY(-2px);
}

.preset-btn.active {
  background: linear-gradient(135deg, rgba(0, 240, 255, 0.25), rgba(0, 255, 136, 0.2));
  border-color: var(--accent-cyan);
  box-shadow: 0 0 16px var(--accent-cyan-glow);
}

.preset-title {
  font-size: 1.15rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: #fff;
  margin-bottom: 4px;
}

.preset-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Primary / Secondary Buttons */
.btn-primary {
  width: 100%;
  padding: 12px 20px;
  background: linear-gradient(135deg, #00f0ff 0%, #00ff88 100%);
  color: #050811;
  border: none;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.3px;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(0, 240, 255, 0.4);
  transition: all 0.2s ease;
}

.btn-primary:hover {
  opacity: 0.95;
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(0, 240, 255, 0.55);
}

.btn-secondary {
  width: 100%;
  padding: 12px 20px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--border-glass);
  color: var(--text-primary);
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
}

/* Help Content */
.help-content {
  color: var(--text-secondary);
  line-height: 1.65;
  font-size: 0.92rem;
}

.help-content h3 {
  color: var(--text-primary);
  font-size: 1.05rem;
  margin-top: 18px;
  margin-bottom: 6px;
}

.help-content h3:first-of-type {
  margin-top: 0;
}

.math {
  font-family: var(--font-mono);
  color: #38bdf8;
  font-weight: 600;
}

.math-equation {
  margin: 12px 0;
  padding: 12px 18px;
  background: rgba(0, 0, 0, 0.4);
  border-left: 3px solid var(--accent-cyan);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 1.15rem;
  color: #38bdf8;
  font-weight: 700;
  text-align: center;
}

.keyboard-shortcuts {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border-glass);
}

.keyboard-shortcuts h4 {
  color: var(--text-primary);
  margin-bottom: 10px;
  font-size: 0.95rem;
}

.keyboard-shortcuts ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.keyboard-shortcuts kbd {
  display: inline-block;
  padding: 2px 6px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--border-glass);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-primary);
}

/* Victory Overlay */
.victory-card {
  text-align: center;
  max-width: 420px;
}

.victory-trophy {
  position: relative;
  width: 72px;
  height: 72px;
  margin: 0 auto 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.trophy-halo {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle, var(--accent-emerald-glow) 0%, transparent 70%);
  animation: pulseGlow 2s infinite ease-in-out;
}

@keyframes pulseGlow {
  0%, 100% { transform: scale(1); opacity: 0.6; }
  50% { transform: scale(1.35); opacity: 1; }
}

.trophy-emoji {
  font-size: 2.5rem;
  z-index: 1;
}

.victory-title {
  font-size: 1.75rem;
  font-weight: 700;
  background: linear-gradient(135deg, #00ff88 0%, #00f0ff 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 6px;
}

.victory-subtitle {
  color: var(--text-secondary);
  font-size: 0.92rem;
  margin-bottom: 24px;
}

.victory-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 24px;
}

.v-stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: rgba(255, 255, 255, 0.04);
  padding: 10px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-glass);
}

.v-stat-val {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
}

.v-stat-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.victory-buttons {
  display: flex;
  gap: 12px;
}

/* Utilities */
.hidden {
  display: none !important;
}

.font-mono {
  font-family: var(--font-mono);
}

/* Responsive */
@media (max-width: 680px) {
  .game-header {
    padding: 10px 14px;
  }
  .logo-text {
    display: none;
  }
  .stat-card {
    min-width: 64px;
    padding: 4px 8px;
  }
  .stat-label {
    font-size: 0.58rem;
  }
  .stat-value {
    font-size: 0.92rem;
  }
  .header-actions {
    gap: 4px;
  }
  .icon-btn {
    width: 34px;
    height: 34px;
  }
  .canvas-footer-tip {
    font-size: 0.75rem;
    padding: 6px 14px;
    bottom: 12px;
    width: 90%;
    white-space: normal;
  }
  .grid-presets {
    grid-template-columns: 1fr;
  }
}


/* --- Left Gaming Cross-Navigation Bar --- */
.lg-crossnav {
  width: 100%;
  background: rgba(6, 8, 14, 0.96);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding: 6px 16px;
  position: relative;
  z-index: 9999;
  box-sizing: border-box;
}
.is-in-iframe .lg-crossnav {
  display: none !important;
}
.lg-crossnav-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.lg-back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #00f0ff;
  text-decoration: none;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.15s;
}
.lg-back-link:hover {
  background: rgba(0, 240, 255, 0.12);
}
.lg-game-dropdown {
  display: flex;
  align-items: center;
  gap: 8px;
}
.lg-hub-pill {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.65rem;
  font-weight: 700;
  color: #94a3b8;
  letter-spacing: 0.1em;
}
.lg-nav-select {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  padding: 4px 10px;
  font-family: inherit;
  font-size: 0.82rem;
  outline: none;
  cursor: pointer;
}
.lg-nav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.lg-fullscreen-btn {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #94a3b8;
  padding: 5px 9px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.lg-fullscreen-btn:hover {
  color: #fff;
  border-color: #00f0ff;
  background: rgba(0, 240, 255, 0.08);
}
@media (max-width: 600px) {
  .lg-back-text {
    display: none;
  }
}
