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

html, body {
  width: 100vw; height: 100vh;
  overflow: hidden;
  background: #0e0e18;
  font-family: 'Cormorant Garamond', serif;
  color: #d0d0d0;
}

#app {
  width: 100vw; height: 100vh;
  position: relative;
  overflow: hidden;
}

#bg-canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 0;
  opacity: 0.4;
  pointer-events: none;
}

.hidden { display: none !important; }

/* ── Title Screen ── */
#title-screen {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  background: rgba(14, 14, 24, 0.94);
}

.title-glitch {
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(3rem, 8vw, 7rem);
  font-weight: 900;
  color: #e0e0e0;
  text-shadow:
    0 0 20px rgba(200, 100, 255, 0.5),
    0 0 60px rgba(120, 200, 255, 0.3),
    0 0 100px rgba(255, 60, 60, 0.15);
  position: relative;
  letter-spacing: 0.15em;
  animation: titlePulse 4s ease-in-out infinite;
}

.title-glitch::before,
.title-glitch::after {
  content: attr(data-text);
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  overflow: hidden;
}

.title-glitch::before {
  color: #ff2040;
  animation: glitch1 3s infinite linear;
  clip-path: polygon(0 0, 100% 0, 100% 45%, 0 45%);
}

.title-glitch::after {
  color: #40e0ff;
  animation: glitch2 2.5s infinite linear;
  clip-path: polygon(0 55%, 100% 55%, 100% 100%, 0 100%);
}

@keyframes glitch1 {
  0%, 90%, 100% { transform: translate(0); }
  92% { transform: translate(-3px, 1px); }
  94% { transform: translate(3px, -1px); }
  96% { transform: translate(-1px, 2px); }
}

@keyframes glitch2 {
  0%, 88%, 100% { transform: translate(0); }
  90% { transform: translate(2px, -1px); }
  93% { transform: translate(-2px, 1px); }
  95% { transform: translate(1px, -2px); }
}

@keyframes titlePulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.85; }
}

.title-sub {
  font-family: 'Share Tech Mono', monospace;
  font-size: clamp(0.9rem, 2.5vw, 1.5rem);
  color: #607890;
  margin-top: 1rem;
  letter-spacing: 0.4em;
  text-transform: lowercase;
}

.title-prompt {
  font-family: 'Share Tech Mono', monospace;
  font-size: clamp(0.7rem, 1.5vw, 1rem);
  color: #405060;
  margin-top: 3rem;
  animation: blink 1.5s ease-in-out infinite;
}

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

/* ── Novel View ── */
#novel-view {
  position: relative;
  z-index: 10;
  width: 100%; height: 100%;
  display: flex;
  flex-direction: column;
}

/* ── Chapter Title Overlay ── */
#chapter-title {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #0e0e18;
  font-family: 'Orbitron', sans-serif;
  color: #c0c0c0;
  opacity: 0;
  transition: opacity 0.8s ease;
  pointer-events: none;
}

#chapter-title.visible {
  opacity: 1;
  pointer-events: auto;
}

#chapter-title .ch-num {
  font-size: clamp(0.8rem, 1.5vw, 1.1rem);
  letter-spacing: 0.5em;
  color: #506070;
  margin-bottom: 0.5rem;
}

#chapter-title .ch-name {
  font-size: clamp(2rem, 5vw, 4rem);
  font-weight: 900;
  text-shadow: 0 0 40px rgba(120, 200, 255, 0.3);
}

/* ── Panels Container ── */
#panels-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem 2rem;
  min-height: 0;
}

#page-panels {
  display: grid;
  gap: 4px;
  width: 100%;
  height: 100%;
  max-width: 1400px;
  max-height: calc(100vh - 10rem);
}

.panel {
  position: relative;
  border: 3px solid #1a1a2a;
  border-radius: 2px;
  overflow: hidden;
  background: #141422;
  box-shadow: inset 0 0 0 1px #000, 4px 4px 0 #000;
}

.panel canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
}

.panel-text {
  position: absolute;
  z-index: 5;
  font-family: 'Caveat', cursive;
  font-size: clamp(0.85rem, 1.5vw, 1.15rem);
  font-weight: 500;
  line-height: 1.4;
  opacity: 0;
  transition: opacity 0.6s ease;
  text-transform: uppercase;
  white-space: nowrap;
  max-width: 100%;
}

.panel-text.visible { opacity: 1; }

