/* ==========================================================================
   WIREFLOW — Cyberpunk Blueprint & Neon SaaS Command Center Theme
   Inspired by BRAINIAC SaaS Blueprint
   ========================================================================== */

/* ---------- Design Tokens ---------- */
:root {
  --bg-color: #091421;
  --bg-darker: #060d16;
  --bg-surface: rgba(9, 20, 33, 0.88);
  --surface-card: rgba(17, 24, 39, 0.72);
  --surface-card-hover: rgba(22, 33, 54, 0.9);
  --surface-modal: rgba(10, 20, 34, 0.95);
  --surface-dock: rgba(13, 22, 36, 0.92);

  --brand-cyan: #40e0cf;
  --brand-cyan-bright: #3ce8ec;
  --brand-cyan-glow: rgba(64, 224, 207, 0.4);
  --brand-cyan-subtle: rgba(64, 224, 207, 0.12);
  --brand-blue-dark: #1d3d5f;

  --brand-red: #ff4d4d;
  --brand-red-glow: rgba(255, 77, 77, 0.4);
  --brand-gold: #ffd166;
  --brand-gold-glow: rgba(255, 209, 102, 0.4);
  --brand-green: #27c93f;
  --brand-magenta: #ff007f;

  --text-main: #ffffff;
  --text-muted: #768b9a;
  --text-dim: #455a6c;

  --border-color: rgba(29, 61, 95, 0.65);
  --border-cyan: rgba(64, 224, 207, 0.3);
  --border-cyan-bright: rgba(64, 224, 207, 0.7);

  /* Typography */
  --font-headings: 'Space Grotesk', system-ui, sans-serif;
  --font-body: 'Rubik', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-pill: 999px;

  /* Glows and Shadows */
  --glow-cyan: 0 0 15px rgba(64, 224, 207, 0.35);
  --glow-cyan-lg: 0 0 25px rgba(64, 224, 207, 0.5), 0 0 45px rgba(64, 224, 207, 0.2);
  --glow-gold: 0 0 15px rgba(255, 209, 102, 0.4);
  --glow-red: 0 0 15px rgba(255, 77, 77, 0.4);
  --shadow-subtle: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-prominent: 0 12px 32px rgba(0, 0, 0, 0.6), 0 0 1px rgba(64, 224, 207, 0.3);
  --shadow-modal: 0 25px 60px rgba(0, 0, 0, 0.85), 0 0 35px rgba(64, 224, 207, 0.15);
}

/* ---------- Reset & Base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

::selection {
  background-color: var(--brand-cyan);
  color: var(--bg-color);
}

html {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background-color: var(--bg-color);
}

body {
  background-color: var(--bg-color);
  color: var(--text-main);
  font-family: var(--font-body);
  height: 100%;
  height: 100vh;
  height: 100dvh;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 10px;
  padding-top: max(8px, env(safe-area-inset-top));
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  padding-left: max(10px, env(safe-area-inset-left));
  padding-right: max(10px, env(safe-area-inset-right));
  overflow: hidden;
  position: relative;
  -webkit-font-smoothing: antialiased;
}

/* Cyberpunk Grid Background */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(var(--border-color) 1px, transparent 1px),
    linear-gradient(90deg, var(--border-color) 1px, transparent 1px);
  background-size: 50px 50px;
  z-index: -2;
  pointer-events: none;
  opacity: 0.4;
}

/* Grid Dots at Intersections */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  background-image: radial-gradient(circle at 0px 0px, var(--brand-cyan) 1.5px, transparent 2.5px);
  background-size: 50px 50px;
  z-index: -1;
  pointer-events: none;
  opacity: 0.65;
  filter: drop-shadow(0 0 3px var(--brand-cyan));
}

.game-container {
  max-width: 680px;
  width: 100%;
  height: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: space-between;
  gap: 8px;
  box-sizing: border-box;
  overflow: hidden;
  position: relative;
  z-index: 1;
}

