/* CSS Variables & Theme */
:root {
  --color-bg-dark: #011a10;
  --color-felt: #043f2e;
  --color-gold-1: #fbf5b7;
  --color-gold-2: #bf953f;
  --color-gold-3: #b38728;
  --color-gold-4: #8b6c42; /* Bronze/Shadow */
  --color-text-gold: #f4eeb1;
  --color-white: #ffffff;
  --shadow-inner: inset 0 0 20px rgba(0, 0, 0, 0.8);
  --shadow-drop: 0 10px 20px rgba(0, 0, 0, 0.5);

  --font-heading: "Cinzel", serif;
  --font-ui: "Montserrat", sans-serif;
}

/* Global Reset & Body */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--color-bg-dark);
    background-image: url('assets/bg.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
  color: var(--color-text-gold);
  font-family: var(--font-ui);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
}

/* Animations */
@keyframes sparkle {
  0%,
  100% {
    opacity: 0.3;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.2);
  }
}

@keyframes glow {
  0% {
    text-shadow: 0 0 5px var(--color-gold-2);
  }
  50% {
    text-shadow: 0 0 20px var(--color-gold-1);
  }
  100% {
    text-shadow: 0 0 5px var(--color-gold-2);
  }
}

/* Top Nav */
.top-nav {
  display: flex;
  justify-content: center;
  gap: 20px;
  padding: 10px 0;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.8), transparent);
  width: 100%;
}

.nav-link {
  color: var(--color-gold-2);
  text-decoration: none;
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.9rem;
  padding: 5px 10px;
  border-bottom: 2px solid transparent;
  transition: all 0.3s;
}

.nav-link:hover,
.nav-link.active {
  color: var(--color-gold-1);
  border-bottom: 2px solid var(--color-gold-1);
  text-shadow: 0 0 8px rgba(251, 245, 183, 0.4);
}

/* Ad Containers */
.ad-container {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px;
}

.ad-placeholder {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--color-gold-4);
  color: var(--color-gold-4);
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 0.8rem;
  letter-spacing: 1px;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
}

.ad-top {
  margin-bottom: 20px;
}

/* Header */
.main-header {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 30px;
    gap: 15px;
    position: relative;
    padding: 15px 0;
    width: 100%;
}

.main-header::before,
.main-header::after {
    content: '';
    position: absolute;
    left: 0;
    width: 100%;
    height: 4px; /* Thickness of the border */
    background: linear-gradient(90deg, #D4AF62, #CAC89E, #D9CB99, #CAC89E, #D4AF62);
    border-radius: 2px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

.main-header::before {
    top: 0;
}

.main-header::after {
    bottom: 0;
}

.main-header img {
    /* Ensure image fits within */
    max-height: 80px; 
    object-fit: contain;
}

.main-header h1 {
  font-family: var(--font-heading);
  font-size: 2.5rem;
  background: linear-gradient(
    to bottom,
    var(--color-gold-1),
    var(--color-gold-2)
  );
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  filter: drop-shadow(0 0 5px rgba(179, 135, 40, 0.3));
}

.ornament {
  width: 40px;
  height: 40px;
  background: radial-gradient(circle, var(--color-gold-1), var(--color-gold-3));
  border-radius: 50%;
  box-shadow:
    0 2px 5px rgba(0, 0, 0, 0.5),
    inset 0 -2px 5px rgba(0, 0, 0, 0.3);
  border: 2px solid var(--color-gold-2);
}

/* Main Layout */
.main-grid {
  display: grid;
  grid-template-columns: 1fr 400px 320px;
  gap: 30px;
  max-width: 1200px;
  width: 95%;
  margin-bottom: 60px;
}

/* Gold Frame Component */
.gold-frame {
  background-image: url('assets/inside_frame.png');
  background-size: 100% 100%;
  background-position: center;
  background-repeat: no-repeat;
  border: 3px solid #b38728; /* Mid Gold */
  box-shadow: 
      0 0 0 2px #022b1c, /* Dark Emerald Gap */
      0 0 0 4px #d4af37, /* Outer Gold */
      inset 0 0 0 2px #022b1c, /* Inner Gap */
      inset 0 0 0 4px #8b6c42, /* Inner Bronze Ring */
      inset 0 0 40px rgba(0,0,0,0.8); /* Depth */
  padding: 20px;
  position: relative;
  overflow: hidden;
}

.gold-frame::after {
  /* Shine effect top corner */
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 50%;
  background: linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.05),
    transparent
  );
  pointer-events: none;
}

