/* === Reset & Base === */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --accent: #ff6b9d;
  --accent-light: #ffb3d0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  position: fixed;
  background: #0a0a12;
  color: #c8c8d0;
  font-family: 'Silkscreen', 'Courier New', monospace;
  font-size: 12px;
  -webkit-font-smoothing: none;
  -moz-osx-font-smoothing: unset;
}

.hidden {
  display: none !important;
}

/* === Start Screen === */
#start-screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #0a0a12;
  z-index: 100;
  transition: opacity 0.8s ease;
  gap: 32px;
  padding: 24px;
}

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

.start-header {
  text-align: center;
}

.start-title {
  font-family: 'Silkscreen', 'Courier New', monospace;
  font-size: 28px;
  color: #e8e8f0;
  letter-spacing: 4px;
  text-transform: uppercase;
  text-align: center;
}

.start-subtitle {
  font-size: 10px;
  color: #555;
  letter-spacing: 2px;
  margin-top: 8px;
}

.start-prompt {
  font-size: 11px;
  color: #555;
  letter-spacing: 1px;
  text-align: center;
  animation: blink 2s ease-in-out infinite;
}

@keyframes blink {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

/* === Scene Vignettes (Start Screen) === */
.vignettes {
  display: flex;
  gap: 20px;
  align-items: stretch;
  justify-content: center;
  width: 100%;
  max-width: 640px;
}

.vignette-card {
  flex: 1;
  max-width: 300px;
  cursor: pointer;
  border: 2px solid #222;
  background: #0f0f18;
  overflow: hidden;
  transition: border-color 0.8s ease-in-out, transform 0.6s ease-in-out;
  position: relative;
}

.vignette-card:hover,
.vignette-card:focus-visible {
  border-color: rgba(255, 107, 157, 0.6);
  transform: scale(1.03);
}

.vignette-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.vignette-thumbnail {
  width: 100%;
  aspect-ratio: 16 / 9;
  position: relative;
  overflow: hidden;
  background: #111;
}

.vignette-thumbnail img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
}

/* Subtle vignette overlay on thumbnails */
.vignette-thumbnail::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(
    ellipse at center,
    transparent 50%,
    rgba(0, 0, 0, 0.4) 100%
  );
  pointer-events: none;
}

.vignette-info {
  padding: 10px 12px;
  text-align: center;
}

.vignette-name {
  font-size: 12px;
  color: #e8e8f0;
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 2px;
}

.vignette-subtitle {
  font-size: 9px;
  color: var(--accent);
  letter-spacing: 1px;
  opacity: 0.7;
}

/* Breathing brightness pulse on hover */
@keyframes thumbnail-breathe {
  0%, 100% { opacity: 0; }
  50% { opacity: 0.08; }
}

.vignette-card:hover .vignette-thumbnail::before,
.vignette-card:focus-visible .vignette-thumbnail::before {
  content: '';
  position: absolute;
  inset: 0;
  background: white;
  animation: thumbnail-breathe 2.5s ease-in-out infinite;
  z-index: 1;
  pointer-events: none;
}

/* === App Layout — vertical stack, centered === */
.app-layout {
  width: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-y: auto;
  overflow-x: hidden;
}

/* === Scene Frame — contains the pixel art canvas === */
.scene-frame {
  width: 100%;
  max-width: 960px;
  position: relative;
  flex-shrink: 0;
}

/* CRT vignette over the scene */
.scene-frame::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  background: radial-gradient(
    ellipse at center,
    transparent 55%,
    rgba(0, 0, 0, 0.5) 100%
  );
}

/* === Canvas === */
#scene {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
}

/* === Scene Switcher (in-app, subtle) === */
.scene-switcher {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 10px 0 4px;
  max-width: 480px;
  width: 100%;
}

.scene-nav {
  background: none;
  border: 2px solid #333;
  color: #666;
  font-family: 'Silkscreen', 'Courier New', monospace;
  font-size: 14px;
  width: 32px;
  height: 32px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.2s, color 0.2s;
}

.scene-nav:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.scene-name {
  font-size: 10px;
  color: #555;
  letter-spacing: 1px;
  text-transform: uppercase;
  min-width: 160px;
  text-align: center;
}

/* === Controls Panel === */
.controls-panel {
  width: 100%;
  max-width: 480px;
  padding: 20px 24px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.slider-row label {
  width: 72px;
  flex-shrink: 0;
  font-size: 12px;
  color: #888;
  letter-spacing: 1px;
  text-transform: uppercase;
  -webkit-user-select: none;
  user-select: none;
}

.slider-row input[type="range"] {
  flex: 1;
  min-width: 0;
}

.slider-value {
  width: 28px;
  flex-shrink: 0;
  font-size: 10px;
  color: #666;
  text-align: right;
}

/* === Range Slider === */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 28px;
  background: transparent;
  cursor: pointer;
  touch-action: none;
}