/* =========================================================
   1. UNIFIED APP HEADER (Brand + Stats + Quick Actions)
   ========================================================= */
.header {
  width: 100%;
  background: var(--surface-dock);
  border: 1px solid var(--border-cyan);
  border-radius: var(--radius-md);
  padding: 6px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow-prominent);
  flex-shrink: 0;
}

.header-main-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  gap: 6px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex-wrap: nowrap;
}

.level-chip {
  background: rgba(29, 61, 95, 0.45);
  color: #ffffff;
  border: 1px solid var(--border-cyan);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  white-space: nowrap;
  box-shadow: inset 0 0 8px rgba(64, 224, 207, 0.05);
}

.mode-chip {
  background: rgba(64, 224, 207, 0.12) !important;
  border: 1px solid var(--brand-cyan) !important;
  color: var(--brand-cyan) !important;
  cursor: pointer;
  transition: all 0.2s ease;
}

.mode-chip:hover {
  background: rgba(64, 224, 207, 0.22) !important;
  box-shadow: var(--glow-cyan);
}

.diff-chip {
  background: rgba(39, 201, 63, 0.12) !important;
  border: 1px solid rgba(39, 201, 63, 0.4) !important;
  color: #4ade80 !important;
}

.test-chip {
  background: rgba(255, 209, 102, 0.15) !important;
  border: 1px solid var(--brand-gold) !important;
  color: var(--brand-gold) !important;
}

/* HUD Stats (Цели / Ходы / Par / Звезды) */
.hud-stats-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  width: 100%;
}

.hud-stats {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.stat-badge {
  padding: 4px 6px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.72rem;
  white-space: nowrap;
  background: rgba(17, 24, 39, 0.65);
  color: var(--text-main);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 4px;
  letter-spacing: 0.3px;
  transition: border-color 0.2s ease;
  width: 100%;
  box-sizing: border-box;
}

.stat-targets {
  border-color: rgba(64, 224, 207, 0.45);
  color: var(--brand-cyan);
  background: rgba(64, 224, 207, 0.1);
}

.stat-moves {
  border-color: rgba(255, 255, 255, 0.15);
  color: var(--text-main);
}

.stat-par {
  color: var(--text-muted);
  border-color: rgba(255, 255, 255, 0.1);
}

.stat-stars {
  color: var(--brand-gold);
  border-color: rgba(255, 209, 102, 0.35);
  background: rgba(255, 209, 102, 0.08);
}

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

button.btn-icon {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  border: 1px solid var(--border-cyan);
  border-radius: var(--radius-sm);
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  padding: 0;
}

button.btn-icon:hover {
  background: rgba(64, 224, 207, 0.15);
  border-color: var(--brand-cyan);
  color: var(--brand-cyan);
  box-shadow: var(--glow-cyan);
  transform: translateY(-1px);
}

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

button.btn-icon:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-menu-trigger {
  border-color: var(--border-cyan) !important;
}

.btn-hint {
  border-color: rgba(255, 209, 102, 0.5) !important;
  color: var(--brand-gold) !important;
}

.btn-hint:hover {
  background: rgba(255, 209, 102, 0.2) !important;
  border-color: var(--brand-gold) !important;
  box-shadow: var(--glow-gold) !important;
}

/* =========================================================
   2. HERO CANVAS WRAPPER (Центр игрового процесса)
   ========================================================= */
.canvas-wrapper {
  position: relative;
  background: #091421;
  border: 1px solid var(--border-cyan);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-prominent), inset 0 0 50px rgba(0, 0, 0, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  flex: 1 1 0;
  min-height: 200px;
}

/* Tech corner brackets - hidden to avoid clash with crisp PCB plate */
.canvas-wrapper::before,
.canvas-wrapper::after {
  display: none;
}

canvas#game-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: pointer;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

/* Floating Toast Banner (Мгновенная обратная связь) */
.toast-banner {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  opacity: 0;
  pointer-events: none;
  background: rgba(255, 77, 77, 0.95);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: var(--radius-sm);
  padding: 6px 16px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.4px;
  box-shadow: var(--glow-red), 0 8px 24px rgba(0, 0, 0, 0.6);
  transition: all 0.25s cubic-bezier(0.18, 0.89, 0.32, 1.28);
  z-index: 20;
  white-space: nowrap;
  max-width: 90%;
  text-align: center;
  backdrop-filter: blur(8px);
}

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

.toast-banner.warning {
  background: rgba(255, 209, 102, 0.95);
  color: #091421;
  box-shadow: var(--glow-gold);
}

.toast-banner.success {
  background: rgba(64, 224, 207, 0.95);
  color: #091421;
  box-shadow: var(--glow-cyan);
}

/* =========================================================
   3. INDUSTRIAL CONTROL DECK (Единая панель управления)
   ========================================================= */
.control-deck {
  width: 100%;
  background: var(--surface-dock);
  border: 1px solid var(--border-cyan);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: var(--shadow-prominent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  flex-shrink: 0;
  min-height: 58px;
}

.lever-toggle-btn {
  width: 100%;
  background: linear-gradient(135deg, rgba(64, 224, 207, 0.12) 0%, rgba(29, 61, 95, 0.35) 100%);
  color: #ffffff;
  border: 1px solid var(--border-cyan-bright);
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-family: var(--font-headings);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4), inset 0 0 12px rgba(64, 224, 207, 0.1);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  white-space: nowrap;
  min-height: 46px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  text-shadow: 0 0 10px rgba(64, 224, 207, 0.4);
}

.lever-toggle-btn:hover {
  background: linear-gradient(135deg, rgba(64, 224, 207, 0.25) 0%, rgba(29, 61, 95, 0.55) 100%);
  border-color: var(--brand-cyan);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5), var(--glow-cyan);
  transform: translateY(-2px);
}

