/* 
   Modern Design System: 时空对话 (Curation Edition)
   Using CSS Variables for Real-time Theme Syncing
*/

:root {
  /* Default Design Tokens */
  --theme-primary: #00e5ff;
  --theme-secondary: #008ba3;
  --theme-bg-dark: #0a0e14;
  --theme-surface: rgba(10, 14, 20, 0.85);
  --theme-text-main: #ffffff;
  --theme-text-sub: rgba(255, 255, 255, 0.7);
  --glass-border: rgba(255, 255, 255, 0.1);
  --accent-glow: rgba(0, 229, 255, 0.3);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body, html {
  margin: 0; padding: 0; width: 100%; height: 100%;
  font-family: 'Inter', 'Noto Sans TC', -apple-system, sans-serif;
  background-color: var(--theme-bg-dark);
  color: var(--theme-text-main);
}

/* 針對 AR App 頁面的全域限制 */
body.ar-app {
  overflow: hidden;
  user-select: none;
  touch-action: none;
}

body.scene-paused #ar-scene {
  opacity: 0;
  pointer-events: none;
}

body.ar-active #ar-scene {
  opacity: 1;
}

/* Glassmorphism Utility */
.glass-panel {
  background: var(--theme-surface);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
}

/* Start Screen Overlay */
#start-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--theme-bg-dark);
  background-size: cover;
  background-position: center;
  z-index: 2000;
  transition: opacity 0.8s ease-out;
  contain: layout paint style;
  will-change: opacity;
}

#start-overlay h1 {
  font-size: 2.2rem; font-weight: 200; letter-spacing: 6px; margin: 0 0 20px 0;
  text-shadow: 0 0 20px var(--accent-glow);
  text-align: center;
}

#start-hint {
  font-size: 0.9rem; opacity: 0.6; margin-bottom: 30px;
  letter-spacing: 2px;
}

#loading-bar-container {
  width: 80%; max-width: 300px; height: 3px; background: rgba(255,255,255,0.1);
  margin-bottom: 25px; border-radius: 10px; overflow: hidden;
}

#loading-bar {
  height: 100%; width: 0%; background: var(--theme-primary);
  box-shadow: 0 0 10px var(--theme-primary);
  transition: width 0.3s;
}

.btn-start {
  padding: 16px 50px;
  background: linear-gradient(135deg, var(--theme-primary), var(--theme-secondary));
  color: #000 !important; font-weight: 700; font-size: 1rem;
  border: none; border-radius: 50px; cursor: pointer;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
  transition: all 0.3s ease;
  letter-spacing: 2px;
}

.btn-start:hover {
  transform: scale(1.05) translateY(-3px);
  box-shadow: 0 15px 40px var(--accent-glow);
}

/* 2D HUD Layout */
#story-ui-2d {
  position: fixed; bottom: 30px; left: 50%; transform: translate3d(-50%, 0, 0);
  width: 90%; max-width: 500px; padding: 25px;
  z-index: 1000; display: none;
  opacity: 0; transition: opacity 0.5s, transform 0.5s;
  contain: layout paint style;
  will-change: opacity, transform;
}

#story-ui-2d.active { display: block; opacity: 1; transform: translate3d(-50%, 0, 0); }

#story-ui-2d.pending {
  opacity: 0.45;
  transform: translate3d(-50%, 12px, 0);
}

#story-text-2d {
  font-size: 1.1rem; line-height: 1.6; font-weight: 300; margin-bottom: 20px;
  color: var(--theme-text-main);
}

/* Choice Buttons (2D Mode) */
.btn-choice-2d {
  width: 100%; padding: 14px; margin-bottom: 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass-border);
  color: var(--theme-text-main);
  border-radius: 8px; text-align: center; cursor: pointer;
  transition: all 0.2s ease;
  font-size: 1rem;
}

.btn-choice-2d:hover {
  background: var(--theme-primary);
  color: #000; border-color: var(--theme-primary);
}

/* Top Overlay for Selection (3D/AR Mode) */
#story-options-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 1500;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  padding-bottom: 60px;
  gap: 15px; opacity: 0; transition: opacity 0.5s;
  contain: layout paint style;
  will-change: opacity;
}

