/* iPhone Duo Podcast
   One skeleton — stage, card (list + episode panel), rail, seam — rearranged
   into four device modes. The media element never moves in the DOM, so
   rotating or unfolding never restarts playback.
   ------------------------------------------------------------------ */

/* --- Star White (default) ------------------------------------------ */
:root {
  --bg:        #E9ECF1;
  --leaf:      #FBFCFD;
  --leaf-2:    #F2F4F8;
  --ink:       #101623;
  --ink-soft:  #3D4657;
  --muted:     #69707E;
  --hair:      #DDE2EA;
  --hair-soft: #E9EDF3;
  --accent:    #4A46E8;
  --accent-ink:#FFFFFF;
  --accent-wash:rgba(74, 70, 232, .09);
  --sel:       rgba(74, 70, 232, .07);
  --hover:     rgba(16, 22, 35, .04);

  --seam-strength: .5;
  --seam-valley: 16, 22, 35;
  --seam-ridge:  255, 255, 255;
  --seam-w: 34px;

  --shadow-sheet: 0 -2px 40px rgba(16, 22, 35, .16);
  --shadow-pop:   0 8px 30px rgba(16, 22, 35, .13);
  --shadow-panel: -12px 0 44px rgba(16, 22, 35, .14);

  --font-display: "Archivo", "Helvetica Neue", Arial, sans-serif;
  --font-ui: "Instrument Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  --sa-t: env(safe-area-inset-top, 0px);
  --sa-r: env(safe-area-inset-right, 0px);
  --sa-b: env(safe-area-inset-bottom, 0px);
  --sa-l: env(safe-area-inset-left, 0px);

  --rail: 54px;                              /* the icon strip itself */
  --rail-w: calc(54px + var(--sa-r));        /* what the layout must reserve */
  --ease: cubic-bezier(.22, .61, .36, 1);
  color-scheme: light;
}

/* --- Night Sky ------------------------------------------------------ */
:root[data-theme="night"] {
  --bg:        #05070C;
  --leaf:      #131824;
  --leaf-2:    #0E121C;
  --ink:       #E8ECF4;
  --ink-soft:  #B7C0D2;
  --muted:     #8892A6;
  --hair:      #232A3A;
  --hair-soft: #1C2231;
  --accent:    #7B76FF;
  --accent-ink:#0A0D14;
  --accent-wash:rgba(123, 118, 255, .16);
  --sel:       rgba(123, 118, 255, .12);
  --hover:     rgba(232, 236, 244, .05);

  --seam-strength: .6;
  --seam-valley: 0, 0, 0;
  --seam-ridge: 168, 180, 255;

  --shadow-sheet: 0 -2px 44px rgba(0, 0, 0, .6);
  --shadow-pop:   0 8px 30px rgba(0, 0, 0, .5);
  --shadow-panel: -12px 0 44px rgba(0, 0, 0, .55);
  color-scheme: dark;
}

:root[data-seam="original"] { --seam-strength: 1;   --seam-w: 48px; }
:root[data-seam="subtle"]   { --seam-strength: .74; --seam-w: 40px; }
:root[data-seam="most"]     { --seam-strength: .5;  --seam-w: 34px; }
:root[data-theme="night"][data-seam="original"] { --seam-strength: 1.15; }
:root[data-theme="night"][data-seam="subtle"]   { --seam-strength: .85; }
:root[data-theme="night"][data-seam="most"]     { --seam-strength: .6;  }

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--accent); color: var(--accent-ink); }
.sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* the page-level audio element is never displayed */
#audio { display: none; }

/* ==================================================================
   App shell
   ================================================================== */

.app {
  display: grid;
  width: 100vw;
  height: 100dvh;
  background: var(--leaf);
  position: relative;
  isolation: isolate;
  overflow: hidden;
}

/* Previewing a mode on the wrong hardware: render it at the device's own
   proportions instead of stretching it across a desktop. */
body[data-forced="1"] { display: grid; place-items: center; padding: 18px; }
.app[data-forced="1"] {
  width: var(--fw);
  height: var(--fh);
  max-width: calc(100vw - 36px);
  max-height: calc(100svh - 36px);
  max-height: calc(100dvh - 36px);
  border-radius: 16px;
  box-shadow: 0 26px 70px rgba(0, 0, 0, .28), 0 0 0 1px var(--hair);
}

