/* =============================================================================
   story-panel.css — Visual novel panel presentation

   Brand: dark cinematic base, JJK fighters, Spider-Verse Buffster
   Colors from brand-guidelines:
     bg: #0a0a14, gold: #ffd700, blue: #00d4ff,
     red: #ff3b3b, green: #00ff88, purple: #aa44ff
   Typography: Buffster = italic serif, UI = clean sans-serif
   ============================================================================= */

/* --- Cross-screen leak guard ---
   story-panel narration/advance/mentor/banner are position:fixed (viewport-anchored).
   Per CSS spec, an ancestor's display:none hides position:fixed descendants — but
   on iOS Safari, first-paint compositor edge cases can let these elements bleed
   into a sibling screen (e.g. the fight host-bar area appearing as a stacked
   Buffster box). Force-hide them whenever they're inside a non-active .screen. */
.screen:not(.active) .story-panel-narration,
.screen:not(.active) .story-panel-advance,
.screen:not(.active) .story-panel-mentor,
.screen:not(.active) .story-panel-fight-banner {
  display: none !important;
}

/* --- Container --- */

.story-panel-container {
  position: absolute;
  inset: 0;
  background: #0a0a14;
  user-select: none;
  overflow: hidden;
  z-index: 1;
}

/* --- Image Layers (for parallax) --- */

.story-panel-image-wrapper {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.story-panel-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
  z-index: 2;
  opacity: 1;
}

.story-panel-image.layer-bg {
  z-index: 1;
  filter: brightness(0.6) blur(1px);
}

.story-panel-image.layer-mid {
  z-index: 2;
}

.story-panel-image.layer-fg {
  z-index: 3;
}

/* Placeholder gradient when no image */
.story-panel-image-placeholder {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: radial-gradient(ellipse at center bottom, #1a1025 0%, #0a0a14 70%);
}

/* --- Crossfade Transition --- */

.story-panel-image.entering {
  animation: panelFadeIn 0.8s ease forwards;
}

.story-panel-image.exiting {
  animation: panelFadeOut 0.6s ease forwards;
}

@keyframes panelFadeIn {
  from { opacity: 0; transform: scale(1.02); }
  to   { opacity: 1; transform: scale(1); }
}

@keyframes panelFadeOut {
  from { opacity: 1; }
  to   { opacity: 0; }
}

/* --- Ken Burns Effect --- */

.story-panel-image.ken-burns-in {
  animation: kenBurnsIn 12s ease-out forwards;
}

.story-panel-image.ken-burns-out {
  animation: kenBurnsOut 12s ease-out forwards;
}

.story-panel-image.ken-burns-left {
  animation: kenBurnsLeft 12s ease-out forwards;
}

@keyframes kenBurnsIn {
  from { transform: scale(1); }
  to   { transform: scale(1.05); }
}

@keyframes kenBurnsOut {
  from { transform: scale(1.05); }
  to   { transform: scale(1); }
}

@keyframes kenBurnsLeft {
  from { transform: scale(1.02) translateX(1%); }
  to   { transform: scale(1.02) translateX(-1%); }
}

/* Respect reduced-motion: hold a still frame instead of the slow pan/zoom. */
@media (prefers-reduced-motion: reduce) {
  .story-panel-image.ken-burns-in,
  .story-panel-image.ken-burns-out,
  .story-panel-image.ken-burns-left {
    animation: none;
  }
}

/* --- Parallax (mouse/time driven via JS transform) --- */

.story-panel-image.parallax-enabled {
  transition: transform 0.3s ease-out;
}

/* --- Screen Shake --- */

.story-panel-container.shake {
  animation: screenShake 0.4s ease-out;
}

@keyframes screenShake {
  0%   { transform: translate(0, 0); }
  15%  { transform: translate(-4px, 2px); }
  30%  { transform: translate(3px, -3px); }
  45%  { transform: translate(-2px, 1px); }
  60%  { transform: translate(2px, -1px); }
  75%  { transform: translate(-1px, 1px); }
  100% { transform: translate(0, 0); }
}

/* Heavy shake for boss reveals / KO */
.story-panel-container.shake-heavy {
  animation: screenShakeHeavy 0.6s ease-out;
}

@keyframes screenShakeHeavy {
  0%   { transform: translate(0, 0) rotate(0deg); }
  10%  { transform: translate(-6px, 3px) rotate(-0.5deg); }
  20%  { transform: translate(5px, -4px) rotate(0.5deg); }
  30%  { transform: translate(-4px, 2px) rotate(-0.3deg); }
  40%  { transform: translate(3px, -2px) rotate(0.3deg); }
  50%  { transform: translate(-2px, 1px) rotate(-0.1deg); }
  70%  { transform: translate(1px, -1px); }
  100% { transform: translate(0, 0) rotate(0deg); }
}

/* --- Narration Box --- */

.story-panel-narration {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 200;
  padding: 20px 24px calc(16px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(10, 10, 20, 0.97) 50%, rgba(10, 10, 20, 0) 100%);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.story-panel-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center 15%;
  border: 2px solid rgba(255,215,0,0.4);
  box-shadow: 0 0 10px rgba(255,215,0,0.15), 0 2px 8px rgba(0,0,0,0.4);
  margin-bottom: 6px;
}
.story-panel-avatar.speaker-avatar-buffster { border-color: rgba(255,215,0,0.4); }
.story-panel-avatar.speaker-avatar-gamemaker { border-color: rgba(170,68,255,0.4); }
.story-panel-avatar.speaker-avatar-fighter { border-color: rgba(0,212,255,0.4); }
/* The player speaking as themselves — bright "you" ring, avatar is their live PFP. */
.story-panel-avatar.speaker-avatar-player {
  border-color: rgba(255,255,255,0.6);
  box-shadow: 0 0 12px rgba(255,255,255,0.22), 0 2px 8px rgba(0,0,0,0.4);
}

.story-panel-speaker {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 6px;
  color: #ffd700;
}

.story-panel-speaker.speaker-buffster {
  color: #ffd700;
}

.story-panel-speaker.speaker-narrator {
  color: #888;
}

.story-panel-speaker.speaker-gamemaker {
  color: #aa44ff;
}

.story-panel-speaker.speaker-fighter {
  color: #00d4ff;
}

.story-panel-speaker.speaker-player {
  color: #ffffff;
}

.story-panel-text {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 19px;
  line-height: 1.7;
  color: #e8e8e8;
  max-width: 720px;
}

/* Buffster narration gets italic serif */
.story-panel-text.voice-buffster {
  font-style: italic;
  color: #fff;
}

/* Typewriter cursor */
.story-panel-text .cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: #ffd700;
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: cursorBlink 0.6s step-end infinite;
}

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

