/* Player bar */

.player {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 900;
  background: var(--paper);
  border-top: 1px solid var(--rule-strong);
  color: var(--ink);
  font-family: var(--ui);
  /* Keep the seek track above the iPhone home gesture area. The toolbar can report zero inset. */
  padding-bottom: var(--player-pad);
}
.player-controls, .player-seek {
  max-width: var(--shell); margin-inline: auto; padding-inline: var(--edge);
}

.player-controls {
  display: flex; align-items: center; gap: .7rem;
  padding-block: .4rem;
  min-height: 64px;
}

.player-transport { display: flex; align-items: center; gap: .45rem; }

#sleep-btn, #room-btn { display: grid; place-items: center; }
#sleep-btn svg, #room-btn svg { width: 19px; height: 19px; display: block; }

.player-meta {
  flex: 1 1 auto; min-width: 0;
  display: flex; flex-direction: column; justify-content: center;
  font-family: var(--ui);
}
.player-meta .meta-title {
  font-size: .95rem; font-weight: 500; letter-spacing: .02em; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* Use the ink token to preserve contrast across chapter backgrounds. */
.player-meta .meta-time {
  font-size: .82rem; color: var(--ink-soft); letter-spacing: .02em;
}

.btn-icon.is-active { color: var(--accent); }

.player-secondary { display: flex; align-items: center; gap: .25rem; }
.player-secondary .btn-icon { min-width: 44px; min-height: 44px; font-size: .85rem; }
#speed-btn { font-family: var(--ui); font-size: var(--ap-md); min-width: 44px; }

/* Suspended Follow stays enabled while the reader scrolls independently. */
#follow-btn.is-suspended { color: var(--ink-faint); }
#follow-btn.is-suspended::after {
  content: ''; display: block; height: 1px; margin-top: 2px;
  background: currentColor; opacity: .5;
}

.player-seek { position: relative; padding-bottom: .5rem; }
.seekbar {
  position: relative;
  height: 3px;
  margin: 19px 0;    /* Leave room for the hit area to extend beyond the track. */
  background: color-mix(in srgb, var(--ink) 14%, transparent);
  cursor: pointer;
  touch-action: none;
}
.seekbar::before {
  content: "";
  position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-50%);
  height: 44px;
}
.seekbar-fill {
  position: absolute; top: 0; left: 0; height: 100%;
  background: var(--accent);
  width: 0%;
  pointer-events: none;
}
.seekbar-buffered {
  position: absolute; top: 0; left: 0; height: 100%;
  background: color-mix(in srgb, var(--ink) 22%, transparent);
  width: 0%;
  pointer-events: none;
}
/* The Room shares the seek bar hit area. */
.seekbar-edge {
  position: absolute; left: 0; right: 0;
  bottom: max(0px, env(safe-area-inset-bottom));
  margin: 0; height: 2px; z-index: 2;
  /* Use a stronger track over the photograph for contrast. */
  background: color-mix(in srgb, var(--ink) 20%, transparent);
}
.seekbar-edge:focus-visible { outline: 2px solid var(--accent); outline-offset: -4px; }
/* Chapter shortcuts */
/* Leave room for the current chapter underline above the seek track. */
.chapter-rail {
  position: relative;
  height: 22px;
  margin: 0 0 7px;
}
.seekbar-marks { position: absolute; inset: 0; }

.seek-mark {
  position: absolute; top: 0;
  transform: translateX(-50%);
  padding: 0 .18em 3px;
  background: none; border: 0; cursor: pointer;
  font-family: var(--serif);
  font-variation-settings: var(--lit-normal);
  font-size: .86rem; font-weight: 500; font-style: normal;
  letter-spacing: .05em; line-height: 1;
  color: var(--ink-faint);
  border-bottom: 1px solid transparent;
  transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.seek-mark::before {
  content: "";
  position: absolute; top: 50%; left: 50%;
  width: 44px; height: 44px; min-width: 100%;
  transform: translate(-50%, -50%);
}
.seek-mark-label { font-style: normal; }
.seek-mark:hover, .seek-mark:focus-visible { color: var(--ink); }
.seek-mark.is-complete { color: var(--ink-soft); }
.seek-mark.is-current {
  color: var(--accent); font-weight: 600;
  border-bottom-color: var(--accent);
}
/* Align the end labels inward so they stay inside the bar. */
.seek-mark:first-child { transform: none; }
.seek-mark:last-child { transform: translateX(-100%); }

.seek-handle {
  position: absolute; top: 50%; width: 11px; height: 11px; margin-left: -5.5px;
  background: var(--ink); border-radius: 50%;
  transform: translateY(-50%);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--paper) 85%, transparent);
}

.player[data-state="unavailable"] .player-transport,
.player[data-state="unavailable"] .seekbar {
  opacity: .45; pointer-events: none;
}

/* Idle player */
.player {
  transform: translateY(0);
  transition: transform var(--dur-med) var(--ease);
  will-change: transform;
}
.player[data-state="idle"] {
  transform: translateY(100%);
  pointer-events: none;
}
/* Keep --player-h aligned with the rendered bar height at both breakpoints.
   Read-along scrolling and controls above the bar use it for clearance. */
:root {
  --player-pad: env(safe-area-inset-bottom, 0px);
  --player-h: calc(136px + var(--player-pad));
}
@media (max-width: 640px) {
  :root {
    --player-pad: max(env(safe-area-inset-bottom, 0px), 16px);
    --player-h: calc(92px + var(--player-pad));
  }
}
body:has(.player[data-state="idle"]) { --player-h: 0px; }
@media (prefers-reduced-motion: reduce) { .player { transition: none; } }

/* On mobile, the Listening Room provides the controls hidden here. */
@media (max-width: 640px) {
  .player-controls {
    flex-wrap: nowrap;
    gap: .35rem;
    padding: .25rem .6rem;
    min-height: 56px;
  }
  .player-transport { gap: 0; }
  .player-meta { flex: 1 1 auto; min-width: 0; }
  .player-meta .meta-time { display: none; }
  #speed-btn, #follow-btn, #sleep-btn { display: none; }
  .player-seek { padding-bottom: .25rem; }
  .seekbar { margin: 14px 0; }
  .chapter-rail { display: none; }
}


/* Sleep sheet */
.sleep-options { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6em; margin: 1em 0 1.4em; }
.sleep-options .btn.is-active { background: color-mix(in srgb, var(--accent) 30%, transparent); }

/* Completion modal */
.completion-actions { display: flex; gap: .8em; flex-wrap: wrap; margin-top: 1.4em; }

/* Offline downloads */
.save-all-row { margin-top: 1.4em; padding-top: 1.2em; border-top: 1px solid var(--rule); }
.save-all-row .btn { width: 100%; justify-content: center; }
.save-all-row .btn + .btn { margin-top: .6em; }
.save-all-row .sheet-note {
  margin: .7em 0 0;
  font-family: var(--ui); font-size: var(--ap-sm);
  color: var(--ink-faint); line-height: 1.5;
}
