/* ============================================================
   КИБЕР-ЩИТ — оформление в стиле терминала SOC
   ============================================================ */

:root {
  --bg: #05080c;
  --panel: #0b1219;
  --panel-2: #101a24;
  --line: #1c2b38;
  --text: #c9e3ef;
  --muted: #6f8a9c;
  --accent: #2ee6a6;
  --accent-dim: #1b8f68;
  --danger: #ff4d5e;
  --warn: #ffcc4d;
  --boss: #ff6a3d;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  padding: 1.5rem;
  display: block;
  font-family: "Consolas", "JetBrains Mono", ui-monospace, monospace;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(46, 230, 166, 0.06), transparent 60%),
    var(--bg);
}

.hidden { display: none !important; }

/* ---------- ФОН: МАТРИЦА ---------- */
#matrixCanvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: -1;
  pointer-events: none;
  opacity: 0.3;
}

/* ---------- Стартовый экран ---------- */
.start-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10; /* Чтобы быть поверх холста с матрицей */
}

.start-card {
  max-width: 560px;
  width: 100%;
  padding: 2.2rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(11, 18, 25, 0.9), rgba(16, 26, 36, 0.9));
  backdrop-filter: blur(4px);
  box-shadow: 0 0 60px rgba(46, 230, 166, 0.08), inset 0 0 0 1px rgba(255,255,255,0.02);
  text-align: center;
}

.start-card h1 {
  margin: 0 0 0.25rem;
  font-size: 2rem;
  letter-spacing: 0.08em;
  color: var(--accent);
  text-shadow: 0 0 18px rgba(46, 230, 166, 0.45);
}

.subtitle {
  margin: 0 0 1.4rem;
  color: var(--muted);
  letter-spacing: 0.12em;
  font-size: 0.85rem;
  text-transform: uppercase;
}

.rules {
  text-align: left;
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 0.9rem 1.1rem;
  background: rgba(0, 0, 0, 0.35);
  margin-bottom: 1.6rem;
}

.rules p { margin: 0 0 0.5rem; color: var(--accent); }
.rules ul { margin: 0; padding-left: 1.1rem; }
.rules li { margin: 0.35rem 0; color: var(--text); font-size: 0.92rem; line-height: 1.4; }

.btn-start {
  font-family: inherit;
  font-size: 1.05rem;
  letter-spacing: 0.15em;
  padding: 0.85rem 2.4rem;
  color: #04120c;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
  transition: transform 0.08s ease, box-shadow 0.2s ease;
  box-shadow: 0 0 24px rgba(46, 230, 166, 0.35);
}
.btn-start:hover { transform: translateY(-1px); box-shadow: 0 0 34px rgba(46,230,166,0.55); }
.btn-start:active { transform: translateY(1px); }

/* ---------- Игровой экран ---------- */
.game {
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

.hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(11, 18, 25, 0.85);
  backdrop-filter: blur(4px);
  margin-bottom: 1rem;
}

.hud-left { display: flex; align-items: center; gap: 1rem; }
.hud-right { display: flex; align-items: center; gap: 0.6rem; }

#waveInfo {
  font-size: 0.95rem;
  letter-spacing: 0.06em;
  color: var(--muted);
  text-transform: uppercase;
}

.boss-timer {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--warn);
  padding: 0.15rem 0.6rem;
  border: 1px solid currentColor;
  border-radius: 6px;
  letter-spacing: 0.1em;
  transition: color 0.2s, background 0.2s;
}
.boss-timer.danger {
  color: #fff;
  background: var(--danger);
  border-color: var(--danger);
  animation: pulse 0.6s infinite alternate;
}
@keyframes pulse { from { opacity: 1; } to { opacity: 0.55; } }

.money {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  padding: 0.2rem 0.7rem;
  border: 1px solid var(--accent-dim);
  border-radius: 6px;
  background: rgba(46, 230, 166, 0.06);
  min-width: 70px;
  text-align: right;
}

.sound-btn, .reset-btn {
  font-size: 1rem;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.35rem 0.55rem;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.sound-btn:hover, .reset-btn:hover { border-color: var(--accent-dim); background: rgba(46,230,166,0.06); }

/* ---------- Арена ---------- */
.arena {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.8rem;
  padding: 2rem 1rem 2.2rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background:
    repeating-linear-gradient(0deg, rgba(255,255,255,0.015) 0 1px, transparent 1px 24px),
    rgba(16, 26, 36, 0.85);
  backdrop-filter: blur(4px);
  margin-bottom: 1rem;
  overflow: hidden;
}

.virus-image {
  width: 128px;
  height: 128px;
  object-fit: contain;
  cursor: pointer;
  user-select: none;
  transition: transform 0.08s ease;
  filter: drop-shadow(0 0 18px rgba(255, 77, 94, 0.35));
  animation: float 3s ease-in-out infinite;
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-6px); }
}