@media (prefers-reduced-motion: no-preference) {
  .app[data-unfold="1"] { animation: unfold 760ms var(--ease) both; }
  .app[data-unfold="1"] .seam::after { animation: sheen 1200ms var(--ease) 180ms both; }
}
@keyframes unfold { from { opacity: 0; transform: scale(.99); } to { opacity: 1; transform: none; } }
@keyframes sheen { 0% { opacity: 0; transform: scaleY(0); } 40% { opacity: 1; } 100% { opacity: .55; transform: scaleY(1); } }

/* ==================================================================
   Mode layouts
   ================================================================== */

/* Outer, portrait — media in the top half, list below, rail at the right. */
.app[data-mode="outer-portrait"] {
  grid-template-columns: 1fr var(--rail-w);
  grid-template-rows: 1fr 1fr;
  grid-template-areas: "stage stage" "card  rail";
}

/* Outer, landscape — video fills the panel; the list arrives as a drawer. */
.app[data-mode="outer-landscape"] {
  grid-template-columns: 1fr var(--rail-w);
  grid-template-rows: 1fr;
  grid-template-areas: "card rail";
}
.app[data-mode="outer-landscape"] .stage { display: none; }

/* choosing video hands the whole panel to the picture */
.app[data-mode="outer-landscape"][data-fs="1"] { grid-template-areas: "stage stage"; }
.app[data-mode="outer-landscape"][data-fs="1"] .stage { display: grid; }
.app[data-mode="outer-landscape"][data-fs="1"] .card { display: none; }

/* Unfolded, landscape — two leaves, 50/50, seam on the fold. */
.app[data-mode="inner-landscape"] {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  grid-template-areas: "browse stage" "browse aside";
}

/* Unfolded, portrait — media above the crease, list and notes below it. */
.app[data-mode="inner-portrait"] {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  grid-template-areas: "stage  stage" "browse aside";
}

/* Unfolded portrait playing audio — no picture to show, so the transport
   moves to the rail and the whole screen becomes the list. */
.app[data-mode="inner-portrait"][data-format="audio"] {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
  grid-template-areas: "card";
}

.stage  { grid-area: stage; }
.browse { grid-area: browse; }
.aside  { grid-area: aside; }
.card   { grid-area: card; }

/* In split modes the card is a passthrough: its two children become
   grid items in their own right. In flip modes it becomes the flipper. */
.card { display: contents; }

/* only unfolded-portrait audio drops the media pane; outer-landscape IS the video */
.app[data-mode="inner-portrait"][data-format="audio"] .stage { display: none; }

/* ==================================================================
   Stage
   ================================================================== */

.stage {
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  background: var(--leaf-2);
  overflow: hidden;
}

.stage-frame {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  display: grid;
  place-items: center;
  background: #000;
  overflow: hidden;
}

/* the outer screen shows a 4:3 window */
/* The media band is exactly half the screen. Half of a 4:3 leaf stood on end is
   3:2, and 4:3 is narrower than that, so the frame is driven by the height and
   sits centred with a margin either side. Do not switch this to width:100% —
   that fills the width but breaks the 4:3 and the exact half. */
.app[data-mode="outer-portrait"] .stage-frame {
  aspect-ratio: 4 / 3;
  height: 100%;
  width: auto;
  max-width: 100%;
  place-self: center;
}

/* unfolded, the media sits at 16:9 and the panel below takes the rest */
.app[data-mode="inner-landscape"] .stage-frame,
.app[data-mode="inner-portrait"] .stage-frame,
.app[data-mode="outer-landscape"] .stage-frame {
  aspect-ratio: auto;
  width: 100%;
  height: 100%;
}

/* the rail floats over the right leaf, so anything under it needs clearance */
.app[data-mode="inner-landscape"] .aside .face-bar,
.app[data-mode="inner-landscape"] .aside .pane { padding-right: calc(var(--rail-w) + 8px); }
.app[data-mode="inner-portrait"][data-format="video"] .aside .face-bar,
.app[data-mode="inner-portrait"][data-format="video"] .aside .pane { padding-right: calc(var(--rail-w) + 8px); }
.app[data-mode="inner-portrait"][data-format="audio"] .face-bar,
.app[data-mode="inner-portrait"][data-format="audio"] .ep,
.app[data-mode="inner-portrait"][data-format="audio"] .pane { padding-right: calc(var(--rail-w) + 8px); }

