/* Shared visual system for the workspace, player and sign-in. */
:root {
  --bg: #000;
  --surface: #16181c;
  --surface-2: #202327;
  --text: #e7e9ea;
  --muted: #9ba0a6;
  --line: #2f3336;
  --accent: #1d9bf0;
  --accent-ink: #061927;
  --danger: #ff778f;
  --rail-gap: 24px;
  --feed-padding: 20px;
}

body { background: var(--bg); color: var(--text); }
.primary-button { border-radius: 999px; font-weight: 700; }
.primary-button:hover:not(:disabled) { background: #51b7ff; }
.external-player, .sort-control select { border-radius: 999px; }
.brand-mark { background: var(--text); }
.logout-button { color: var(--muted); }
.logout-button:hover { color: var(--text); }

/* Desktop: navigation, work feed, and cloud status. */
.app-layout {
  display: grid;
  grid-template-columns: 210px minmax(0, 760px) minmax(0, 256px);
  justify-content: center;
  gap: var(--rail-gap);
  max-width: 1320px;
  margin-inline: auto;
  padding-inline: 16px;
}
.app-layout .sidebar {
  position: sticky;
  top: 0;
  height: 100svh;
  width: auto;
  align-self: start;
  padding: 20px 0;
  background: var(--bg);
  border: 0;
  z-index: 27;
}
.sidebar-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-inline-end: 8px; }
.sidebar .brand { display: flex; gap: 10px; margin: 0 14px; font-size: 20px; }
.sidebar .brand small { font-size: 11px; }
.account-menu { position: relative; flex: none; }
.account-menu summary {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: var(--muted);
  list-style: none;
  cursor: pointer;
}
.account-menu summary::-webkit-details-marker { display: none; }
.account-menu summary svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }
.account-menu summary:hover, .account-menu[open] summary { background: var(--surface); color: var(--text); }
.account-menu-panel {
  position: absolute;
  inset: calc(100% + 4px) 0 auto auto;
  min-width: 124px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 8px 24px #0008;
}
.account-menu-panel .logout-button { width: 100%; min-height: 40px; padding: 8px 12px; border-radius: 8px; text-align: start; color: var(--text); }
.account-menu-panel .logout-button:hover { background: var(--surface-2); }
.workspace-nav { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; margin: 22px 0 0; padding: 0; }
.workspace-nav button {
  flex-direction: row;
  gap: 16px;
  min-height: 48px;
  padding: 10px 14px;
  border-radius: 999px;
  color: var(--text);
  font-size: 16px;
}
.workspace-nav button[aria-current="true"] { background: var(--surface); color: var(--text); font-weight: 750; }
.workspace-nav button[aria-current="true"] svg { stroke: var(--accent); stroke-width: 2; }
.workspace-nav svg { width: 23px; height: 23px; }
.app-layout .workspace { min-width: 0; width: 100%; margin: 0; padding: 0; min-height: 100svh; border-inline: 1px solid var(--line); }
.workspace-heading { position: sticky; top: 0; z-index: 26; gap: 12px; min-height: 61px; padding: 10px var(--feed-padding); background: var(--bg); }
.workspace-heading h1 { margin: 0; font-size: 20px; font-weight: 800; }
.workspace-heading p { margin-top: 4px; font-size: 12px; }
.workspace-heading .cloud-shortcut { min-height: 36px; gap: 8px; padding: 6px 14px; }
.workspace-heading .cloud-shortcut[hidden] { display: none; }
.context-rail { align-self: start; position: sticky; top: 16px; min-width: 0; padding-top: 1px; }
.context-panel { padding: 16px; border: 1px solid var(--line); border-radius: 16px; }
.context-panel summary { cursor: pointer; font-size: 16px; font-weight: 750; }
.context-panel .sidebar-context { position: static; display: grid; max-width: none; margin: 14px 0; padding: 0; }
.context-panel #deployment-kind { display: block; }
.context-panel .service-state { color: var(--text); font-size: 12px; overflow-wrap: anywhere; }
.context-panel .capacity { padding: 14px 0 0; border-top: 1px solid var(--line); }
.context-panel .capacity-copy strong { font-size: 16px; letter-spacing: 0; }
.context-panel .capacity-track { height: 4px; margin: 10px 0 6px; border-radius: 999px; }
.context-panel .capacity small { font-size: 11px; overflow-wrap: anywhere; }