.lever-toggle-btn:active {
  transform: translateY(1px);
}

.lever-toggle-btn.active {
  background: linear-gradient(135deg, var(--brand-cyan) 0%, #20b2aa 100%);
  color: #091421;
  font-weight: 800;
  border-color: #ffffff;
  box-shadow: var(--glow-cyan-lg);
  text-shadow: none;
  animation: electricPulse 1.8s infinite alternate;
}

@keyframes electricPulse {
  0% {
    box-shadow: 0 0 20px rgba(64, 224, 207, 0.6);
  }
  100% {
    box-shadow: 0 0 35px rgba(64, 224, 207, 0.9), 0 0 15px #ffffff;
  }
}

.switch-status-led {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--brand-cyan);
  box-shadow: 0 0 8px var(--brand-cyan);
  display: inline-block;
  flex-shrink: 0;
  transition: all 0.2s ease;
}

.lever-toggle-btn.active .switch-status-led {
  background: #ff4d4d;
  box-shadow: 0 0 10px #ff4d4d, 0 0 16px rgba(255, 77, 77, 0.6);
  animation: pulseLed 1s infinite alternate;
}

@keyframes pulseLed {
  0% { transform: scale(0.9); opacity: 0.8; }
  100% { transform: scale(1.15); opacity: 1; }
}

/* =========================================================
   4. MAIN MENU (Главное меню при старте)
   ========================================================= */
.main-menu-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(9, 20, 33, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
  z-index: 200;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.main-menu-overlay.hidden {
  display: none !important;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.menu-card {
  background: var(--surface-modal);
  border: 1px solid var(--border-cyan);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  box-shadow: var(--shadow-modal);
  max-width: 460px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 18px;
  animation: popIn 0.25s cubic-bezier(0.18, 0.89, 0.32, 1.28);
  position: relative;
  overflow: hidden;
}

.menu-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--brand-cyan), transparent);
}