.panel-text.caption {
  background: rgba(15, 12, 25, 0.92);
  border: 3px solid #4a3a5a;
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
  padding: 0.25rem 0.75rem;
  font-family: 'Patrick Hand', cursive;
  font-size: clamp(0.7rem, 1.2vw, 0.95rem);
  color: #c0b8d0;
  box-shadow: 2px 3px 0 rgba(0, 0, 0, 0.4);
}

.panel-text.thought {
  font-style: italic;
  color: #c0d8f0;
  text-shadow: 0 0 20px rgba(120, 200, 255, 0.3);
  font-size: clamp(0.95rem, 1.6vw, 1.3rem);
  font-weight: 600;
  background: rgba(12, 15, 30, 0.9);
  border: 3px solid rgba(120, 170, 240, 0.5);
  border-radius: 15px 225px 15px 255px / 225px 15px 255px 15px;
  padding: 0.3rem 0.75rem;
  box-shadow: 2px 3px 0 rgba(0, 0, 0, 0.35);
}

.panel-text.voice {
  font-family: 'Caveat', cursive;
  font-weight: 700;
  color: #f0e8f0;
  text-shadow: 0 0 15px rgba(255, 255, 255, 0.4);
  font-size: clamp(0.9rem, 1.6vw, 1.25rem);
  letter-spacing: 0.02em;
  background: rgba(20, 15, 20, 0.92);
  border: 4px solid rgba(220, 200, 240, 0.5);
  border-radius: 225px 15px 255px 15px / 15px 255px 15px 225px;
  padding: 0.3rem 0.75rem;
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.45);
}

.panel-text.whisper {
  font-family: 'Patrick Hand', cursive;
  color: #8890a8;
  font-size: clamp(0.65rem, 1vw, 0.85rem);
  letter-spacing: 0.05em;
  background: rgba(10, 10, 18, 0.88);
  border: 2px solid rgba(90, 80, 120, 0.45);
  border-radius: 15px 255px 225px 15px / 255px 15px 15px 225px;
  padding: 0.25rem 0.6rem;
  box-shadow: 1px 2px 0 rgba(0, 0, 0, 0.3);
}

/* ── Narration Bar ── */
#narration-bar {
  padding: 0.6rem 2rem;
  min-height: 3.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(14, 12, 20, 0.95);
  border-top: 2px solid #2a2040;
}

#narration-text {
  font-family: 'Caveat', cursive;
  font-size: clamp(1rem, 1.8vw, 1.35rem);
  font-weight: 500;
  font-style: italic;
  color: #a0a8c0;
  text-align: center;
  max-width: 900px;
  line-height: 1.5;
  text-transform: uppercase;
}

#narration-text .typed-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: #607080;
  margin-left: 2px;
  animation: blink 0.8s step-end infinite;
  vertical-align: text-bottom;
}

/* ── Nav Bar ── */
#nav-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  padding: 0.5rem 1rem;
  background: rgba(12, 10, 18, 0.95);
  border-top: 2px solid #201838;
}

.nav-btn {
  font-family: 'Share Tech Mono', monospace;
  font-size: clamp(0.65rem, 1vw, 0.85rem);
  color: #607080;
  background: none;
  border: 1px solid #252535;
  padding: 0.3rem 1.2rem;
  cursor: pointer;
  letter-spacing: 0.1em;
  transition: all 0.3s ease;
}

.nav-btn:hover:not(:disabled) {
  color: #a0c0e0;
  border-color: #405060;
  text-shadow: 0 0 10px rgba(120, 200, 255, 0.3);
}

.nav-btn:disabled {
  opacity: 0.25;
  cursor: default;
}

#page-indicator {
  font-family: 'Share Tech Mono', monospace;
  font-size: clamp(0.6rem, 0.9vw, 0.8rem);
  color: #404858;
  letter-spacing: 0.2em;
}

/* ── Panel position helpers (set via JS) ── */
.pos-top-left     { top: 0; left: 0; text-align: left; }
.pos-top-right    { top: 0; right: 0; text-align: right; }
.pos-bottom-left  { bottom: 0; left: 0; text-align: left; }
.pos-bottom-right { bottom: 0; right: 0; text-align: right; }
.pos-center       { top: 50%; left: 50%; transform: translate(-50%, -50%); text-align: center; }
.pos-top-center   { top: 0; left: 50%; transform: translateX(-50%); text-align: center; }
.pos-bottom-center { bottom: 0; left: 50%; transform: translateX(-50%); text-align: center; }

/* ── Ben-Day dot overlay on panels ── */
.panel::after {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: radial-gradient(circle, rgba(0,0,0,0.08) 1px, transparent 1px);
  background-size: 4px 4px;
  pointer-events: none;
  z-index: 3;
}