.btn-choice-top {
  pointer-events: auto;
  background: rgba(10, 14, 20, 0.7);
  backdrop-filter: blur(10px);
  border: 1px solid var(--theme-primary);
  color: var(--theme-primary);
  padding: 15px 30px; border-radius: 30px;
  text-align: center; font-size: 0.95rem; font-weight: bold;
  cursor: pointer; box-shadow: 0 4px 15px rgba(0,0,0,0.5);
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  min-width: 200px;
  will-change: transform, opacity;
}

.btn-choice-top:hover {
  transform: translate3d(0, 0, 0) scale(1.05);
  background: var(--theme-primary);
  color: #000;
}

.btn-choice-top:active { transform: translate3d(0, 0, 0) scale(0.95); }

/* Reset Button Style (Enhanced) */
.btn-reset {
  background: rgba(244, 67, 54, 0.15) !important;
  border-color: #ff4444 !important;
  color: #ff4444 !important;
  box-shadow: 0 0 15px rgba(255, 68, 68, 0.2);
}

.btn-reset:hover {
  background: #ff4444 !important;
  color: #fff !important;
}

/* Global Flash Layer */
#global-flash {
  position: fixed;
  top: 0; left: 0; width: 100vw; height: 100vh;
  background: #fff;
  z-index: 9999;
  pointer-events: none;
  opacity: 0;
}

#global-flash.active {
  animation: flash-anim 1.2s cubic-bezier(0.23, 1, 0.32, 1) forwards;
}

#signal-noise-overlay,
#dust-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
  contain: strict;
  will-change: opacity, transform;
}

#signal-noise-overlay {
  z-index: 4500;
  background:
    repeating-linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.1) 0px,
      rgba(255, 255, 255, 0.1) 1px,
      rgba(0, 0, 0, 0.08) 2px,
      rgba(0, 0, 0, 0.08) 4px
    ),
    linear-gradient(135deg, rgba(194, 74, 58, 0.12), rgba(159, 191, 59, 0.08));
  mix-blend-mode: screen;
}

#dust-overlay {
  z-index: 4400;
  background-image:
    radial-gradient(circle at 18% 22%, rgba(255,255,255,0.14) 0 1px, transparent 2px),
    radial-gradient(circle at 72% 34%, rgba(255,255,255,0.12) 0 1.5px, transparent 2.5px),
    radial-gradient(circle at 40% 78%, rgba(255,255,255,0.10) 0 1px, transparent 2px),
    radial-gradient(circle at 82% 62%, rgba(255,255,255,0.12) 0 1.5px, transparent 2.5px);
  background-size: 260px 260px, 320px 320px, 280px 280px, 360px 360px;
}

/* --- Video Transition System --- */
#video-transition-container {
  position: fixed;
  top: 0; left: 0; width: 100vw; height: 100vh;
  background: #000;
  z-index: 5000;
  display: none;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  contain: layout paint style;
  will-change: opacity, transform;
}

#transition-video {
  width: 100%; height: 100%;
  object-fit: cover;
}

#skip-video {
  position: absolute;
  bottom: 30px;
  right: 30px;
  color: #fff;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(5px);
  padding: 10px 20px;
  border-radius: 30px;
  font-size: 14px;
  letter-spacing: 2px;
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.3);
  z-index: 5100;
  transition: all 0.3s ease;
}

#skip-video:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.05);
}

@keyframes flash-anim {
  0% { opacity: 0; }
  30% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes film-jitter {
  0% { transform: translate(0, 0) scale(1); }
  25% { transform: translate(-0.5px, 0.4px) scale(1.002); }
  50% { transform: translate(0.7px, -0.5px) scale(0.999); }
  75% { transform: translate(-0.4px, 0.6px) scale(1.001); }
  100% { transform: translate(0, 0) scale(1); }
}

@keyframes signal-flicker {
  0% { opacity: 0.15; }
  50% { opacity: 0.55; }
  100% { opacity: 0.22; }
}

@keyframes dust-float {
  0% { transform: translate3d(0, 0, 0); }
  50% { transform: translate3d(-8px, 12px, 0); }
  100% { transform: translate3d(0, 22px, 0); }
}

@keyframes projector-warmup {
  0% { opacity: 0.95; filter: blur(12px); }
  40% { opacity: 0.65; filter: blur(4px); }
  100% { opacity: 0; filter: blur(0); }
}

body.is-film-jitter #video-transition-container,
body.is-film-jitter #newspaper-overlay {
  animation: film-jitter 0.16s steps(2, end) infinite;
}