.menu-header {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.menu-badge {
  background: rgba(64, 224, 207, 0.1);
  color: var(--brand-cyan);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid rgba(64, 224, 207, 0.3);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.badge-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  background: var(--brand-cyan);
  border-radius: 50%;
  box-shadow: 0 0 6px var(--brand-cyan);
}

.menu-title {
  font-family: var(--font-headings);
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1;
  color: #ffffff;
  margin-top: 4px;
  background: linear-gradient(180deg, #ffffff 0%, #b2f5ea 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 15px rgba(64, 224, 207, 0.7)) drop-shadow(0 0 35px rgba(64, 224, 207, 0.35));
}

.menu-subtitle {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  line-height: 1.3;
}

.menu-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.menu-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  background: rgba(17, 24, 39, 0.6);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-family: var(--font-body);
  box-shadow: var(--shadow-subtle);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  touch-action: manipulation;
  text-align: left;
  color: var(--text-main);
  position: relative;
  overflow: hidden;
  pointer-events: auto !important;
}

.menu-btn * {
  pointer-events: none !important;
}

.menu-btn:hover {
  background: rgba(22, 33, 54, 0.85);
  border-color: var(--brand-cyan);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5), 0 0 15px rgba(64, 224, 207, 0.2);
  transform: translateY(-2px);
}

.menu-btn:active {
  transform: translateY(1px);
}

.menu-btn-icon {
  font-size: 1.3rem;
  width: 40px;
  height: 40px;
  min-width: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-cyan);
  border-radius: var(--radius-sm);
  background: rgba(9, 20, 33, 0.85);
  box-shadow: inset 0 0 10px rgba(64, 224, 207, 0.1);
  color: var(--brand-cyan);
}

.menu-btn-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.menu-btn-main {
  font-family: var(--font-headings);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #ffffff;
}

.menu-btn-sub {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
}

.menu-btn-continue {
  border-color: rgba(64, 224, 207, 0.5);
  background: linear-gradient(135deg, rgba(64, 224, 207, 0.14) 0%, rgba(17, 24, 39, 0.6) 100%);
}

.menu-btn-continue:hover {
  background: linear-gradient(135deg, rgba(64, 224, 207, 0.25) 0%, rgba(17, 24, 39, 0.8) 100%);
  box-shadow: var(--glow-cyan);
}

.menu-progress-box {
  background: rgba(17, 24, 39, 0.6);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.menu-progress-labels {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

.menu-progress-labels strong {
  color: var(--brand-cyan);
}

.menu-progress-track {
  width: 100%;
  height: 8px;
  background: rgba(9, 20, 33, 0.8);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.menu-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--brand-cyan-bright), var(--brand-cyan));
  border-radius: var(--radius-pill);
  box-shadow: 0 0 10px var(--brand-cyan);
  transition: width 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

/* =========================================================
   5. MODALS (Modes, Levels, Settings, Victory, Help)
   ========================================================= */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 13, 22, 0.85);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  display: none;
  justify-content: center;
  align-items: center;
  padding: 14px;
  z-index: 500;
}

.modal-content {
  background: var(--surface-modal);
  border: 1px solid var(--border-cyan);
  border-radius: var(--radius-lg);
  padding: 22px 20px;
  box-shadow: var(--shadow-modal);
  max-width: 460px;
  width: 100%;
  animation: popIn 0.22s cubic-bezier(0.18, 0.89, 0.32, 1.28);
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
  color: var(--text-main);
}

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

.modal-badge {
  background: rgba(64, 224, 207, 0.12);
  color: var(--brand-cyan);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  border: 1px solid rgba(64, 224, 207, 0.3);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  align-self: flex-start;
}

.modal-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.btn-modal-close {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
  touch-action: manipulation;
}

.btn-modal-close:hover {
  background: rgba(255, 77, 77, 0.2);
  border-color: var(--brand-red);
  color: var(--brand-red);
  box-shadow: var(--glow-red);
}

.modal-content h2 {
  font-family: var(--font-headings);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-main);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  line-height: 1.15;
}

