/* Import retro/pixel fonts for spooky 8-bit aesthetic */
@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&family=Space+Mono:ital,wght@0,400;0,700;1,400;1,700&display=swap');

/* CSS Custom Properties */
:root {
  --ink: #0A0A0F;
  --moon: #FFFFFF;
  --witch: #4A1A7A;
  --slime: #3B8B47;
  --candy: #C4396B;
  --fog: rgba(255,255,255,0.15);
  --shadow: rgba(0,0,0,0.8);
  --text-glow: rgba(255,255,255,0.3);
  
  /* Typography - Retro/Pixel Style */
  --font-family: 'Space Mono', 'Orbitron', 'Courier New', monospace;
  --title-font: 'Orbitron', 'Space Mono', monospace;
  --title-size: clamp(20px, 3.5vw, 36px);
  --body-size: clamp(13px, 2vw, 16px);
  --line-height: 1.5;
}

/* Reset and Base */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-family);
  font-size: var(--body-size);
  line-height: var(--line-height);
  background: var(--ink);
  color: var(--moon);
  text-shadow: 0 0 3px var(--text-glow);
  font-weight: 400;
  letter-spacing: 0.5px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* App Layout */
#app {
  height: 100vh;
  position: relative;
  overflow: hidden;
}

.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.screen[hidden] {
  display: none !important;
}

/* Start Screen */
#start {
  background: var(--ink);
  text-align: center;
  padding: 2rem;
  z-index: 10;
}

#start:not([hidden]) {
  display: flex !important;
}

.logo {
  font-family: var(--title-font);
  font-size: var(--title-size);
  font-weight: 900;
  letter-spacing: 2px;
  margin-bottom: 0.5rem;
  color: var(--witch);
  text-transform: uppercase;
  text-shadow: 3px 3px 0px var(--shadow), 0 0 10px var(--witch);
  filter: drop-shadow(0 0 5px var(--witch));
}

.subtitle {
  color: var(--moon);
  opacity: 0.7;
  margin-bottom: 2rem;
  font-size: clamp(12px, 1.8vw, 16px);
}

/* Scene Layout */
#scene {
  display: grid;
  grid-template-areas: "image";
  grid-template-rows: 1fr;
  grid-template-columns: 1fr;
  z-index: 5;
}

#image-wrap {
  grid-area: image;
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--ink); /* Fallback */
}

/* Blurred background image */
#scene-img-bg {
  position: absolute;
  top: -10%;
  left: -10%;
  width: 120%;
  height: 120%;
  object-fit: cover;
  object-position: center;
  filter: blur(20px) brightness(0.3);
  z-index: 1;
  transform: scale(1.1);
}

#scene-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  transition: transform 0.3s ease-out;
  display: block;
  z-index: 2;
  position: relative;
}

/* Ken Burns Animation - 5 second slow zoom */
.kenburns {
  animation: ken-burns 5s ease-out forwards;
}

@keyframes ken-burns {
  from {
    transform: scale(1);
  }
  to {
    transform: scale(1.08);
  }
}

/* Overlays */
.vignette {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(
    circle at center,
    transparent 20%,
    rgba(0,0,0,0.3) 70%,
    var(--shadow) 100%
  );
  pointer-events: none;
}

.grain {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0.08;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
}

#black-fade {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--ink);
  opacity: 0; /* Start transparent */
  pointer-events: none;
  z-index: 3; /* Above image but below UI */
  transition: opacity 1.5s ease-out;
}

/* Audio Toggle */
#audio-toggle {
  position: absolute;
  top: 1.5rem;
  right: 1.5rem;
  z-index: 10;
  background: rgba(0,0,0,0.5);
  border: none;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  color: var(--moon);
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: all 0.2s ease;
}

#audio-toggle:hover {
  background: rgba(0,0,0,0.7);
  transform: scale(1.05);
}

#audio-toggle:focus-visible {
  outline: 2px solid var(--candy);
  outline-offset: 2px;
}

#audio-toggle.muted .sound-waves {
  opacity: 0.3;
}

/* Flag X Indicator Star */
.flag-indicator {
  position: absolute;
  top: 1.5rem;
  left: 1.5rem;
  z-index: 10;
  background: rgba(0,0,0,0.5);
  border: none;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  color: var(--candy);
  backdrop-filter: blur(8px);
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: star-glow 2s ease-in-out infinite alternate;
}

.flag-indicator[hidden] {
  display: none !important;
}

@keyframes star-glow {
  from {
    box-shadow: 0 0 10px rgba(196, 57, 107, 0.5);
    transform: scale(1);
  }
  to {
    box-shadow: 0 0 20px rgba(196, 57, 107, 0.8);
    transform: scale(1.05);
  }
}

/* Content Card */
#card {
  grid-area: image;
  place-self: end center;
  z-index: 6;
  max-width: min(90vw, 1200px);
  max-height: 35vh;
  margin-bottom: 3vh;
  padding: 1rem 2.5rem;
  background: color-mix(in srgb, var(--fog) 85%, transparent);
  backdrop-filter: blur(8px) saturate(120%);
  border-radius: 16px;
  box-shadow: 
    0 6px 24px rgba(0,0,0,0.25),
    inset 0 1px 0 rgba(255,255,255,0.1);
  color: var(--ink);
  text-align: left;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--witch) transparent;
}

#card::-webkit-scrollbar {
  width: 4px;
}

#card::-webkit-scrollbar-track {
  background: transparent;
}

#card::-webkit-scrollbar-thumb {
  background: var(--witch);
  border-radius: 2px;
}

