/* Import a modern, readable font from Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap');

/* Define the color palette for our dark theme */
:root {
  --bg-dark: #111827;      /* Deep charcoal page background */
  --bg-card: #1f2937;      /* Lighter charcoal for cards */
  --border: #374151;       /* Muted gray for borders */
  --text-primary: #f9fafb; /* Off-white for primary text */
  --text-muted: #9ca3af;   /* Lighter gray for muted text */
  --accent: #3b82f6;       /* Vibrant blue for accents */
  --accent-hover: #60a5fa; /* Lighter blue for hover states */
}

* {
  box-sizing: border-box;
}

body {
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  margin: 2rem;
  line-height: 1.6;
  background: var(--bg-dark);
  color: var(--text-primary);
}

/* --- Main Header Styles --- */
.main-header {
  max-width: 800px;
  margin: 1rem auto 3rem auto;
  text-align: center;
  padding: 0 1rem;
}

.main-header h1 {
  font-size: 2.75rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
}

.main-header .subtitle {
  font-size: 1.15rem;
  color: var(--text-muted);
  max-width: 700px;
  margin: 0 auto;
  line-height: 1.7;
}

.main-header .episode-summary {
  margin-top: 1.5rem;
  font-size: 1.1rem;
  line-height: 1.7;
  color: var(--text-primary);
}

.wrap {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
  max-width: 1100px;
  margin: 0 auto;
}

@media (min-width: 1000px) {
  .wrap {
    grid-template-columns: 2fr 1.2fr;
  }
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.5rem 1.75rem;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .75rem;
  position: relative;
}
.card-header h2 {
  margin: 0;
}

.card h2 {
  margin: 0 0 .75rem;
  font-size: 1.5rem;
  font-weight: 700;
}

aside.card h2 {
  margin: 0 0 .5rem;
  font-size: 1.25rem;
  font-weight: 600;
}

audio {
  width: 100%;
  margin-top: 1rem;
  filter: invert(1) hue-rotate(180deg);
}

/* --- Bookmarks Styling --- */
.bookmarks {
  list-style: none;
  padding-left: 0;
  margin: .5rem 0 0;
}

.bookmarks li {
  margin: 0;
}

.bm-header {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 1.5rem 0 .25rem 0;
  padding-bottom: .25rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  position: relative;
  user-select: none;
}

.bm-header::after {
  content: '−';
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-muted);
}

.bm-header.collapsed::after {
  content: '+';
}

.bookmarks.collapsed {
  display: none;
}

.bm-btn {
  width: 100%;
  text-align: left;
  padding: .75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  margin: .4rem 0;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.bm-btn:hover {
  background: rgba(255, 255, 255, .05);
  border-color: var(--accent-hover);
}

.bm-title {
  display: block;
  font-weight: 600;
  font-size: 1rem;
}

.bm-time {
  display: block;
  color: var(--text-muted);
  font-size: .9rem;
}

.bm-sum-short {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: .35rem;
  line-height: 1.4;
  font-size: .9em;
  color: var(--text-muted);
}

.bm-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.bm-btn.active .bm-time,
.bm-btn.active .bm-sum-short {
  color: rgba(255, 255, 255, .85);
}

.bookmarks.level-2 { padding-left: 1rem; }
.bookmarks.level-3 { padding-left: 2rem; }

.bm-level-2, .bm-level-3 {
  border-left-width: 3px;
}

/* --- Chapter Summary Box --- */
.chapter {
  margin-top: 1.5rem;
  padding: 1rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-dark);
}
.chapter.hidden { display:none; }
.chapter-time { font-size:.85rem; color:var(--text-muted); margin-bottom:.25rem; }
.chapter-title { font-weight:700; margin-bottom:.25rem; }
.chapter-text { color: var(--text-primary); }

/* --- Gated Access Modal --- */
.overlay{
  position:fixed;
  inset:0;
  display:none;
  align-items:center;
  justify-content:center;
  background:rgba(17, 24, 39, .8);
  backdrop-filter: blur(8px);
  z-index:9999
}
.overlay.show{display:flex}
.overlay .modal{
  width:min(560px,92vw);
  background: var(--bg-card);
  border:1px solid var(--border);
  border-radius:16px;
  box-shadow:0 10px 30px rgba(0,0,0,.3);
  padding:1.75rem 2rem;
}
.overlay h3{margin:0 0 .5rem;font-size:1.5rem}
.overlay p{margin:.25rem 0 1rem;color: var(--text-muted)}
.overlay .input{
  width:100%;
  padding:.75rem .85rem;
  border:1px solid var(--border);
  border-radius:10px;
  background: var(--bg-dark);
  color: var(--text-primary);
  font-size: 1rem;
}
.overlay .input:focus {
  outline: none;
  border-color: var(--accent);
}