/* Globe Column */
.col-globe {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 400px;
}

.globe-frame {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px;
}

.globe-window {
  width: 300px;
  height: 300px;
  border-radius: 50%;
  background:
    radial-gradient(
      circle at 30% 30%,
      rgba(255, 255, 255, 0.1),
      rgba(0, 0, 0, 0) 60%
    ),
    rgba(0, 0, 0, 0.2);
  border: 8px solid rgba(255, 255, 255, 0.1);
  box-shadow:
    inset 0 0 40px rgba(0, 0, 0, 0.8),
    0 0 30px rgba(251, 245, 183, 0.1);
  position: relative;
  overflow: hidden;
}

.globe-shine {
  position: absolute;
  top: 20px;
  left: 40px;
  width: 100px;
  height: 60px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  transform: rotate(-45deg);
  filter: blur(10px);
  pointer-events: none;
  z-index: 10;
}

.balls-stage {
  width: 100%;
  height: 100%;
  position: relative;
}

/* Balls */
.ball {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 800;
  color: white;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  background: radial-gradient(
    circle at 30% 30%,
    rgb(255, 100, 100),
    rgb(150, 0, 0)
  ); /* Default RED base */
  box-shadow:
    inset -5px -5px 10px rgba(0, 0, 0, 0.5),
    2px 5px 10px rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.2);
  /* Transition for positioning */
  transition: transform 0.5s ease-out;
  text-align: center;
  line-height: 1;
  overflow: hidden;
  white-space: nowrap;
}

/* Setup Panel */
.panel {
  height: 100%;
  display: flex;
  flex-direction: column;
}
.panel.hidden {
  display: none;
}

.control-frame {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.input-group label {
  display: block;
  margin-bottom: 8px;
  color: var(--color-gold-1);
  font-size: 0.9rem;
  text-transform: uppercase;
}

.input-row {
  display: flex;
  gap: 10px;
}

input[type="text"] {
  flex: 1;
  background: rgba(0, 0, 0, 0.3);
  border: 2px solid var(--color-gold-4);
  padding: 10px;
  color: var(--color-text-gold);
  font-family: var(--font-ui);
  border-radius: 4px;
  outline: none;
  transition: border 0.3s;
}

input[type="text"]:focus {
  border-color: var(--color-gold-1);
  box-shadow: 0 0 10px rgba(191, 149, 63, 0.3);
}

/* Custom Checkboxes */
.toggles {
  display: flex;
  gap: 20px;
  font-size: 0.8rem;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--color-gold-1);
}

.toggle-label input {
  display: none;
}
.checkbox-custom {
  width: 16px;
  height: 16px;
  border: 2px solid var(--color-gold-2);
  background: rgba(0, 0, 0, 0.5);
  display: inline-block;
  position: relative;
}
.toggle-label input:checked + .checkbox-custom::after {
  content: "✓";
  position: absolute;
  top: -4px;
  left: 1px;
  color: var(--color-gold-1);
  font-size: 14px;
}

/* List */
.list-container {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--color-gold-4);
  height: 200px;
  overflow-y: auto;
  padding: 10px;
  border-radius: 4px;
}

.list-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
  font-size: 0.8rem;
  color: var(--color-gold-2);
}

.text-link {
  background: none;
  border: none;
  color: var(--color-gold-2);
  text-decoration: underline;
  cursor: pointer;
  font-size: 0.8rem;
}
.text-link:hover {
  color: var(--color-gold-1);
}

#name-list {
  list-style: none;
}

#name-list li {
  background: rgba(15, 89, 59, 0.3);
  margin-bottom: 5px;
  padding: 5px 10px;
  display: flex;
  justify-content: space-between;
  color: white;
  border-radius: 3px;
  border-left: 2px solid var(--color-gold-4);
}
#name-list li button {
  background: none;
  border: none;
  color: #ff6b6b;
  cursor: pointer;
  font-weight: bold;
}