#scene-title {
  font-family: var(--title-font);
  font-size: clamp(14px, 2vw, 20px);
  font-weight: 900;
  margin-bottom: 0.6rem;
  line-height: 1.2;
  color: var(--moon);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 1px;
  text-shadow: 2px 2px 0px var(--shadow);
}

#scene-text {
  font-size: clamp(12px, 1.5vw, 14px);
  margin-bottom: 1rem;
  line-height: 1.4;
  color: var(--moon);
}

/* Choices */
.choices {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 0.8rem;
  width: 100%;
  justify-content: center;
  align-items: center;
}

/* Buttons */
.btn {
  position: relative;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 20px;
  font-family: inherit;
  font-size: clamp(11px, 1.4vw, 13px);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  overflow: hidden;
  text-align: center;
  min-height: 36px;
  flex: 1;
  max-width: 280px;
  min-width: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn:focus-visible {
  outline: 2px solid var(--candy);
  outline-offset: 1px;
  box-shadow: 
    0 0 0 1px var(--moon),
    0 0 20px rgba(255, 92, 168, 0.5);
}

/* Primary Button (Start, Play Again) */
.btn.primary {
  background: linear-gradient(135deg, var(--witch), var(--slime));
  color: var(--moon);
  position: relative;
  width: 100%;
  max-width: 400px;
  flex: none;
}

.btn.primary::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
  transition: left 0.5s ease;
}

.btn.primary:hover::before {
  left: 100%;
}

.btn.primary:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 8px 25px rgba(107, 56, 251, 0.4);
}

.btn.primary:active {
  transform: translateY(0) scale(0.98);
}

/* Secondary Button (Scene Choices) */
.btn.secondary {
  background: rgba(255,255,255,0.1);
  color: var(--moon);
  border: 1px solid color-mix(in srgb, var(--moon) 30%, transparent);
  backdrop-filter: blur(4px);
}

.btn.secondary:hover {
  background: rgba(255,255,255,0.2);
  transform: translateY(-1px);
  box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

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

/* Play Again Button */
.btn.play-again {
  background: linear-gradient(135deg, var(--candy), var(--witch));
  color: var(--moon);
  width: 100%;
  max-width: 400px;
  flex: none;
}

.btn.play-again:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 8px 25px rgba(255, 92, 168, 0.4);
}

/* Button Ripple Effect */
.btn-ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255,255,255,0.6);
  transform: scale(0);
  animation: ripple 0.6s linear;
  pointer-events: none;
}

@keyframes ripple {
  to {
    transform: scale(4);
    opacity: 0;
  }
}

/* Icon Button */
.icon-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.icon-btn svg {
  transition: all 0.2s ease;
}

/* Responsive Design */
@media (max-height: 600px) {
  :root {
    --title-size: clamp(18px, 3vw, 28px);
    --body-size: clamp(11px, 1.6vw, 14px);
  }
  
  #card {
    padding: 1rem 1.5rem;
    max-height: 80vh;
  }
  
  #scene-title {
    font-size: clamp(14px, 2.2vw, 20px);
    margin-bottom: 0.5rem;
  }
  
  #scene-text {
    font-size: clamp(11px, 1.6vw, 14px);
    margin-bottom: 1rem;
  }
  
  .btn {
    padding: 0.5rem 1rem;
    min-height: 38px;
    font-size: clamp(11px, 1.6vw, 13px);
  }
  
  .choices {
    gap: 0.4rem;
  }
}

@media (max-width: 480px) {
  #card {
    padding: 1rem 1.25rem;
    max-width: 98vw;
    margin-bottom: 1vh;
  }
  
  #scene-title {
    font-size: clamp(14px, 2.8vw, 18px);
  }
  
  #scene-text {
    font-size: clamp(12px, 2.2vw, 14px);
  }
  
  .btn {
    max-width: 100%;
    font-size: clamp(12px, 2.2vw, 14px);
    padding: 0.6rem 1rem;
  }
  
  #audio-toggle {
    top: 1rem;
    right: 1rem;
    width: 42px;
    height: 42px;
  }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  .kenburns {
    animation: none;
  }
  
  .btn:hover {
    transform: none;
  }
  
  .btn-ripple {
    display: none;
  }
  
  #black-fade {
    transition: opacity 0.3s ease;
  }
}

/* Typewriter Animation */
.typewriter {
  overflow: hidden;
  border-right: 2px solid var(--moon);
  white-space: nowrap;
  margin: 0 auto;
  animation: blink-caret 1s step-end infinite;
}

@keyframes typing {
  from { width: 0 }
  to { width: 100% }
}

@keyframes blink-caret {
  from, to { border-color: transparent }
  50% { border-color: var(--moon) }
}

.typing-container {
  overflow: hidden;
}

.typing-text {
  display: inline-block;
  opacity: 0;
  transition: opacity 0.1s ease;
}

.typing-text.show {
  opacity: 1;
}

/* Removed distracting fadeInChar animation */

/* Spooky text effects */
.glitch {
  animation: glitch 2s infinite;
}

@keyframes glitch {
  0%, 90%, 100% { transform: translate(0); }
  10% { transform: translate(-1px, 1px); }
  20% { transform: translate(1px, -1px); }
  30% { transform: translate(-1px, -1px); }
  40% { transform: translate(1px, 1px); }
  50% { transform: translate(-1px, 1px); }
  60% { transform: translate(1px, -1px); }
  70% { transform: translate(-1px, -1px); }
  80% { transform: translate(1px, 1px); }
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
  :root {
    --fog: rgba(255,255,255,0.95);
  }
  
  .btn.secondary {
    border-width: 2px;
  }
}