.virus-image.hit { animation: shake 0.15s ease; }
.virus-image.crit-hit { animation: shake 0.2s ease, flash 0.25s ease; }
@keyframes shake {
  0% { transform: translate(0, 0) rotate(0); }
  25% { transform: translate(-4px, -3px) rotate(-3deg); }
  50% { transform: translate(4px, 2px) rotate(3deg); }
  75% { transform: translate(-3px, 2px) rotate(-2deg); }
  100% { transform: translate(0, 0) rotate(0); }
}
@keyframes flash {
  0%, 100% { filter: drop-shadow(0 0 18px rgba(255, 77, 94, 0.35)); }
  50%      { filter: drop-shadow(0 0 28px rgba(255, 204, 77, 0.95)) brightness(1.5); }
}

.virus-name {
  font-size: 0.95rem;
  letter-spacing: 0.12em;
  color: var(--muted);
  text-transform: uppercase;
}

/* Шкала HP */
.hp-bar {
  position: relative;
  width: min(560px, 90%);
  height: 26px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #060b10;
  overflow: hidden;
}
.hp-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #1fbf8a, #2ee6a6);
  box-shadow: inset 0 0 12px rgba(46, 230, 166, 0.4);
  transition: width 0.15s linear;
}
.hp-fill.boss {
  background: linear-gradient(90deg, #b8321a, #ff6a3d);
  box-shadow: inset 0 0 14px rgba(255, 106, 61, 0.5);
}
.hp-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #eafff7;
  text-shadow: 0 1px 2px #000;
  pointer-events: none;
}

/* Слой всплывающих цифр */
.damage-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.dmg {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 0 6px rgba(255,255,255,0.6), 0 1px 2px #000;
  animation: rise 0.9s ease-out forwards;
  white-space: nowrap;
}
.dmg.crit {
  color: var(--danger);
  font-size: 1.45rem;
  text-shadow: 0 0 10px rgba(255, 77, 94, 0.9), 0 1px 2px #000;
}
@keyframes rise {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  20%  { opacity: 1; transform: translate(-50%, -80%) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -160%) scale(1); }
}

/* ---------- Улучшения ---------- */
.upgrades {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.9rem;
}

.upgrade-card {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.9rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(11, 18, 25, 0.85), rgba(16, 26, 36, 0.85));
  backdrop-filter: blur(4px);
  transition: border-color 0.2s, transform 0.1s;
}
.upgrade-card:hover { border-color: var(--accent-dim); transform: translateY(-2px); }

.upg-icon { font-size: 1.6rem; }
.upg-title { font-size: 0.95rem; font-weight: 700; color: var(--accent); letter-spacing: 0.03em; }
.upg-effect { font-size: 0.82rem; color: var(--muted); }
.upg-level { font-size: 0.8rem; color: var(--text); margin-top: 0.15rem; }

