/* ============================================================
   BooksYard — Audiobook player (dark theme)
   Fit-to-screen: no scrolling, everything in 100dvh.
   Transport layout (standard audiobook pattern):
     prev-track | back-15 | PLAY | fwd-15 | next-track
   ============================================================ */

/* [hidden] must beat display:flex/grid on the drawer, backdrop and sheets */
[hidden] { display: none !important; }

.player-body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  background: #121417;
  color: #EDEFF2;
  font-family: "Segoe UI", Roboto, "Noto Sans Devanagari", "Nirmala UI", Arial, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.player-body svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ===== Top bar ===== */
.p-topbar {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 2px;
  padding: 10px 6px;
  min-height: 56px;
}
.p-icon {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border: 0; background: transparent;
  color: #EDEFF2;
  border-radius: 50%;
  cursor: pointer;
}
.p-icon:hover { background: rgba(255,255,255,.09); }
.p-icon:active { transform: scale(.94); }
.p-top-title { flex: 1; min-width: 0; padding: 0 6px; }
.p-top-title strong {
  display: block; font-size: 14.5px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.p-top-title span { display: block; font-size: 12px; color: #9AA3AE; }

/* ===== Cover =====
   This is the only flex:1 element — it absorbs all leftover vertical
   space. The cover image inside is capped against both viewport width
   and the available height so it never overflows. */
.p-cover-wrap {
  flex: 1 1 auto;
  display: grid; place-items: center;
  padding: 8px 22px 10px;
  min-height: 0;
  overflow: hidden;
}
.p-cover {
  width: min(78vw, 300px, 44dvh);
  aspect-ratio: 3 / 4;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 18px 44px rgba(0,0,0,.55);
  background: #1D2126;
}
.p-cover img { width: 100%; height: 100%; object-fit: cover; }

/* ===== Episode select ===== */
.p-episode { flex: 0 0 auto; padding: 0 18px; }
.p-episode-label {
  display: block;
  font-size: 11px; font-weight: 700;
  letter-spacing: .8px; text-transform: uppercase;
  color: #9AA3AE;
  margin-bottom: 6px;
}
.p-select-wrap { position: relative; }
.p-select-wrap select {
  width: 100%;
  appearance: none; -webkit-appearance: none;
  background: #1D2126;
  color: #EDEFF2;
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 12px;
  padding: 12px 42px 12px 15px;
  font-size: 14px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  outline: none;
}
.p-select-wrap select:focus { border-color: #12BFA4; }
.p-caret {
  position: absolute; right: 14px; top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: #9AA3AE;
  width: 19px; height: 19px;
}

/* ===== Track title ===== */
.p-track-title {
  flex: 0 0 auto;
  margin: 10px 18px 6px;
  text-align: center;
  font-size: 17px; font-weight: 700;
  letter-spacing: -.2px;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ===== Seek ===== */
.p-seek { flex: 0 0 auto; padding: 0 22px; }
.p-seek input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 22px;
  background: transparent; cursor: pointer;
}
.p-seek input[type=range]::-webkit-slider-runnable-track {
  height: 5px; border-radius: 3px;
  background: rgba(255,255,255,.18);
}
.p-seek input[type=range]::-moz-range-track {
  height: 5px; border-radius: 3px; background: rgba(255,255,255,.18);
}
.p-seek input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: #12BFA4;
  box-shadow: 0 1px 6px rgba(0,0,0,.5);
  margin-top: -5.5px;
}
.p-seek input[type=range]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: #12BFA4; border: 0;
}
.p-times {
  display: flex; justify-content: space-between;
  font-size: 12px; color: #9AA3AE;
  font-variant-numeric: tabular-nums;
  margin-top: -1px;
}

/* ===== Controls =====
   Layout: prev-track | back-15 | PLAY | fwd-15 | next-track
   Play is the center anchor; skip-15 buttons flank it; track buttons
   are on the outside. */
.p-controls {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  gap: 14px;
  padding: 12px 16px 2px;
}
.p-round {
  position: relative;
  width: 50px; height: 50px;
  flex: 0 0 auto;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: #22272D;
  color: #EDEFF2;
  cursor: pointer;
  transition: background .15s, transform .12s;
}
.p-round:hover { background: #2B3138; }
.p-round:active { transform: scale(.93); }
.p-round svg { width: 26px; height: 26px; }

/* Skip-15 icons: the "15" text is baked into the SVG, no separate element */
.skip15-icon text {
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
}

.p-play {
  width: 68px; height: 68px;
  flex: 0 0 auto;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: #FFFFFF;
  color: #121417;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(0,0,0,.4);
  transition: transform .12s;
}
.p-play:active { transform: scale(.94); }
.p-play svg { width: 28px; height: 28px; fill: currentColor; stroke: none; }
.p-play svg.pause-icon { fill: none; stroke: currentColor; stroke-width: 3; }

/* ===== Options ===== */
.p-options {
  flex: 0 0 auto;
  display: flex; gap: 12px;
  justify-content: center;
  padding: 10px 18px calc(20px + env(safe-area-inset-bottom));
  flex-wrap: wrap;
}
.p-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 17px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.12);
  background: #1D2126;
  color: #EDEFF2;
  font-size: 13px; font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.p-chip:hover { background: #262B31; border-color: rgba(255,255,255,.22); }
.p-chip svg { width: 17px; height: 17px; color: #9AA3AE; }
.p-chip.is-on { border-color: #12BFA4; color: #12BFA4; }
.p-chip.is-on svg { color: #12BFA4; }

/* ===== Drawer ===== */
.p-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 40;
  animation: fade .2s ease;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }

.p-drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 320px; max-width: 88vw;
  background: #191D22;
  z-index: 50;
  display: flex; flex-direction: column;
  box-shadow: -8px 0 30px rgba(0,0,0,.5);
  animation: slideIn .25s cubic-bezier(.2,.8,.3,1);
}
@keyframes slideIn { from { transform: translateX(100%) } to { transform: none } }

.p-drawer-head {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 10px 14px 18px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  font-size: 15px;
}
.p-drawer-body { flex: 1; overflow-y: auto; padding: 8px 0 24px; }

.p-ep {
  display: flex; align-items: center; gap: 12px;
  width: 100%; text-align: left;
  padding: 11px 16px;
  border: 0; background: transparent;
  color: #EDEFF2;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  border-left: 3px solid transparent;
}
.p-ep:hover { background: rgba(255,255,255,.06); }
.p-ep.is-current { border-left-color: #12BFA4; background: rgba(18,191,164,.09); }
.p-ep .ep-no {
  flex: 0 0 auto;
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: rgba(255,255,255,.09);
  font-size: 12px; font-weight: 700;
}
.p-ep.is-current .ep-no { background: #12BFA4; color: #121417; }
.p-ep .ep-main { flex: 1; min-width: 0; }
.p-ep .ep-title {
  display: block;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-weight: 500;
}
.p-ep .ep-dur { font-size: 11.5px; color: #9AA3AE; }

/* ===== Sheets ===== */
.p-sheet {
  position: fixed;
  left: 50%; bottom: 0;
  transform: translateX(-50%);
  width: min(460px, 100%);
  background: #191D22;
  border-radius: 18px 18px 0 0;
  z-index: 60;
  box-shadow: 0 -10px 34px rgba(0,0,0,.55);
  animation: slideUp .25s cubic-bezier(.2,.8,.3,1);
  padding-bottom: env(safe-area-inset-bottom);
}
@keyframes slideUp { from { transform: translate(-50%, 100%) } to { transform: translate(-50%, 0) } }

.p-sheet-head {
  padding: 16px 20px 10px;
  font-size: 15px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.p-sheet-body {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 14px 16px 22px;
}
.p-sheet-body button {
  padding: 12px 8px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.12);
  background: #22272D;
  color: #EDEFF2;
  font-size: 13.5px; font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.p-sheet-body button:hover { background: #2B3138; }
.p-sheet-body button.is-active { border-color: #12BFA4; color: #12BFA4; background: rgba(18,191,164,.1); }
.p-sheet-body button.is-off { grid-column: 1 / -1; }

/* ===== Toast ===== */
.p-toast {
  position: fixed;
  left: 50%; bottom: 26px;
  transform: translateX(-50%);
  background: rgba(30,35,41,.96);
  color: #EDEFF2;
  padding: 11px 20px;
  border-radius: 999px;
  font-size: 13.5px;
  box-shadow: 0 10px 28px rgba(0,0,0,.5);
  z-index: 200;
  max-width: 88vw;
  text-align: center;
  animation: toastIn .22s ease;
}
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 14px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ============================================================
   Responsive — fit-to-screen on every device
   ============================================================ */
@media (min-width: 700px) {
  .p-body-wide { max-width: 560px; margin: 0 auto; }
  .p-cover { width: min(300px, 44dvh); }
}

/* Small phones */
@media (max-width: 420px) {
  .p-cover-wrap { padding: 6px 16px 8px; }
  .p-cover { width: min(70vw, 230px, 38dvh); }
  .p-episode { padding: 0 14px; }
  .p-track-title { margin: 8px 14px 4px; font-size: 16px; }
  .p-seek { padding: 0 18px; }
  .p-controls { gap: 10px; padding: 10px 10px 0; }
  .p-round { width: 44px; height: 44px; }
  .p-round svg { width: 22px; height: 22px; }
  .p-play { width: 60px; height: 60px; }
  .p-play svg { width: 25px; height: 25px; }
  .p-options { padding: 8px 14px calc(16px + env(safe-area-inset-bottom)); gap: 9px; }
  .p-chip { padding: 8px 15px; font-size: 12px; }
}

/* Short screens — shrink cover harder */
@media (max-height: 700px) {
  .p-topbar { min-height: 48px; padding: 6px 6px; }
  .p-cover-wrap { padding: 4px 16px 6px; }
  .p-cover { width: min(48vw, 160px, 28dvh); }
  .p-episode-label { margin-bottom: 3px; }
  .p-select-wrap select { padding: 10px 38px 10px 14px; }
  .p-track-title { margin: 6px 14px 3px; font-size: 14.5px; }
  .p-controls { padding: 8px 12px 0; gap: 10px; }
  .p-round { width: 40px; height: 40px; }
  .p-round svg { width: 20px; height: 20px; }
  .p-play { width: 52px; height: 52px; }
  .p-play svg { width: 22px; height: 22px; }
  .p-options { padding: 6px 14px calc(14px + env(safe-area-inset-bottom)); }
  .p-chip { padding: 7px 14px; font-size: 11.5px; }
}

/* Very short screens (landscape phones) */
@media (max-height: 500px) {
  .p-topbar { min-height: 42px; padding: 4px 6px; }
  .p-cover-wrap { padding: 2px 12px 4px; }
  .p-cover { width: min(36vw, 110px, 22dvh); }
  .p-episode-label { display: none; }
  .p-select-wrap select { padding: 8px 36px 8px 12px; font-size: 13px; }
  .p-track-title { margin: 4px 12px 2px; font-size: 13px; }
  .p-seek { padding: 0 14px; }
  .p-controls { padding: 4px 10px 0; gap: 8px; }
  .p-round { width: 34px; height: 34px; }
  .p-round svg { width: 17px; height: 17px; }
  .p-play { width: 44px; height: 44px; }
  .p-play svg { width: 18px; height: 18px; }
  .p-options { padding: 4px 12px calc(10px + env(safe-area-inset-bottom)); }
  .p-chip { padding: 5px 12px; font-size: 10.5px; }
  .p-chip svg { width: 13px; height: 13px; }
}

/* Landscape phones: two-column grid — cover left, controls right */
@media (orientation: landscape) and (max-height: 560px) {
  .player-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
    grid-template-rows: auto auto auto auto auto auto;
    grid-template-areas:
      "top   top"
      "cover ep"
      "cover title"
      "cover seek"
      "cover ctrl"
      "cover opts";
    align-content: start;
    overflow: hidden;
  }
  .p-topbar     { grid-area: top;   min-height: 44px; padding: 5px 8px; }
  .p-cover-wrap { grid-area: cover; padding: 4px 8px 4px 14px; align-items: center; }
  .p-cover      { width: min(30vw, 150px, 65dvh); }

  .p-episode     { grid-area: ep;    padding: 0 16px 6px; }
  .p-track-title { grid-area: title; padding: 0 16px 6px; font-size: 14.5px; }
  .p-seek        { grid-area: seek;  padding: 0 16px 6px; }
  .p-controls    { grid-area: ctrl;  padding: 0 16px 8px; gap: 12px; }
  .p-options     { grid-area: opts;  padding: 0 16px calc(4px + env(safe-area-inset-bottom)); }

  .p-episode-label { display: none; }
  .p-select-wrap select { padding: 9px 38px 9px 13px; font-size: 13px; }
  .p-round { width: 38px; height: 38px; }
  .p-round svg { width: 19px; height: 19px; }
  .p-play { width: 50px; height: 50px; }
  .p-play svg { width: 21px; height: 21px; }
  .p-chip { padding: 6px 13px; font-size: 11px; width: auto; justify-self: center; }
  .p-chip svg { width: 14px; height: 14px; }
  .p-options { justify-content: center; padding: 0 16px calc(8px + env(safe-area-inset-bottom)); }
}

/* Very narrow phones */
@media (max-width: 340px) {
  .p-controls { gap: 7px; }
  .p-round { width: 38px; height: 38px; }
  .p-round svg { width: 18px; height: 18px; }
  .p-play { width: 52px; height: 52px; }
  .p-play svg { width: 21px; height: 21px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
