:root {
  /* Custom property for viewport height to fix iOS issues */
  --vh: 1vh;
  
  /* Fluid typography */
  --fluid-min-width: 320;
  --fluid-max-width: 1920;
  
  /* Font sizes */
  --fluid-min-size: 16;
  --fluid-max-size: 22;
  --fluid-min-ratio: 1.2;
  --fluid-max-ratio: 1.333;
  
  /* Calculate fluid sizes */
  --fluid-size: clamp(
    var(--fluid-min-size) * 1px,
    calc(1rem + ((1vw - var(--fluid-min-width) * 1px) * var(--fluid-max-ratio))),
    var(--fluid-max-size) * 1px
  );
  
  /* Larger text for important elements */
  --fluid-large-min-size: 18;
  --fluid-large-max-size: 28;
  --fluid-large-size: clamp(
    var(--fluid-large-min-size) * 1px,
    calc(1.125rem + ((1vw - var(--fluid-min-width) * 1px) * var(--fluid-max-ratio))),
    var(--fluid-large-max-size) * 1px
  );
  
  /* Line heights */
  --line-height-normal: 1.5;
  --line-height-relaxed: 1.7;
  --line-height-tight: 1.3;
}

/* Main container styles */
body {
  font-family: 'Georgia', serif;
  font-size: var(--fluid-size);
  margin: 0;
  padding: 0;
  background-color: #000;
  color: #fff;
  line-height: var(--line-height-relaxed);
  height: 100vh;
  height: calc(var(--vh, 1vh) * 100);
  overflow: hidden;
}

p, div {
  font-size: var(--fluid-size);
  line-height: var(--line-height-relaxed);
}

/* Main app container */
.scene-container {
  position: relative;
  width: 100vw;
  height: 100%;
  overflow: hidden;
}

.scene-header {
  text-align: center;
  padding: 15px 20px;
  background-color: #fff;
  border-bottom: 2px solid #eee;
  position: sticky;
  top: 0;
  z-index: 10;
}

#scene-title {
  color: #222222;
  font-size: clamp(20px, 2vw, 26px);
  font-weight: 600;
  line-height: var(--line-height-tight);
}

/* Loading indicator */
.loading {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10;
  background: rgba(0,0,0,0.8);
  color: #fff;
  padding: 20px 40px;
  border-radius: 8px;
  backdrop-filter: blur(4px);
}

/* Content area */
#scene-content {
  display: flex;
  flex-direction: column;
}

/* Container that holds the scene image */
.scene-image-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

/* The actual image - cover to fill screen while maintaining aspect ratio */
.scene-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity 0.6s ease-in-out;
}

/* Story overlay at bottom */
.story-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.9), rgba(0, 0, 0, 0.7) 70%, transparent);
  color: #fff;
  padding: 2rem;
  z-index: 2;
  transform: translateY(0);
  opacity: 1;
  transition: transform 0.6s ease-in-out, opacity 0.6s ease-in-out;
  will-change: transform, opacity;
}

/* Story container */
.story-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 12px 16px;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  height: 100%;
  overflow-y: auto;
  box-sizing: border-box;
}

/* Story segments */
.story-segment {
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-radius: 6px;
  line-height: var(--line-height-relaxed);
  font-size: var(--fluid-size);
  opacity: 0;
  transform: translateY(20px);
  animation: fadeIn 0.3s ease-out forwards;
  animation-delay: 0.05s;
  will-change: opacity, transform;
}