.modal-subtext {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 8px;
  font-family: var(--font-mono);
}

.modal-buttons-row {
  display: flex;
  gap: 10px;
  width: 100%;
  margin-top: 4px;
}

.btn-ctrl {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  cursor: pointer;
  font-family: var(--font-headings);
  font-weight: 700;
  font-size: 0.88rem;
  text-transform: uppercase;
  transition: all 0.2s ease;
  touch-action: manipulation;
  flex: 1;
  min-height: 44px;
}

.btn-ctrl:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--border-cyan);
  color: #ffffff;
}

.btn-ctrl:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--brand-cyan);
  color: #091421;
  border: 1px solid #ffffff;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-family: var(--font-headings);
  font-size: 0.92rem;
  font-weight: 800;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: var(--glow-cyan);
  transition: all 0.2s ease;
  touch-action: manipulation;
  width: 100%;
  min-height: 46px;
  flex: 1.4;
}

.btn-primary:hover {
  background: #5cf4e3;
  box-shadow: var(--glow-cyan-lg);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(1px);
}

/* =========================================================
   6. MODES MODAL (8 Режимов сложности)
   ========================================================= */
.modes-content {
  max-width: 640px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
}

.modes-scroll-container {
  overflow-y: auto;
  max-height: 60vh;
  padding: 4px;
  margin: 6px 0;
}

.modes-scroll-container::-webkit-scrollbar {
  width: 6px;
}
.modes-scroll-container::-webkit-scrollbar-track {
  background: rgba(9, 20, 33, 0.5);
  border-radius: 4px;
}
.modes-scroll-container::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}
.modes-scroll-container::-webkit-scrollbar-thumb:hover {
  background: var(--brand-cyan);
}

.modes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.mode-card {
  background: var(--surface-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
  box-shadow: var(--shadow-subtle);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
  transition: all 0.25s ease;
}

.mode-card:hover {
  background: var(--surface-card-hover);
  border-color: var(--brand-cyan);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5), 0 0 15px rgba(64, 224, 207, 0.15);
  transform: translateY(-2px);
}

