:root {
  --font-main: system-ui, -apple-system, sans-serif;
  --color-bg: #05070a;
  --color-card: rgba(20, 25, 40, 0.6);
  --color-border: rgba(255, 255, 255, 0.1);
  --color-accent: #38bdf8; /* Cyan */
  --color-accent-glow: rgba(56, 189, 248, 0.4);
  --color-text: #f0f9ff;
  --color-muted: #94a3b8;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0;
  height: 100vh;
  width: 100vw;
  font-family: var(--font-main);
  background-color: var(--color-bg);
  /* Use your main image here. Ensure the path is correct */
  background-image: url("assets/img/background.png"); 
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  color: var(--color-text);
  overflow-x: hidden;
}

/* Glassmorphism Layout */
.layout {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 20px;
  background: radial-gradient(circle at center, rgba(0,0,0,0.2) 0%, rgba(0,0,0,0.8) 100%);
}

.site-header {
  text-align: center;
  margin-bottom: 2rem;
  text-shadow: 0 4px 10px rgba(0,0,0,0.8);
}

.site-header h1 {
  font-size: clamp(1.5rem, 4vw, 3rem);
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 2px;
  background: linear-gradient(to right, #fff, var(--color-accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  color: var(--color-accent);
  font-weight: 600;
  margin-top: 0.5rem;
  position: relative; /* Container for absolute debug text */
}

/* Debug Text - Hidden by default, absolute to prevent layout shift */
#date-debug {
  display: none; /* Hidden unless JS enables it */
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.8rem;
  color: #ff4444; /* Red to indicate debug mode */
  white-space: nowrap;
  margin-top: 5px;
}

/* Grid Layout */
.content {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 30px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  flex: 1;
}

@media (max-width: 850px) {
  .content { grid-template-columns: 1fr; }
}

/* Cards */
.dice-section, .video-section {
  background: var(--color-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--color-border);
  border-radius: 24px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
  width: 100%; /* Ensure card takes full width of grid cell */
  position: relative;
  overflow: hidden; /* For background effects */
}

/* Pokemon Cyber Pattern for Video Section */
.video-section::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.1;
  pointer-events: none;
  background-image: 
    radial-gradient(circle at 50% 50%, transparent 9px, var(--color-accent) 10px, var(--color-accent) 12px, transparent 13px),
    radial-gradient(circle at 50% 50%, var(--color-accent) 0, var(--color-accent) 4px, transparent 5px),
    linear-gradient(to bottom, transparent 48%, var(--color-accent) 48%, var(--color-accent) 52%, transparent 52%);
  background-size: 60px 60px;
  mask-image: linear-gradient(to bottom, black, transparent); /* Fade out at bottom */
  -webkit-mask-image: linear-gradient(to bottom, black, transparent);
  z-index: -1;
}

/* Hex Tech Pattern for Dice Section */
.dice-section::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.05;
  pointer-events: none;
  background-image: 
    linear-gradient(30deg, var(--color-accent) 12%, transparent 12.5%, transparent 87%, var(--color-accent) 87.5%, var(--color-accent)),
    linear-gradient(150deg, var(--color-accent) 12%, transparent 12.5%, transparent 87%, var(--color-accent) 87.5%, var(--color-accent)),
    linear-gradient(30deg, var(--color-accent) 12%, transparent 12.5%, transparent 87%, var(--color-accent) 87.5%, var(--color-accent)),
    linear-gradient(150deg, var(--color-accent) 12%, transparent 12.5%, transparent 87%, var(--color-accent) 87.5%, var(--color-accent)),
    linear-gradient(60deg, rgba(56, 189, 248, 0.5) 25%, transparent 25.5%, transparent 75%, rgba(56, 189, 248, 0.5) 75%, rgba(56, 189, 248, 0.5)),
    linear-gradient(60deg, rgba(56, 189, 248, 0.5) 25%, transparent 25.5%, transparent 75%, rgba(56, 189, 248, 0.5) 75%, rgba(56, 189, 248, 0.5));
  background-size: 40px 70px;
  background-position: 0 0, 0 0, 20px 35px, 20px 35px, 0 0, 20px 35px;
  z-index: -1;
}

/* Dice Container - Responsive */
#dice-container {
  width: 100%;
  aspect-ratio: 1 / 1;
  max-height: 50vh; /* Don't take up too much vertical space */
  min-height: 300px; /* Ensure it's never too small */
  position: relative;
  background: transparent;
  margin-bottom: 20px;
  display: block;
}

/* Force canvas to fill container to prevent flicker during resize */
#dice-container canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

/* Animated Scanner Effect */
#dice-container::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--color-accent);
  box-shadow: 0 0 15px var(--color-accent), 0 0 30px var(--color-accent);
  opacity: 0;
  pointer-events: none;
  animation: scan 4s ease-in-out infinite;
}