/* Buttons */
.btn-glossy {
  font-family: var(--font-heading);
  font-weight: 700;
  text-transform: uppercase;
  border: none;
  padding: 12px 24px;
  cursor: pointer;
  color: #1a1a1a;
  box-shadow:
    0 4px 6px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.3);
  transition:
    transform 0.1s,
    filter 0.2s;
}

.btn-glossy:active {
  transform: translateY(2px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}
.btn-glossy:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  filter: grayscale(1);
}

.btn-gold {
  /* User requested image */
  background: url('assets/gold-bg-btn.png') no-repeat center center;
  background-size: cover;
  
  /* Premium Border & Shadow Effect */
  color: #3e2b11;
  border: 1px solid #b38728;
  box-shadow: 
      0 0 0 1px #022b1c, /* Dark Emerald thin outline */
      0 0 0 2px #d4af37, /* Outer Gold ring */
      inset 0 1px 0 rgba(255, 255, 255, 0.4),
      0 4px 6px rgba(0, 0, 0, 0.5);
}
.btn-emerald {
  background: url('assets/greeny-bg-btn.png') no-repeat center center;
  background-size: cover;
  
  color: #fff;
  border: 1px solid #b38728;
  box-shadow: 
      0 0 0 1px #022b1c, 
      0 0 0 2px #d4af37, 
      inset 0 1px 0 rgba(255, 255, 255, 0.4),
      0 4px 6px rgba(0, 0, 0, 0.5);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}
