:root {
  --purple-dark: #12071c;
  --purple-deep: #1d0c2b;
  --purple-vivid: #7b2ff7;
  --purple-light: #d28aff;
  --pink: #ff69b4;
  --gold: #ffd24d;
  --gold-amber: #ffbf00;
  --yellow: #ffc107;
  --lime: #a4ff6c;
  --blue: #40c4ff;
  --green: #32ffb3;
  --red: #ff4f6d;
}

* {
  box-sizing: border-box;
  font-family: 'Press Start 2P', cursive;
}

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: radial-gradient(circle at top, rgba(123, 47, 247, 0.25), transparent 55%),
              radial-gradient(circle at bottom, rgba(255, 105, 180, 0.2), transparent 60%),
              linear-gradient(135deg, #0c0513, #1a0d24 60%, #0f0718);
  color: #fefefe;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: url('https://www.transparenttextures.com/patterns/dark-matter.png');
  opacity: 0.2;
  pointer-events: none;
}

.crt {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    rgba(255, 255, 255, 0.04) 0px,
    rgba(255, 255, 255, 0.04) 1px,
    transparent 1px,
    transparent 2px
  );
  mix-blend-mode: screen;
  animation: scan 8s linear infinite;
  opacity: 0.5;
  z-index: 1;
}

@keyframes scan {
  0% { transform: translateY(0); }
  100% { transform: translateY(10px); }
}

.game-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 24px clamp(16px, 3vw, 48px);
  gap: 16px;
  z-index: 2;
}

.hud {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 32px;
  padding: 16px 24px;
  background: rgba(13, 6, 22, 0.8);
  border: 3px solid var(--purple-vivid);
  border-radius: 18px;
  box-shadow: 0 0 25px rgba(123, 47, 247, 0.4);
}

.hud-left {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
}

.brand {
  font-size: clamp(14px, 1.4vw, 20px);
  color: var(--gold);
  text-shadow: 0 0 12px rgba(255, 210, 77, 0.8);
  letter-spacing: 2px;
}

.scoreboard {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.score-block {
  background: rgba(255, 255, 255, 0.04);
  border: 2px solid rgba(255, 255, 255, 0.2);
  padding: 10px 14px;
  border-radius: 12px;
  min-width: 120px;
}

.score-block .label {
  display: block;
  font-size: 10px;
  color: rgba(255, 255, 255, 0.7);
  margin-bottom: 6px;
}

.score-block .value {
  font-size: clamp(14px, 1.4vw, 22px);
  color: var(--gold);
}

.score-block.hearts {
  display: flex;
  gap: 10px;
  align-items: center;
  min-width: auto;
}

.heart {
  width: 22px;
  height: 20px;
  clip-path: polygon(50% 90%, 0% 35%, 12% 0%, 35% 7%, 50% 0%, 65% 7%, 88% 0%, 100% 35%);
  background: rgba(255, 255, 255, 0.2);
  transition: background 0.2s ease, filter 0.2s ease;
}

.heart.filled {
  background: radial-gradient(circle at 30% 30%, #ff94c2, #ff237f 70%);
  filter: drop-shadow(0 0 6px rgba(255, 71, 126, 0.9));
}

.shields {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: auto !important;
}

.shield-icon {
  font-size: 18px;
  filter: drop-shadow(0 0 4px rgba(192, 192, 192, 0.8));
}

.shield-count {
  font-size: 16px;
  color: #c0c0c0;
  font-weight: bold;
}

.level-display {
  min-width: 90px !important;
}

.xp-bar-container {
  position: relative;
  width: 100%;
  max-width: 300px;
  height: 28px;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-radius: 14px;
  overflow: hidden;
  margin-bottom: 8px;
}

.xp-bar-fill {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--purple-vivid), var(--pink));
  transition: width 0.3s ease;
  box-shadow: 0 0 12px rgba(123, 47, 247, 0.6);
}

.xp-bar-text {
  position: absolute;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: #fff;
  z-index: 1;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.ability-panel {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
}

.ability {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.05);
  min-width: 180px;
}

.ability .key {
  padding: 8px 14px;
  border-radius: 10px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  font-size: 12px;
  text-align: center;
}

.ability[data-color="blue"] .key { color: var(--blue); border-color: rgba(64, 196, 255, 0.6); }
.ability[data-color="green"] .key { color: var(--green); border-color: rgba(50, 255, 179, 0.6); }
.ability[data-color="red"] .key { color: var(--red); border-color: rgba(255, 79, 109, 0.6); }

.cooldown {
  width: 120px;
  height: 6px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 999px;
  overflow: hidden;
}

.cooldown .bar {
  display: block;
  width: 100%;
  height: 100%;
  transform-origin: left;
  transform: scaleX(0);
  background: linear-gradient(90deg, var(--gold), var(--purple-light));
  transition: transform 0.15s linear;
}

