/* Centralized Color System */
:root {
  /* Background & Base Colors */
  --bg-primary: #000;
  --bg-secondary: rgba(0, 0, 0, 0.1);
  --bg-tertiary: rgba(0, 0, 0, 0.05);
  
  /* Text Colors (high contrast on dark background) */
  --instructions-primary: #ffffff;
  --instructions-secondary: #ffffffa9;
  --text-primary: #fff0d6;
  --text-secondary: #fff0d6;
  --text-muted: #b0b0b0;
  --text-accent: #ffff00;
  
  /* Highlight & Interactive Colors */
  --highlight-primary: #ffe17e;    /* Bright orange for main highlights */
  --highlight-secondary: #8235ff;  /* Purple for secondary highlights */
  --highlight-tertiary: #ffe17e;   /* Cyan for tertiary highlights */
  
  /* Play/Stop & CTA Colors */
  --cta-primary: #ff0066;          /* Hot pink for play/stop */
  --cta-secondary: #ffff00;        /* Yellow for secondary CTAs */
  --cta-glow: rgba(255, 0, 102, 0.6);
  
  /* Progress & UI Elements */
  --progress-bg: rgba(255, 255, 255, 0.2);
  --progress-fill: var(--highlight-primary);
  --progress-hover: var(--highlight-secondary);
  
  /* Borders & Separators */
  --border-primary: rgba(255, 255, 255, 0.3);
  --border-secondary: rgba(255, 255, 255, 0.1);
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: monospace;
  /* Prevent scroll bounce on mobile */
  -webkit-overflow-scrolling: touch;
  position: fixed;
  width: 100%;
}

#app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  /* Desktop background by default */
  background: url('web_background_desktop.png') center center / cover no-repeat fixed;
}

/* Title Section */
#title-section {
  flex-shrink: 0;
  height: 150px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-primary);
  backdrop-filter: blur(1px);
}

.main-title {
  text-align: center;
  font-family: monospace;
}

.subtitle {
  font-size: 18px;
  font-weight: normal;
  color: var(--text-primary);
  letter-spacing: 0.05em;
  margin-top: 20px;
}

.explore {
  display: block;
  font-size: 32px;
  font-weight: normal;
  color: var(--text-primary);
  letter-spacing: 0.05em;
  margin: 0;
  line-height: 1;
  margin-bottom: 12px;
}

/* Highlighted words use the project's highlight color */
.highlight {
  color: var(--highlight-primary);
  font-size: 42px;
  font-weight: bold;
  text-shadow: 0 0 4px var(--highlight-primary);
}

/* Queue State */
#queue-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  text-align: center;
}

.queue-content {
  max-width: 600px;
  padding: 40px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: 8px;
  backdrop-filter: blur(1px);
}

.queue-content h2 {
  color: var(--highlight-primary);
  font-size: 32px;
  margin-bottom: 20px;
  font-weight: bold;
}

.queue-content p {
  color: var(--text-primary);
  font-size: 18px;
  margin-bottom: 20px;
  line-height: 1.5;
}

#queue-position {
  color: var(--text-secondary);
  font-size: 16px;
  margin-top: 20px;
}

#position-number {
  color: var(--highlight-primary);
  font-weight: bold;
  font-size: 18px;
}

.bold {
  color: var(--text-primary);
  font-size: 22px;
  font-weight: bold;
}

/* Grid Container */
#grid-container {
  /* Fill remaining vertical space but allow shrinking so header/progress/footer stay visible */
  flex: 1 1 auto;
  min-height: 0; /* allow flex child to be smaller than its content */
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
}

#ascii-canvas {
  display: block;
  width: 100%;
  height: 100%;
  max-height: 100%;
  padding-top: 20px;
  padding-bottom: 20px;
  background: transparent;
  cursor: pointer;
  /* Improve touch responsiveness */
  touch-action: manipulation;
  /* Prevent text selection on mobile */
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  /* PERFORMANCE: Hardware acceleration for better performance */
  will-change: transform;
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

/* Morph Position Display */
#morph-container {
  flex-shrink: 0;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 20px;
}

#morph-display {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: monospace;
  font-size: 14px;
  color: var(--text-secondary);
  white-space: nowrap;
}

#slash {
  margin: 0 8px;
  font-weight: bold;
  color: var(--text-primary);
}

#culocodo-percentage,
#brbrt-percentage {
  font-weight: bold;
  font-size: 18px;
  color: var(--highlight-tertiary);
}

#percentage-text,
#brbrt-text {
  color: var(--text-secondary);
  font-size: 14px;
}

/* Progress Bar */
#progress-container {
  flex-shrink: 0;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 24px;
}

#progress-bar {
  width: 100%;
  max-width: 600px;
  height: 8px;
  background: var(--progress-bg);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid var(--border-primary);
}

#progress-bar:hover {
  height: 12px;
  background: rgba(255, 255, 255, 0.3);
  box-shadow: 0 0 10px var(--progress-hover);
}

#progress-bar:hover #progress-fill {
  background: var(--progress-hover);
  box-shadow: 0 0 15px var(--progress-hover);
}

#progress-bar.seeking {
  height: 12px;
  background: rgba(255, 255, 255, 0.4);
  box-shadow: 0 0 20px var(--highlight-primary);
}

