/* ============================================================
   Universe Smash 1 — style.css
   Mobile-first, glassmorphism UI. All colors are friendly &
   playful. No external fonts/images are required.
   ============================================================ */

:root {
  --bg-deep:   #05030f;
  --bg-mid:    #120a2e;
  --glass:     rgba(255, 255, 255, 0.08);
  --glass-2:   rgba(255, 255, 255, 0.14);
  --stroke:    rgba(255, 255, 255, 0.22);
  --text:      #f4f1ff;
  --text-dim:  #b9b2dd;
  --accent:    #7c5cff;
  --accent-2:  #00e0ff;
  --good:      #46e6a0;
  --warn:      #ffcf5c;
  --radius:    20px;
  --shadow:    0 8px 30px rgba(0, 0, 0, 0.45);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top:    env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;            /* prevent page scroll while playing */
  overscroll-behavior: none;
  background: radial-gradient(circle at 50% 30%, var(--bg-mid), var(--bg-deep) 70%);
  color: var(--text);
  font-family: "Baloo 2", "Comic Sans MS", "Chalkboard SE", "Segoe UI Rounded", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;          /* we handle gestures ourselves */
}

/* The 3D canvas lives here and fills the screen */
#scene-container {
  position: fixed;
  inset: 0;
  z-index: 0;
}
#scene-container canvas { display: block; }

/* ===================== Loader ===================== */
#loader {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: radial-gradient(circle at 50% 40%, var(--bg-mid), var(--bg-deep) 75%);
  transition: opacity 0.5s ease;
}
#loader.hide { opacity: 0; pointer-events: none; }
.loader-planet {
  width: 70px; height: 70px; border-radius: 50%;
  background: conic-gradient(from 0deg, var(--accent), var(--accent-2), var(--good), var(--accent));
  box-shadow: 0 0 40px rgba(124, 92, 255, 0.7);
  animation: spin 1.6s linear infinite;
}
.loader-text { color: var(--text-dim); font-size: 15px; letter-spacing: 0.5px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===================== CDN error ===================== */
#cdn-error {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  padding: 24px; background: rgba(5, 3, 15, 0.92);
}
.cdn-error-card {
  max-width: 460px; padding: 26px; border-radius: var(--radius);
  background: var(--glass); border: 1px solid var(--stroke);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.cdn-error-card h2 { margin: 0 0 12px; }
.cdn-error-card p { color: var(--text-dim); line-height: 1.5; }
.cdn-error-card code {
  background: rgba(0,0,0,0.35); padding: 2px 6px; border-radius: 6px;
  color: var(--accent-2);
}

/* ===================== HUD (top) ===================== */
#hud {
  position: fixed;
  top: calc(10px + var(--safe-top));
  left: 10px;
  z-index: 10;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  max-width: 70vw;
}
.hud-pill {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  background: var(--glass); border: 1px solid var(--stroke);
  border-radius: 999px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}
.hud-icon { font-size: 18px; }
.hud-stack { display: flex; flex-direction: column; line-height: 1.05; }
.hud-label { font-size: 9px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.6px; }
.hud-value { font-size: 16px; font-weight: 700; }
.combo-pill {
  background: linear-gradient(135deg, rgba(255,140,80,0.5), rgba(255,80,140,0.45));
  animation: combo-pop 0.25s ease;
}
.combo-pill .hud-value { font-size: 18px; }
@keyframes combo-pop { 0% { transform: scale(0.6); } 60% { transform: scale(1.18); } 100% { transform: scale(1); } }

/* Daily mission banner */
#mission-banner {
  position: fixed;
  top: calc(64px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 9;
  max-width: 90vw;
  padding: 7px 16px;
  font-size: 12.5px;
  text-align: center;
  color: var(--text);
  background: var(--glass);
  border: 1px solid var(--stroke);
  border-radius: 999px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}
#mission-banner.done { background: linear-gradient(135deg, rgba(70,230,160,0.4), rgba(0,224,255,0.3)); }

/* ===================== Action buttons (top-right) ===================== */
#actions {
  position: fixed;
  top: calc(10px + var(--safe-top));
  right: 10px;
  z-index: 10;
  display: flex;
  gap: 8px;
}
.action-btn {
  width: 46px; height: 46px;
  font-size: 20px;
  display: flex; align-items: center; justify-content: center;
  background: var(--glass); border: 1px solid var(--stroke);
  border-radius: 14px;
  color: var(--text);
  cursor: pointer;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, background 0.2s ease;
}
.action-btn:hover { background: var(--glass-2); }
.action-btn:active { transform: scale(0.9); }
.action-btn.off { opacity: 0.45; }

/* ===================== Toolbar ===================== */
#toolbar {
  position: fixed;
  z-index: 10;
  left: 50%;
  bottom: calc(12px + var(--safe-bottom));
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  padding: 10px;
  max-width: calc(100vw - 20px);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  background: var(--glass);
  border: 1px solid var(--stroke);
  border-radius: 22px;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
  scroll-snap-type: x proximity;
}
#toolbar::-webkit-scrollbar { display: none; }