.overlay .actions{display:flex;gap:.75rem;margin-top:1rem}
.overlay .btn{
  padding:.7rem 1.1rem;
  border:1px solid var(--accent);
  border-radius:10px;
  background: var(--accent);
  color: #fff;
  cursor:pointer;
  font-size: 1rem;
  font-weight: 600;
  transition: background-color 0.2s ease;
}
.overlay .btn:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}
.overlay .btn.secondary{
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}
.overlay .btn.secondary:hover {
  background: var(--bg-dark);
  color: var(--text-primary);
}
.overlay .note{font-size:.9rem;color:var(--text-muted);margin-top:1rem; line-height: 1.5;}
.locked .wrap{filter: blur(5px); pointer-events:none;}

/* --- Share Button & Modal Styles --- */
.share-btn {
  padding: .4rem .9rem;
  font-size: .9rem;
  font-weight: 600;
  background: var(--border);
  color: var(--text-primary);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color .2s ease;
}
.share-btn:hover {
  background: var(--accent);
}

.share-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, .8);
  backdrop-filter: blur(8px);
  z-index: 10000;
  display: none;
  align-items: center;
  justify-content: center;
}
.share-modal-overlay.show {
  display: flex;
}
.share-modal {
  background: var(--bg-card);
  padding: 2rem;
  border-radius: 16px;
  border: 1px solid var(--border);
  width: min(450px, 90vw);
  text-align: center;
  position: relative;
}
.share-modal h3 {
  margin: 0 0 1.5rem 0;
  font-size: 1.5rem;
}
.close-btn {
  position: absolute;
  top: .5rem;
  right: 1rem;
  font-size: 2rem;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
}
.share-options {
  display: grid;
  gap: .75rem;
}
.share-link {
  display: block;
  width: 100%;
  padding: .8rem;
  border: 1px solid var(--border);
  background: var(--bg-dark);
  color: var(--text-primary);
  border-radius: 8px;
  text-decoration: none;
  font-size: 1rem;
  font-weight: 600;
  transition: background-color .2s ease, border-color .2s ease;
}
.share-link:hover {
  background: var(--accent);
  border-color: var(--accent);
}
.copy-msg {
  margin-top: 1rem;
  color: var(--accent);
  font-weight: 600;
  height: 1.2em;
}

/* --- NEW: Bookmark Highlight Animation --- */
@keyframes nudge-highlight {
  0% {
    box-shadow: 0 0 0 0px rgba(59, 130, 246, 0.4);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(59, 130, 246, 0);
  }
  100% {
    box-shadow: 0 0 0 0px rgba(59, 130, 246, 0);
  }
}

.nudge {
  animation: nudge-highlight 1.5s ease-out;
}

/* --- Bookmark Share Icon Styles --- */
.bm-title-wrap {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.bm-share-btn {
  font-size: 1.2rem;
  opacity: 0.5;
  transition: opacity 0.2s ease, transform 0.2s ease;
  padding: 0 .5rem;
}
.bm-btn:hover .bm-share-btn {
  opacity: 1;
}
.bm-share-btn:hover {
  transform: scale(1.1);
}
/* --- Episode Artwork Styles --- */
.episode-artwork {
  width: 100%;
  height: auto;
  border-radius: 12px;
  margin-bottom: 1.5rem;
  display: block;
}

/* --- Gate Cleanup --- */
#gateCancel {
  display: none;
}

/* --- Particle Canvas Styles --- */
.canvas-container {
  display: none; /* Hide the container by default */
  position: relative;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-dark);
}

body.immersion-mode .canvas-container {
  display: block; /* Show the container in immersive mode */
  position: fixed;
  inset: 0;
  z-index: 1;
  border: none;
  border-radius: 0;
  background: transparent;
}

#particleCanvas {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 12px;
}