.btn-buy {
  margin-top: 0.5rem;
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.5rem 0.6rem;
  color: #04120c;
  background: var(--accent);
  border: none;
  border-radius: 7px;
  cursor: pointer;
  font-weight: 700;
  transition: background 0.2s, opacity 0.2s, transform 0.08s;
}
.btn-buy:hover:not(:disabled) { background: #6bffcf; }
.btn-buy:active:not(:disabled) { transform: scale(0.97); }
.btn-buy:disabled {
  background: #1a2733;
  color: #4a6172;
  cursor: not-allowed;
}

/* ---------- Адаптив ---------- */
@media (max-width: 720px) {
  body { padding: 0.8rem; }
  .upgrades { grid-template-columns: 1fr; }
  .virus-image { width: 96px; height: 96px; }
  .hud { flex-direction: column; align-items: stretch; }
  .hud-left, .hud-right { justify-content: space-between; }
}

@font-face {
  font-family: "JetBrains Mono Local";
  src: local("JetBrains Mono"), local("JetBrainsMono-Regular");
  font-display: swap;
}

body {
  font-family: "JetBrains Mono Local", "Consolas", ui-monospace, monospace;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  opacity: 0.12;
  background: repeating-linear-gradient(to bottom, transparent 0 2px, rgba(0, 0, 0, 0.36) 3px 4px);
}

.screen-vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.screen-vignette {
  z-index: 1;
  background: radial-gradient(circle, transparent 40%, rgba(0, 0, 0, 0.58) 100%);
}

.start-card h1,
.money #money { animation: flicker 3.8s steps(1, end) infinite; }
@keyframes flicker {
  0%, 94%, 96%, 100% { opacity: 1; }
  95% { opacity: 0.96; }
}

.game.active .arena,
.game.active .upgrade-card {
  animation: rise-in 0.45s ease both;
}
.game.active .upgrade-card:nth-child(2) { animation-delay: 0.08s; }
.game.active .upgrade-card:nth-child(3) { animation-delay: 0.16s; }
@keyframes rise-in {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.hud { position: relative; }
.hud-brand { display: flex; align-items: center; gap: 0.55rem; }
.soc-badge {
  padding: 0.25rem 0.45rem;
  color: #07150f;
  background: var(--accent);
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 800;
}
.online-status { color: var(--accent); font-size: 0.65rem; letter-spacing: 0.08em; }
.online-status::before { content: ""; display: inline-block; width: 6px; height: 6px; margin-right: 5px; border-radius: 50%; background: currentColor; box-shadow: 0 0 8px currentColor; }

.boss-timer {
  position: relative;
  width: 58px;
  height: 58px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 0;
  color: var(--accent);
  font-size: 0.78rem;
  letter-spacing: 0;
}
.timer-gauge { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.timer-track, .timer-ring { fill: none; stroke-width: 4; }
.timer-track { stroke: var(--line); }
.timer-ring { stroke: currentColor; stroke-dasharray: 213.63; stroke-dashoffset: 0; stroke-linecap: round; transition: stroke-dashoffset 0.15s linear, stroke 0.25s ease; }
.boss-timer.timer-warn { color: var(--warn); }
.boss-timer.timer-critical { color: var(--danger); }
.boss-timer.timer-shake #bossTimerText { animation: timer-shake 0.15s infinite; }
.boss-timer.timer-critical .timer-ring { animation: ring-pulse 0.55s infinite alternate; }
@keyframes timer-shake { 25% { transform: translateX(-1px); } 75% { transform: translateX(1px); } }
@keyframes ring-pulse { to { filter: drop-shadow(0 0 5px currentColor); opacity: 0.65; } }

.money { position: relative; display: flex; align-items: center; gap: 0.22rem; }
.money-currency { color: var(--warn); }
.money-cursor { color: var(--accent); animation: cursor-blink 0.9s steps(1, end) infinite; }
@keyframes cursor-blink { 50% { opacity: 0; } }
.money.pop { animation: money-pop 0.28s ease-out; }
@keyframes money-pop { 50% { transform: scale(1.15); color: #9bffd8; } }
.money-gain { position: absolute; right: 0; top: -1.1rem; width: max-content; color: var(--accent); font-size: 0.82rem; font-weight: 700; pointer-events: none; }
.money-gain.show { animation: money-gain 0.9s ease-out forwards; }
@keyframes money-gain { 0% { opacity: 0; transform: translateY(4px); } 20% { opacity: 1; } 100% { opacity: 0; transform: translateY(-24px); } }

.arena { isolation: isolate; }
.arena::before,
.arena::after { content: ""; position: absolute; z-index: 0; pointer-events: none; }
.arena::before {
  inset: 0;
  opacity: 0.22;
  background-image: linear-gradient(rgba(46, 230, 166, 0.1) 1px, transparent 1px), linear-gradient(90deg, rgba(46, 230, 166, 0.1) 1px, transparent 1px);
  background-size: 22px 22px;
}
.arena::after {
  width: min(460px, 82vw);
  aspect-ratio: 1;
  border: 1px solid rgba(46, 230, 166, 0.1);
  border-radius: 50%;
  background: conic-gradient(from 0deg, transparent 0 78%, rgba(46, 230, 166, 0.1) 92%, transparent 100%);
  animation: radar-spin 18s linear infinite;
}
@keyframes radar-spin { to { transform: rotate(360deg); } }
.arena > :not(.damage-layer) { z-index: 1; }
.arena .damage-layer { z-index: 3; }

.target-reticle { position: relative; width: 156px; height: 156px; display: grid; place-items: center; }
.target-reticle::before,
.target-reticle::after { content: ""; position: absolute; inset: 7px; border-radius: 50%; opacity: 0; transition: opacity 0.15s, transform 0.2s; pointer-events: none; }
.target-reticle::before { border: 1px dashed rgba(46, 230, 166, 0.75); transform: scale(0.88); }
.target-reticle::after { inset: 0; background: linear-gradient(transparent calc(50% - 0.5px), rgba(46, 230, 166, 0.38) 50%, transparent calc(50% + 0.5px)), linear-gradient(90deg, transparent calc(50% - 0.5px), rgba(46, 230, 166, 0.38) 50%, transparent calc(50% + 0.5px)); }
.target-reticle:hover::before,
.target-reticle:hover::after { opacity: 1; transform: scale(1); }
.virus-image { position: relative; z-index: 1; }
.virus-image:hover { transform: scale(1.05); }
.virus-image.boss-aura { filter: drop-shadow(0 0 11px rgba(255, 76, 70, 0.7)); animation: boss-aura 1.4s ease-in-out infinite alternate, float 3s ease-in-out infinite; }
@keyframes boss-aura { to { filter: drop-shadow(0 0 25px rgba(255, 76, 70, 0.98)) saturate(1.3); } }
.virus-image.destroying { animation: enemy-destroy 0.15s ease-in forwards !important; pointer-events: none; }
.virus-image.enemy-entrance { animation: enemy-appear 0.22s ease-out both; }
@keyframes enemy-destroy { to { opacity: 0; transform: scale(1.2); filter: brightness(2) drop-shadow(0 0 30px #fff); } }
@keyframes enemy-appear { from { opacity: 0; transform: scale(0.8); } to { opacity: 1; transform: scale(1); } }

.hp-fill.low { background: linear-gradient(90deg, #a52835, #ff4d5e); animation: hp-pulse 0.8s infinite alternate; }
@keyframes hp-pulse { to { box-shadow: inset 0 0 14px rgba(255, 77, 94, 0.8), 0 0 10px rgba(255, 77, 94, 0.4); } }
.ripple { position: absolute; width: 18px; height: 18px; border: 2px solid rgba(46, 230, 166, 0.9); border-radius: 50%; transform: translate(-50%, -50%); animation: ripple 0.4s ease-out forwards; }
@keyframes ripple { to { width: 84px; height: 84px; opacity: 0; box-shadow: 0 0 22px rgba(46, 230, 166, 0.55); } }

.upgrade-card { position: relative; overflow: hidden; }
.upgrade-card::after {
  content: "";
  position: absolute;
  inset: -40% auto -40% -70%;
  z-index: 0;
  width: 45%;
  transform: skewX(-18deg);
  background: linear-gradient(120deg, transparent, rgba(255, 255, 255, 0.07), transparent);
  pointer-events: none;
}
.upgrade-card:hover::after { animation: hologram-sweep 0.65s ease-out; }
@keyframes hologram-sweep { to { left: 130%; } }
.upgrade-card > * { position: relative; z-index: 1; }
.upgrade-card.locked { opacity: 0.62; }
.upgrade-card.locked:hover { opacity: 0.82; }
.upgrade-progress { height: 3px; margin-top: auto; overflow: hidden; border-radius: 4px; background: #17252d; }
.upgrade-progress > div { width: 0; height: 100%; background: var(--accent); box-shadow: 0 0 8px rgba(46, 230, 166, 0.65); transition: width 0.25s ease; }
.upg-progress-label { min-height: 0.9rem; color: var(--muted); font-size: 0.65rem; }
.btn-buy { display: flex; align-items: center; justify-content: center; gap: 0.4rem; }
.btn-buy svg { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; }
.btn-buy svg text { fill: currentColor; stroke: none; font-family: inherit; font-size: 11px; font-weight: 700; text-anchor: middle; }
.btn-start:disabled { cursor: wait; opacity: 0.72; }

.wave-banner { position: fixed; z-index: 8; top: 42%; left: 50%; opacity: 0; color: var(--accent); font-size: clamp(1.5rem, 6vw, 3rem); font-weight: 800; letter-spacing: 0.08em; text-shadow: 0 0 18px currentColor; pointer-events: none; transform: translate(-50%, -50%) scale(0.7); }
.wave-banner.show { animation: wave-banner 1.6s ease-out forwards; }
@keyframes wave-banner { 15% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); } 75% { opacity: 1; transform: translate(-50%, -50%) scale(1); } 100% { opacity: 0; transform: translate(-50%, -60%) scale(0.95); } }
.boss-warning { position: absolute; top: 0.8rem; z-index: 4; color: var(--danger); font-size: 0.78rem; font-weight: 800; letter-spacing: 0.08em; opacity: 0; }
.boss-warning.show { animation: warning-flash 1.7s ease-out forwards; }
@keyframes warning-flash { 10%, 55% { opacity: 1; text-shadow: 0 0 12px currentColor; } 100% { opacity: 0; } }

.system-log { width: 100%; margin-top: 0.7rem; overflow: hidden; border-top: 1px solid var(--line); color: #658273; font-size: 0.68rem; white-space: nowrap; }
.system-log span { display: inline-block; min-width: max-content; padding-top: 0.45rem; animation: log-scroll 28s linear infinite; }
@keyframes log-scroll { to { transform: translateX(-50%); } }

@media (max-width: 720px) {
  .hud { display: grid; grid-template-columns: auto 1fr; }
  .hud-brand { grid-column: 1 / -1; }
  .hud-left { min-width: 0; }
  #waveInfo { font-size: 0.78rem; }
  .target-reticle { width: 124px; height: 124px; }
  .upgrade-card::after { display: none; }
}

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