.mode-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.mode-card-badge {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--radius-pill);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.badge-story { background: rgba(255, 209, 102, 0.15); color: var(--brand-gold); border: 1px solid rgba(255, 209, 102, 0.4); }
.badge-stress { background: rgba(255, 77, 77, 0.15); color: var(--brand-red); border: 1px solid rgba(255, 77, 77, 0.4); }
.badge-tactic { background: rgba(39, 201, 63, 0.15); color: #4ade80; border: 1px solid rgba(39, 201, 63, 0.4); }
.badge-danger { background: rgba(255, 0, 127, 0.15); color: #ff007f; border: 1px solid rgba(255, 0, 127, 0.4); }
.badge-hardcore { background: rgba(150, 150, 150, 0.15); color: #e2e8f0; border: 1px solid rgba(150, 150, 150, 0.4); }
.badge-deduction { background: rgba(64, 224, 207, 0.15); color: var(--brand-cyan); border: 1px solid rgba(64, 224, 207, 0.4); }
.badge-endless { background: rgba(255, 209, 102, 0.15); color: var(--brand-gold); border: 1px solid rgba(255, 209, 102, 0.4); }
.badge-sandbox { background: rgba(60, 232, 236, 0.15); color: #3ce8ec; border: 1px solid rgba(60, 232, 236, 0.4); }

.mode-card-code {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--brand-cyan);
  background: rgba(64, 224, 207, 0.1);
  border: 1px solid rgba(64, 224, 207, 0.3);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  letter-spacing: 0.5px;
}

.mode-card h3 {
  font-family: var(--font-headings);
  font-size: 1.05rem;
  font-weight: 700;
  color: #ffffff;
  margin: 0;
}

.mode-card p {
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--text-muted);
  margin: 0;
  flex-grow: 1;
}

.btn-mode-select {
  background: rgba(64, 224, 207, 0.12);
  color: var(--brand-cyan);
  border: 1px solid var(--border-cyan);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 8px 12px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  transition: all 0.2s ease;
}

.btn-mode-select:hover {
  background: var(--brand-cyan);
  color: #091421;
  box-shadow: var(--glow-cyan);
}

/* =========================================================
   7. ALL LEVELS MODAL & GRID
   ========================================================= */
.levels-content {
  max-width: 640px;
  max-height: 86vh;
}

.levels-header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.levels-stat-chip {
  background: rgba(64, 224, 207, 0.15);
  color: var(--brand-cyan);
  border: 1px solid var(--border-cyan);
  border-radius: var(--radius-pill);
  padding: 3px 10px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
}

.sector-tabs-container {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 6px;
  margin-bottom: 8px;
  scrollbar-width: thin;
}

.sector-tab {
  background: rgba(17, 24, 39, 0.6);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  padding: 5px 10px;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.2s ease;
}

.sector-tab:hover {
  color: var(--text-main);
  border-color: var(--border-cyan);
}

.sector-tab.active {
  background: rgba(64, 224, 207, 0.15);
  color: var(--brand-cyan);
  border-color: var(--brand-cyan);
  box-shadow: var(--glow-cyan);
}

.levels-scroll-container {
  overflow-y: auto;
  max-height: 56vh;
  padding-right: 4px;
  margin: 4px 0;
}

.levels-scroll-container::-webkit-scrollbar {
  width: 6px;
}
.levels-scroll-container::-webkit-scrollbar-track {
  background: rgba(9, 20, 33, 0.5);
  border-radius: 4px;
}
.levels-scroll-container::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}
.levels-scroll-container::-webkit-scrollbar-thumb:hover {
  background: var(--brand-cyan);
}

.levels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}

.level-card {
  background: var(--surface-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
  box-shadow: var(--shadow-subtle);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  color: var(--text-main);
  pointer-events: auto !important;
}

.level-card * {
  pointer-events: none !important;
}

.level-card:hover {
  background: var(--surface-card-hover);
  border-color: var(--brand-cyan);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.5), 0 0 12px rgba(64, 224, 207, 0.15);
  transform: translateY(-2px);
}

.level-card:active {
  transform: translateY(1px);
}

.level-card.is-current {
  border-color: var(--brand-cyan);
  background: rgba(64, 224, 207, 0.08);
  box-shadow: var(--glow-cyan);
}

.level-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.level-card-num {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  background: rgba(29, 61, 95, 0.6);
  color: var(--text-main);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

.level-card-diff {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
}

.level-card-status {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  background: rgba(64, 224, 207, 0.15);
  color: var(--brand-cyan);
  border: 1px solid var(--border-cyan);
}

.level-card-title {
  font-family: var(--font-headings);
  font-size: 0.92rem;
  font-weight: 700;
  color: #ffffff;
  line-height: 1.2;
}

.level-card-chapter {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-muted);
}

.level-card-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 2px;
  border-top: 1px dashed rgba(255, 255, 255, 0.1);
  padding-top: 6px;
}

.level-card-stars {
  font-size: 0.85rem;
  color: var(--brand-gold);
  text-shadow: 0 0 6px rgba(255, 209, 102, 0.5);
}

.level-play-tag {
  background: rgba(64, 224, 207, 0.15);
  color: var(--brand-cyan);
  border: 1px solid var(--border-cyan);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
}

/* =========================================================
   8. SETTINGS MODAL & FORM CONTROLS
   ========================================================= */
.settings-content {
  max-width: 480px;
  max-height: 88vh;
}

.settings-items-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 4px 0;
  max-height: 60vh;
  overflow-y: auto;
  padding-right: 4px;
}