/* Advance indicator — sits above the narration box gradient (z-index 200)
   so the pulsing affordance is actually visible. Pill backdrop so it
   stays readable against image backgrounds too. */
.story-panel-advance {
  position: fixed;
  bottom: calc(12px + env(safe-area-inset-bottom));
  right: 16px;
  z-index: 210;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 2px;
  color: #f5e6a8;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(10, 10, 20, 0.65);
  border: 1px solid rgba(255, 215, 100, 0.25);
  pointer-events: none;
  animation: advancePulse 1.8s ease-in-out infinite;
}

@keyframes advancePulse {
  0%, 100% { opacity: 0.55; transform: translateY(0); }
  50%      { opacity: 1;    transform: translateY(-1px); }
}

/* --- Choice UI --- */

.story-panel-choices {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 12;
  padding: 16px 24px 20px;
  background: linear-gradient(to top, rgba(10, 10, 20, 0.97) 70%, rgba(10, 10, 20, 0) 100%);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.story-panel-choice-prompt {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 17px;
  line-height: 1.6;
  color: #e0e0e0;
  margin-bottom: 8px;
}

.story-panel-choice-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 16px;
  background: rgba(255, 215, 0, 0.06);
  border: 1px solid rgba(255, 215, 0, 0.2);
  border-radius: 4px;
  color: #e8e8e8;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.story-panel-choice-btn:hover {
  background: rgba(255, 215, 0, 0.12);
  border-color: #ffd700;
  color: #fff;
  transform: translateX(4px);
}

.story-panel-choice-btn:active {
  transform: translateX(2px);
  background: rgba(255, 215, 0, 0.18);
}

.story-panel-choice-flavor {
  display: block;
  font-size: 12px;
  color: #666;
  margin-top: 4px;
  font-style: italic;
}

/* --- Mentor Choice (special styling) --- */

.story-panel-mentor {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 12;
  padding: 16px 24px 20px;
  background: linear-gradient(to top, rgba(10, 10, 20, 0.97) 70%, rgba(10, 10, 20, 0) 100%);
}