.tool-btn {
  position: relative;
  flex: 0 0 auto;
  width: 70px; height: 70px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px;
  background: var(--glass-2);
  border: 2px solid transparent;
  border-radius: 20px;
  color: var(--text);
  cursor: pointer;
  scroll-snap-align: center;
  transition: transform 0.12s cubic-bezier(.2,1.5,.4,1), border-color 0.2s ease, background 0.2s ease;
}
.tool-btn .t-emoji { font-size: 30px; line-height: 1; }
.tool-btn .t-name  { font-size: 11px; font-weight: 700; color: var(--text-dim); }
.tool-btn:active { transform: scale(0.88); }
.tool-btn.selected {
  border-color: #ffd54f;
  background: linear-gradient(135deg, rgba(255,140,200,0.5), rgba(124,92,255,0.45));
  box-shadow: 0 0 20px rgba(255,213,79,0.6);
  animation: toolBounce 0.4s ease;
}
.tool-btn.selected .t-name { color: #fff; }
@keyframes toolBounce { 0% { transform: scale(0.85); } 55% { transform: scale(1.14); } 100% { transform: scale(1); } }
.tool-btn.locked { cursor: not-allowed; }
.tool-btn.locked .t-emoji,
.tool-btn.locked .t-name { opacity: 0.25; }
.tool-btn .lock {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 18px;
  border-radius: 20px;
  background: rgba(0,0,0,0.35);
}
.tool-btn .lock small { font-size: 8px; color: var(--warn); margin-top: 2px; }

/* ===================== Achievement popup ===================== */
#achievement {
  position: fixed;
  top: calc(96px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%) translateY(-12px);
  z-index: 30;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 18px;
  background: linear-gradient(135deg, rgba(124,92,255,0.6), rgba(0,224,255,0.45));
  border: 1px solid var(--stroke);
  border-radius: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
#achievement.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.ach-icon { font-size: 30px; }
.ach-stack { display: flex; flex-direction: column; }
.ach-title { font-weight: 800; font-size: 15px; }
.ach-sub { font-size: 11px; color: rgba(255,255,255,0.85); }

/* ===================== Floating popups ===================== */
#float-layer { position: fixed; inset: 0; z-index: 8; pointer-events: none; }
.float-pop {
  position: absolute;
  font-weight: 800;
  font-size: 22px;
  color: #fff;
  text-shadow: 0 2px 8px rgba(0,0,0,0.55), 0 0 14px rgba(124,92,255,0.6);
  animation: floatUp 0.95s cubic-bezier(.2,1.4,.4,1) forwards;
  white-space: nowrap;
}
@keyframes floatUp {
  0%   { opacity: 0; transform: translate(-50%, 0) scale(0.4) rotate(-6deg); }
  25%  { opacity: 1; transform: translate(-50%, -14px) scale(1.25) rotate(4deg); }
  100% { opacity: 0; transform: translate(-50%, -78px) scale(1) rotate(0deg); }
}

/* Falling emoji confetti for big moments */
.confetti {
  position: absolute;
  top: -8vh;
  will-change: transform, opacity;
  animation-name: confettiFall;
  animation-timing-function: ease-in;
  animation-fill-mode: forwards;
  pointer-events: none;
}
@keyframes confettiFall {
  0%   { opacity: 0; transform: translateY(0) rotate(0deg); }
  10%  { opacity: 1; }
  100% { opacity: 0; transform: translateY(112vh) rotate(360deg); }
}

/* ===================== Help modal ===================== */
#help-modal {
  position: fixed; inset: 0; z-index: 40;
  display: flex; align-items: center; justify-content: center;
  padding: 22px; background: rgba(5,3,15,0.75);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.modal-card {
  max-width: 420px; width: 100%;
  padding: 24px;
  background: var(--glass); border: 1px solid var(--stroke);
  border-radius: var(--radius);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
}
.modal-card h2 { margin: 0 0 14px; }
.modal-card ul { margin: 0 0 20px; padding-left: 20px; line-height: 1.7; color: var(--text-dim); }
.modal-card ul b { color: var(--text); }
#help-close {
  width: 100%; padding: 13px;
  font-size: 15px; font-weight: 700;
  color: #fff; cursor: pointer;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none; border-radius: 14px;
}
#help-close:active { transform: scale(0.97); }

/* ===================== Responsive ===================== */

/* Desktop / large tablet (landscape): tools become a side panel */
@media (min-width: 900px) and (orientation: landscape) {
  #toolbar {
    left: 14px;
    bottom: 50%;
    transform: translateY(50%);
    flex-direction: column;
    max-width: none;
    max-height: 86vh;
    overflow-x: hidden;
    overflow-y: auto;
  }
  .tool-btn { width: 76px; height: 76px; }
}

/* Very small phones: shrink things a touch */
@media (max-width: 360px) {
  .tool-btn { width: 62px; height: 62px; }
  .tool-btn .t-emoji { font-size: 26px; }
  .action-btn { width: 44px; height: 44px; font-size: 19px; }
  .hud-value { font-size: 14px; }
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  .loader-planet { animation: none; }
  .float-pop { animation-duration: 0.4s; }
  .confetti { display: none; }
}
