/* Skibidi Sun Worm - Premium Cosmic Dark Theme */
:root {
  --bg-deep: #05060d;
  --panel-bg: rgba(13, 17, 33, 0.75);
  --panel-border: rgba(255, 215, 0, 0.25);
  --sun-gold: #ffd700;
  --sun-white: #ffffff;
  --sun-glow: rgba(255, 230, 100, 0.6);
  --flare-orange: #ff7700;
  --hazard-red: #ff3344;
  --void-purple: #8a2be2;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --font-display: 'Orbitron', 'Cinzel', sans-serif;
  --font-body: 'Outfit', -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  margin: 0;
  padding: 0;
  overflow: hidden;
  position: fixed;
  inset: 0;
  background-color: var(--bg-deep);
  color: var(--text-main);
  font-family: var(--font-body);
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

#gameWrapper {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: radial-gradient(circle at center, #090e24 0%, #03040a 100%);
  overflow: hidden;
  touch-action: none;
}

/* Header HUD */
#cosmicHeader {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  box-sizing: border-box;
  padding: 8px 14px;
  padding-top: max(8px, env(safe-area-inset-top));
  padding-left: max(10px, env(safe-area-inset-left));
  padding-right: max(10px, env(safe-area-inset-right));
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(180deg, rgba(5, 7, 18, 0.92) 0%, rgba(5, 7, 18, 0) 100%);
  z-index: 20;
  pointer-events: none;
}

.hud-group {
  display: flex;
  align-items: center;
  gap: 12px;
  pointer-events: auto;
}

.brand-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-right: 8px;
}

.brand-bar .brand-link {
  font-family: 'Cinzel', serif;
  font-size: 1.25rem;
  font-weight: 900;
  letter-spacing: 2px;
  color: #ffd700;
  text-decoration: none;
  transition: filter 0.2s;
  line-height: 1;
}

.brand-bar .brand-link:hover {
  filter: drop-shadow(0 0 8px rgba(255, 215, 0, 0.7));
}

.brand-bar .nav-divider {
  color: #94a3b8;
  opacity: 0.4;
  font-size: 1.1rem;
  line-height: 1;
}

.brand-bar .nav-sublink {
  color: #cbd5e1;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 1px;
  transition: color 0.2s;
  line-height: 1;
}

.brand-bar .nav-sublink:hover {
  color: #fff;
}

.brand-bar .game-badge {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.25), rgba(217, 119, 6, 0.15));
  border: 1px solid rgba(245, 158, 11, 0.4);
  color: #ffd700;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 1px;
  padding: 3px 10px;
  border-radius: 20px;
  line-height: 1;
}

@media (max-width: 768px) {
  .brand-bar {
    display: none !important;
  }
}

.hud-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(10px);
  padding: 6px 14px;
  border-radius: 9999px;
  font-size: 0.9rem;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
}

.tier-badge {
  border-color: rgba(255, 215, 0, 0.4);
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.05em;
  color: #fff6a9;
  text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

.mass-pill strong, .score-pill strong {
  font-family: var(--font-display);
  color: var(--sun-gold);
}

/* Solar Flare Energy Meter */
.flare-meter-wrap {
  display: flex;
  flex-direction: column;
  width: 110px;
  gap: 3px;
}

.meter-title {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #ff9d42;
}

.meter-outer {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid rgba(255, 119, 0, 0.3);
}

.meter-inner {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #ff7700, #ffd700);
  border-radius: 4px;
  transition: width 0.1s linear;
  box-shadow: 0 0 8px rgba(255, 119, 0, 0.8);
}

/* Black Hole Threat Indicator */
#blackHoleWarning {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 9999px;
  background: rgba(45, 10, 60, 0.85);
  border: 1px solid rgba(210, 40, 255, 0.6);
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 700;
  color: #f7a8ff;
  animation: pulseWarning 1s infinite alternate;
}

@keyframes pulseWarning {
  from {
    transform: scale(0.98);
    box-shadow: 0 0 10px rgba(180, 0, 255, 0.3);
  }
  to {
    transform: scale(1.04);
    box-shadow: 0 0 20px rgba(255, 0, 128, 0.7);
  }
}

.icon-btn {
  background: var(--panel-bg);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--text-main);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  transition: all 0.2s ease;
  backdrop-filter: blur(8px);
}

.icon-btn:hover {
  border-color: var(--sun-gold);
  transform: scale(1.08);
  box-shadow: 0 0 12px rgba(255, 215, 0, 0.4);
}

/* Canvas Viewport */
#viewportContainer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

#starCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Mobile Touch Controls */
#mobileControls {
  position: fixed;
  bottom: max(18px, calc(env(safe-area-inset-bottom) + 12px));
  right: max(18px, calc(env(safe-area-inset-right) + 12px));
  z-index: 25;
  pointer-events: none;
}

#btnBoost {
  pointer-events: auto;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffb703 0%, #fb8500 50%, #d00000 100%);
  border: 3px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 0 25px rgba(255, 119, 0, 0.8);
  color: #fff;
  font-family: var(--font-display);
  font-weight: 900;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  pointer-events: auto;
  transition: transform 0.1s ease;
  touch-action: none;
}

#btnBoost:active {
  transform: scale(0.92);
  box-shadow: 0 0 35px rgba(255, 60, 0, 1);
}

.boost-icon {
  font-size: 1.5rem;
}

.boost-text {
  font-size: 0.65rem;
  letter-spacing: 0.1em;
}

/* Modals */
.modal-backdrop, .modal-backdrop *, .modal-card, .modal-card * {
  touch-action: pan-y !important;
  -webkit-overflow-scrolling: touch;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  background: rgba(3, 4, 10, 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  z-index: 50;
  padding: max(16px, env(safe-area-inset-top, 16px)) max(12px, env(safe-area-inset-right, 12px)) max(24px, env(safe-area-inset-bottom, 24px)) max(12px, env(safe-area-inset-left, 12px));
  overflow-y: auto;
  box-sizing: border-box;
  transition: opacity 0.3s ease;
  overscroll-behavior: contain;
}

.modal-backdrop.hidden {
  display: none !important;
  opacity: 0;
  pointer-events: none;
}

.modal-card {
  max-width: 520px;
  width: 100%;
  margin: auto;
  max-height: calc(100dvh - 36px);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: linear-gradient(135deg, rgba(20, 26, 50, 0.96) 0%, rgba(9, 12, 25, 0.98) 100%);
  border: 1px solid rgba(255, 215, 0, 0.35);
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.85), 0 0 35px rgba(255, 215, 0, 0.2);
  border-radius: 20px;
  padding: 24px 20px;
  text-align: center;
  color: var(--text-main);
  animation: modalPop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modalPop {
  from { transform: scale(0.88); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.logo-icon {
  font-size: 3rem;
  filter: drop-shadow(0 0 15px rgba(255, 215, 0, 0.8));
  margin-bottom: 8px;
}

.modal-title {
  font-family: var(--font-display);
  font-size: 1.9rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  background: linear-gradient(90deg, #ffffff 0%, #ffe875 50%, #ff9e00 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 4px;
}

.modal-subtitle {
  font-size: 0.85rem;
  letter-spacing: 0.15em;
  font-weight: 700;
  color: #ffaa33;
  margin-bottom: 22px;
}

.rules-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 24px;
  font-size: 0.9rem;
  line-height: 1.45;
}

.rule-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.rule-icon {
  font-size: 1.3rem;
  line-height: 1;
}

.rule-text strong {
  color: #fff;
}

.rule-text span {
  color: var(--text-muted);
}

.primary-btn {
  width: 100%;
  padding: 14px;
  background: linear-gradient(90deg, #ffd700 0%, #ff8800 100%);
  border: none;
  border-radius: 12px;
  color: #111;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(255, 170, 0, 0.4);
  transition: all 0.2s ease;
  margin-bottom: 14px;
}

.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(255, 200, 0, 0.6);
}

.sub-link {
  display: inline-block;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
  transition: color 0.2s;
}

.sub-link:hover {
  color: var(--sun-gold);
}

/* Game Over Stats */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 700;
}

.stat-value {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--sun-gold);
}

/* Floating on-screen event banner */
#eventBanner {
  position: absolute;
  top: 76px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 20px;
  border-radius: 9999px;
  background: rgba(18, 5, 30, 0.9);
  border: 1px solid rgba(255, 60, 120, 0.8);
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 800;
  color: #ff99bb;
  box-shadow: 0 0 25px rgba(255, 30, 100, 0.6);
  z-index: 30;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

#eventBanner.show {
  opacity: 1;
  transform: translateX(-50%) translateY(5px);
}