#gameCanvas {
  flex: 1 1 auto;
  width: min(100%, 1280px);
  aspect-ratio: 16 / 9;
  height: auto;
  border-radius: 28px;
  border: 4px solid rgba(255, 255, 255, 0.08);
  background: radial-gradient(circle at center, rgba(18, 7, 28, 0.85) 20%, rgba(8, 3, 14, 0.95) 80%);
  box-shadow: inset 0 0 40px rgba(255, 210, 77, 0.1), 0 15px 60px rgba(10, 4, 18, 0.8);
  align-self: center;
}

.guide-widget {
  position: absolute;
  right: 36px;
  bottom: 36px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  z-index: 5;
}

.guide-toggle {
  border: 0;
  border-radius: 999px;
  padding: 12px 22px;
  font-size: 12px;
  color: #12071c;
  background: linear-gradient(135deg, var(--gold), var(--yellow));
  box-shadow: 0 12px 25px rgba(255, 210, 77, 0.35);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.guide-toggle:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 18px 35px rgba(255, 210, 77, 0.45);
}

.guide-panel {
  width: min(340px, 90vw);
  padding: 20px 24px;
  border-radius: 20px;
  border: 2px solid rgba(255, 255, 255, 0.18);
  background: linear-gradient(145deg, rgba(47, 16, 75, 0.95), rgba(23, 8, 35, 0.92));
  box-shadow: 0 18px 40px rgba(123, 47, 247, 0.3);
  font-size: 10px;
  line-height: 1.8;
  opacity: 0;
  transform: translateY(10px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.guide-panel.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.guide-panel h2 {
  font-size: 14px;
  color: var(--gold);
  margin: 0 0 12px;
}

.guide-panel ul {
  padding-left: 18px;
  margin: 0;
  list-style: none;
}

.guide-panel li {
  margin-bottom: 10px;
  position: relative;
}

.guide-panel li::before {
  content: '✦';
  position: absolute;
  left: -16px;
  color: var(--purple-light);
}

.pause-btn {
  border: 2px solid rgba(255, 255, 255, 0.25);
  background: linear-gradient(135deg, var(--purple-vivid), var(--pink));
  color: #fff;
  font-size: 10px;
  padding: 10px 16px;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 6px 16px rgba(153, 51, 255, 0.45);
}

.pause-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 20px rgba(153, 51, 255, 0.6);
}

.pause-btn[aria-pressed="true"] {
  background: linear-gradient(135deg, var(--gold-amber), var(--gold));
  color: var(--purple-dark);
  box-shadow: 0 10px 20px rgba(255, 210, 77, 0.45);
}

.level-up-content {
  max-width: 800px;
  width: 95vw;
}

.level-up-subtitle {
  margin: 16px 0 24px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.8);
}

.augment-choices {
  display: flex;
  gap: 20px;
  justify-content: center;
  flex-wrap: wrap;
}

.augment-card {
  flex: 1;
  min-width: 200px;
  max-width: 240px;
  padding: 20px;
  border-radius: 16px;
  border: 3px solid;
  background: rgba(18, 7, 28, 0.85);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  position: relative;
}

.augment-card:hover {
  transform: translateY(-8px) scale(1.02);
}