.setting-row {
  background: rgba(17, 24, 39, 0.6);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.setting-desc {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.setting-desc strong {
  font-family: var(--font-headings);
  font-size: 0.88rem;
  font-weight: 700;
  color: #ffffff;
}

.setting-desc span {
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.25;
}

/* Custom Cyberpunk Toggle */
.brutal-toggle {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 24px;
  flex-shrink: 0;
  cursor: pointer;
}

.brutal-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.brutal-toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: rgba(29, 61, 95, 0.6);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-pill);
  transition: all 0.2s ease;
}

.brutal-toggle-slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 3px;
  top: 3px;
  background-color: #ffffff;
  border-radius: 50%;
  transition: transform 0.2s cubic-bezier(0.18, 0.89, 0.32, 1.28);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.brutal-toggle input:checked + .brutal-toggle-slider {
  background-color: rgba(64, 224, 207, 0.3);
  border-color: var(--brand-cyan);
  box-shadow: var(--glow-cyan);
}

.brutal-toggle input:checked + .brutal-toggle-slider:before {
  transform: translateX(24px);
  background-color: var(--brand-cyan);
}

/* Range Slider */
.setting-slider-row {
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}

.setting-slider-row .setting-desc {
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}

.setting-slider-row .setting-desc span {
  font-family: var(--font-mono);
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--brand-cyan);
}

.slider-wrapper {
  width: 100%;
}

.brutal-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  background: rgba(29, 61, 95, 0.6);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-pill);
  outline: none;
}

.brutal-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  background: var(--brand-cyan);
  border: 2px solid #ffffff;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: var(--glow-cyan);
  transition: transform 0.15s ease;
}

.brutal-slider::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

.brutal-slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  background: var(--brand-cyan);
  border: 2px solid #ffffff;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: var(--glow-cyan);
}

.btn-setting-action {
  flex: none;
  padding: 6px 12px;
  font-size: 0.78rem;
  min-height: 34px;
}

.btn-danger {
  background: rgba(255, 77, 77, 0.15);
  color: var(--brand-red);
  border: 1px solid rgba(255, 77, 77, 0.4);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-family: var(--font-headings);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  text-transform: uppercase;
  flex: none;
  min-height: 34px;
  transition: all 0.2s ease;
}

.btn-danger:hover {
  background: var(--brand-red);
  color: #ffffff;
  box-shadow: var(--glow-red);
  transform: translateY(-1px);
}

/* =========================================================
   9. VICTORY MODAL (Level Completed)
   ========================================================= */
.victory-content {
  text-align: center;
  align-items: center;
}

.victory-icon-wrap {
  font-size: 2.2rem;
  margin: 2px 0;
  filter: drop-shadow(0 0 12px rgba(64, 224, 207, 0.5));
}

.victory-content p {
  color: var(--text-muted);
  font-size: 0.88rem;
  line-height: 1.35;
}

.victory-stars-box {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 8px 0;
}

.v-star {
  font-size: 2.4rem;
  color: rgba(255, 255, 255, 0.18);
  transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275), color 0.2s ease;
}

.v-star.earned {
  color: var(--brand-gold);
  text-shadow: 0 0 15px rgba(255, 209, 102, 0.7);
  transform: scale(1.2);
}

.victory-stars-title {
  font-family: var(--font-headings);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--brand-cyan);
  margin-bottom: 8px;
  text-shadow: 0 0 10px rgba(64, 224, 207, 0.4);
}

.victory-stats-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  width: 100%;
  margin: 4px 0;
}

.victory-stat-item {
  background: rgba(17, 24, 39, 0.6);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 8px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 90px;
}

.v-stat-label {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-muted);
}

.v-stat-val {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 800;
  color: #ffffff;
}

.victory-buttons {
  display: flex;
  gap: 10px;
  width: 100%;
  margin-top: 4px;
}

/* =========================================================
   10. HELP MODAL & LEGEND
   ========================================================= */
.help-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 4px 0 8px 0;
}

.help-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(17, 24, 39, 0.6);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 8px 12px;
}