@media (max-width: 650px) {
  #cosmicHeader {
    padding: 4px 6px;
    padding-top: max(4px, env(safe-area-inset-top));
    padding-left: max(6px, env(safe-area-inset-left));
    padding-right: max(6px, env(safe-area-inset-right));
  }
  .hud-group {
    gap: 4px;
  }
  .hud-pill {
    padding: 3px 6px;
    font-size: 0.72rem;
    gap: 3px;
  }
  .tier-badge {
    font-size: 0.68rem;
    letter-spacing: 0;
  }
  .flare-meter-wrap {
    width: 55px;
    gap: 1px;
  }
  .meter-title {
    font-size: 0.55rem;
  }
  .icon-btn {
    width: 30px;
    height: 30px;
    font-size: 0.95rem;
  }
  #btnBoost {
    width: 66px;
    height: 66px;
  }
  .boost-icon {
    font-size: 1.25rem;
  }
  .boost-text {
    font-size: 0.58rem;
  }
  .modal-card {
    padding: 18px 14px;
    border-radius: 16px;
  }
  .modal-title {
    font-size: 1.45rem;
  }
  .modal-subtitle {
    font-size: 0.72rem;
    margin-bottom: 12px;
  }
  .rules-grid {
    padding: 10px;
    gap: 8px;
    margin-bottom: 14px;
    font-size: 0.78rem;
  }
  .primary-btn {
    padding: 12px;
    font-size: 0.95rem;
  }
}

@media (max-height: 520px) {
  #cosmicHeader {
    padding: 3px 8px;
    padding-top: max(3px, env(safe-area-inset-top));
  }
  .hud-pill {
    padding: 2px 5px;
    font-size: 0.68rem;
  }
  .icon-btn {
    width: 26px;
    height: 26px;
    font-size: 0.85rem;
  }
  #btnBoost {
    width: 56px;
    height: 56px;
  }
  .modal-card {
    padding: 12px 14px;
    max-height: calc(100dvh - 16px);
  }
  .logo-icon {
    display: none;
  }
  .modal-title {
    font-size: 1.2rem;
  }
  .rules-grid {
    padding: 6px 10px;
    margin-bottom: 8px;
    gap: 4px;
  }
}

/* Ko-fi Button */
.kofi-footer-container {
  margin: 12px 0 4px 0;
  display: flex;
  justify-content: center;
  width: 100%;
}
.kofi-button {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  color: #000000 !important;
  font-family: var(--font-body), system-ui, sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 8px 20px;
  border-radius: 9999px;
  text-decoration: none;
  box-shadow: 0 4px 18px rgba(245, 158, 11, 0.4);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid rgba(255, 255, 255, 0.35);
  cursor: pointer;
}
.kofi-button:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 8px 26px rgba(245, 158, 11, 0.6);
  filter: brightness(1.05);
}
.kofi-icon {
  font-size: 1.15rem;
  display: inline-block;
  animation: kofi-wiggle 3.5s ease-in-out infinite;
  transform-origin: bottom center;
}
@keyframes kofi-wiggle {
  0%, 82%, 100% { transform: rotate(0deg); }
  86% { transform: rotate(-12deg); }
  90% { transform: rotate(10deg); }
  94% { transform: rotate(-6deg); }
  97% { transform: rotate(4deg); }
}

/* Live In-Game Cosmic Universe Leaderboard */
.universe-lb-panel {
  position: absolute;
  top: 64px;
  right: 14px;
  width: 220px;
  background: rgba(10, 15, 30, 0.78);
  border: 1px solid rgba(255, 215, 0, 0.3);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 14px;
  padding: 10px 14px;
  z-index: 25;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  font-family: var(--font-body);
  transition: opacity 0.3s ease;
}

.universe-lb-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 800;
  color: #ffd700;
  letter-spacing: 1px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 6px;
}

.universe-lb-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.universe-lb-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.76rem;
  color: #cbd5e1;
  padding: 2px 4px;
  border-radius: 6px;
}

.universe-lb-item.me {
  background: rgba(255, 215, 0, 0.2);
  border: 1px solid rgba(255, 215, 0, 0.5);
  color: #ffffff;
  font-weight: 700;
}

.universe-lb-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 130px;
}

.universe-lb-mass {
  font-weight: 800;
  color: #ffd700;
  font-family: var(--font-display);
  font-size: 0.72rem;
}

@media (max-width: 768px) {
  .universe-lb-panel {
    top: 50px;
    right: 6px;
    width: 120px;
    padding: 4px 8px;
    background: rgba(10, 15, 30, 0.65);
    border-radius: 8px;
  }
  .universe-lb-header {
    font-size: 0.58rem;
    padding-bottom: 3px;
    margin-bottom: 3px;
  }
  .universe-lb-list {
    gap: 2px;
  }
  .universe-lb-item {
    font-size: 0.58rem;
    padding: 1px 2px;
  }
  .universe-lb-name {
    max-width: 72px;
    font-size: 0.58rem;
  }
  .universe-lb-mass {
    font-size: 0.56rem;
  }
}