.augment-card.common { border-color: #ffffff; box-shadow: 0 8px 20px rgba(255, 255, 255, 0.3); }
.augment-card.uncommon { border-color: #32ffb3; box-shadow: 0 8px 20px rgba(50, 255, 179, 0.4); }
.augment-card.rare { border-color: #40c4ff; box-shadow: 0 8px 20px rgba(64, 196, 255, 0.5); }
.augment-card.epic { border-color: #a855f7; box-shadow: 0 8px 20px rgba(168, 85, 247, 0.6); }
.augment-card.legendary { border-color: #ffd24d; box-shadow: 0 8px 20px rgba(255, 210, 77, 0.7); }

.augment-card:hover.common { box-shadow: 0 12px 30px rgba(255, 255, 255, 0.5); }
.augment-card:hover.uncommon { box-shadow: 0 12px 30px rgba(50, 255, 179, 0.6); }
.augment-card:hover.rare { box-shadow: 0 12px 30px rgba(64, 196, 255, 0.7); }
.augment-card:hover.epic { box-shadow: 0 12px 30px rgba(168, 85, 247, 0.8); }
.augment-card:hover.legendary { box-shadow: 0 12px 30px rgba(255, 210, 77, 0.9); }

.augment-rarity {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 9px;
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.6);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.augment-card.common .augment-rarity { color: #ffffff; }
.augment-card.uncommon .augment-rarity { color: #32ffb3; }
.augment-card.rare .augment-rarity { color: #40c4ff; }
.augment-card.epic .augment-rarity { color: #a855f7; }
.augment-card.legendary .augment-rarity { color: #ffd24d; }

.augment-name {
  font-size: 14px;
  margin-bottom: 12px;
  color: var(--gold);
  line-height: 1.4;
}

.augment-desc {
  font-size: 10px;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.85);
}

.augment-replace-warning {
  margin-top: 10px;
  padding: 8px;
  background: rgba(255, 79, 109, 0.2);
  border: 1px solid var(--red);
  border-radius: 8px;
  font-size: 9px;
  color: #ffaaaa;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(6, 2, 10, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99;
  backdrop-filter: blur(4px);
}

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

.modal-content {
  background: linear-gradient(135deg, rgba(18, 7, 28, 0.9), rgba(30, 10, 46, 0.9));
  border: 4px solid var(--purple-vivid);
  border-radius: 28px;
  padding: 32px;
  width: min(420px, 90vw);
  text-align: center;
  box-shadow: 0 0 40px rgba(123, 47, 247, 0.5);
}

.modal-content h3 {
  margin-top: 0;
  color: var(--gold);
  font-size: 24px;
  letter-spacing: 4px;
}

.modal-content button {
  margin-top: 20px;
  padding: 14px 26px;
  border: 0;
  background: linear-gradient(135deg, var(--purple-vivid), var(--pink));
  color: #fff;
  border-radius: 16px;
  cursor: pointer;
  font-size: 12px;
  box-shadow: 0 0 20px rgba(255, 210, 77, 0.3);
}

.modal-content button:hover {
  filter: brightness(1.1);
}

.final-score {
  margin: 12px 0 6px;
  font-size: 16px;
}

.final-tip {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.7);
}

#gameShell.shake {
  animation: shake 0.35s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-12px); }
  40% { transform: translateX(12px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

@media (max-width: 1024px) {
  .hud {
    flex-direction: column;
    align-items: stretch;
  }
  .xp-bar-container {
    max-width: 100%;
  }
  .guide-widget {
    position: static;
    width: 100%;
    align-items: flex-start;
  }
  .guide-panel {
    width: 100%;
    max-width: none;
  }
}

@media (max-width: 640px) {
  .ability-panel {
    justify-content: center;
  }
  .ability {
    min-width: auto;
    width: 100%;
  }
  .pause-btn {
    width: 100%;
    text-align: center;
  }
  .xp-bar-container {
    max-width: 100%;
  }
  .augment-choices {
    flex-direction: column;
  }
  .augment-card {
    max-width: 100%;
  }
  .scoreboard {
    justify-content: center;
  }
  .game-shell {
    padding: 16px;
  }
  .guide-toggle {
    width: 100%;
    text-align: center;
  }
}

/* ===== AUTH MODAL ===== */
.auth-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}

.auth-modal-content {
  background: linear-gradient(135deg, var(--purple-deep) 0%, #0a0015 100%);
  border: 2px solid var(--purple-vivid);
  border-radius: 12px;
  padding: 32px;
  max-width: 420px;
  width: 90%;
  box-shadow: 0 8px 32px rgba(123, 47, 247, 0.4);
}

.auth-header {
  text-align: center;
  margin-bottom: 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.auth-header h2 {
  color: var(--purple-vivid);
  font-size: 18px;
  text-shadow: 0 0 10px rgba(123, 47, 247, 0.8);
  flex: 1;
}

.auth-close {
  background: none;
  border: none;
  color: var(--purple-light);
  font-size: 32px;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  line-height: 1;
}

.auth-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
}

.auth-tab {
  flex: 1;
  padding: 12px;
  background: rgba(123, 47, 247, 0.1);
  border: 2px solid rgba(123, 47, 247, 0.3);
  color: var(--purple-light);
  font-size: 10px;
  cursor: pointer;
  transition: all 0.3s;
}

.auth-tab:hover {
  background: rgba(123, 47, 247, 0.2);
  border-color: var(--purple-vivid);
}

.auth-tab.active {
  background: var(--purple-vivid);
  color: white;
  border-color: var(--purple-vivid);
  box-shadow: 0 0 16px rgba(123, 47, 247, 0.6);
}

.auth-form {
  display: none;
}

.auth-form.active {
  display: block;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  color: var(--purple-light);
  font-size: 10px;
  margin-bottom: 8px;
}

.form-group input {
  width: 100%;
  padding: 12px;
  background: rgba(0, 0, 0, 0.5);
  border: 2px solid rgba(123, 47, 247, 0.3);
  color: white;
  font-size: 12px;
  font-family: 'Press Start 2P', cursive;
  transition: all 0.3s;
}

.form-group input:focus {
  outline: none;
  border-color: var(--purple-vivid);
  box-shadow: 0 0 12px rgba(123, 47, 247, 0.4);
}

.form-group small {
  display: block;
  color: var(--purple-light);
  font-size: 8px;
  margin-top: 4px;
  opacity: 0.7;
}

.auth-btn {
  width: 100%;
  padding: 14px;
  border: none;
  font-size: 11px;
  cursor: pointer;
  font-family: 'Press Start 2P', cursive;
  transition: all 0.3s;
  margin-bottom: 12px;
}

.auth-btn.primary {
  background: linear-gradient(135deg, var(--purple-vivid) 0%, #5a1bb0 100%);
  color: white;
  box-shadow: 0 4px 16px rgba(123, 47, 247, 0.4);
}

.auth-btn.primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(123, 47, 247, 0.6);
}

.auth-btn.google {
  background: white;
  color: #444;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border: 2px solid #ddd;
}

.auth-btn.google img {
  width: 20px;
  height: 20px;
}

.auth-btn.google:hover {
  background: #f8f8f8;
  transform: translateY(-2px);
}

.auth-divider {
  text-align: center;
  color: var(--purple-light);
  font-size: 10px;
  margin: 20px 0;
  opacity: 0.5;
}

.auth-error {
  display: none;
  background: rgba(255, 79, 109, 0.2);
  border: 2px solid var(--red);
  color: var(--red);
  padding: 12px;
  margin-top: 16px;
  font-size: 9px;
  text-align: center;
}

/* ===== USER INFO MINI ===== */
.user-info-mini {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 9px;
  color: var(--purple-light);
  padding: 8px 0;
  flex-wrap: wrap;
}

.user-info-mini > span {
  padding: 4px 8px;
  background: rgba(123, 47, 247, 0.2);
  border: 1px solid rgba(123, 47, 247, 0.4);
  border-radius: 4px;
}

.btn-ranking {
  background: linear-gradient(135deg, var(--gold) 0%, var(--gold-amber) 100%);
  color: var(--purple-dark);
  border: none;
  padding: 8px 14px;
  font-size: 8px;
  cursor: pointer;
  font-family: 'Press Start 2P', cursive;
  box-shadow: 0 4px 12px rgba(255, 210, 77, 0.4);
  transition: all 0.3s;
  border-radius: 6px;
  font-weight: bold;
}

.btn-ranking:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(255, 210, 77, 0.6);
}

.btn-logout-mini {
  background: rgba(255, 79, 109, 0.2);
  color: var(--red);
  border: 2px solid var(--red);
  padding: 6px 10px;
  font-size: 7px;
  cursor: pointer;
  font-family: 'Press Start 2P', cursive;
  transition: all 0.3s;
  border-radius: 4px;
}

.btn-logout-mini:hover {
  background: rgba(255, 79, 109, 0.3);
  transform: translateY(-2px);
}

/* ===== RANKING MODAL ===== */
.ranking-content {
  max-width: 800px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 2px solid rgba(123, 47, 247, 0.3);
}

.modal-header h3 {
  margin: 0;
  color: var(--gold);
  text-shadow: 0 0 12px rgba(255, 210, 77, 0.6);
}

.modal-close-btn {
  background: none;
  border: none;
  color: var(--purple-light);
  font-size: 32px;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  line-height: 1;
  transition: all 0.3s;
}

.modal-close-btn:hover {
  color: var(--red);
  transform: scale(1.2);
}

.ranking-header-row {
  display: grid;
  grid-template-columns: 80px 1fr 150px;
  padding: 12px 16px;
  background: rgba(123, 47, 247, 0.2);
  border: 2px solid var(--purple-vivid);
  margin-bottom: 12px;
  font-size: 10px;
  color: var(--purple-vivid);
}

.ranking-row {
  display: grid;
  grid-template-columns: 80px 1fr 150px;
  padding: 12px 16px;
  background: rgba(0, 0, 0, 0.3);
  border: 2px solid rgba(123, 47, 247, 0.2);
  margin-bottom: 8px;
  font-size: 10px;
  color: var(--purple-light);
  transition: all 0.3s;
}

.ranking-row:hover {
  background: rgba(123, 47, 247, 0.1);
  border-color: var(--purple-vivid);
  transform: translateX(4px);
}

.ranking-row.current-user {
  background: rgba(123, 47, 247, 0.2);
  border-color: var(--purple-vivid);
  color: var(--gold);
  box-shadow: 0 0 16px rgba(123, 47, 247, 0.4);
}

.rank-col {
  text-align: center;
  font-size: 14px;
}

.player-col {
  padding-left: 16px;
}

.score-col {
  text-align: right;
  color: var(--gold);
}

.ranking-loading,
.ranking-empty,
.ranking-error {
  text-align: center;
  padding: 48px 24px;
  color: var(--purple-light);
  font-size: 11px;
}

.ranking-error {
  color: var(--red);
}