/* --- Canvas Overlay Styles --- */
#canvasOverlay {
  position: absolute;
  inset: 0;
  background: rgba(31, 41, 55, 0.5);
  backdrop-filter: blur(2px);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 1rem;
}
#canvasOverlay h3 {
  margin: 0 0 .5rem;
  font-size: 1.25rem;
}
#canvasOverlay p {
  margin: 0; /* Let child rules handle margin */
  color: var(--text-primary);
}

/* --- Canvas Overlay Form Styles --- */
#createPasswordForm, #loginForm {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  padding: 0 1rem;
}
#createPassUserInfo, #loginUserInfo {
  line-height: 1.5;
  margin-bottom: 1.5rem;
}
#canvasOverlay .input,
#canvasOverlay .btn {
  width: 100%;
  max-width: 280px;
  margin-bottom: .75rem;
  box-sizing: border-box;
}
#canvasOverlay .btn {
  padding: .6rem 1rem;
}

/* --- Logout Link --- */
.logout-link {
  display: inline-block;
  margin-bottom: 1rem;
  padding: .4rem .9rem;
  background: var(--border);
  color: var(--text-muted);
  text-decoration: none;
  border-radius: 8px;
  font-size: .9rem;
  transition: background-color .2s ease, color .2s ease;
}
.logout-link:hover {
  background: var(--accent);
  color: var(--text-primary);
}


/* --- Premium Immersion Mode Styles --- */
body.immersion-mode {
  overflow: hidden; /* Prevent scrolling */
}
body.immersion-mode .main-header {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}
body.immersion-mode .wrap {
  display: block;
  max-width: none;
  grid-template-columns: 1fr;
}

/* --- Floating Widget Styles (Complete Replacement) --- */
body.immersion-mode #playerWidget,
body.immersion-mode #bookmarksWidget {
  /* Base styles for both widgets */
  display: block !important;
  visibility: visible !important;
  position: fixed;
  z-index: 10;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.5rem 1.75rem;
  box-shadow: 0 10px 30px rgba(0,0,0,.3);
  cursor: move;
  user-select: none;
  -webkit-user-select: none;
}

body.immersion-mode #playerWidget {
  /* Player-specific position */
  top: 50px;
  left: 50px;
  width: 450px;
  max-width: 90vw;
}

body.immersion-mode #bookmarksWidget {
  /* Bookmarks-specific position */
  top: 50px;
  right: 50px;
  left: auto;
  width: 350px;
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
}

/* --- Widget Content Visibility --- */
body.immersion-mode #playerWidget.minimized > .episode-artwork,
body.immersion-mode #playerWidget.minimized > #chapterBox,
body.immersion-mode #bookmarksWidget.minimized > #bookmarks {
  display: none;
}

/* --- Draggability Improvements --- */
body.immersion-mode #playerWidget,
body.immersion-mode #bookmarksWidget {
  user-select: none;
  -webkit-user-select: none; /* For Safari */
}

body.immersion-mode .chapter-text,
body.immersion-mode .bm-sum-short {
  user-select: text;
  -webkit-user-select: text;
}

/* --- Exit Immersion Button --- */
#exitImmersionBtn {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  padding: .6rem 1.2rem;
  font-size: 1rem;
  font-weight: 600;
  background: var(--accent);
  color: var(--text-primary);
  border: 1px solid var(--accent-hover);
  border-radius: 10px;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(0,0,0,.3);
  transition: background-color .2s ease;
}

#exitImmersionBtn:hover {
  background: var(--accent-hover);
}

body:not(.immersion-mode) #exitImmersionBtn {
  display: none;
}

/* --- Widget Header Controls --- */
.card-header-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.widget-minimize-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  background: var(--bg-dark);
  border-radius: 8px;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.widget-minimize-btn:hover {
  border-color: var(--accent-hover);
  background: #374151;
}

/* Create the 'minimize' icon */
.widget-minimize-btn::before {
  content: '';
  display: block;
  width: 12px;
  height: 2px;
  background-color: var(--text-muted);
  transition: all 0.2s ease;
}

.widget-minimize-btn:hover::before {
  background-color: var(--text-primary);
}

/* Change to a 'maximize' icon when widget is minimized */
.minimized .widget-minimize-btn::before {
  width: 11px;
  height: 11px;
  background-color: transparent;
  border: 2px solid var(--text-muted);
  border-radius: 2px;
}

.minimized .widget-minimize-btn:hover::before {
  border-color: var(--text-primary);
}