/* Core Styling for 3D Physics Ball Balancer */

:root {
  --bg-dark-top: #070b14;
  --bg-dark-bottom: #0d1527;
  --panel-bg: rgba(15, 23, 42, 0.9);
  --panel-border: rgba(0, 243, 255, 0.25);
  --text-primary: #f8fafc;
  --text-muted: #94a3b8;
  --accent-cyan: #00f3ff;
  --accent-purple: #8f00ff;
  --accent-green: #10b981;
  --font-sans: 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at 50% 30%, #0f172a 0%, #070b14 70%, #030712 100%);
  font-family: var(--font-sans);
  color: var(--text-primary);
  user-select: none;
}

/* AMBIENT BACKGROUND GLOWS & GRID */
.bg-glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(120px);
  pointer-events: none;
  z-index: 0;
}

.glow-1 {
  width: 600px;
  height: 600px;
  background: rgba(0, 243, 255, 0.08);
  top: -150px;
  left: 20%;
}

.glow-2 {
  width: 700px;
  height: 700px;
  background: rgba(143, 0, 255, 0.08);
  bottom: -200px;
  right: 15%;
}

.bg-grid {
  position: absolute;
  inset: 0;
  background-image: 
    linear-gradient(to right, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
  background-size: 50px 50px;
  pointer-events: none;
  z-index: 0;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  z-index: 1;
}

#canvas-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

/* Sleek Timer in the top center (adjusted to accommodate side ad banners) */
#game-timer {
  position: absolute;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 10px 22px;
  font-family: var(--font-mono);
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  transition: opacity 0.5s ease;
}

#game-timer.hidden {
  opacity: 0;
  pointer-events: none;
}

.timer-label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.timer-value {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent-cyan);
  text-shadow: 0 0 8px rgba(0, 243, 255, 0.3);
}

/* On-Screen Virtual Joystick Styling */
.joystick-container {
  position: absolute;
  bottom: 28px;
  right: 235px;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  user-select: none;
  touch-action: none;
}

.joystick-base {
  position: relative;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: var(--panel-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 2px solid rgba(0, 243, 255, 0.4);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35), inset 0 0 12px rgba(0, 243, 255, 0.15);
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: grab;
  touch-action: none;
}

.joystick-base:active {
  cursor: grabbing;
}

.joystick-ring {
  position: absolute;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 1px dashed rgba(255, 255, 255, 0.2);
  pointer-events: none;
}

.joystick-crosshair-x {
  position: absolute;
  width: 100%;
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
  pointer-events: none;
}

.joystick-crosshair-y {
  position: absolute;
  width: 1px;
  height: 100%;
  background: rgba(255, 255, 255, 0.08);
  pointer-events: none;
}

.joystick-stick {
  position: absolute;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #00f3ff 0%, #0099b8 70%, #005f73 100%);
  border: 2px solid #ffffff;
  box-shadow: 0 4px 16px rgba(0, 243, 255, 0.5), inset 0 2px 4px rgba(255, 255, 255, 0.6);
  transform: translate(0px, 0px);
  transition: transform 0.05s ease-out;
  pointer-events: none;
}

.joystick-stick.resetting {
  transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.joystick-label {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--text-muted);
  background: var(--panel-bg);
  padding: 3px 8px;
  border-radius: 4px;
  border: 1px solid var(--panel-border);
}

@media (max-width: 900px) {
  .joystick-container {
    right: 160px;
  }
}

@media (max-width: 650px) {
  .joystick-container {
    right: 20px;
    bottom: 20px;
  }
}

/* Side Ad Banners Styling */
.ad-sidebar {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 210px;
  z-index: 20;
  padding: 24px 14px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.ad-sidebar.left {
  left: 0;
  border-right: 1px solid var(--panel-border);
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
}

.ad-sidebar.right {
  right: 0;
  border-left: 1px solid var(--panel-border);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.15);
}

.ad-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 8px;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.12);
}

.ad-badge {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.15em;
  color: var(--text-muted);
}

