/* ===========================
   Start Session Overlay (Aurora UI) — FINAL (CLEAN)
   - Overlay ALWAYS scrollable (fixes mobile/short height)
   - Card centered when possible, scrolls when needed
   - Summary text NOT scrollable (card scrolls)
   - Duplicates removed (hover/active)
   =========================== */

/* Overlay */
#initializeSession {
  position: fixed;
  inset: 0;
  z-index: 10050;

  /* ✅ ALWAYS allow scroll (mobile fix) */
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;

  /* Center card when there is room */
  display: grid;
  place-items: center;

  padding-top: calc(env(safe-area-inset-top, 0px) + 18px);
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
  padding-left: 12px;
  padding-right: 12px;

  background: #f2f2f7;
}

/* hide helper */
#initializeSession.hidden {
  display: none !important;
}

/* Back to library */
.init-back {
  position: fixed; /* ✅ stable while scrolling */
  left: 18px;
  top: calc(env(safe-area-inset-top, 0px) + 16px);
  z-index: 10000;

  display: inline-flex;
  align-items: center;
  gap: 8px;

  padding: 10px 12px;
  border-radius: 999px;

  border: 1px solid #e6ebf1;
  background: #ffffff;

  color: #111928;
  text-decoration: none;
  font-family:
    system-ui,
    -apple-system,
    Segoe UI,
    Roboto,
    Arial,
    sans-serif;
  font-weight: 850;
  font-size: 13px;

  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.06);
}

.init-back:active {
  transform: scale(0.98);
}

/* Main card */
.init-card {
  width: min(960px, 92vw);
  border-radius: 16px;

  border: 1px solid #e6ebf1;
  background: #ffffff;

  box-shadow:
    0 1px 3px rgba(16, 24, 40, 0.05),
    0 12px 32px rgba(16, 24, 40, 0.08);

  padding: 29px;
  position: relative;

  display: grid;
  grid-template-columns: 240px 1fr;
  column-gap: 32px;
  row-gap: 14px;
  align-items: start;

  box-sizing: border-box;

  max-height: calc(
    100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) -
      36px
  );
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Right-side rows: top buffer / title / start / bottom buffer, so title+start are vertically centered against the cover */
.init-card { grid-template-rows: 1fr auto auto 1fr; }
.init-card > .init-cover { grid-column: 1; grid-row: 1 / 5; align-self: center; }
.init-card > .init-title { grid-column: 2; grid-row: 2; align-self: end; justify-self: start; }
.init-card > .init-start { grid-column: 2; grid-row: 3; align-self: start; justify-self: start; }
.init-card > .init-secondary-actions { grid-column: 2; grid-row: 4; align-self: start; justify-self: start; }
.init-card > .init-summary-wrap { grid-column: 1 / -1; grid-row: 5; }

@media (max-width: 720px) {
  .init-card {
    width: clamp(280px, 92vw, 540px);
    grid-template-columns: 1fr;
    padding: 18px;
    row-gap: 14px;
  }
  .init-card > .init-cover { grid-column: 1; grid-row: 1; justify-self: center; align-self: center; }
  .init-card > .init-title { grid-column: 1; grid-row: 2; justify-self: center; text-align: center; }
  .init-card > .init-start { grid-column: 1; grid-row: 3; justify-self: center; }
  .init-card > .init-secondary-actions { grid-column: 1; grid-row: 4; justify-self: center; }
  .init-card > .init-summary-wrap { grid-column: 1; grid-row: 5; }
}

@media (max-height: 640px) {
  #initializeSession {
    place-items: start center;
  }
  .init-card {
    row-gap: 10px;
    padding: 18px;
  }
}

/* Close button */
.init-close {
  position: absolute;
  right: 14px;
  top: 14px;

  width: 38px;
  height: 38px;
  border-radius: 999px;

  border: 1px solid #e6ebf1;
  background: #ffffff;

  color: #4b5563;
  cursor: pointer;

  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.06);
  transition: background 160ms ease, color 160ms ease;
}

.init-close:active {
  transform: scale(0.98);
}

