/* ========== Токены и основа ========== */
:root {
  --brand: #f59e0b;
  --brand-2: #ea580c;
  --accent: #10b981;
  --bg: #0f1419;
  --surface: #1a1f2e;
  --surface-2: #252d3f;
  --text: #e5e7eb;
  --text-2: #9ca3af;
  --border: rgba(255,255,255,0.08);
  --shadow: 0 4px 12px rgba(0,0,0,0.4), 0 1px 3px rgba(0,0,0,0.3);
  --radius: 16px;
  --trans: 0.2s cubic-bezier(0.4,0,0.2,1);
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

.game-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* ========== Шапка ========== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 100;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-logo {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
}

.brand-name {
  font-family: 'Baloo 2', system-ui, sans-serif;
  font-weight: 700;
  font-size: clamp(1rem, 3vw, 1.25rem);
  color: var(--brand);
  white-space: nowrap;
}

.brand-name em {
  font-style: normal;
  color: var(--text);
}

.topnav {
  display: flex;
  gap: 0.5rem;
}

.btn-ghost {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-2);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all var(--trans);
}

.btn-ghost:hover {
  color: var(--text);
  border-color: var(--brand);
  background: rgba(245,158,11,0.1);
}

/* ========== Основная сцена ========== */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* HUD */
.hud {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.75rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.hud-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.hud-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-2);
}

.hud-val {
  font-family: 'Baloo 2', system-ui, sans-serif;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--brand);
}

.hud-time .hud-val {
  color: var(--accent);
}

.hud-pause {
  margin-left: auto;
}

/* Игровое поле */
.field-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #0f1419 0%, #1a1f2e 100%);
}

#game {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  border: 2px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

/* Оверлеи */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15,20,25,0.95);
  backdrop-filter: blur(8px);
  z-index: 50;
  padding: 1.5rem;
  overflow-y: auto;
}

.panel {
  width: 100%;
  max-width: 640px;
  padding: 2.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel-sm {
  max-width: 480px;
}

.panel h1, .panel h2 {
  font-family: 'Baloo 2', system-ui, sans-serif;
  font-weight: 800;
  font-size: clamp(1.75rem, 5vw, 2.5rem);
  line-height: 1.2;
  color: var(--brand);
  margin-bottom: 1rem;
}

.panel h2 {
  font-size: clamp(1.5rem, 4vw, 2rem);
}

.lead {
  font-size: 1.125rem;
  line-height: 1.6;
  color: var(--text-2);
  margin-bottom: 1.5rem;
}

.rules {
  list-style: none;
  margin: 1.5rem 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.rules li {
  padding-left: 1.5rem;
  position: relative;
  color: var(--text-2);
  line-height: 1.6;
}

.rules li::before {
  content: '→';
  position: absolute;
  left: 0;
  color: var(--accent);
  font-weight: 700;
}

.rules b {
  color: var(--text);
  font-weight: 600;
}

.cta-row {
  display: flex;
  gap: 1rem;
  margin-top: 2rem;
  flex-wrap: wrap;
}

.btn {
  padding: 0.875rem 2rem;
  font-size: 1rem;
  font-weight: 700;
  color: #0f1419;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: all var(--trans);
  box-shadow: 0 2px 8px rgba(245,158,11,0.3);
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(245,158,11,0.4);
}

.btn-play {
  font-family: 'Baloo 2', system-ui, sans-serif;
  font-size: 1.125rem;
}

/* Результат */
.result-big {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 2rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin: 1.5rem 0;
}

.result-big span {
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-2);
}

.result-big strong {
  font-family: 'Baloo 2', system-ui, sans-serif;
  font-size: clamp(2.5rem, 6vw, 4rem);
  font-weight: 800;
  color: var(--brand);
}

/* Форма сохранения */
.save-form {
  margin: 1.5rem 0;
}

.save-form label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 0.75rem;
}

.save-row {
  display: flex;
  gap: 0.75rem;
}

.save-row input {
  flex: 1;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  transition: border-color var(--trans);
}

.save-row input:focus {
  border-color: var(--brand);
}

.save-hint {
  margin-top: 0.75rem;
  font-size: 0.875rem;
  color: var(--accent);
}

/* Таблица рекордов */
.scoreboard {
  list-style: none;
  margin: 1.5rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.scoreboard li {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: background var(--trans);
}

.scoreboard li:hover {
  background: rgba(245,158,11,0.05);
}

.sb-rank {
  font-family: 'Baloo 2', system-ui, sans-serif;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--brand);
  min-width: 2rem;
}

.sb-name {
  flex: 1;
  font-weight: 600;
  color: var(--text);
}

.sb-score {
  font-family: 'Baloo 2', system-ui, sans-serif;
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--brand);
}

.sb-wave {
  font-size: 0.875rem;
  color: var(--text-2);
}

.sb-loading {
  text-align: center;
  color: var(--text-2);
  padding: 2rem;
}

/* D-Pad для мобилок */
.dpad {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  grid-template: 
    ". up ." 50px
    "left . right" 50px
    ". down ." 50px
    / 50px 50px 50px;
  gap: 0.5rem;
  z-index: 60;
}

.dbtn {
  width: 50px;
  height: 50px;
  font-size: 1.25rem;
  color: var(--text);
  background: rgba(26,31,46,0.9);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all var(--trans);
  backdrop-filter: blur(4px);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.dbtn:active {
  background: var(--brand);
  color: #0f1419;
  transform: scale(0.95);
}

.dbtn-up { grid-area: up; }
.dbtn-left { grid-area: left; }
.dbtn-right { grid-area: right; }
.dbtn-down { grid-area: down; }

/* Подвал */
.botbar {
  padding: 1rem 1.5rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 0.875rem;
  color: var(--text-2);
  flex-shrink: 0;
}

/* Адаптив */
@media (max-width: 640px) {
  .topbar {
    padding: 0.5rem 1rem;
  }
  .brand-name {
    font-size: 0.875rem;
  }
  .topnav {
    gap: 0.25rem;
  }
  .btn-ghost {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
  }
  .hud {
    gap: 1rem;
    padding: 0.5rem 1rem;
  }
  .hud-val {
    font-size: 1rem;
  }
  .panel {
    padding: 1.5rem;
  }
  .cta-row {
    flex-direction: column;
  }
  .btn, .btn-ghost {
    width: 100%;
  }
  .save-row {
    flex-direction: column;
  }
  .botbar {
    font-size: 0.75rem;
    padding: 0.75rem 1rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Экраны игры прячутся атрибутом hidden, а .overlay задаёт display:flex —
   собственное правило сильнее браузерного [hidden]{display:none}, поэтому
   стартовый экран оставался поверх поля и в игру было не войти. */
[hidden] { display: none !important; }