input[type="range"]:focus {
  outline: none;
}

input[type="range"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Track — WebKit */
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  background: #222;
  border: none;
}

/* Track — Firefox */
input[type="range"]::-moz-range-track {
  height: 4px;
  background: #222;
  border: none;
}

/* Thumb — WebKit */
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  background: var(--accent);
  border: 2px solid var(--accent-light);
  border-radius: 0;
  margin-top: -6px;
  image-rendering: pixelated;
}

/* Thumb — Firefox */
input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: var(--accent);
  border: 2px solid var(--accent-light);
  border-radius: 0;
}

/* === Controls Footer === */
.controls-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
}

/* === Mute Button === */
.mute-btn {
  background: transparent;
  border: 2px solid #333;
  color: #777;
  font-family: 'Silkscreen', 'Courier New', monospace;
  font-size: 11px;
  padding: 5px 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  touch-action: manipulation;
  transition: border-color 0.2s, color 0.2s;
}

.mute-btn:hover,
.mute-btn:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
}

.mute-btn[aria-pressed="true"] {
  border-color: #ff3366;
  color: #ff3366;
}

/* === Credits === */
.credits-link {
  background: none;
  border: none;
  color: #444;
  font-family: 'Silkscreen', 'Courier New', monospace;
  font-size: 10px;
  cursor: pointer;
  letter-spacing: 1px;
}

.credits-link:hover {
  color: #555;
}

.credits-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 18, 0.95);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
}

.credits-content {
  max-width: 400px;
  padding: 24px;
  text-align: center;
}

.credits-content h2 {
  font-size: 16px;
  color: #e8e8f0;
  margin-bottom: 12px;
}

.credits-content p {
  font-size: 11px;
  color: #888;
  line-height: 1.6;
  margin-bottom: 12px;
}

.credits-content a {
  color: var(--accent);
  text-decoration: none;
}

.credits-content a:hover {
  text-decoration: underline;
}

.credits-content ul {
  list-style: none;
  font-size: 10px;
  color: #666;
  margin-bottom: 16px;
}

.credits-content ul li {
  margin-bottom: 4px;
}

.credits-close {
  background: none;
  border: 2px solid #333;
  color: #777;
  font-family: 'Silkscreen', 'Courier New', monospace;
  font-size: 11px;
  padding: 6px 16px;
  cursor: pointer;
  letter-spacing: 1px;
}

.credits-close:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* === Loading Overlay === */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: #0a0a12;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 400ms ease-out;
}

.loading-overlay.fade-out {
  opacity: 0;
  pointer-events: none;
}

.loading-overlay.fast-fade {
  transition: opacity 100ms ease-out;
}

.loading-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.loading-pulse {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.5;
  animation: loading-pulse 2.5s ease-in-out infinite;
}

@keyframes loading-pulse {
  0%, 100% { opacity: 0.3; transform: scale(0.9); }
  50% { opacity: 0.8; transform: scale(1.1); }
}

.loading-scene-name {
  font-family: 'Silkscreen', 'Courier New', monospace;
  font-size: 20px;
  color: #e8e8f0;
  letter-spacing: 3px;
  text-transform: uppercase;
}

.loading-scene-subtitle {
  font-family: 'Silkscreen', 'Courier New', monospace;
  font-size: 10px;
  color: var(--accent);
  letter-spacing: 1px;
  opacity: 0.7;
}

/* === Reduced Motion === */
@media (prefers-reduced-motion: reduce) {
  .start-prompt {
    animation: none;
    opacity: 0.7;
  }

  .loading-pulse {
    animation: none;
    opacity: 0.5;
  }

  .loading-overlay {
    transition: none;
  }

  .vignette-card {
    transition: border-color 0.3s ease !important;
  }

  .vignette-card:hover,
  .vignette-card:focus-visible {
    transform: none;
  }

  .vignette-card:hover .vignette-thumbnail::before,
  .vignette-card:focus-visible .vignette-thumbnail::before {
    animation: none;
    opacity: 0;
  }
}

/* === Mobile adjustments === */
@media (max-width: 480px) {
  .vignettes {
    flex-direction: column;
    align-items: center;
    gap: 16px;
  }

  .vignette-card {
    max-width: 280px;
    width: 100%;
  }

  .controls-panel {
    padding: 12px 16px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }

  .slider-row label {
    width: 48px;
    font-size: 9px;
  }

  .start-title {
    font-size: 22px;
  }

  .start-subtitle {
    font-size: 9px;
  }

  .loading-scene-name {
    font-size: 16px;
  }
}