.btn-bronze {
  background: linear-gradient(to bottom, #cd7f32, #a0522d);
  color: white;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  border: 1px solid #8b4513;
}
.btn-block {
  width: 100%;
  font-size: 1.2rem;
  letter-spacing: 1px;
}

/* Winner Panel */
.winner-frame {
  text-align: center;
  /* background removed to show gold-frame image */
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100%;
}

/* Header Row for Crown + Title */
.winner-header-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.crown-img {
  width: 48px; 
  height: 48px;
}

.winner-title {
  font-family: var(--font-heading);
  color: var(--color-gold-1);
  font-size: 2rem;
}

.laurel-wreath {
  margin: 20px 0;
  position: relative;
  padding: 0 40px;
}
.laurel-wreath::before,
.laurel-wreath::after {
  content: "🌿";
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 2rem;
  color: var(--color-gold-2);
}
.laurel-wreath::before {
  left: 0;
  transform: translateY(-50%) rotate(-15deg);
}
.laurel-wreath::after {
  right: 0;
  transform: translateY(-50%) scaleX(-1) rotate(-15deg);
}

.winner-name-text {
  font-size: 2.5rem;
  font-family: var(--font-heading);
  color: white;
  text-transform: uppercase;
  font-weight: 900;
  text-shadow: 0 0 10px var(--color-gold-1);
}

.winner-subtext {
  color: var(--color-gold-4);
  font-size: 0.9rem;
  margin-bottom: 30px;
}

.draw-controls {
  display: flex;
  flex-direction: column;
  gap: 15px;
  width: 100%;
}

.controls-row {
  display: flex;
  gap: 15px;
  width: 100%;
  justify-content: space-between;
}

.controls-row .btn-glossy {
  flex: 1; /* Split 50/50 */
  padding: 12px 10px; /* Reduced side padding for fit */
  font-size: 1rem;
}

.secondary-actions {
  display: flex;
  justify-content: center;
  width: 100%;
}
.secondary-actions .btn-glossy {
  width: 100%; /* Full width for Back button */
}

/* Inline Ad */
.ad-inline {
  margin-top: 20px;
}

/* Sticky Ad (Mobile) */
.sticky-ad-wrapper {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  background: rgba(0, 0, 0, 0.9);
  display: none; /* Hidden on desktop by default */
  justify-content: center;
  align-items: center;
  padding: 5px;
  border-top: 2px solid var(--color-gold-4);
  z-index: 1000;
}
.btn-close-ad {
  position: absolute;
  right: 10px;
  top: 5px;
  background: #333;
  color: white;
  border: 1px solid white;
  border-radius: 50%;
  width: 25px;
  height: 25px;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Responsive */
@media (max-width: 1024px) {
  .main-grid {
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: 100%;
  }
  .col-globe,
  .col-center,
  .col-ad-right {
    width: 100%;
    max-width: 500px;
  }
  .col-ad-right .ad-placeholder {
    margin: 0 auto;
    /* Sidebar ad might need to be hidden or repurposed on mobile if standard practice, 
           but user said "Stack sections". A 300x600 is tall for mobile stack, 
           but I will respect "stack sections" request. */
  }
  /* Reorder flex items to match Mobile Layout < 1024px: 
       1. Name Entry (in Center)
       2. Globe (Left)
       3. Draw Button (in Center)
       4. Winner (Center)
       Wait, controls are inside Center. I might need to use order property if I split them.
       But the user said Setup State vs Draw State.
       "Mobile Layout: 1. Name Entry, 2. Globe..."
       This suggests the layout changes significantly. 
       Let's use `order` property on the grid/flex children.
    */
  .main-grid {
    display: flex;
    flex-direction: column;
  }

  /* We need to re-structure slightly for the "Order" requirement if panels are monolithic.
       Actually, since Setup and Draw are mutually exclusive (mostly), 
       If Setup is Active:
         1. Setup Panel
         2. Globe
       If Draw is Active:
         2. Globe
         3. Winner Panel
       
       So simply putting Center col ABOVE Left col works for Setup.
    */
  .col-center {
    order: 1;
  }
  .col-globe {
    order: 2;
    margin-top: 20px;
  }
  .col-ad-right {
    order: 3;
  }

  .sticky-ad-wrapper {
    display: flex;
  }
}

/* Premium Sidebar Ad Frame */
.ad-premium-sidebar {
    width: 300px;
    height: 600px;
    background-image: url('assets/bg-ads.png');
    background-size: cover;
    background-position: center;
    position: relative;
    border: 3px solid #b38728; /* Mid Gold */
    /* Double border effect using box-shadow */
    box-shadow: 
        0 0 0 2px #022b1c, /* Dark Emerald Gap */
        0 0 0 4px #d4af37, /* Outer Gold */
        inset 0 0 0 2px #022b1c, /* Inner Gap */
        inset 0 0 0 4px #8b6c42, /* Inner Bronze Ring */
        inset 0 0 40px rgba(0,0,0,0.8); /* Depth */
    
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    margin: 0 auto;
}

/* Premium Top Ad Frame */
.ad-premium-top {
    width: 95%;
    max-width: 728px;
    margin: 20px auto; /* Center horizontally */
    height: 90px;
    margin-top: 20px;
    background-image: url('assets/top-ad-bg.png');
    background-size: cover;
    background-position: center;
    position: relative;
    border: 3px solid #b38728;
    box-shadow: 
        0 0 0 2px #022b1c,
        0 0 0 4px #d4af37, 
        inset 0 0 0 2px #022b1c, 
        inset 0 0 0 4px #8b6c42, 
        inset 0 0 20px rgba(0,0,0,0.8);
    
    display: flex;
    flex-direction: row; /* Horizontal layout for top ad */
    justify-content: space-between;
    align-items: center;
    padding: 0 40px;
    margin-bottom: 20px;
}

.ad-premium-top .ad-premium-label {
    font-size: 1rem;
    margin-right: 20px;
}

.ad-premium-top .ad-premium-size {
    font-size: 2.5rem;
}

.ad-premium-top .mobile-size {
    display: none;
}

.ad-premium-top .desktop-size {
    display: inline;
}

/* Premium Inline Ad (300x250) */
.ad-premium-inline {
    width: 300px;
    height: 250px;
    background-image: url('assets/bg-ads.png');
    background-size: cover;
    background-position: center;
    position: relative;
    border: 3px solid #b38728;
    box-shadow: 
        0 0 0 2px #022b1c,
        0 0 0 4px #d4af37, 
        inset 0 0 0 2px #022b1c, 
        inset 0 0 0 4px #8b6c42, 
        inset 0 0 20px rgba(0,0,0,0.8);
    
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    margin: 20px auto 0; /* Centered with top margin */
}

/* Premium Sticky Ad (320x50) */
.ad-premium-sticky {
    width: 320px;
    height: 50px;
    background-image: url('assets/top-ad-bg.png');
    background-size: cover;
    background-position: center;
    position: relative;
    border: 3px solid #b38728;
    box-shadow: 
        0 0 0 2px #022b1c,
        0 0 0 4px #d4af37, 
        inset 0 0 0 2px #022b1c, 
        inset 0 0 0 4px #8b6c42, 
        inset 0 0 10px rgba(0,0,0,0.8);
    
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 15px;
}

.ad-premium-sticky .ad-premium-label {
    font-size: 0.8rem;
}
.ad-premium-sticky .ad-premium-size {
    font-size: 1.5rem;
}

.ad-premium-content {
    display: flex;
    flex-direction: column;
    gap: 5px;
    z-index: 10;
}

.ad-premium-label {
    font-family: var(--font-ui);
    color: rgba(251, 245, 183, 0.6); /* Muted Gold */
    font-size: 1.2rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.footer-ad-section {
    width: 100%;
    display: flex;
    justify-content: center;
    padding: 20px 0;
    margin-bottom: 60px; /* Space for sticky ad */
}
.ad-premium-size {
    font-family: var(--font-heading); /* Cinzel */
    color: #fbf5b7; /* Bright Gold */
    font-size: 3.5rem;
    font-weight: 900;
    text-shadow: 0 4px 8px rgba(0,0,0,0.8);
    line-height: 1;
}

.ad-premium-top-text {
    position: absolute;
    top: 30px;
    width: 100%;
    text-align: center;
    font-family: var(--font-ui);
    color: rgba(251, 245, 183, 0.4);
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 2px;
}

/* --- 3D Machine Layout --- */
.col-globe {
    display: flex;
    justify-content: center;
    align-items: center;
    /* padding: 20px; */
    /* Ensure it doesn't overflow */
    overflow: hidden; 
}

.machine-wrapper {
    position: relative;
    width: 100%;
    max-width: 500px;
    /* Maintain aspect ratio of the SVG */
    aspect-ratio: 544 / 597; 
}

.machine-bg {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    position: relative;
    z-index: 10;
}

#lottery-3d-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 20;
    pointer-events: none; /* Let clicks pass through if needed, though buttons are elsewhere */
}

/* Hide old globe elements */
/* Hide old globe elements */
.globe-frame, .globe-window, .globe-base {
    display: none !important;
}

/* --- Mobile Responsiveness --- */
@media (max-width: 900px) {
    .main-grid {
        display: flex; /* Flex is easier for reordering than grid sometimes, or just 1-col grid */
        flex-direction: column;
        width: 100%;
        padding: 0 10px;
        gap: 20px;
    }

    /* Order: Globe (Visual) First, then Controls, then List/Ad */
    .col-globe {
        order: -1; 
        min-height: auto; /* Remove fixed height */
    }
    
    .machine-wrapper {
        max-width: 80%; /* Don't be too huge on tablets */
    }

    /* Sidebar Ad - Move to bottom or hide if space is tight */
    .sidebar-right {
        order: 10;
        display: flex;
        justify-content: center;
    }
    
    /* Controls Section */
    .col-center {
        width: 100%;
        max-width: 500px;
        margin: 0 auto;
    }

    /* Text Sizes */
    .winner-title {
        font-size: 1.8rem;
    }
    .winner-name-text {
        font-size: 2rem;
    }
    .main-header h1 {
        font-size: 1.8rem;
    }
}

@media (max-width: 768px) {
    /* Top ad becomes 320x50 on mobile */
    .ad-premium-top {
        max-width: 320px;
        height: 50px;
        padding: 0 10px;
    }
    
    .ad-premium-top .desktop-size {
        display: none;
    }
    
    .ad-premium-top .mobile-size {
        display: inline;
    }
    
    .ad-premium-top .ad-premium-label {
        font-size: 0.7rem;
    }
    
    .ad-premium-top .ad-premium-size {
        font-size: 1.2rem;
    }
    
    /* Show sticky ad on mobile */
    .sticky-ad-wrapper {
        display: flex;
    }
    
    /* Hide sidebar ad on mobile */
    .col-ad-right {
        display: none;
    }
    
    /* Inline ads visible on mobile */
    .footer-ad-section {
        display: flex !important;
        justify-content: center;
        padding: 20px 0;
    }
}

@media (max-width: 480px) {
    .machine-wrapper {
        max-width: 100%; /* Full width on small phones */
    }
    .winner-content {
        transform: scale(0.9); /* Shrink winner UI slightly */
    }
}