.ad-tag {
  font-size: 0.6rem;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.1);
  color: var(--accent-cyan);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid rgba(0, 243, 255, 0.3);
}

.ad-card {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: all 0.3s ease;
}

.ad-card:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(0, 243, 255, 0.3);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

.ad-card-badge {
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--accent-purple);
  background: rgba(143, 0, 255, 0.15);
  padding: 3px 7px;
  border-radius: 4px;
  width: fit-content;
}

.ad-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.2;
  margin: 0;
}

.ad-desc {
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.35;
  margin: 0;
}

.ad-cta {
  margin-top: 6px;
  display: inline-block;
  box-sizing: border-box;
  text-decoration: none;
  background: rgba(0, 243, 255, 0.08);
  color: var(--accent-cyan);
  border: 1px solid rgba(0, 243, 255, 0.5);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: all 0.25 ease;
  width: 100%;
  text-align: center;
}

.ad-cta:hover {
  background: var(--accent-cyan);
  color: #0f172a;
  box-shadow: 0 0 14px rgba(0, 243, 255, 0.5);
}

.ad-card.ad-promo {
  border-color: rgba(0, 243, 255, 0.2);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.05) 0%, rgba(0, 243, 255, 0.05) 100%);
}

@media (max-width: 900px) {
  .ad-sidebar {
    width: 140px;
    padding: 16px 8px;
  }
  .ad-desc {
    display: none;
  }
}

@media (max-width: 650px) {
  .ad-sidebar {
    display: none;
  }
}

/* How To Play Instructions Overlay Pop-up */
#instructions-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 90;
  background: rgba(10, 15, 30, 0.82);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

#instructions-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.instructions-box {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 36px 40px;
  text-align: center;
  max-width: 580px;
  width: 90%;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.6);
  transform: scale(0.92);
  transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#instructions-overlay.visible .instructions-box {
  transform: scale(1);
}

.instructions-header {
  margin-bottom: 24px;
}

.instructions-badge {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--accent-cyan);
  background: rgba(0, 243, 255, 0.12);
  border: 1px solid rgba(0, 243, 255, 0.3);
  padding: 4px 10px;
  border-radius: 6px;
  display: inline-block;
  margin-bottom: 10px;
}

.instructions-title {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--text-primary);
  margin: 4px 0 6px 0;
}

.instructions-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0;
}

.instructions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 28px;
  text-align: left;
}

.instruction-card {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.card-icon {
  font-size: 1.4rem;
  line-height: 1;
}

.card-content h4 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-cyan);
  margin: 0 0 4px 0;
}

.card-content p {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.35;
  margin: 0;
}

.card-content strong {
  color: var(--text-primary);
}

.start-btn {
  background: linear-gradient(135deg, var(--accent-cyan) 0%, #00d7e6 100%);
  color: #0b0f19;
  border: none;
  border-radius: 10px;
  padding: 16px 48px;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  cursor: pointer;
  font-family: var(--font-sans);
  box-shadow: 0 6px 24px rgba(0, 243, 255, 0.35);
  transition: all 0.3s ease;
  width: 100%;
}

.start-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(0, 243, 255, 0.55);
}

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

@media (max-width: 600px) {
  .instructions-grid {
    grid-template-columns: 1fr;
  }
  .instructions-box {
    padding: 24px 20px;
  }
}

/* Simulation Completion / Score Results Overlay */
#results-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 100;
  background: rgba(10, 15, 30, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

#results-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.results-box {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 40px;
  text-align: center;
  max-width: 420px;
  width: 90%;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
  transform: scale(0.9);
  transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#results-overlay.visible .results-box {
  transform: scale(1);
}

.results-title {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  color: var(--text-muted);
  margin-bottom: 24px;
  margin-top: 0;
}

.results-score {
  font-size: 3.8rem;
  font-weight: 600;
  color: var(--accent-cyan);
  text-shadow: 0 0 15px rgba(0, 243, 255, 0.4);
  margin-bottom: 12px;
}