@keyframes scan {
  0% { top: 10%; opacity: 0; }
  10% { opacity: 0.5; }
  50% { top: 90%; opacity: 0.5; }
  90% { opacity: 0; }
  100% { top: 90%; opacity: 0; }
}

/* Video Styling */
.video-wrapper {
  width: 100%;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 0 30px rgba(56, 189, 248, 0.2);
  border: 1px solid var(--color-accent);
  background: #000;
  aspect-ratio: 16 / 9;
  max-height: 50vh; /* Match dice constraint */
  position: relative;
  
  /* Initial State: Turned Off Screen */
  opacity: 0.3;
  filter: grayscale(1) brightness(0.5);
  transition: all 0.5s ease;
}

/* Activated State (Triggered by JS) */
.video-wrapper.active {
  opacity: 1;
  filter: grayscale(0) brightness(1) drop-shadow(0 0 15px var(--color-accent));
  animation: turnOnScreen 0.6s cubic-bezier(0.23, 1, 0.32, 1) forwards;
}

/* CRT Turn-On Effect */
@keyframes turnOnScreen {
  0% {
    transform: scale(1, 0.01);
    opacity: 0.5;
    filter: brightness(3) contrast(2);
  }
  50% {
    transform: scale(1, 0.05);
    opacity: 0.8;
  }
  70% {
    transform: scale(1, 1.1); /* Overshoot height */
  }
  100% {
    transform: scale(1, 1);
    opacity: 1;
    filter: brightness(1) contrast(1);
  }
}

/* Holographic Corner Accents */
.video-wrapper::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 2px solid transparent;
  border-radius: 16px;
  background: 
    linear-gradient(to right, var(--color-accent) 20px, transparent 20px) top left,
    linear-gradient(to bottom, var(--color-accent) 20px, transparent 20px) top left,
    linear-gradient(to left, var(--color-accent) 20px, transparent 20px) top right,
    linear-gradient(to bottom, var(--color-accent) 20px, transparent 20px) top right,
    linear-gradient(to right, var(--color-accent) 20px, transparent 20px) bottom left,
    linear-gradient(to top, var(--color-accent) 20px, transparent 20px) bottom left,
    linear-gradient(to left, var(--color-accent) 20px, transparent 20px) bottom right,
    linear-gradient(to top, var(--color-accent) 20px, transparent 20px) bottom right;
  background-repeat: no-repeat;
  opacity: 0.6;
  pointer-events: none;
}

.video-player {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none; /* Disables clicking/interaction */
  opacity: 0; /* Ensure video is hidden initially so poster doesn't show */
  transition: opacity 0.2s ease;
}

.video-wrapper.active .video-player {
  opacity: 1;
}

/* Buttons */
.primary-button {
  background: var(--color-accent);
  color: #000;
  border: none;
  padding: 12px 32px;
  font-size: 1rem;
  font-weight: 800;
  text-transform: uppercase;
  border-radius: 50px;
  cursor: pointer;
  box-shadow: 0 0 20px var(--color-accent-glow);
  transition: all 0.2s ease;
  margin-top: 10px;
}

.primary-button:hover {
  transform: scale(1.05);
  box-shadow: 0 0 35px var(--color-accent-glow);
  background: #fff;
}

.primary-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  filter: grayscale(1);
}

/* Text Info */
.roll-info {
  text-align: center;
  margin-top: 1rem;
}
#current-day-label { font-size: 1.2rem; font-weight: bold; color: #fff; }
#current-day-caption { color: var(--color-muted); font-size: 0.9rem; margin-top: 5px; }

/* Overlay */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.95);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 999;
  transition: opacity 0.5s;
}
.overlay.hidden { opacity: 0; pointer-events: none; }
.overlay-content { text-align: center; color: white; }

.site-footer { text-align: center; padding: 20px; opacity: 0.6; font-size: 0.8rem; }

/* ------------------------------------------------------------ */
/* Mobile refinements                                            */
/* ------------------------------------------------------------ */
@media (max-width: 540px) {
  body {
    background-attachment: scroll; /* Avoid jank on mobile */
  }

  .layout {
    padding: 12px;
  }

  .site-header {
    margin-bottom: 1.25rem;
  }

  .site-header h1 {
    font-size: clamp(1.25rem, 6vw, 2rem);
  }

  .subtitle {
    margin-top: 0.25rem;
  }

  .content {
    gap: 12px; /* Reduced gap */
  }

  .dice-section, .video-section {
    padding: 12px;
    border-radius: 16px;
  }

  #dice-container {
    /* Fit both elements in viewport comfortably */
    max-height: 35vh; 
    min-height: 180px;
  }

  .video-wrapper {
    max-height: 35vh;
    border-radius: 14px;
  }

  .primary-button {
    width: 100%;
    padding: 12px 16px;
    font-size: 0.9rem;
    margin-top: 8px;
  }

  .roll-info {
    margin-top: 0.5rem;
  }
  
  .site-header h1 {
    font-size: 1.5rem;
  }
}