.stage-frame > video {
  width: 100%;
  height: 100%;
  object-fit: contain;   /* never crop the picture to fill a frame */
  display: block;
  background: #000;
}
.stage-frame > video[hidden] { display: none; }

/* --- audio face: artwork with a transport across the foot ---------- */
.audio-face { position: absolute; inset: 0; display: grid; }
.audio-art { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.audio-shade {
  position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(3, 5, 10, .12) 0%, rgba(3, 5, 10, .38) 46%, rgba(3, 5, 10, .88) 100%);
}

/* --- nothing posted yet -------------------------------------------- */
.stage-empty { position: absolute; inset: 0; }
.stage-empty-art { width: 100%; height: 100%; object-fit: cover; display: block; }
.stage-empty-note {
  position: absolute; inset: auto 0 0 0;
  margin: 0;
  padding: 12px 16px;
  background: linear-gradient(180deg, rgba(5, 7, 12, 0), rgba(5, 7, 12, .86));
  color: #fff;
  font-size: 13px;
}

/* ==================================================================
   Transport (audio)
   ================================================================== */

.tp { display: flex; align-items: center; gap: 10px; }

.tp--wide {
  position: relative;
  align-self: end;
  margin: auto 0 0;
  padding: 14px 16px;
  color: #fff;
}
.tp--wide .tp-time { color: rgba(255, 255, 255, .82); }

.tp-btn {
  border: 0;
  background: none;
  color: inherit;
  padding: 5px;
  border-radius: 8px;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex: none;
  transition: background 140ms, opacity 140ms;
}
.tp-btn:hover { background: rgba(255, 255, 255, .14); }

.tp-play {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .16);
  backdrop-filter: blur(6px);
}
.tp-play:hover { background: rgba(255, 255, 255, .26); }

.tp-time {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  flex: none;
  min-width: 34px;
}

.tp-bar {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  min-width: 40px;
  height: 20px;
  background: none;
  cursor: pointer;
}
.tp-bar::-webkit-slider-runnable-track {
  height: 4px; border-radius: 999px;
  background: linear-gradient(90deg, currentColor var(--pct, 0%), rgba(255, 255, 255, .3) var(--pct, 0%));
}
.tp-bar::-moz-range-track { height: 4px; border-radius: 999px; background: rgba(255, 255, 255, .3); }
.tp-bar::-moz-range-progress { height: 4px; border-radius: 999px; background: currentColor; }
.tp-bar::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 12px;
  margin-top: -4px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .4);
}
.tp-bar::-moz-range-thumb {
  width: 12px; height: 12px; border: 0; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .4);
}

/* rail transport: a progress ring around the play button */
.tp--rail {
  flex-direction: column;
  gap: 4px;
  margin-top: auto;
  padding: 10px 0 4px;
  border-top: 1px solid var(--hair);
  color: var(--ink);
}
.tp--rail .tp-btn:hover { background: var(--hover); }
.tp--rail .tp-play {
  width: 44px; height: 44px;
  background: none;
  backdrop-filter: none;
  position: relative;
  color: var(--accent);
}
.tp--rail .tp-play:hover { background: var(--hover); }
.tp-ring { position: absolute; inset: 0; }
.tp--rail .tp-play svg.tp-glyph { position: relative; color: var(--ink); }
.tp-time--rail { min-width: 0; font-size: 11px; }

/* ==================================================================
   Card: list on the front, episode panel on the back
   ================================================================== */

.browse, .aside {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--leaf);
  overflow: hidden;
}
.browse { background: var(--leaf-2); }

.face-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px 10px 16px;
  border-bottom: 1px solid var(--hair-soft);
  flex: none;
  min-height: 46px;
}
.face-title {
  font-family: var(--font-display);
  font-variation-settings: "wdth" 108, "wght" 600;
  font-size: 14px;
  letter-spacing: -.004em;
  margin: 0;
}

.flip-btn {
  display: none;
  align-items: center;
  gap: 3px;
  margin-left: auto;
  padding: 5px 9px;
  border: 1px solid var(--hair);
  background: var(--leaf);
  border-radius: 8px;
  color: var(--ink-soft);
  font-size: 13px;
  cursor: pointer;
  flex: none;
  transition: background 140ms, border-color 140ms;
}
.flip-btn:hover { background: var(--hover); border-color: var(--muted); }
.flip-btn--back { margin-left: 0; margin-right: auto; }
.app[data-flip="1"] .flip-btn { display: inline-flex; }