/* Define the fadeIn animation */
@keyframes fadeIn {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Keep the dialog-segment animation with slideIn effect */
.dialog-segment {
  display: flex;
  flex-direction: column;
  animation: slideIn 0.4s ease-out forwards;
  padding-bottom: 0;
  margin-bottom: 20px;
}

/* We can keep the fade-in class for backward compatibility */
.story-segment.fade-in {
  opacity: 1;
  transform: translateY(0);
}

/* Image caption segment */
.image-caption-segment {
  text-align: center;
  font-style: italic;
  border-radius: 4px;
}

/* Narration segment */
.narration-segment {
  font-style: italic;
  color: #fff;
  background: rgba(0, 0, 0, 0.3);
  padding: 8px 12px;
  border-left: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  line-height: var(--line-height-relaxed);
  width: 100%;
  max-width: 700px;
  margin: 0 auto 12px;
  font-size: var(--fluid-size);
}

/* Decision section */
.decision-section {
  width: 100%;
  box-sizing: border-box;
  position: relative;
  z-index: 3;
  border-radius: 4px 4px 0 0;
  animation: decisionFadeIn 0.8s ease-out;
}

.decision-prompt {
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  margin-bottom: 12px;
  text-align: center;
  font-size: var(--fluid-large-size);
  font-weight: 600;
  animation: promptSlideUp 0.6s ease-out;
  line-height: var(--line-height-tight);
  max-width: 800px;
  margin-left: auto;
  margin-right: auto;
}

/* Enhanced choice styling */
.choices {
  display: flex;
  flex-direction: row;
  gap: 12px;
  max-width: 1200px;
  margin: 0 auto;
  justify-content: center;
  flex-wrap: wrap;
  padding-bottom: 10px;
}

.choice-container {
  position: relative;
  padding: 16px 20px;
  border-radius: 12px;
  background: linear-gradient(135deg, 
    rgba(255, 255, 255, 0.25) 0%,
    rgba(255, 255, 255, 0.15) 50%,
    rgba(255, 255, 255, 0.1) 100%
  );
  border: 2px solid rgba(255, 255, 255, 0.3);
  cursor: pointer;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  animation: choiceSlideIn 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  animation-fill-mode: both;
  animation-delay: calc(var(--choice-index, 0) * 0.15s);
  flex: 1;
  min-width: 160px;
  max-width: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 
    0 4px 12px rgba(0, 0, 0, 0.2),
    0 0 0 1px rgba(255, 255, 255, 0.1) inset;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.choice-container:hover {
  transform: translateY(-4px) scale(1.02);
  background: linear-gradient(135deg, 
    rgba(255, 255, 255, 0.35) 0%,
    rgba(255, 255, 255, 0.25) 50%,
    rgba(255, 255, 255, 0.2) 100%
  );
  border-color: rgba(255, 255, 255, 0.5);
  box-shadow: 
    0 8px 24px rgba(0, 0, 0, 0.3),
    0 0 0 1px rgba(255, 255, 255, 0.2) inset;
}

.choice-container:active {
  transform: translateY(2px) scale(0.98);
  box-shadow: 
    0 2px 8px rgba(0, 0, 0, 0.2),
    0 0 0 1px rgba(255, 255, 255, 0.1) inset;
}

.choice-container:focus {
  outline: none;
  border-color: rgba(255, 255, 255, 0.7);
  box-shadow: 
    0 0 0 3px rgba(255, 255, 255, 0.2),
    0 4px 12px rgba(0, 0, 0, 0.2);
}

.choice-text {
  color: #fff;
  font-size: calc(var(--fluid-size) * 1.1);
  line-height: var(--line-height-normal);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  text-align: center;
  margin: 0;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* Mobile optimizations */
@media (hover: none) {
  .choice-container {
    padding: 20px 24px;
  }
  
  .choice-container:active {
    background: linear-gradient(135deg, 
      rgba(255, 255, 255, 0.4) 0%,
      rgba(255, 255, 255, 0.3) 50%,
      rgba(255, 255, 255, 0.25) 100%
    );
    transform: scale(0.98);
  }
  
  .choice-text {
    font-size: calc(var(--fluid-size) * 1.2);
  }
}

/* Desktop-specific enhancements */
@media (hover: hover) and (pointer: fine) {
  .choice-container:hover {
    box-shadow: 
      0 8px 24px rgba(0, 0, 0, 0.3),
      0 0 0 1px rgba(255, 255, 255, 0.2) inset,
      0 0 20px rgba(255, 255, 255, 0.1);
  }
}

/* High contrast mode support */
@media (forced-colors: active) {
  .choice-container {
    border: 2px solid ButtonText;
    background: Canvas;
    box-shadow: none;
  }
  
  .choice-container:hover {
    background: Highlight;
    color: HighlightText;
  }
}

/* Dialog styling */
.dialog-content {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.dialog-portrait-container {
  flex-shrink: 0;
  width: 60px;
  text-align: center;
}

.character-portrait {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255,255,255,0.3);
}

.character-name {
  margin-top: 4px;
  font-weight: 600;
  font-size: calc(var(--fluid-size) * 0.9);
}

.dialog-text {
  position: relative;
  background: rgba(0, 0, 0, 0.4);
  padding: 8px 12px;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  color: #fff;
  font-size: var(--fluid-size);
  line-height: var(--line-height-relaxed);
  flex: 1;
  min-width: 0;
  margin-top: 4px;
  border-left: 2px solid rgba(255, 255, 255, 0.3);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  font-weight: 500;
  letter-spacing: 0.01em;
}

/* Animations */
@keyframes choiceSlideIn {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes promptSlideUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Media queries for different orientations */
@media (orientation: portrait) {
  .scene-image-container {
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
  }

  .scene-image {
    height: 100%;
    width: auto;
    min-width: 100%;
    object-fit: cover;
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    margin: 0;
    padding: 0;
  }
}

/* Enhanced Dialog Styling */
.dialog-segment:hover .character-portrait {
  transform: scale(1.05);
}

/* Progress bars container - positioned at top of scene */
.progress-bars-container {
  max-width: 800px; /* Match max width of scene image */
  display: flex;
  gap: 4px;
  padding: 8px 20px;
  margin: 0 auto;
  position: relative;
  z-index: 15;
  backdrop-filter: blur(4px);
}

.progress-bar {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  transition: background-color 0.3s ease;
}

.progress-bar.completed {
  background-color: #5c4a31; /* Match the earthy brown theme */
}

.progress-bar.current {
  background-color: rgba(92, 74, 49, 0.8); /* Semi-transparent earthy brown */
}

.progress-bar.future {
  background-color: rgba(92, 74, 49, 0.3); /* More transparent earthy brown */
}

/* Next segment indicator - keep separate from progress bars */
.segment-progress-indicator {
  position: absolute;
  right: 30px;
  top: 0;
  bottom: 0;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  z-index: 10;
  pointer-events: auto;
  height: 100%;
  padding-right: 20px;
}

.next-segment-button {
  width: 54px; /* Increased from 50px */
  height: 54px; /* Increased from 50px */
  background-image: url('../assets/images/next-arrow.svg');
  background-size: 60%;
  background-repeat: no-repeat;
  background-position: center;
  cursor: pointer;
  opacity: 0.5;
  transition: all 0.3s ease;
  background-color: #f5f0e1;
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.next-segment-button:hover {
  opacity: 1;
  transform: scale(1.15);
  background-color: #eae0c8;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.next-segment-button:active {
  transform: scale(0.95);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

/* Transition states */
.story-overlay.transitioning-out {
  transform: translateY(100%);
  opacity: 0;
}

.story-overlay.transitioning-in {
  transform: translateY(100%);
  opacity: 0;
}

.story-overlay.transition-active {
  transform: translateY(0);
  opacity: 1;
}

/* Author website button */
.author-website-button {
  position: fixed;
  top: 15px;
  left: 15px;
  width: 65px;
  height: 65px;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  z-index: 2000;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.author-website-button img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.author-website-button:hover {
  transform: scale(1.05);
  background-color: rgba(255, 255, 255, 0.25);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.author-website-button:active {
  transform: scale(0.95);
}

/* Add touch feedback for mobile devices */
@media (hover: none) {
  .next-segment-button:active {
    opacity: 1;
    transform: scale(0.92);
    background-color: #eae0c8;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  }
}

/* Extra small screens */
@media screen and (max-width: 480px) {
  .story-container {
    max-width: 100%;
    padding: 15px 0px;
  }

  .choices {
    gap: 8px;
  }
  
  .choice-text {
    font-size: calc(var(--fluid-size) * 0.9);
    line-height: var(--line-height-normal);
  }

  .story-overlay {
    padding-left: 10px;
    padding-right: 10px;
    padding-bottom: 5dvh;
  }

  .author-website-button {
    width: 36px;
    height: 36px;
    top: 10px;
    left: 10px;
  }

  .dialog-content {
    gap: 8px;
  }

  .dialog-segment {
    margin-bottom: 25px;
  }

  .image-caption-segment {
    margin-bottom: 25px;
  }

  .action-segment {
    margin-bottom: 25px;
  }
  
  .dialog-portrait-container {
    width: 60px;
  }
  
  .character-portrait {
    width: 60px;
    height: 60px;
  }

  .decision-prompt {
    margin-bottom: 2px;
  }
  
  .decision-section {
    margin-bottom: 30px;
  }

  .choice-container {
    padding: 10px;
  }
}

@media (min-width: 768px) {
  .story-overlay {
    min-height: 12vh;
  }
}

/* Touch device optimization to prevent overflow without scrolling */
@media (hover: none) and (pointer: coarse) {
  .story-overlay {
    max-height: 55%;
    height: auto;
  }
  
  .decision-section {
    padding-bottom: 10px;
    margin-bottom: 10px;
  }
  
  .segment-progress-indicator {
    bottom: 25px;
    padding-bottom: 15px;
  }
  
  /* Improve spacing for other segment types */
  .story-segment {
    margin-bottom: 20px;
    padding-bottom: 12px;
  }
  
  .narration-segment {
    margin-bottom: 20px;
    padding: 12px 16px;
  }
  
  .dialog-segment {
    margin-bottom: 25px;
  }
  
  .image-caption-segment {
    margin-bottom: 20px;
    padding: 8px 12px;
  }
  
  .dialog-text {
    padding: 12px 16px;
  }
}