.results-details {
  font-size: 0.95rem;
  color: var(--text-primary);
  font-family: var(--font-mono);
  margin-bottom: 32px;
}

.restart-btn {
  background: var(--accent-cyan);
  color: #0b0f19;
  border: none;
  border-radius: 8px;
  padding: 14px 36px;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  cursor: pointer;
  font-family: var(--font-primary);
  box-shadow: 0 4px 16px rgba(0, 243, 255, 0.2);
  transition: all 0.3s ease;
}

.restart-btn:hover {
  background: #00d7e6;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 243, 255, 0.4);
}

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

/* Loading Overlay */
#loader {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-color);
  z-index: 100;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: opacity 0.6s cubic-bezier(0.25, 1, 0.5, 1);
}

#loader.fade-out {
  opacity: 0;
  pointer-events: none;
}

.loader-content {
  text-align: center;
}

.spinner {
  width: 50px;
  height: 50px;
  border: 3px solid rgba(0, 0, 0, 0.08); /* Darker base border for light background */
  border-top: 3px solid var(--accent-purple);
  border-right: 3px solid var(--accent-cyan);
  border-radius: 50%;
  animation: spin 1.2s cubic-bezier(0.5, 0.1, 0.4, 0.9) infinite;
  margin: 0 auto 20px auto;
  box-shadow: 0 0 15px rgba(143, 0, 255, 0.1);
}

.loader-text {
  font-size: 0.8rem;
  letter-spacing: 0.2em;
  color: #475569; /* Darker text for visibility on light background */
  font-weight: 500;
  animation: pulse 1.8s ease-in-out infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

/* Overlay Button Row Layout */
.overlay-button-row {
  display: flex;
  gap: 14px;
  width: 100%;
  margin-top: 10px;
}

.overlay-button-row .start-btn,
.overlay-button-row .restart-btn {
  flex: 1;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
}

.overlay-button-row .secondary-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--text-primary);
  box-shadow: none;
}

.overlay-button-row .secondary-btn:hover {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.4);
  box-shadow: 0 4px 16px rgba(255, 255, 255, 0.1);
}

/* Ball Game Top Navigation Bar */
.ball-top-nav {
  position: absolute;
  top: 20px;
  left: 260px; /* Offset past left ad sidebar when present */
  z-index: 85;
}

.ball-nav-back-btn {
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(0, 243, 255, 0.4);
  color: var(--accent-cyan);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  padding: 8px 16px;
  border-radius: 8px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  transition: all 0.25s ease;
}

.ball-nav-back-btn:hover {
  background: rgba(0, 243, 255, 0.15);
  border-color: var(--accent-cyan);
  color: #ffffff;
  box-shadow: 0 0 20px rgba(0, 243, 255, 0.4);
  transform: translateY(-2px);
}

@media (max-width: 900px) {
  .ball-top-nav {
    left: 155px;
  }
}

@media (max-width: 650px) {
  .ball-top-nav {
    left: 16px;
  }
}

/* COPYRIGHT BAR AT BOTTOM */
.copyright-bar {
  position: fixed !important;
  bottom: 0 !important;
  left: 0 !important;
  width: 100% !important;
  height: 34px !important;
  line-height: 34px !important;
  text-align: center !important;
  font-family: 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
  font-size: 0.8rem !important;
  color: #94a3b8 !important;
  background: rgba(13, 20, 36, 0.92) !important;
  border-top: 1px solid rgba(255, 255, 255, 0.1) !important;
  backdrop-filter: blur(16px) !important;
  -webkit-backdrop-filter: blur(16px) !important;
  z-index: 99999 !important;
  pointer-events: auto !important;
}

.copyright-bar .footer-brand {
  font-weight: 700 !important;
  color: #ffffff !important;
}

.copyright-bar .accent-cyan {
  color: #00f3ff !important;
  text-shadow: 0 0 10px rgba(0, 243, 255, 0.4) !important;
}

.copyright-bar .accent-purple {
  color: #c084fc !important;
  text-shadow: 0 0 10px rgba(192, 132, 252, 0.4) !important;
}
