/* --- Story Viewer Common Styles --- */
/* --- Imports & Root Variables --- */
@import url("https://fonts.googleapis.com/icon?family=Material+Icons");

:root {
  /* Light Mode (Default) */
  --bg-color: #f4f7fa;
  --text-color: #333333;
  --header-bg: rgba(255, 255, 255, 0.85);
  --card-bg: #ffffff;
  --dialogue-bg: rgba(255, 255, 255, 0.9);
  --border-color: #d1d9e6;
  --input-bg: #ffffff;
  --accent-color: #007bff;
  --subtitle-color: #555555;
  --shadow-color: rgba(44, 62, 80, 0.15);
}

body.dark-mode {
  /* Dark Mode */
  --bg-color: #121212;
  --text-color: #e0e0e0;
  --header-bg: rgba(28, 28, 28, 0.9);
  --card-bg: rgba(30, 30, 30, 0.85);
  --dialogue-bg: rgba(28, 28, 28, 0.9);
  --border-color: #444444;
  --input-bg: #2a2a2a;
  --accent-color: #4dabf7;
  --subtitle-color: #aaaaaa;
  --shadow-color: rgba(0, 0, 0, 0.4);
}

/* --- General Body & Utility Styles --- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Noto Sans KR", "Roboto", sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  line-height: 1.6;
  transition: background-color 0.3s, color 0.3s;
}

.hidden {
  display: none !important;
}

.error-container {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  background-color: #e74c3c;
  color: white;
  padding: 1rem 2rem;
  border-radius: 0.5rem;
  z-index: 2000;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

/* --- Soft Popup Notification --- */
.soft-popup {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background-color: rgba(28, 28, 28, 0.9);
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 50px;
  z-index: 2000;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  font-size: 0.9rem;
  opacity: 0;
  transition: opacity 0.4s ease-out, transform 0.4s ease-out;
  pointer-events: none;
}

.soft-popup.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* --- Selection View Header --- */
.viewer-header {
  background-color: var(--header-bg);
  backdrop-filter: blur(10px);
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 999;
  border-bottom: 1px solid var(--border-color);
  box-shadow: 0 2px 4px var(--shadow-color);
}

.header-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 1rem;
}

.search-container {
  flex-grow: 1;
  margin: 0 2rem;
  max-width: 400px;
}

#search-bar {
  width: 100%;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border-color);
  background-color: var(--input-bg);
  color: var(--text-color);
  font-size: 1rem;
}

/* --- Selection View Grid & Cards --- */
.story-grid-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
  padding: 2rem;
  max-width: 1600px;
  margin: 0 auto;
}

.grid-card {
  background-color: var(--card-bg);
  border-radius: 0.75rem;
  overflow: hidden;
  box-shadow: 0 4px 15px var(--shadow-color);
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  position: relative;
}

.grid-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 25px var(--shadow-color);
}

.grid-card.highlighted-card {
  border: 2px solid var(--accent-color);
  box-shadow: 0 6px 25px color-mix(in srgb, var(--accent-color) 50%, transparent);
  transform: translateY(-5px) scale(1.02);
}

.grid-card.highlighted-card::after {
  content: '다음 회차보기';
  position: absolute;
  top: 1rem;
  right: -2.2rem;
  background-color: var(--accent-color);
  color: #ffffff;
  padding: 0.2rem 2.5rem;
  font-size: 0.8rem;
  font-weight: 700;
  text-align: center;
  transform: rotate(45deg);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
  white-space: nowrap;
}

.card-thumbnail {
  width: 100%;
  height: 160px;
  background-color: #ccc;
  background-size: cover;
  background-position: center;
}

.card-content {
  padding: 1rem;
  flex-grow: 1;
}

.card-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  word-break: keep-all;
}

.card-subtitle {
  font-size: 0.9rem;
  color: var(--subtitle-color);
}

/* --- Story Viewer Layout --- */
#story-viewer-view {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: calc(100dvh - var(--navbar-height, 56px));
  -webkit-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.viewer-container {
  display: flex;
  flex-direction: column;
  position: relative;
  flex-grow: 1;
  width: 100%;
  padding-bottom: 1.5rem;
}