.help-badge {
  width: 34px;
  height: 34px;
  min-width: 34px;
  border: 1px solid var(--border-cyan);
  border-radius: var(--radius-sm);
  background: rgba(9, 20, 33, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

.help-item-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.help-item-text strong {
  font-family: var(--font-headings);
  font-size: 0.88rem;
  font-weight: 700;
  color: #ffffff;
}

.help-item-text span {
  font-size: 0.74rem;
  color: var(--text-muted);
  line-height: 1.25;
}

/* =========================================================
   11. DYNAMIC HUD & SANDBOX CONTROLS
   ========================================================= */
.mode-hud-deck {
  width: 100%;
  background: var(--surface-dock);
  border: 1px solid var(--border-cyan);
  border-radius: var(--radius-md);
  padding: 6px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  box-shadow: var(--shadow-subtle);
  box-sizing: border-box;
}

.mode-hud-stat {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-main);
}

.meter-track {
  width: 110px;
  height: 8px;
  background: rgba(9, 20, 33, 0.9);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-pill);
  overflow: hidden;
  display: inline-block;
  vertical-align: middle;
}

.meter-fill-heat {
  height: 100%;
  background: var(--brand-cyan);
  box-shadow: 0 0 8px var(--brand-cyan);
  transition: width 0.2s ease, background-color 0.2s ease;
}

.meter-fill-battery {
  height: 100%;
  background: #4ade80;
  box-shadow: 0 0 8px #4ade80;
  transition: width 0.15s ease;
}

.sandbox-palette-row {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  align-items: center;
}

.sb-tool-btn {
  background: rgba(17, 24, 39, 0.6);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: var(--radius-sm);
  padding: 3px 8px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
}

.sb-tool-btn.active {
  background: rgba(64, 224, 207, 0.2);
  border-color: var(--brand-cyan);
  color: var(--brand-cyan);
  box-shadow: var(--glow-cyan);
}

.cyber-textarea {
  width: 100%;
  height: 180px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 10px;
  border: 1px solid var(--border-cyan);
  border-radius: var(--radius-sm);
  box-sizing: border-box;
  background: rgba(9, 20, 33, 0.9);
  color: var(--brand-cyan);
  resize: none;
  outline: none;
}

/* =========================================================
   12. RESPONSIVE ADAPTATIONS
   ========================================================= */
@media (max-width: 520px) {
  body {
    padding: 6px 8px;
  }

  .game-container {
    gap: 6px;
  }

  .header {
    padding: 5px 8px;
    gap: 5px;
  }

  .level-chip {
    font-size: 0.68rem;
    padding: 2px 5px;
  }

  .hud-stats-bar {
    gap: 4px;
  }

  .stat-badge {
    padding: 3px 2px;
    font-size: 0.68rem;
  }

  button.btn-icon {
    width: 28px;
    height: 28px;
    font-size: 0.78rem;
  }

  .control-deck {
    padding: 6px 8px;
    min-height: 50px;
  }

  .lever-toggle-btn {
    padding: 8px 12px;
    font-size: 0.84rem;
    min-height: 40px;
  }

  .menu-title {
    font-size: 2.3rem;
  }
}

@media (max-width: 360px) {
  .hud-stats,
  .hud-stats-bar {
    gap: 3px;
  }

  .level-chip {
    font-size: 0.62rem;
    padding: 2px 4px;
  }

  .stat-badge {
    font-size: 0.62rem;
    padding: 2px 2px;
  }

  button.btn-icon {
    width: 26px;
    height: 26px;
    font-size: 0.72rem;
  }

  .lever-toggle-btn {
    font-size: 0.76rem;
  }
}

@media (max-height: 440px) {
  body {
    padding: 4px;
  }

  .game-container {
    gap: 4px;
  }

  .control-deck {
    min-height: 42px;
    padding: 4px 8px;
  }

  .lever-toggle-btn {
    min-height: 34px;
    padding: 4px 10px;
  }
}