/* A single flow for composers, media entries and task history. */
.library-page [data-workspace] { min-width: 0; padding: 0 var(--feed-padding) 20px; }
.library-page .cloud-download { padding-top: 16px; }
.cloud-download summary { gap: 8px; }
.cloud-download summary h2 { font-weight: 750; }
.cloud-download textarea { min-height: 112px; padding: 12px 0; border: 0; border-radius: 0; background: transparent; font-size: 17px; }
.cloud-download textarea:focus { outline: none; box-shadow: inset 0 -1px var(--accent); }
.cloud-download form { margin-top: 12px; }
.cloud-download form > label { margin-bottom: 0; color: var(--muted); }
.cloud-controls { gap: 8px 14px; border-top: 1px solid var(--line); }
.cloud-controls .cloud-mode { margin: 0; }
.cloud-controls #cloud-submit { margin-inline-start: auto; }
.cloud-mode select { border-radius: 999px; }
.cloud-history-head { margin: 16px 0 0; border-top: 1px solid var(--line); }
.cloud-tasks { max-height: none; overflow: visible; }
.cloud-task { gap: 6px 12px; min-height: 0; padding-block: 14px; grid-template-columns: minmax(0, 1fr) auto; }
.cloud-task-copy { grid-column: 1 / -1; }
.cloud-task-copy strong { display: block; font-size: 14px; font-weight: 700; }
.cloud-task-detail { display: block; margin-top: 4px; color: var(--muted); overflow-wrap: anywhere; }
.cloud-task-actions { justify-self: start; }
.cloud-task-actions .play-link { border: 1px solid var(--line); border-radius: 999px; background: var(--surface); }
.library-page .local-queue { min-height: 0; }
.local-queue .section-heading { margin: 16px 0 4px; }
.library-page .local-queue .empty { padding: 10px 0; }
.library-page .library-tabs { margin: 0 calc(-1 * var(--feed-padding)) 16px; padding-inline: var(--feed-padding); gap: 22px; }
.library-tabs button { min-height: 48px; border-bottom-width: 3px; padding-block: 12px; font-weight: 650; }
.library-tabs button[aria-pressed="true"] { color: var(--text); }
.library-page .library-head { flex-wrap: wrap; align-items: start; margin-bottom: 10px; gap: 12px; }
.library-page :is(.library-tools, .library-head > div) { min-width: 0; }
.library-page .library-tools { align-items: center; gap: 8px; }
.library-page .search { min-width: min(190px, 100%); width: auto; border-radius: 999px; border-color: transparent; }
.library-page .search:focus-within { border-color: var(--accent); }
.library-page .search input { min-width: 0; }
.library-page :is(.magnet-library, .settings-workspace) { padding-top: 16px; }
.library-page .sync-detail { margin-bottom: 8px; }
.library-page .media-row {
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  min-height: 0;
  padding-block: 14px;
}
.library-page .media-name strong {
  display: block;
  white-space: normal;
  overflow-wrap: anywhere;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.45;
}
.library-page .media-name small {
  display: block;
  margin-top: 3px;
  white-space: normal;
  overflow-wrap: anywhere;
}
.library-page .media-row-metadata { font-variant-numeric: tabular-nums; }
.library-page .media-row .media-actions { display: flex; justify-content: flex-start; flex-wrap: wrap; gap: 8px; }
.library-page .media-actions > :is(.play-link, .media-delete, .media-organize-disabled),
.library-page .media-actions > :is(.media-organize, .local-save) > summary {
  width: auto;
  min-height: 34px;
  padding: 6px 12px;
  border-radius: 999px;
  background: transparent;
}
.media-organize > div, .save-options {
  left: 0;
  right: auto;
  background: var(--surface);
  max-width: min(260px, calc(100vw - 90px));
}
.library-page .local-media-row { grid-template-columns: minmax(0, 1fr) auto; }
.library-page .local-media-row .media-meta { display: none; }
.library-page .local-media-row .play-link { justify-self: start; }
.disk-ledger { gap: 8px; margin-bottom: 16px; }
.disk-item { padding: 0 0 12px; }
.magnet-library-row { grid-template-columns: minmax(0, 1fr); gap: 8px; padding-block: 14px; }
.magnet-library-actions { justify-content: flex-start; }
.catalog-columns { display: none; }
.catalog-row { grid-template-columns: minmax(0, 1fr) auto; gap: 6px 12px; padding-block: 14px; }
.catalog-kind { grid-column: 2; grid-row: 1; text-align: right; }
.catalog-path { grid-column: 1 / -1; grid-row: 2; }
.catalog-row-actions { grid-column: 1 / -1; justify-content: flex-start; flex-wrap: wrap; margin-top: 2px; }
.library-page .library-footer { margin: 14px 0 0; padding: 12px var(--feed-padding); gap: 4px 12px; }
#workspace-notice { margin: 8px var(--feed-padding); }
#workspace-notice:empty, .cloud-feedback:empty, .cloud-preview:empty { display: none; }

