/* ==========================================================================
   Crease — listen player (js/player.js). Dark panel by default (sits in a .night
   section); .is-compact switches to a light single-row sample player.
   ========================================================================== */

.player { width: 100%; min-width: 0; }

.pl {
  --pl-bg: var(--night-2);
  --pl-line: var(--night-line);
  --pl-ink: var(--night-ink);
  --pl-muted: var(--night-muted);
  --pl-dim: rgb(241 238 230 / 0.54);
  --pl-hover: rgb(241 238 230 / 0.84);
  --pl-hi: rgb(111 132 98 / 0.35);
  --pl-track: rgb(241 238 230 / 0.16);
  --pl-soft: rgb(241 238 230 / 0.08);
  --pl-btn-bg: var(--night-ink);
  --pl-btn-fg: var(--night);
  --pl-chip-sub: rgb(26 27 24 / 0.62);
  --pl-focus: var(--night-ink);

  position: relative;
  display: grid;
  grid-template-columns: clamp(292px, 33vw, 368px) minmax(0, 1fr);
  min-height: 560px;
  background: var(--pl-bg);
  color: var(--pl-ink);
  border: 1px solid var(--pl-line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  text-align: left;
  font-size: 16px;
  line-height: 1.4;
}
.pl :focus-visible { outline-color: var(--pl-focus); }
:where(.pl) button {
  appearance: none; background: none; border: 0; padding: 0; margin: 0;
  color: inherit; font: inherit; text-align: inherit; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.pl-boot { min-height: 560px; }
.pl-fail {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  min-height: 240px; grid-template-columns: none; text-align: center;
}
.pl-retry {
  min-height: 44px; padding: 0 20px; border-radius: var(--pill);
  border: 1px solid var(--pl-line); font-weight: 600; font-size: 15px;
}
.pl-retry:hover { border-color: var(--pl-ink); }

/* ---------- Left: cover, title, thumbnails ---------- */
.pl-aside {
  display: flex; flex-direction: column; align-items: center; gap: 20px;
  padding: 30px 20px 24px;
  border-right: 1px solid var(--pl-line);
  text-align: center;
}
.pl-cover {
  width: 200px; flex: none;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgb(0 0 0 / 0.32), 0 28px 48px -14px rgb(0 0 0 / 0.7);
}
.pl-meta { display: grid; gap: 4px; width: 100%; }
.pl-title {
  font-size: 20px; line-height: 1.25; font-weight: 650; letter-spacing: -0.01em;
  text-wrap: balance; min-height: 2.5em; display: grid; align-items: end; justify-items: center;
}
.pl-by { font-size: 15px; color: var(--pl-muted); }

.pl-thumbs {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px;
  width: 100%; margin-top: auto; padding: 6px 0 3px;
}
.pl-thumb {
  display: block; position: relative; border-radius: 5px; opacity: 0.6;
  transition: transform 0.25s var(--ease), opacity 0.2s;
}
.pl-thumb img {
  width: 100%; aspect-ratio: 2 / 3; object-fit: cover; border-radius: 4px; background: var(--night);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.45);
  transition: box-shadow 0.25s var(--ease);
}
.pl-thumb:hover { opacity: 1; }
.pl-thumb[aria-pressed="true"] { opacity: 1; transform: translateY(-3px); }
.pl-thumb[aria-pressed="true"] img {
  box-shadow: 0 0 0 2px var(--pl-bg), 0 0 0 3.5px var(--pl-ink), 0 10px 18px -4px rgb(0 0 0 / 0.65);
}

/* ---------- Right: passage, controls, voices ---------- */
.pl-main {
  display: flex; flex-direction: column; gap: 20px; min-width: 0;
  padding: 32px 40px 28px;
}

.pl-passage {
  flex: 1 1 0; min-height: 0; position: relative;
  overflow-y: auto; overscroll-behavior: contain;
  padding: 22px 8px 22px 6px; margin: -22px -8px -22px -6px;
  font-family: var(--font-book); font-style: normal; font-weight: 400;
  font-size: clamp(21px, 1.85vw, 25px); line-height: 1.68; letter-spacing: 0;
  color: var(--pl-dim);
  text-wrap: pretty;
  scrollbar-width: thin; scrollbar-color: var(--pl-line) transparent;
  --fade-t: 0px; --fade-b: 0px;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 var(--fade-t), #000 calc(100% - var(--fade-b)), transparent 100%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 var(--fade-t), #000 calc(100% - var(--fade-b)), transparent 100%);
}
.pl-passage.can-up { --fade-t: 30px; }
.pl-passage.can-down { --fade-b: 30px; }

.pl-s {
  cursor: pointer; border-radius: 0.3em;
  -webkit-box-decoration-break: clone; box-decoration-break: clone;
  transition: color 0.3s, background-color 0.3s, box-shadow 0.3s;
}
.pl-s:hover { color: var(--pl-hover); }
.pl-s:focus-visible { outline: 2px solid var(--pl-focus); outline-offset: 3px; border-radius: 0.3em; }
.pl-s.is-current {
  color: var(--pl-ink);
  background: var(--pl-hi);
  box-shadow: 0 0 0 0.14em var(--pl-hi);
}
/* Current word: a soft olive pill behind full-brightness text. The pill is a box-shadow spread
   (not padding), so lines never reflow as the word moves. */
.pl-w {
  border-radius: 4px;
  transition: color 0.12s, background-color 0.12s, box-shadow 0.12s;
}
.pl-w.is-word {
  color: #fff;
  background: rgb(150 172 135 / 0.58);
  box-shadow: 0 0 0 3px rgb(150 172 135 / 0.58);
}

/* Controls */
.pl-controls {
  display: flex; align-items: center; gap: 20px;
  padding-top: 20px; border-top: 1px solid var(--pl-line);
}
.pl-buttons { display: flex; align-items: center; gap: 10px; flex: none; }

.pl-play {
  position: relative; flex: none;
  width: 60px; height: 60px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--pl-btn-bg); color: var(--pl-btn-fg);
  transition: transform 0.2s var(--ease), opacity 0.2s;
}
.pl-play:hover { transform: scale(1.05); }
.pl-play:active { transform: scale(0.97); }
.pl-ico { grid-area: 1 / 1; display: grid; place-items: center; transition: opacity 0.15s; }
.pl-ico-pause { opacity: 0; }
.is-playing .pl-ico-play { opacity: 0; }
.is-playing .pl-ico-pause { opacity: 1; }
.pl-ring {
  position: absolute; inset: -6px; border-radius: 50%; pointer-events: none;
  border: 2px solid transparent; border-top-color: var(--pl-ink);
  opacity: 0; transition: opacity 0.2s;
}
.is-loading .pl-ring { opacity: 0.85; animation: pl-spin 0.9s linear infinite; }
.is-loading .pl-ico { opacity: 0.45; }
@keyframes pl-spin { to { transform: rotate(360deg); } }