.story-background {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center;
  z-index: -1;
  transition: background-image 0.5s ease-in-out;
}

.story-header {
  width: 100%;
  padding: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: var(--header-bg);
  box-shadow: 0 2px 4px var(--shadow-color);
  z-index: 10;
  color: var(--text-color);
  margin-bottom: auto;
}

#story-title {
  margin-left: 1rem;
  font-size: 1.5rem;
  flex-grow: 1;
  text-align: center;
}

body.dark-mode .story-header {
  color: #ffffff;
}

/* --- Story Viewer UI Elements --- */
.info-screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: flex-end;
  align-items: flex-end;
  padding: 3rem 4rem 6rem;
  z-index: 5;
  pointer-events: none;
}

#info-screen-text {
  color: white;
  font-size: 1.4rem;
  font-weight: 500;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
  text-align: right;
}

.dialogue-box {
  background-color: var(--dialogue-bg);
  backdrop-filter: blur(5px);
  width: 90%;
  max-width: 800px;
  margin: 0 auto 1rem auto;
  border-radius: 0.75rem;
  padding: 1.5rem;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  z-index: 10;
}

.actor-portrait {
  width: 100px;
  height: 100px;
  margin-right: 1.5rem;
  flex-shrink: 0;
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid var(--border-color);
  background-color: var(--bg-color);
}

.actor-portrait.actor-shadow {
  box-shadow: 0 0 10px 5px rgba(0, 0, 0, 0.5);
}

.actor-portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.dialogue-content {
  flex-grow: 1;
}

.actor-name {
  font-size: 1.25rem;
  font-weight: bold;
  margin-bottom: 0.5rem;
}

.dialogue-text {
  font-size: 1.1rem;
}

.next-page-indicator {
  position: absolute;
  bottom: 1rem;
  right: 1.5rem;
  font-size: 1.5rem;
  animation: bounce 1s infinite;
}

.options-box {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 90%;
  max-width: 600px;
  margin: 0 auto 2rem auto;
}

.option-button {
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  color: var(--text-color);
  padding: 0.75rem 1.5rem;
  border-radius: 0.3rem;
  cursor: pointer;
  font-size: 1rem;
  width: 100%;
  text-align: center;
  transition: background-color 0.2s;
}

.option-button:hover {
  background-color: var(--border-color);
}

/* --- Bottom Bar & Controls --- */
.bottom-bar-container {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  width: 100%;
  padding: 0 1.5rem;
  /* margin-top: auto; */
  margin-bottom: 1rem;
}

.story-nav-arrows {
  display: flex;
  justify-content: center;
  gap: 2rem;
  grid-column: 2 / 3;
}

.nav-button, .story-nav-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--text-color);
  padding: 0.5rem 1rem;
  border-radius: 0.3rem;
  transition: background-color 0.2s;
  cursor: pointer;
  font-size: 1rem;
  text-decoration: none;
  font-family: "Noto Sans KR", "Roboto", sans-serif;
}

.story-nav-btn {
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
}

.nav-button:hover, .story-nav-btn:hover {
  background-color: var(--border-color);
}

.story-nav-btn:disabled {
  background-color: var(--border-color);
  color: var(--subtitle-color);
  cursor: not-allowed;
}

.theme-toggle {
  font-size: 1.5rem;
  line-height: 1;
  border: none;
}

/* Add this new class for the BGM name */
.bgm-name {
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 50px; /* Give it some base width */
  flex-grow: 1;   /* Allow it to take up available space */
  text-align: center;
  margin: 0 0.5rem;
}

/* Add this missing style for the volume control container */
.volume-control {
    display: flex;
    align-items: center;
    gap: 0.5rem; /* Adds a little space between mute button and slider */
}

.audio-player-container {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background-color: var(--dialogue-bg);
  padding: 0.5rem 1rem;
  border-radius: 50px;
  box-shadow: 0 4px 15px var(--shadow-color);
  backdrop-filter: blur(5px);
  z-index: 20;
  grid-column: 1 / 2;
  justify-self: start;
  min-width: 180px; /* Prevents the container from being squished */
  flex-wrap: nowrap;  /* Keeps all controls on a single line */
}

