/* =========================================================
   Space Defender Pro — Styles
   ========================================================= */

/* ---- Reset & Base ---- */
* { box-sizing: border-box; }

body {
  margin: 0;
  overflow: hidden;
  background: radial-gradient(circle at center, #0a0a25 0%, #050510 100%);
  font-family: 'Inter', sans-serif;
  color: white;
  user-select: none;
  -webkit-user-select: none;
}

canvas { display: block; }

/* ---- Overlays ---- */
.overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100vw; height: 100vh;
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 10;
  padding: 20px;
  overflow-y: auto; /* Allow scrolling on small screens */
}

.overlay.active { display: flex; }

#menu-bg-canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: -1;
  pointer-events: none;
}

.overlay h1 {
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(1.8rem, 5vw, 3rem);
  margin-bottom: 20px;
  text-shadow: 0 0 15px currentColor;
  text-align: center;
}

.overlay p {
  font-size: 1.1rem;
  margin-bottom: 30px;
  text-align: center;
  max-width: 700px;
  line-height: 1.6;
  color: #ccc;
}

/* ---- Buttons ---- */
.btn-group {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  justify-content: center;
}

.btn {
  background: transparent;
  border: 2px solid cyan;
  color: cyan;
  font-family: 'Orbitron', sans-serif;
  font-size: 1.1rem;
  padding: 12px 25px;
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.2s ease;
  text-transform: uppercase;
  box-shadow: 0 0 10px rgba(0, 255, 255, 0.2);
  min-width: 180px;
}

.btn:hover {
  background: cyan;
  color: black;
  box-shadow: 0 0 20px cyan;
  transform: translateY(-2px);
}

.btn:active {
  transform: translateY(0);
}

.btn.secondary {
  border-color: #f1c40f;
  color: #f1c40f;
}

.btn.secondary:hover {
  background: #f1c40f;
  color: black;
  box-shadow: 0 0 20px #f1c40f;
}

/* ---- Tutorial Tabs ---- */
#tutorial-menu {
  background: rgba(10, 10, 30, 0.95);
  width: 100%;
  max-width: 900px;
  border-radius: 15px;
  border: 1px solid rgba(0, 255, 255, 0.3);
  padding: 0;
  overflow: hidden;
}

.tabs-header {
  display: flex;
  background: rgba(0, 0, 0, 0.5);
  border-bottom: 1px solid rgba(0, 255, 255, 0.2);
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs-header::-webkit-scrollbar { display: none; }

.tab-btn {
  padding: 15px 20px;
  font-family: 'Orbitron', sans-serif;
  font-size: 0.9rem;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.3s, color 0.3s, background 0.3s;
  white-space: nowrap;
  border: none;
  background: none;
  color: white;
}

.tab-btn.active {
  opacity: 1;
  border-bottom: 3px solid cyan;
  color: cyan;
  background: rgba(0, 255, 255, 0.05);
}

.tab-content {
  padding: 30px;
  display: none;
  min-height: 350px;
  max-height: 60vh;
  overflow-y: auto;
}

.tab-content.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

.tab-content h2 {
  margin-top: 0;
  color: cyan;
  font-family: 'Orbitron', sans-serif;
}

.tab-content ul { padding-left: 20px; }
.tab-content li { margin-bottom: 15px; color: #ddd; }

.tutorial-footer {
  padding: 20px;
  display: flex;
  justify-content: space-between;
  border-top: 1px solid rgba(0, 255, 255, 0.1);
}

/* ---- Countdown ---- */
#countdown {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(8rem, 20vw, 15rem);
  color: #fff;
  text-shadow: 0 0 40px cyan, 0 0 80px #00ffff;
  pointer-events: none;
  display: none;
  z-index: 200;
}

.countdown-anim {
  animation: countdownPop 1s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes countdownPop {
  0% { transform: translate(-50%, -50%) scale(0.2); opacity: 0; filter: blur(10px); }
  30% { transform: translate(-50%, -50%) scale(1.1); opacity: 1; filter: blur(0px); }
  70% { transform: translate(-50%, -50%) scale(1); opacity: 1; filter: blur(0px); }
  100% { transform: translate(-50%, -50%) scale(2.5); opacity: 0; filter: blur(15px); }
}

/* ---- Bottom HUD ---- */
#ui-bottom {
  position: absolute;
  bottom: 0; left: 0;
  width: 100%;
  background: rgba(10, 10, 25, 0.9);
  border-top: 1px solid rgba(0, 255, 255, 0.3);
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1rem;
  z-index: 5;
  box-shadow: 0 -5px 20px rgba(0, 0, 0, 0.5);
  flex-wrap: wrap;
  gap: 10px;
}

.stat-box {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

.stat-label {
  color: #88c0d0;
  font-family: 'Orbitron', sans-serif;
  font-size: 0.8rem;
  text-transform: uppercase;
}

.stat-value {
  font-size: 1.1rem;
  min-width: 30px;
  text-shadow: 0 0 5px white;
}

/* ---- Records Table ---- */
.records-table {
  width: 100%;
  max-width: 450px;
  margin: 20px auto;
  border-collapse: collapse;
}

.records-table th,
.records-table td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.records-table th {
  color: cyan;
  font-family: 'Orbitron', sans-serif;
  font-size: 0.9rem;
}

.highlight-record {
  color: #f1c40f;
  font-weight: bold;
  animation: pulse 1s infinite alternate;
}

.history-row td {
  font-size: 0.85rem;
  color: #aaa;
}

.history-row:hover td {
  color: #fff;
  background: rgba(0, 255, 255, 0.05);
}

.delete-btn {
  background: rgba(255, 51, 102, 0.1);
  border: 1px solid #ff3366;
  color: #ff3366;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.delete-btn:hover {
  background: #ff3366;
  color: white;
  box-shadow: 0 0 10px #ff3366;
}

/* ---- Mobile Controls ---- */
/* ---- Mobile Controls (Left/Only Mobile) ---- */
#mobile-controls {
  position: absolute;
  bottom: 85px; left: 20px;
  display: none; /* Hidden by default, let JS show it if mobile is detected */
  flex-direction: column;
  gap: 15px;
  z-index: 100;
}

@media (max-width: 1024px) {
  #mobile-controls { display: flex; }
  /* Performance optimizations for mobile browsers */
  .overlay, #tutorial-menu { backdrop-filter: none; background: rgba(5, 5, 15, 0.98); }
  * { box-shadow: none !important; text-shadow: none !important; }
}

@media (min-width: 1025px) {
  #mobile-controls { display: none !important; }
}

.touch-btn {
  width: 65px; height: 65px;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(0, 255, 255, 0.5);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: cyan;
  font-size: 1.3rem;
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  user-select: none;
  -webkit-touch-callout: none;
}

.touch-btn:active {
  background: rgba(0, 255, 255, 0.3);
  transform: scale(0.9);
}

/* ---- Announcements ---- */
#announcement {
  position: absolute;
  top: 40%; left: 50%;
  transform: translate(-50%, -50%);
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(1.2rem, 4vw, 2rem);
  color: #f1c40f;
  text-shadow: 0 0 20px #f1c40f;
  pointer-events: none;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.5s;
  text-align: center;
  white-space: nowrap;
}