#progress-bar.seeking #progress-fill {
  background: var(--highlight-primary);
  box-shadow: 0 0 20px var(--highlight-primary);
}

#progress-fill {
  height: 100%;
  background: var(--progress-fill);
  border-radius: 4px;
  width: 0%;
  transition: width 0.1s ease-out, background 0.2s ease;
  pointer-events: none;
  box-shadow: 0 0 10px var(--progress-fill);
}

/* Bottom Info Section */
#info-section {
  flex-shrink: 0;
  height: 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-primary);
  padding: 0 20px;
  backdrop-filter: blur(1px);
}

#info-section p {
  margin: 4px 0;
  font-size: 18px;
  color: var(--text-secondary);
  text-align: center;
  line-height: 1.4;
}

#info-section p:first-child {
  color: var(--text-primary);
}

.play-cta {
  animation: pulse 1.5s infinite;
  color: var(--cta-primary) !important;
  text-shadow: 0 0 10px var(--cta-glow);
}

@keyframes pulse {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.1);
    opacity: 0.7;
    text-shadow: 0 0 20px var(--cta-glow);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.loading-bar {
  background-color: var(--progress-bg);
}

/* Mobile responsive adjustments */
@media screen and (max-width: 768px) {
  /* Mobile background image */
  #app-container {
    background: url('web_background_phone.png') center center / cover no-repeat fixed;
  }
  
  /* Reduce vertical footprint so everything fits in a fixed viewport */
  #title-section {
    height: 80px;
  }
  
  .explore {
    font-size: 14px;
    line-height: 1;
  }

  .highlight {
    color: var(--highlight-primary);
    font-size: 18px;
    font-weight: bold;
    text-shadow: 0 0 8px var(--highlight-primary);
  }

  .subtitle {
    font-size: 12px;
    font-weight: normal;
    color: var(--text-primary);
    letter-spacing: 0.05em;
    margin-top: 12px;
  }
  .bold {
    color: var(--text-primary);
    font-size: 14px;
    font-weight: bold;
  }

  /* Slightly smaller progress area */
  #progress-container {
    height: 32px;
    padding: 0 12px;
  }

  /* Compact morph display */
  #morph-container {
    height: 40px;
    padding: 0 10px;
  }

  #morph-display {
    font-size: 12px;
  }

  #progress-bar {
    height: 6px;
  }

  #progress-bar:hover {
    height: 10px;
  }

  /* Compact info/footer so two lines fit without scrolling */
  #info-section {
    height: 64px;
    padding: 4px 10px;
  }
  
  #info-section p {
    margin: 2px 0;
    font-size: 11px;
    line-height: 1.2;
  }

  /* Force grid to only take remaining space: 100vh - header(80) - morph(40) - progress(32) - footer(64) = calc(100vh - 275px) */
  #grid-container {
    flex: none !important;
    height: calc(100vh - 275px) !important;
    max-height: calc(100vh - 275px) !important;
  }
}

/* First Time Overlay */
#first-time-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(2px);
  z-index: 10000;
  display: none; /* Start hidden, will be shown by JavaScript */
  align-items: center;
  justify-content: center;
  opacity: 1;
  transition: opacity 0.5s ease-out;
  cursor: pointer; /* Ensure cursor shows clickability */
}

#first-time-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.overlay-content {
  text-align: center;
  max-width: 600px;
  padding: 40px;
}

.info-text {
  margin-bottom: 30px;
  gap: 8px;
  font-size: 18px;
  color: var(--instructions-primary);
  flex-wrap: wrap;
  justify-content: center;
  font-family: monospace;
  letter-spacing: 0.05em;
}

.separator-line {
  width: 100%;
  height: 1px;
  background: var(--border-primary);
  margin: 30px 0;
}

.instructions-text {
  font-size: 24px;
  margin-bottom: 30px;
  color: var(--instructions-primary);
  line-height: 1.3;
}

.drag-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.finger-icon {
  font-size: 48px;
  animation: bounce 2s infinite;
}

.play-stop-instructions {
  margin-top: 30px;
  display: flex;
  flex-direction: column;
  gap: 15px;
  align-items: center;
}

.instruction-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  color: var(--instructions-secondary);
  flex-wrap: wrap;
  justify-content: center;
}

.instruction-text {
  font-family: monospace;
  letter-spacing: 0.05em;
}

@keyframes bounce {
  0%, 20%, 50%, 80%, 100% {
    transform: translateX(0);
  }
  40% {
    transform: translateX(-5px);
  }
  60% {
    transform: translateX(-2px);
  }
}

/* Mobile adjustments for overlay */
@media screen and (max-width: 768px) {
  .overlay-content {
    max-width: 300px;
    padding: 30px 20px;
  }

  .info-text {
    margin-bottom: 20px;
    font-size: 14px;
  }

  .separator-line {
    margin: 20px 0;
  }

  .instructions-text {
    font-size: 18px;
    margin-bottom: 20px;
  }

  .finger-icon {
    font-size: 36px;
  }

  .play-stop-instructions {
    margin-top: 20px;
    gap: 12px;
  }

  .instruction-item {
    font-size: 16px;
    gap: 6px;
  }

  .play-symbol,
  .stop-symbol {
    font-size: 18px !important;
  }

  .drag-line {
    width: 30px;
    height: 2px;
  }
}