body.is-dusty #dust-overlay {
  opacity: 0.35;
  animation: dust-float 14s linear infinite;
}

body.is-signal-noise #signal-noise-overlay {
  opacity: 0.5;
  animation: signal-flicker 0.18s steps(2, end) 6;
}

body.is-projection-startup #video-transition-container::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(255,255,255,0.18) 0%, rgba(255,255,255,0.02) 48%, rgba(0,0,0,0.88) 100%);
  animation: projector-warmup 1.2s ease-out forwards;
  pointer-events: none;
  z-index: 5002;
}

body.is-flash-overexposed #global-flash {
  opacity: 0.92;
  animation: flash-anim 0.8s cubic-bezier(0.23, 1, 0.32, 1) forwards;
}

/* --- Newspaper Intro System (StPageFlip) --- */
#newspaper-overlay {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background:
    radial-gradient(circle at center, rgba(255, 250, 235, 0.92) 0%, rgba(232, 220, 192, 0.96) 62%, rgba(208, 192, 160, 1) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3000;
  overflow: hidden;
  transition: opacity 1s ease-in-out;
  contain: layout paint style;
  will-change: opacity;
}

.st-book-container {
  width: 100vw;
  height: 100vh;
  box-shadow: none;
  background: transparent;
}

.st-page {
  background-color: #fdf6e3;
  overflow: hidden;
  box-shadow: inset 0 0 50px rgba(0,0,0,0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  contain: paint;
}

.page-img {
  width: 100%; height: 100%;
  object-fit: cover;
  filter: sepia(0.2) contrast(1.1);
  pointer-events: none;
}

.stf__parent,
.stf__wrapper,
.stf__block,
.stf__item {
  background: transparent !important;
}

/* Page Texture Overlay */
.st-page::after {
  content: '';
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  background: url('https://www.transparenttextures.com/patterns/old-paper.png');
  opacity: 0.3;
  pointer-events: none;
}

.newspaper-hint {
  position: absolute;
  bottom: 30px;
  width: 100%;
  text-align: center;
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.85rem;
  letter-spacing: 3px;
  text-transform: uppercase;
  animation: pulse 2s infinite;
  pointer-events: none;
  z-index: 3500;
  will-change: opacity, transform;
}

@keyframes pulse {
  0%, 100% { opacity: 0.3; transform: scale(1); }
  50% { opacity: 0.9; transform: scale(1.05); }
}

/* Responsive Fixes & Enhancements */
@media (max-width: 600px) {
  :root {
    --start-h1-size: 1.6rem;
    --hud-padding: 20px;
    --hud-font-size: 1rem;
  }
  
  #start-overlay h1 { 
    font-size: var(--start-h1-size); 
    letter-spacing: 3px; 
    padding: 0 20px;
  }
  
  .btn-start { padding: 14px 35px; font-size: 0.95rem; }
  
  #story-ui-2d {
    width: 95%;
    padding: var(--hud-padding);
    bottom: 20px;
  }
  
  #story-text-2d { font-size: var(--hud-font-size); }
  
  .btn-choice-top {
    min-width: 160px;
    padding: 12px 20px;
    font-size: 0.85rem;
  }
  
  .book {
    width: 90vw;
  }
}

@media (min-width: 1024px) {
  #start-overlay h1 { font-size: 3.5rem; }
  .book { max-width: 600px; }
  #story-ui-2d { max-width: 700px; }
}

/* Orientation Fix for Mobile */
@media (max-height: 500px) and (orientation: landscape) {
  #start-overlay h1 { font-size: 1.2rem; margin-bottom: 10px; }
  #target-helper { display: none; }
  .book { height: 80vh; width: auto; aspect-ratio: 3/4; }
  #story-ui-2d { 
    bottom: 10px; padding: 15px;
    display: grid; grid-template-columns: 1fr 1fr; gap: 15px;
  }
  #story-text-2d { font-size: 0.9rem; margin-bottom: 0; }
}