#announcement.active {
  opacity: 1;
  animation: slideUp 3s forwards;
}

/* ---- Power Choice Cards (Level Up Menu) ---- */
.power-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
  justify-content: center;
  max-width: 700px;
  margin-top: 10px;
}

.power-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(0, 255, 255, 0.3);
  border-radius: 12px;
  padding: 18px 22px;
  cursor: pointer;
  transition: all 0.25s ease;
  text-align: center;
  min-width: 130px;
  flex: 1 1 130px;
}

.power-btn:hover {
  background: rgba(0, 255, 255, 0.1);
  border-color: cyan;
  transform: translateY(-4px);
  box-shadow: 0 8px 25px rgba(0, 255, 255, 0.2);
}

.power-btn h3 {
  margin: 0 0 6px 0;
  font-family: 'Orbitron', sans-serif;
  font-size: 0.95rem;
  color: cyan;
}

.power-btn p {
  margin: 0;
  font-size: 0.8rem;
  color: #aaa;
  line-height: 1.3;
}

/* ---- PWA Install Banner ---- */
#install-banner {
  position: fixed;
  top: -120px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  background: rgba(10, 10, 40, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(0, 255, 255, 0.35);
  border-radius: 16px;
  padding: 18px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: 420px;
  width: calc(100% - 32px);
  box-shadow: 0 4px 30px rgba(0, 255, 255, 0.15), 0 0 60px rgba(0, 0, 0, 0.5);
  transition: top 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#install-banner.visible {
  top: 16px;
}

#install-banner img {
  width: 48px; height: 48px;
  border-radius: 10px;
  flex-shrink: 0;
}

.install-info {
  flex: 1;
  min-width: 0;
}

.install-info strong {
  display: block;
  font-family: 'Orbitron', sans-serif;
  font-size: 0.85rem;
  color: #fff;
  margin-bottom: 3px;
}

.install-info span {
  font-size: 0.75rem;
  color: #88c0d0;
}

.install-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.install-btn {
  background: linear-gradient(135deg, #00cccc, #0088ff);
  border: none;
  color: #fff;
  font-family: 'Orbitron', sans-serif;
  font-size: 0.75rem;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  text-transform: uppercase;
  transition: all 0.2s;
  box-shadow: 0 2px 12px rgba(0, 200, 255, 0.3);
}

.install-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 20px rgba(0, 200, 255, 0.5);
}

.install-close {
  background: none;
  border: none;
  color: #666;
  font-size: 1.4rem;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  transition: color 0.2s;
}

.install-close:hover { color: #fff; }

/* ---- Animations ---- */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
  from { opacity: 0.8; transform: scale(1); }
  to   { opacity: 1; transform: scale(1.05); }
}

@keyframes slideUp {
  0%   { opacity: 0; transform: translate(-50%, 0); }
  20%  { opacity: 1; transform: translate(-50%, -50%); }
  80%  { opacity: 1; transform: translate(-50%, -50%); }
  100% { opacity: 0; transform: translate(-50%, -100%); }
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0, 255, 255, 0.3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0, 255, 255, 0.5); }

/* ---- Ultra Energy Bar & Button ---- */
.energy-bar-bg {
  width: 100%; max-width: 150px;
  height: 12px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 0, 127, 0.3);
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}

.energy-bar-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #ff007f, #f1c40f);
  box-shadow: 0 0 10px #ff007f;
  transition: width 0.3s ease;
}

.energy-bar-fill.ready {
  animation: pulse-ultra 0.8s infinite alternate;
}

@keyframes pulse-ultra {
  from { box-shadow: 0 0 10px #ff007f; filter: brightness(1); }
  to { box-shadow: 0 0 25px #f1c40f; filter: brightness(1.5); }
}

.ultra-btn-disabled {
  opacity: 0.3; pointer-events: none;
  filter: grayscale(1);
}

.ultra-btn-ready {
  background: rgba(255, 0, 127, 0.2);
  border-color: #ff007f;
  box-shadow: 0 0 20px #ff007f;
  animation: pulse-ultra-btn 1s infinite alternate;
}

@keyframes pulse-ultra-btn {
  from { transform: scale(1); box-shadow: 0 0 10px #ff007f; }
  to { transform: scale(1.1); box-shadow: 0 0 30px #f1c40f; }
}