.audio-btn {
  background: none;
  border: none;
  color: var(--text-color);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem;
}

.audio-btn .material-icons {
  font-size: 2rem;
}

#volume-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100px;
  height: 5px;
  background: var(--border-color);
  outline: none;
  border-radius: 5px;
}

/* --- ADD/REPLACE with these cross-browser slider styles --- */
#volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 15px;
  height: 15px;
  background: var(--accent-color);
  cursor: pointer;
  border-radius: 50%;
}

#volume-slider::-moz-range-thumb {
  width: 15px;
  height: 15px;
  background: var(--accent-color);
  cursor: pointer;
  border-radius: 50%;
  border: none;
}

/* --- Modals (Full Script & Summary) --- */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.7);
  z-index: 2000;
  display: flex;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(5px);
}

.modal-content {
  background-color: var(--card-bg);
  padding: 2rem;
  border-radius: 0.75rem;
  max-width: 800px;
  width: 90%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

#summary-modal-content h2 {
  font-size: 1.8rem;
  color: var(--accent-color);
  margin-bottom: 1rem;
  border-bottom: 2px solid var(--border-color);
  padding-bottom: 0.5rem;
}

#summary-modal-content h3 {
  font-size: 1.4rem;
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
  color: var(--text-color);
}

#summary-modal-content p {
  line-height: 1.7;
  margin-bottom: 1rem;
}

#summary-modal-content ul {
  list-style-type: none;
  padding-left: 0;
}

#summary-modal-content li {
  background-color: var(--bg-color);
  border-left: 4px solid var(--accent-color);
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
  border-radius: 4px;
}

.close-modal-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--subtitle-color);
}

.full-script-content, #summary-modal-content {
  overflow-y: auto;
  padding-right: 1rem;
}

.full-script-content p {
  margin-bottom: 1rem;
}

.full-script-content strong, #summary-modal-content strong {
  color: var(--accent-color);
  margin-right: 0.5em;
}

#summary-modal-content h2, #summary-modal-content h3 {
  color: var(--accent-color);
  margin-bottom: 1rem;
}

#view-script-btn {
  display: flex;
  align-items: center;
  gap: 0.5em;
}

/* --- Effects & Animations --- */
.fade-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: black;
  z-index: 9998;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease-in-out;
}

.fade-overlay.visible {
  opacity: 1;
}

.shake {
  animation: shake 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

.flash {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: white;
  z-index: 9999;
  animation: flash-anim 0.3s ease-out;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

@keyframes shake {
  10%, 90% { transform: translate3d(-1px, 0, 0); }
  20%, 80% { transform: translate3d(2px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
  40%, 60% { transform: translate3d(4px, 0, 0); }
}

@keyframes flash-anim {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* --- Responsive Media Queries --- */
@media (max-width: 600px) {
  .viewer-header {
    flex-wrap: wrap;
    justify-content: center;
    padding: 0.75rem 1rem;
    gap: 0.75rem;
  }
  
  .header-title {
    width: 100%;
    text-align: center;
    font-size: 1.3rem;
    order: 1;
    margin: 0 0 0.5rem 0;
  }
  
  .viewer-header .nav-button { order: 2; }
  .search-container { order: 3; flex-grow: 1; min-width: 120px; margin: 0; }
  .viewer-header .theme-toggle { order: 4; }

  .story-header { padding: 0.5rem 0.75rem; }
  #story-title { font-size: 1.1rem; margin-left: 0.5rem; }
  
  #view-script-btn {
    font-size: 0; /* Hides the text node */
    padding: 0.5rem;
    gap: 0;
  }
  #view-script-btn .material-icons { font-size: 1.5rem; }
  
  .dialogue-box { width: 95%; padding: 1rem; }
  .actor-portrait { width: 80px; height: 80px; margin-right: 1rem; }
  .dialogue-text { font-size: 1rem; }
  
  .bottom-bar-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding: 0;
    margin-bottom: 1rem;
  }
}