.story-panel-mentor-prompt {
  font-family: Georgia, serif;
  font-size: 17px;
  color: #e0e0e0;
  font-style: italic;
  margin-bottom: 14px;
  line-height: 1.55;
}

.story-panel-mentor-options {
  display: flex;
  gap: 12px;
}

.story-panel-mentor-btn {
  flex: 1;
  padding: 16px 18px;
  border-radius: 4px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
}

.story-panel-mentor-btn.accept {
  background: rgba(0, 212, 255, 0.1);
  border: 1px solid rgba(0, 212, 255, 0.3);
  color: #00d4ff;
}

.story-panel-mentor-btn.accept:hover {
  background: rgba(0, 212, 255, 0.2);
  border-color: #00d4ff;
  box-shadow: 0 0 12px rgba(0, 212, 255, 0.15);
}

.story-panel-mentor-btn.refuse {
  background: rgba(255, 215, 0, 0.08);
  border: 1px solid rgba(255, 215, 0, 0.2);
  color: #ffd700;
}

.story-panel-mentor-btn.refuse:hover {
  background: rgba(255, 215, 0, 0.15);
  border-color: #ffd700;
  box-shadow: 0 0 12px rgba(255, 215, 0, 0.15);
}

/* --- Mentor Card Preview --- */

.mentor-option-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mentor-card-preview {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mentor-card-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.mentor-card-type {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  width: 48px;
  flex-shrink: 0;
}

.mentor-card-name {
  font-size: 14px;
  font-weight: 600;
  color: #f0eded;
  flex: 1;
}

.mentor-card-power {
  font-family: 'JetBrains Mono', monospace;
  font-size: 16px;
  font-weight: 700;
  flex-shrink: 0;
}

.mentor-card-effect {
  font-size: 12px;
  color: #9a9292;
  width: 100%;
  margin-top: -2px;
  padding-left: 56px;
  line-height: 1.4;
}

/* --- Energy Particles (canvas overlay) --- */

.story-panel-particles {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}

/* --- Fight Transition --- */

.story-panel-fight-banner {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(10, 10, 20, 0.9);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.story-panel-fight-banner.visible {
  opacity: 1;
  pointer-events: auto;
}

.story-panel-fight-banner h2 {
  font-family: Impact, 'Arial Black', sans-serif;
  font-size: 36px;
  font-weight: 900;
  text-transform: uppercase;
  color: #ff3b3b;
  letter-spacing: 4px;
  margin: 0;
  text-shadow: 0 0 20px rgba(255, 59, 59, 0.4);
}

.story-panel-fight-banner .opponent-name {
  font-family: Impact, 'Arial Black', sans-serif;
  font-size: 22px;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-top: 8px;
}

.story-panel-fight-banner .opponent-desc {
  font-family: Georgia, serif;
  font-size: 13px;
  color: #888;
  font-style: italic;
  margin-top: 6px;
  max-width: 400px;
  text-align: center;
}

.story-panel-fight-banner .fight-start-btn {
  margin-top: 24px;
  padding: 12px 32px;
  background: #ff3b3b;
  border: none;
  border-radius: 4px;
  color: #fff;
  font-family: Impact, 'Arial Black', sans-serif;
  font-size: 16px;
  text-transform: uppercase;
  letter-spacing: 3px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.story-panel-fight-banner .fight-start-btn:hover {
  background: #ff5555;
  transform: scale(1.05);
  box-shadow: 0 0 20px rgba(255, 59, 59, 0.3);
}

/* --- Boss Banner (more dramatic) --- */

.story-panel-fight-banner.boss h2 {
  font-size: 42px;
  color: #ffd700;
  text-shadow: 0 0 30px rgba(255, 215, 0, 0.5);
  animation: bossTextPulse 2s ease-in-out infinite;
}

@keyframes bossTextPulse {
  0%, 100% { text-shadow: 0 0 20px rgba(255, 215, 0, 0.3); }
  50%      { text-shadow: 0 0 40px rgba(255, 215, 0, 0.6); }
}

/* --- Responsive --- */

@media (max-width: 640px) {
  .story-panel-text {
    font-size: 14px;
    line-height: 1.5;
  }

  .story-panel-narration {
    padding: 14px 16px 12px;
  }

  .story-panel-choice-btn {
    padding: 10px 12px;
    font-size: 13px;
  }

  .story-panel-mentor-options {
    flex-direction: column;
  }

  .story-panel-fight-banner h2 {
    font-size: 24px;
  }
}