.pl-skip {
  width: 44px; height: 44px; border-radius: 50%; flex: none;
  display: grid; place-items: center; color: var(--pl-ink);
  transition: background-color 0.2s;
}
.pl-skip:hover { background: var(--pl-soft); }
.pl-skip:active { background: var(--pl-track); }

.pl-seek { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; }
.pl-time {
  flex: none; width: 38px; font-size: 13px; line-height: 1;
  color: var(--pl-muted); font-variant-numeric: tabular-nums;
}
.pl-elapsed { text-align: right; }
.pl-slider {
  position: relative; flex: 1; min-width: 0; height: 44px; cursor: pointer;
  touch-action: pan-y; border-radius: 10px; -webkit-tap-highlight-color: transparent;
}
.pl-track {
  position: absolute; left: 0; right: 0; top: 50%; height: 4px; margin-top: -2px;
  border-radius: 2px; background: var(--pl-track); overflow: hidden;
  transition: height 0.15s, margin-top 0.15s;
}
.pl-slider:hover .pl-track, .pl-slider.is-drag .pl-track { height: 6px; margin-top: -3px; }
.pl-fill {
  position: absolute; inset: 0; background: var(--pl-ink);
  transform-origin: left center; transform: scaleX(0);
}
.pl-knob {
  position: absolute; top: 50%; left: 0; width: 14px; height: 14px; margin: -7px 0 0 -7px;
  border-radius: 50%; background: var(--pl-ink); pointer-events: none;
  transform: scale(0); transition: transform 0.15s var(--ease);
}
.pl-slider:hover .pl-knob, .pl-slider:focus-visible .pl-knob, .pl-slider.is-drag .pl-knob { transform: scale(1); }
@media (hover: none) { .pl-knob { transform: scale(0.85); } }
.pl-slider:focus-visible { outline-offset: 0; }

.pl-rate {
  flex: none; min-width: 60px; height: 44px; padding: 0 14px; border-radius: var(--pill);
  border: 1px solid var(--pl-line);
  font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; text-align: center;
  transition: border-color 0.2s;
}
.pl-rate:hover { border-color: var(--pl-ink); }