/* tabs */
.tabs {
  display: inline-flex;
  position: relative;
  background: var(--hair-soft);
  border-radius: 8px;
  padding: 2px;
  margin-left: auto;
  flex: none;
}
.tabs-thumb {
  position: absolute;
  top: 2px; bottom: 2px; left: 2px;
  border-radius: 6px;
  background: var(--leaf);
  box-shadow: 0 1px 3px rgba(16, 22, 35, .16);
  transition: transform 240ms var(--ease), width 240ms var(--ease);
}
:root[data-theme="night"] .tabs-thumb { background: #2A3143; box-shadow: none; }
.tabs button {
  position: relative;
  z-index: 1;
  border: 0;
  background: none;
  padding: 5px 13px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  transition: color 200ms;
}
.tabs button[aria-selected="true"] { color: var(--ink); font-weight: 500; }
@media (prefers-reduced-motion: reduce) { .tabs-thumb { transition: none; } }

/* --- the list ------------------------------------------------------ */
.ep-list {
  flex: 1; min-height: 0;
  overflow-y: auto; overscroll-behavior: contain;
  padding-bottom: calc(16px + var(--sa-b));
  padding-left: var(--sa-l);
  scrollbar-width: thin;
}

/* A row is a wrapper, not a button, so the per-format controls can be real
   buttons rather than nested ones. */
.ep-row {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--hair-soft);
  position: relative;
  transition: background 120ms;
}
.ep-row:hover { background: var(--hover); }
.ep-row[data-current="true"] { background: var(--sel); }
.ep-row[data-current="true"]::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0;
  width: 2px; background: var(--accent);
}

.ep {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 12px;
  align-items: center;
  padding: 10px 14px 10px 16px;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}

/* Format pickers, shown where the episode panel is not on screen to carry
   the choice — the outer screen held sideways. */
.ep-go { display: none; gap: 4px; padding-right: 10px; flex: none; }
.app[data-mode="outer-landscape"] .ep-go { display: flex; }