/* Playback retains the video geometry and brings related details together. */
.player-topbar { background: var(--bg); border-bottom: 1px solid var(--line); }
.player-shell { width: min(1240px, 100%); }
.player-summary { padding-block: 14px clamp(18px, 2vw, 24px); }
.player-heading h1 { font-size: clamp(18px, 2.2vw, 25px); font-weight: 750; letter-spacing: -.02em; }
.player-heading h1:empty, .video-loading p:empty { display: none; }
.video-loading { background: #080808; pointer-events: none; }
.video-loading:has(p:empty) { grid-template-rows: auto; gap: 0; }
.video-loading p { margin: 0; padding-inline: 12px; text-align: center; }
.seek-loading {
  position: absolute;
  z-index: 19;
  top: 50%;
  left: 50%;
  width: 24px;
  height: 24px;
  margin: -12px 0 0 -12px;
  border: 2px solid rgba(255, 255, 255, .55);
  border-top-color: var(--accent);
  border-radius: 50%;
  filter: drop-shadow(0 1px 2px #000);
  animation: spin .8s linear infinite;
  pointer-events: none;
}
.seek-preview.is-visible + .seek-loading { margin-top: 20px; }
.player-info { padding-top: 4px; animation: none; }
.player-tools { gap: 8px 16px; }
.subtitle-dialog, #subtitle-preview-dialog > header { background: var(--bg); }
.episode-panel { margin-top: 18px; padding-top: 12px; }
.episode-list { gap: 0 12px; }
.episode-link[aria-current="true"] { background: var(--surface); }
.login-panel { border: 1px solid var(--line); border-radius: 20px; padding: clamp(20px, 5vw, 40px); background: var(--bg); }
.login-page { background: var(--bg); }
.login-copy { margin: 32px 0 24px; }
.login-copy h1 { font-size: clamp(24px, 5vw, 36px); line-height: 1.2; letter-spacing: -.03em; }
.login-copy > p:last-child { margin-top: 8px; font-size: 13px; }
.login-form input { padding-inline: 12px; border: 1px solid var(--line); border-radius: 12px; }
.login-form .primary-button { width: 100%; }

@media (max-width: 1120px) {
  .app-layout { grid-template-columns: 70px minmax(0, 760px); gap: 12px; }
  .app-layout .sidebar { grid-row: 1 / 3; }
  .context-rail { position: static; grid-column: 2; margin: 0 0 16px; }
  .sidebar .brand { justify-content: center; margin: 0; }
  .sidebar .brand > span:last-child { display: none; }
  .workspace-nav { align-items: center; }
  .workspace-nav button { gap: 0; width: 48px; justify-content: center; }
  .workspace-nav button span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .sidebar-header { flex-direction: column; padding: 0; }
  .account-menu-panel { inset-inline: 0 auto; }
}

@media (max-width: 640px) {
  :root { --feed-padding: 14px; }
  .app-layout { display: flex; flex-direction: column; gap: 0; padding: 0 0 calc(66px + env(safe-area-inset-bottom)); }
  .app-layout .sidebar { position: static; height: auto; width: 100%; padding: 8px var(--feed-padding); border-bottom: 1px solid var(--line); flex-direction: row; align-items: center; justify-content: space-between; }
  .sidebar .brand > span:last-child { display: inline; font-size: 16px; }
  .sidebar .brand small { display: none; }
  .sidebar .brand-mark { width: 21px; height: 23px; }
  .sidebar-header { width: 100%; flex-direction: row; }
  .account-menu summary { width: 44px; height: 44px; }
  .account-menu-panel { inset-inline: auto 0; }
  .workspace-nav {
    position: fixed;
    z-index: 30;
    inset: auto 0 0;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0;
    margin: 0;
    padding: 3px 0 env(safe-area-inset-bottom);
    background: var(--bg);
    border-top: 1px solid var(--line);
  }
  .workspace-nav button { width: 100%; min-height: 54px; flex-direction: column; gap: 4px; padding: 4px 0; font-size: 11px; border-radius: 0; }
  .workspace-nav button[aria-current="true"] { background: transparent; color: var(--accent); }
  .workspace-nav button span { position: static; width: auto; height: auto; clip-path: none; overflow: visible; }
  .workspace-nav svg { width: 21px; height: 21px; }
  .app-layout .workspace { border-inline: 0; min-height: 0; }
  .workspace-heading { align-items: center; min-height: 52px; }
  .workspace-heading h1 { font-size: 18px; }
  .workspace-heading p { display: none; }
  .context-rail { margin: 12px var(--feed-padding); }
  .library-page .library-head { flex-direction: column; align-items: stretch; }
  .library-page .library-tools { width: 100%; justify-content: flex-start; }
  .library-page .library-tools .search { flex: 1 1 100%; }
  .library-page .sort-control { width: auto; }
  .sort-control select { min-width: 0; }
  .catalog-heading { flex-wrap: wrap; }
  .player-topbar .brand { font-size: 14px; gap: 7px; }
}

@media (max-height: 470px) and (min-width: 641px) {
  .app-layout .sidebar { overflow-y: auto; }
}

.subtitle-heading h2 { margin: 0 0 4px; font-size: 16px; }

.player-title-placeholder { display: none; }
.player-summary[aria-busy="true"] .player-title-placeholder {
  display: block;
  width: min(240px, 68%);
  height: 18px;
  margin-block: 4px;
  border-radius: 4px;
  background: var(--surface);
}
.player-summary[aria-busy="true"] .media-facts { visibility: hidden; }
.play-link[aria-busy="true"], .episode-link[aria-busy="true"] { position: relative; cursor: progress; }
.play-link[aria-busy="true"] { color: transparent !important; }
.play-link[aria-busy="true"]::after, .episode-link[aria-busy="true"]::after {
  content: "";
  position: absolute;
  width: 13px;
  height: 13px;
  inset: 0;
  margin: auto;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