.pl-status { font-size: 14px; color: #e0a79f; margin-top: -8px; }
.pl-status:empty { display: none; }

/* Voices */
.pl-voices {
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
  padding: 4px; margin: -4px;
}
.pl-voices::-webkit-scrollbar, .pl-thumbs::-webkit-scrollbar { display: none; }
.pl-voice {
  flex: 1 0 auto; display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
  min-width: 0; min-height: 48px; padding: 7px 14px 8px;
  border: 1px solid var(--pl-line); border-radius: 14px;
  line-height: 1.2; text-align: left;
  transition: background-color 0.2s, border-color 0.2s, color 0.2s;
}
.pl-vn, .pl-vt { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl-vn { font-size: 14px; font-weight: 600; }
.pl-vt { font-size: 12px; color: var(--pl-muted); }
/* Desktop and tablet: all eight voices visible at once, four across. */
@media (min-width: 820px) {
  .pl-voices { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); overflow: visible; }
  .pl-voice { flex: none; padding-inline: 12px; }
}
.pl-voice:hover { border-color: rgb(241 238 230 / 0.55); }
.pl-voice[aria-pressed="true"] { background: var(--pl-ink); color: var(--pl-btn-fg); border-color: var(--pl-ink); }
.pl-voice[aria-pressed="true"] .pl-vt { color: var(--pl-chip-sub); }
.pl-voice[disabled] { opacity: 0.38; pointer-events: none; }

/* ---------- Compact (books page sample): light, one row ---------- */
.player.is-compact .pl {
  --pl-bg: var(--paper-2);
  --pl-line: var(--line-2);
  --pl-ink: var(--ink);
  --pl-muted: var(--muted);
  --pl-track: rgb(31 30 27 / 0.14);
  --pl-soft: rgb(31 30 27 / 0.06);
  --pl-btn-bg: var(--ink);
  --pl-btn-fg: var(--paper);
  --pl-focus: var(--olive);
  display: block; min-height: 0;
  padding: 8px 22px 8px 8px; border: 0; border-radius: 36px;
}
.player.is-compact .pl-boot { min-height: 64px; padding: 0; }
.player.is-compact .pl-main { padding: 0; gap: 0; }
.player.is-compact .pl-controls { border: 0; padding: 0; gap: 14px; }
.player.is-compact .pl-play { width: 48px; height: 48px; }
.player.is-compact .pl-play .pl-ico svg { width: 22px; height: 22px; }
.player.is-compact .pl-status { color: #a2463d; margin: 6px 0 4px 62px; }
.player.is-compact .pl-fail { min-height: 64px; flex-direction: row; justify-content: space-between; padding: 8px 8px 8px 24px; }

/* ---------- Tablet ---------- */
@media (max-width: 1099.98px) {
  .pl-aside { padding-inline: 16px; }
  .pl-cover { width: 184px; }
  .pl-main { padding: 28px 24px 24px; }
}

/* Narrow tablet: keep four voices across without clipping the trait line. */
@media (min-width: 820px) and (max-width: 899.98px) {
  .pl-main { padding-inline: 20px; }
  .pl-voices { gap: 6px; }
  .pl-voice { padding-inline: 7px; }
}

/* ---------- Mobile: stacked ---------- */
@media (max-width: 819.98px) {
  .pl { display: block; min-height: 0; border-radius: 24px; }
  .pl-boot { min-height: 640px; }
  .pl-aside {
    display: grid; grid-template-columns: 84px minmax(0, 1fr);
    grid-template-areas: "cover meta" "thumbs thumbs";
    align-items: center; gap: 18px 16px;
    padding: 20px 20px 0; border-right: 0; text-align: left;
  }
  .pl-cover { grid-area: cover; width: 84px; border-radius: 6px; box-shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 10px 20px -8px rgb(0 0 0 / 0.6); }
  .pl-meta { grid-area: meta; }
  .pl-title { min-height: 0; font-size: 19px; align-items: start; justify-items: start; text-wrap: pretty; }
  .pl-thumbs {
    grid-area: thumbs; display: flex; overflow-x: auto; scrollbar-width: none; gap: 10px;
    margin: 0 -20px; padding: 8px 20px 6px; width: auto;
  }
  .pl-thumb { flex: none; width: 44px; }
  .pl-main { padding: 10px 20px 20px; gap: 14px; }
  .pl-passage {
    flex: none; height: 236px; font-size: 20px; line-height: 1.64;
    margin: 0 -8px 0 -6px; padding: 18px 8px 18px 6px;
  }
  .pl-controls {
    display: grid; grid-template-columns: 1fr auto 1fr;
    grid-template-areas: "seek seek seek" ". btns rate";
    row-gap: 6px; align-items: center; padding-top: 14px;
  }
  .pl-seek { grid-area: seek; }
  .pl-buttons { grid-area: btns; gap: 8px; }
  .pl-rate { grid-area: rate; justify-self: end; }
  .pl-play { width: 58px; height: 58px; }
  .pl-voices { margin: -4px -20px; padding: 4px 20px; }
  .pl-voice { flex: none; }
  .player.is-compact .pl { padding: 8px 18px 8px 8px; }
  .player.is-compact .pl-controls { display: flex; gap: 12px; padding: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .is-loading .pl-ring { animation: none; border-color: var(--pl-ink); opacity: 0.35; }
}