.ep-go-btn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border: 1px solid var(--hair);
  background: var(--leaf);
  border-radius: 8px;
  color: var(--ink-soft);
  cursor: pointer;
  transition: background 140ms, color 140ms, border-color 140ms;
}
.ep-go-btn:hover { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.ep-go-btn[aria-pressed="true"] { background: var(--accent-wash); border-color: var(--accent); color: var(--accent); }

.ep-thumb { width: 58px; aspect-ratio: 16 / 10; border-radius: 5px; overflow: hidden; background: var(--hair-soft); }
.ep-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ep-body { min-width: 0; }
.ep-title {
  font-size: 14px; font-weight: 600; letter-spacing: -.008em;
  margin: 0 0 2px; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ep-meta { font-size: 12.5px; color: var(--muted); display: flex; gap: 10px; }
.ep-num { font-variant-numeric: tabular-nums; }

.ep-empty { padding: 30px 20px; color: var(--muted); font-size: 14px; line-height: 1.6; }
.ep-empty b { display: block; color: var(--ink); font-weight: 600; margin-bottom: 4px; }

/* --- episode panel -------------------------------------------------- */
.aside-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
.pane { padding: 16px 18px 30px; }
.pane[hidden] { display: none; }

.ep-head { margin-bottom: 14px; }
.ep-kicker { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 9px; flex-wrap: wrap; margin-bottom: 8px; }
.tag { color: var(--accent); background: var(--accent-wash); padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; }

.ep-h1 {
  font-family: var(--font-display);
  font-variation-settings: "wdth" 116, "wght" 700;
  font-size: clamp(21px, 2.4vw, 30px);
  line-height: 1.06;
  letter-spacing: -.018em;
  margin: 0 0 8px;
  text-wrap: balance;
}
.ep-sum { font-size: 15px; color: var(--ink-soft); margin: 0; max-width: 46ch; }

.notes-body p { margin: 0 0 12px; color: var(--ink-soft); font-size: 14.5px; line-height: 1.62; max-width: 66ch; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 11px 0; border-bottom: 1px solid var(--hair-soft); }
.row:last-of-type { border-bottom: 0; }
.row-label { font-size: 14px; color: var(--ink-soft); }

.segmented { display: inline-flex; position: relative; background: var(--hair-soft); border-radius: 8px; padding: 2px; flex: none; }
.segmented-thumb {
  position: absolute; top: 2px; bottom: 2px; left: 2px;
  border-radius: 6px; background: var(--leaf);
  box-shadow: 0 1px 3px rgba(16, 22, 35, .16);
  transition: transform 240ms var(--ease), width 240ms var(--ease);
}
:root[data-theme="night"] .segmented-thumb { background: #2A3143; box-shadow: none; }
.segmented button {
  position: relative; z-index: 1; border: 0; background: none;
  padding: 5px 15px; border-radius: 6px; font-size: 13px;
  color: var(--muted); cursor: pointer; transition: color 200ms;
}
.segmented button[aria-selected="true"] { color: var(--ink); font-weight: 500; }
@media (prefers-reduced-motion: reduce) { .segmented-thumb { transition: none; } }

.toggle { position: relative; width: 44px; height: 26px; border: 0; border-radius: 999px; background: var(--hair); cursor: pointer; flex: none; transition: background 200ms var(--ease); }
.toggle::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(16, 22, 35, .3);
  transition: transform 220ms var(--ease);
}
.toggle[aria-pressed="true"] { background: var(--accent); }
.toggle[aria-pressed="true"]::after { transform: translateX(18px); }
@media (prefers-reduced-motion: reduce) { .toggle, .toggle::after { transition: none; } }

.actions { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 11px 15px; border-radius: 10px;
  border: 1px solid var(--hair); background: var(--leaf); color: var(--ink);
  font-size: 14px; font-weight: 500; cursor: pointer;
  transition: background 140ms, border-color 140ms, transform 90ms;
}
.btn:hover { background: var(--hover); border-color: var(--muted); }
.btn:active { transform: scale(.99); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn--primary:hover { background: var(--accent); border-color: var(--accent); filter: brightness(1.08); }
.btn[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); background: var(--accent-wash); }
.btn:disabled { cursor: not-allowed; color: var(--muted); }
.btn--primary:disabled { background: var(--leaf); border-color: var(--hair); color: var(--muted); filter: none; }
.btn:disabled:hover { background: var(--leaf); border-color: var(--hair); filter: none; }

/* ==================================================================
   Flip: list and episode panel as two faces of one card
   ================================================================== */

.app[data-flip="1"] .card {
  display: block;
  position: relative;
  perspective: 1500px;
  transform-style: preserve-3d;
}
.app[data-flip="1"] .card > * {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transition: transform 520ms var(--ease);
}

/* The face turned away is removed outright once the flip has settled, so it
   can never bleed through where 3D compositing is unavailable. Driven by a
   settled flag rather than a visibility transition, which is not dependable. */
.app[data-flip="1"][data-settled="front"] .aside { visibility: hidden; }
.app[data-flip="1"][data-settled="back"]  .browse { visibility: hidden; }

/* clicks follow the flip immediately, without waiting for it to settle */
.app[data-flip="1"] .aside { pointer-events: none; }
.app[data-flip="1"][data-face="back"] .aside { pointer-events: auto; }
.app[data-flip="1"][data-face="back"] .browse { pointer-events: none; }
.app[data-flip="1"] .browse { transform: rotateY(0deg); }
.app[data-flip="1"] .aside  { transform: rotateY(180deg); }
.app[data-flip="1"][data-face="back"] .browse { transform: rotateY(-180deg); }
.app[data-flip="1"][data-face="back"] .aside  { transform: rotateY(0deg); }

@media (prefers-reduced-motion: reduce) {
  .app[data-flip="1"] .card > * { transition: opacity 180ms; transform: none !important; }
  .app[data-flip="1"] .aside { opacity: 0; pointer-events: none; }
  .app[data-flip="1"][data-face="back"] .browse { opacity: 0; pointer-events: none; }
  .app[data-flip="1"][data-face="back"] .aside { opacity: 1; pointer-events: auto; }
}

/* ==================================================================
   Right-edge rail
   ================================================================== */

.rail {
  grid-area: rail;
  width: var(--rail-w);
  padding-right: var(--sa-r);
  padding-bottom: var(--sa-b);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 0 8px;
  background: var(--leaf);
  border-left: 1px solid var(--hair);
  z-index: 26;
}

/* Unfolded, the rail keeps to the bottom half so the whole top belongs to
   the picture. It occupies the bottom-right quadrant. */
.app[data-mode="inner-landscape"] .rail,
.app[data-mode="inner-portrait"] .rail {
  position: absolute;
  top: 50%; right: 0; bottom: 0;
  border-top: 1px solid var(--hair);
}

/* Full-screen video: the rail floats over the picture and gets out of the way. */
.app[data-fs="1"] .rail {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  background: rgba(10, 13, 20, .55);
  backdrop-filter: blur(12px);
  border-left: 0;
  border-top: 0;
  color: #fff;
  transition: opacity 260ms, transform 260ms var(--ease);
}
.app[data-fs="1"][data-chrome="0"] .rail {
  opacity: 0;
  transform: translateX(100%);
  pointer-events: none;
}

.rail-mark { display: grid; place-items: center; width: 34px; height: 34px; color: var(--ink); flex: none; }
.app[data-fs="1"] .rail-mark { color: #fff; }

/* The mark is masked rather than inlined, so one SVG serves every colourway
   and the markup stays light. */
.rail-mark i {
  display: block;
  width: 25px;
  height: 25px;
  background: currentColor;
  -webkit-mask: url(/assets/mark-compact.svg) center / contain no-repeat;
  mask: url(/assets/mark-compact.svg) center / contain no-repeat;
}

.rail-group { display: flex; flex-direction: column; gap: 3px; margin-top: 6px; }

.rail-btn {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 0; background: none;
  border-radius: 9px;
  color: var(--muted);
  cursor: pointer;
  transition: background 140ms, color 140ms;
}
.rail-btn:hover { background: var(--hover); color: var(--ink); }
.rail-btn[aria-expanded="true"] { background: var(--accent-wash); color: var(--accent); }
.app[data-fs="1"] .rail-btn { color: rgba(255, 255, 255, .74); }
.app[data-fs="1"] .rail-btn:hover { background: rgba(255, 255, 255, .14); color: #fff; }

/* leaving full-screen video is the only thing this button does */
.rail-btn[data-drawer] { display: none; }
.app[data-fs="1"] .rail-btn[data-drawer] { display: grid; }

.icon-btn {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border: 1px solid var(--hair); background: var(--leaf);
  border-radius: 8px; color: var(--ink-soft); cursor: pointer;
  transition: background 140ms, color 140ms;
}
.icon-btn:hover { background: var(--hover); color: var(--ink); }

/* ==================================================================
   Rail panel — search, filters, display settings
   ================================================================== */

.panel-scrim {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(5, 7, 12, .34);
  opacity: 0; pointer-events: none;
  transition: opacity 240ms var(--ease);
}
.panel-scrim[data-open="1"] { opacity: 1; pointer-events: auto; }

.rail-panel {
  position: fixed;
  top: 0; bottom: 0; right: var(--rail-w);
  width: min(330px, calc(100vw - var(--rail-w) - var(--sa-l)));
  z-index: 31;
  display: flex;
  flex-direction: column;
  background: var(--leaf);
  border-left: 1px solid var(--hair);
  box-shadow: var(--shadow-panel);
  transform: translateX(calc(100% + var(--rail)));
  transition: transform 300ms var(--ease);
}
.rail-panel[hidden] { display: none; }
.rail-panel[data-open="1"] { transform: translateX(0); }
@media (prefers-reduced-motion: reduce) { .rail-panel, .panel-scrim { transition: none; } }

.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 14px 12px 18px;
  border-bottom: 1px solid var(--hair-soft); flex: none;
}
.panel-head h2 {
  font-family: var(--font-display);
  font-variation-settings: "wdth" 112, "wght" 700;
  font-size: 17px; letter-spacing: -.014em; margin: 0;
}
.panel-body { padding: 16px 18px calc(26px + var(--sa-b)); overflow-y: auto; }
.panel-body[hidden] { display: none; }
.panel-count { font-size: 13px; color: var(--muted); margin: 14px 0 0; }

.search { position: relative; margin-bottom: 14px; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input {
  width: 100%;
  padding: 9px 30px 9px 31px;
  border: 1px solid var(--hair);
  background: var(--leaf-2);
  border-radius: 9px;
  font-size: 14px;
  transition: border-color 140ms, box-shadow 140ms;
}
.search input::placeholder { color: var(--muted); }
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
.search-clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 22px; height: 22px; border: 0; background: none; border-radius: 50%;
  color: var(--muted); cursor: pointer; display: none; place-items: center;
}
.search-clear:hover { background: var(--hover); color: var(--ink); }
.search[data-filled="1"] .search-clear { display: grid; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 5px 12px;
  border: 1px solid var(--hair);
  background: var(--leaf);
  border-radius: 999px;
  font-size: 13px; color: var(--ink-soft);
  cursor: pointer; white-space: nowrap;
  transition: background 140ms, color 140ms, border-color 140ms;
}
.chip:hover { border-color: var(--muted); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.field { margin-bottom: 22px; }
.field:last-child { margin-bottom: 0; }
.field-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 7px; }
.field-note { font-size: 12.5px; color: var(--muted); margin: -3px 0 8px; line-height: 1.5; max-width: 40ch; }

.pick { display: flex; flex-wrap: wrap; gap: 6px; }
.pick--col { flex-direction: column; align-items: stretch; }
.pick button {
  padding: 7px 13px;
  border: 1px solid var(--hair);
  background: var(--leaf);
  border-radius: 9px;
  font-size: 13.5px; color: var(--ink-soft);
  cursor: pointer; text-align: left;
  transition: background 140ms, color 140ms, border-color 140ms;
}
.pick button:hover { border-color: var(--muted); }
.pick button[aria-pressed="true"] { background: var(--accent-wash); border-color: var(--accent); color: var(--accent); font-weight: 500; }

/* ==================================================================
   Seam — vertical on the landscape fold, horizontal on the portrait one
   ================================================================== */

.seam { position: absolute; pointer-events: none; z-index: 20; display: none; }

.app[data-mode="inner-landscape"] .seam {
  display: block;
  top: 0; bottom: 0; left: 50%;
  width: var(--seam-w);
  transform: translateX(calc(var(--seam-w) / -2));
  background: linear-gradient(90deg,
    rgba(var(--seam-valley), 0) 0%,
    rgba(var(--seam-valley), calc(.10 * var(--seam-strength))) 30%,
    rgba(var(--seam-valley), calc(.21 * var(--seam-strength))) 47%,
    rgba(var(--seam-valley), calc(.06 * var(--seam-strength))) 50%,
    rgba(var(--seam-valley), calc(.21 * var(--seam-strength))) 53%,
    rgba(var(--seam-valley), calc(.10 * var(--seam-strength))) 70%,
    rgba(var(--seam-valley), 0) 100%);
}
.app[data-mode="inner-landscape"] .seam::after {
  content: "";
  position: absolute; inset: 0 0 0 50%;
  width: 1.5px; margin-left: -.75px;
  opacity: .55; transform-origin: top;
  background: linear-gradient(180deg,
    rgba(43, 214, 232, calc(.5 * var(--seam-strength))) 0%,
    rgba(var(--seam-ridge), calc(.85 * var(--seam-strength))) 26%,
    rgba(var(--seam-ridge), calc(.85 * var(--seam-strength))) 68%,
    rgba(232, 92, 192, calc(.42 * var(--seam-strength))) 100%);
}

.app[data-mode="inner-portrait"] .seam {
  display: block;
  left: 0; right: 0; top: 50%;
  height: var(--seam-w);
  transform: translateY(calc(var(--seam-w) / -2));
  background: linear-gradient(180deg,
    rgba(var(--seam-valley), 0) 0%,
    rgba(var(--seam-valley), calc(.10 * var(--seam-strength))) 30%,
    rgba(var(--seam-valley), calc(.21 * var(--seam-strength))) 47%,
    rgba(var(--seam-valley), calc(.06 * var(--seam-strength))) 50%,
    rgba(var(--seam-valley), calc(.21 * var(--seam-strength))) 53%,
    rgba(var(--seam-valley), calc(.10 * var(--seam-strength))) 70%,
    rgba(var(--seam-valley), 0) 100%);
}
.app[data-mode="inner-portrait"] .seam::after {
  content: "";
  position: absolute; inset: 50% 0 0 0;
  height: 1.5px; margin-top: -.75px;
  opacity: .55; transform-origin: left;
  background: linear-gradient(90deg,
    rgba(43, 214, 232, calc(.5 * var(--seam-strength))) 0%,
    rgba(var(--seam-ridge), calc(.85 * var(--seam-strength))) 26%,
    rgba(var(--seam-ridge), calc(.85 * var(--seam-strength))) 68%,
    rgba(232, 92, 192, calc(.42 * var(--seam-strength))) 100%);
}
@keyframes sheenH { 0% { opacity: 0; transform: scaleX(0); } 40% { opacity: 1; } 100% { opacity: .55; transform: scaleX(1); } }
@media (prefers-reduced-motion: no-preference) {
  .app[data-unfold="1"][data-mode="inner-portrait"] .seam::after { animation: sheenH 1200ms var(--ease) 180ms both; }
}

/* ==================================================================
   Sheet
   ================================================================== */

.scrim {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(5, 7, 12, .4);
  opacity: 0; pointer-events: none;
  transition: opacity 260ms var(--ease);
  backdrop-filter: blur(2px);
}
.scrim[data-open="1"] { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-height: 92svh;
  max-height: 92dvh;
  display: flex; flex-direction: column;
  background: var(--leaf);
  border-radius: 16px 16px 0 0;
  box-shadow: var(--shadow-sheet);
  transform: translateY(101%);
  transition: transform 320ms var(--ease);
  will-change: transform;
}
.sheet[hidden] { display: none; }
.sheet[data-open="1"] { transform: translateY(0); }
.sheet[data-dragging="1"] { transition: none; }
@media (prefers-reduced-motion: reduce) { .sheet, .scrim { transition: none; } }

:root[data-mode^="inner"] .sheet {
  left: 50%; right: auto;
  width: min(560px, 94vw);
  transform: translate(-50%, 101%);
  border-radius: 16px;
  bottom: calc(16px + var(--sa-b));
}
:root[data-mode^="inner"] .sheet[data-open="1"] { transform: translate(-50%, 0); }

.sheet-grab { padding: 9px 0 5px; display: grid; place-items: center; cursor: grab; touch-action: none; flex: none; }
.sheet-grab:active { cursor: grabbing; }
.sheet-grab span { width: 38px; height: 5px; border-radius: 999px; background: var(--hair); }

.sheet-head { padding: 4px 20px 12px; border-bottom: 1px solid var(--hair-soft); flex: none; }
.sheet-head h2 {
  font-family: var(--font-display);
  font-variation-settings: "wdth" 112, "wght" 700;
  font-size: 19px; letter-spacing: -.015em; margin: 0;
}
.sheet-body { padding: 16px 20px calc(26px + var(--sa-b)); overflow-y: auto; }
.sheet-body p { margin: 0 0 12px; color: var(--ink-soft); line-height: 1.62; max-width: 62ch; }

.opt { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 13px 0; border-bottom: 1px solid var(--hair-soft); }
.opt:last-of-type { border-bottom: 0; }
.opt-t { font-size: 14.5px; margin: 0 0 2px; }
.opt-d { font-size: 13px; color: var(--muted); margin: 0; max-width: 40ch; }

.share-list { display: flex; flex-direction: column; gap: 8px; }
.copyfield { display: flex; gap: 8px; margin-top: 4px; }
.copyfield input {
  flex: 1; min-width: 0; padding: 10px 12px;
  border: 1px solid var(--hair); background: var(--leaf-2);
  border-radius: 9px; font-size: 13.5px; color: var(--muted);
}
.copyfield .btn { width: auto; flex: none; padding: 10px 16px; }

.toast {
  position: fixed; left: 50%; bottom: 26px; z-index: 60;
  transform: translate(-50%, 20px);
  background: var(--ink); color: var(--leaf);
  padding: 10px 18px; border-radius: 999px; font-size: 14px;
  box-shadow: var(--shadow-pop);
  opacity: 0; pointer-events: none;
  transition: opacity 200ms, transform 260ms var(--ease);
}
.toast[data-open="1"] { opacity: 1; transform: translate(-50%, 0); }

/* ==================================================================
   Density and shape
   ================================================================== */

/* Denser rows on the cover display, where a row has the least room. Keyed to
   the panel rather than a pixel width, which we cannot know for this device. */
.app[data-mode^="outer"] .pane { padding: 14px 15px 26px; }
.app[data-mode^="outer"] .ep { grid-template-columns: 50px 1fr; gap: 10px; padding-left: 13px; }
.app[data-mode^="outer"] .ep-thumb { width: 50px; }

/* Shape, not size: narrower than 3:4 and the two bottom columns get cramped,
   so give the notes the larger share. */
@media (max-aspect-ratio: 3 / 4) {
  .app[data-mode="inner-portrait"][data-format="video"] { grid-template-columns: 44% 56%; }
}