@media (hover: hover) and (pointer: fine) {
  .init-close:hover {
    background: #f3f4f6;
    color: #111928;
  }
}

/* Cover */
.init-cover {
  width: 240px;
  aspect-ratio: 250 / 333;
  height: auto;
  border-radius: 17.5px;
  overflow: hidden;
  position: relative;

  background: #f9fafb;

  box-shadow: 0 10px 30px rgba(17, 25, 40, 0.12);
}

@media (max-width: 720px) {
  .init-cover { width: 200px; }
}

/* Cover media */
.init-cover-video,
.init-cover-img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  transition: opacity 180ms ease;
}

/* Title block */
.init-title {
  max-width: 100%;
  text-align: left;
  margin-top: 0;

  display: grid;
  gap: 6px;

  line-height: 1.2;
  word-break: normal;
  overflow-wrap: anywhere;
}

.init-title-main { display: none; }

.init-title-book {
  color: #111928;
  font-weight: 700;
  font-size: 40px;
  letter-spacing: -0.52px;
  line-height: 1.2;

  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

@media (max-width: 720px) {
  .init-title-book { font-size: 28px; }
}

/* Start button */
.init-start {
  width: auto;
  height: auto;
  padding: 12px 24px;
  border-radius: 10px;

  border: none;
  background: #5750f1;

  color: #ffffff;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.2px;

  cursor: pointer;
  box-shadow: 0 2px 8px rgba(87, 80, 241, 0.3);

  transition:
    transform 120ms ease,
    box-shadow 160ms ease,
    background 160ms ease;
}

.init-start:active {
  transform: scale(0.98);
}

@media (hover: hover) and (pointer: fine) {
  .init-start:hover {
    transform: translateY(-1px);
    background: #4338ca;
    box-shadow: 0 4px 14px rgba(87, 80, 241, 0.4);
  }
}

/* Hint (if used) */
.init-hint {
  color: #6b7280;
  font-weight: 700;
  font-size: 12px;
  text-align: center;
}

/* Disabled state */
#start_button_wrapper.disabled,
.init-start:disabled {
  opacity: 0.5;
  pointer-events: none;
}

/* Summary wrap — rendered as a separate "Hakkında" card visually */
.init-summary-wrap {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  padding: 20px 24px;
  margin-top: 18px;
  border-radius: 14px;
  border: 1px solid #e6ebf1;

  background: #ffffff;

  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.05);

  text-align: left;
  min-width: 0;
}

.init-summary-wrap.hidden {
  display: none !important;
}

.init-summary-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.init-summary-kicker {
  color: #111928;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0;

  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.init-summary-text {
  color: #4b5563;
  font-weight: 500;
  line-height: 1.52;
  font-size: 13.5px;
  letter-spacing: 0.1px;
  max-height: none;
  overflow: visible;
}

/* Summary audio button */
.init-summary-audio {
  width: 46px;
  height: 46px;
  border-radius: 999px;

  border: none;
  background: #5750f1;

  box-shadow: 0 2px 8px rgba(87, 80, 241, 0.3);

  transition:
    transform 120ms ease,
    background 160ms ease,
    box-shadow 180ms ease;
}

.init-summary-audio:active {
  transform: scale(0.98);
}

@media (hover: hover) and (pointer: fine) {
  .init-summary-audio:hover {
    transform: translateY(-1px);
    background: #4338ca;
    box-shadow: 0 4px 14px rgba(87, 80, 241, 0.4);
  }
}

.init-summary-audio:focus-visible {
  box-shadow:
    0 2px 8px rgba(87, 80, 241, 0.3),
    0 0 0 4px rgba(87, 80, 241, 0.18);
}

.init-summary-audio.hidden {
  display: none !important;
}

.init-summary-audio-icon {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;

  will-change: transform, opacity, filter;
  transform-origin: 50% 50%;
}

/* Playing state */
.init-summary-audio.playing {
  background: #4338ca;
  box-shadow:
    0 2px 8px rgba(87, 80, 241, 0.3),
    0 0 0 6px rgba(87, 80, 241, 0.12);
}

/* Mobile tweaks */
@media (max-width: 520px) {
  .init-summary-wrap {
    max-width: calc(100% - 24px);
    margin-left: 12px;
    margin-right: 12px;
    padding: 13px 12px;
  }

  .init-summary-text {
    font-size: 13px;
  }

  .init-summary-audio {
    width: 44px;
    height: 44px;
  }
}

/* Bulletproof: prevent horizontal overflow */
.init-card > * {
  max-width: 100%;
  box-sizing: border-box;
  min-width: 0;
}

/* Icon swap animation */
@keyframes iconSwapPop {
  0% {
    transform: scale(0.82) rotate(-10deg);
    opacity: 0;
    filter: blur(2px) drop-shadow(0 10px 22px rgba(0, 0, 0, 0.25));
  }
  45% {
    transform: scale(1.08) rotate(6deg);
    opacity: 1;
    filter: blur(0px) drop-shadow(0 12px 26px rgba(0, 0, 0, 0.28));
  }
  100% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
    filter: blur(0px) drop-shadow(0 10px 22px rgba(0, 0, 0, 0.25));
  }
}

.init-summary-audio.anim-swap .init-summary-audio-icon {
  animation: iconSwapPop 220ms cubic-bezier(0.2, 0.9, 0.2, 1) both;
}

/* Subtle playing pulse */
@keyframes playingPulse {
  0% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-0.5px);
  }
  100% {
    transform: translateY(0);
  }
}
.init-summary-audio.playing {
  animation: playingPulse 1.4s ease-in-out infinite;
}

/* Secondary actions under Start Reading */
.init-secondary-actions {
  width: min(320px, 86vw);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.init-secondary-btn {
  width: 100%;
  min-width: 0;
  min-height: 64px;
  padding: 12px 14px;
  border-radius: 18px;
  border: 1px solid #e6ebf1;
  background: #f9fafb;
  color: #111928;

  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;

  text-align: left;
  cursor: pointer;
  user-select: none;

  transition:
    transform 120ms ease,
    box-shadow 160ms ease,
    border-color 160ms ease,
    background 160ms ease;
}

.init-secondary-btn:active {
  transform: scale(0.98);
}

@media (hover: hover) and (pointer: fine) {
  .init-secondary-btn:hover {
    border-color: #c7d2fe;
    background: #ffffff;
  }
}

.init-secondary-btn-bonus {
  background: rgba(255, 193, 92, 0.08);
}

.init-secondary-btn-share {
  background: rgba(87, 80, 241, 0.06);
}

.init-secondary-media {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.init-secondary-ico {
  line-height: 1;
  font-size: 17px;
  flex: 0 0 auto;
}

.init-secondary-img {
  width: 22px;
  height: 22px;
  display: block;
  object-fit: contain;
}

.init-secondary-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  flex: 1 1 auto;
}

.init-secondary-title {
  min-width: 0;
  font-weight: 900;
  font-size: 14.5px;
  line-height: 1.1;
  color: #111928;
}

.init-secondary-sub {
  min-width: 0;
  font-size: 12px;
  line-height: 1.3;
  color: #4b5563;
}

@media (max-width: 520px) {
  .init-secondary-actions {
    width: calc(100% - 24px);
    margin-left: 12px;
    margin-right: 12px;
    gap: 8px;
  }

  .init-secondary-btn {
    min-height: 60px;
    padding: 11px 12px;
    gap: 10px;
  }

  .init-secondary-media {
    width: 26px;
    height: 26px;
    flex-basis: 26px;
  }

  .init-secondary-ico {
    font-size: 16px;
  }

  .init-secondary-img {
    width: 20px;
    height: 20px;
  }

  .init-secondary-title {
    font-size: 14px;
  }

  .init-secondary-sub {
    font-size: 11.5px;
    line-height: 1.28;
  }
}

#initializeSession.init-pending .init-cover {
  opacity: 0;
}

#initializeSession .init-cover {
  transition: opacity 120ms ease;
}
