/* The app uses the Telegram theme. The values after the comma are for a normal browser. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #efeff4);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --sub: var(--tg-theme-subtitle-text-color, var(--hint));
  --link: var(--tg-theme-link-color, #2481cc);
  --accent: var(--tg-theme-accent-text-color, var(--link));
  --button: var(--tg-theme-button-color, #2481cc);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --header: var(--tg-theme-section-header-text-color, var(--hint));
  --danger: var(--tg-theme-destructive-text-color, #e53935);
  --separator: var(--tg-theme-section-separator-color, rgba(128, 128, 128, 0.2));
  --soft: rgba(128, 128, 128, 0.12);

  /* The colors of the episode stages. They are the same in light and dark themes. */
  --st-queued: #9a9aa2;
  --st-download: #2f80ed;
  --st-encode: #8e5ad8;
  --st-upload: #0ea5a5;
  --st-retry: #f2994a;
  --st-done: #2fb36b;
  --st-failed: #eb5757;

  --radius: 12px;
  --gap: 16px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  html:not(.in-telegram) {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #ffffff;
    --hint: #98989f;
    --link: #3e88f7;
    --button: #3e88f7;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow-wrap: anywhere;
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 8px 0 calc(32px + var(--tg-safe-area-inset-bottom, 0px));
}

a { color: var(--link); text-decoration: none; }
code, .mono { font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
[hidden] { display: none !important; }

/* region layout */

.page-header { padding: 8px var(--gap) 12px; }
.page-header h1 { font-size: 22px; line-height: 1.25; margin: 0 0 4px; font-weight: 700; }
.home-header h1 { font-size: 26px; }
.overline { margin: 0 0 2px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--hint); }
.title-row { display: flex; align-items: flex-start; gap: 4px; }
.title-row h1 { flex: 1; min-width: 0; }
.edit-btn { width: 36px; height: 36px; margin-top: -2px; color: var(--link); display: grid; place-items: center; }
.page-header .inline-form { margin: 8px 0 4px; }
.page-header .link-box { margin: 6px 0; }

/* A link in a rounded box: the first three lines, and a copy button on the right. */
.link-box {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 4px 8px 12px; border-radius: 10px;
  background: var(--soft); cursor: pointer;
  -webkit-user-select: none; user-select: none;
}
.link-box:active { opacity: 0.6; }
.link-box-text {
  flex: 1; min-width: 0;
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--sub); word-break: break-all;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3; overflow: hidden;
}
.link-box-copy {
  flex: none; display: grid; place-items: center;
  width: 40px; height: 40px; border: 0; border-radius: 8px;
  background: none; color: var(--link); cursor: pointer;
}
.row-extra { padding: 0 var(--gap) 12px; }
.row-extra.with-icon { padding-left: calc(var(--gap) + 36px); }

.section { margin: 0 var(--gap) 20px; }
.section-header {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  margin: 0 var(--gap) 6px; padding: 0;
  font-size: 13px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.02em;
  color: var(--header);
}
.section-header { overflow-wrap: normal; }
.section-header .link-btn { text-transform: none; letter-spacing: 0; font-size: 14px; white-space: nowrap; }
.section-footer { margin: 6px var(--gap) 0; font-size: 13px; color: var(--hint); }

.card {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
}
.card:not(.list) { padding: 12px var(--gap); }
.card + .card, #invite > .card, #gc { margin-top: 8px; }

.hint { color: var(--hint); font-size: 14px; margin: 4px 0 0; }
.text-danger { color: var(--danger); }
.text-hint { color: var(--hint); }

/* endregion */

/* region lists and rows */

.list { list-style: none; margin: 0; padding: 0; }
.list > li + li, .list > .row + .row, .list > .row-link + .row, .list > .row + .row-link,
.list > label + label, .list > label + .row, .list > .row-link + .row-link {
  border-top: 0.5px solid var(--separator);
}

.row, .row-link {
  display: flex; align-items: center; gap: 12px;
  min-height: 44px; padding: 10px var(--gap);
  color: var(--text);
}
.row.column { flex-direction: column; align-items: stretch; gap: 6px; }
.row-link:active, button.row:active, label.row:active { background: var(--soft); }
.row-chevron::after { content: "›"; padding-left: 4px; color: var(--hint); font-size: 22px; line-height: 1; }
.row-chevron > .row-title, .row-chevron > .row-text { flex: 1; }
.row-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.row-title { font-size: 16px; }
.row-sub { font-size: 13px; color: var(--sub); }
.row-value { margin-left: auto; color: var(--hint); text-align: right; }
.row-icon .icon { font-size: 18px; width: 24px; text-align: center; flex: none; }
.row-actions { display: flex; gap: 8px; flex: none; }
.list.compact .row { min-height: 0; padding-top: 8px; padding-bottom: 8px; }

button.row {
  width: 100%; border: 0; background: none; font: inherit; text-align: left; cursor: pointer;
}
.danger-row { color: var(--danger) !important; }
.link-row { color: var(--link) !important; }

/* endregion */

/* region controls */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 16px;
  border: 0; border-radius: 10px;
  background: var(--soft); color: var(--link);
  font: 600 15px/1.2 inherit; font-family: inherit;
  white-space: nowrap; overflow-wrap: normal; flex: none;
  cursor: pointer;
}
.btn:active { opacity: 0.7; }
.btn:disabled { opacity: 0.4; }
.btn-primary { background: var(--button); color: var(--button-text); }
.btn-danger { background: var(--danger); color: #ffffff; }
.btn-small { min-height: 32px; padding: 6px 12px; font-size: 14px; }
.btn-wide { width: 100%; flex: 1 1 auto; }

.link-btn {
  border: 0; background: none; padding: 0; color: var(--link);
  font: inherit; cursor: pointer; list-style: none;
}
.link-btn::-webkit-details-marker { display: none; }

.icon-btn {
  flex: none; width: 44px; height: 44px; border: 0; background: none;
  color: var(--hint); font-size: 16px; cursor: pointer;
}

.input {
  width: 100%; min-height: 40px; padding: 8px 12px;
  border: 0; border-radius: 10px;
  background: var(--soft); color: var(--text);
  font: inherit; outline: none;
}
.input:focus { box-shadow: 0 0 0 2px var(--button); }
.input::placeholder { color: var(--hint); }

input[type=checkbox], input[type=radio] {
  width: 22px; height: 22px; margin: 0; flex: none;
  accent-color: var(--button);
}

.switch {
  appearance: none; -webkit-appearance: none;
  position: relative; width: 51px !important; height: 31px !important;
  border-radius: 16px; background: var(--soft); cursor: pointer;
  transition: background 0.2s;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 27px; height: 27px; border-radius: 50%;
  background: #ffffff; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s;
}
.switch:checked { background: var(--st-done); }
.switch:checked::after { transform: translateX(20px); }
.switch.htmx-request { opacity: 0.6; }

.paste-form, .inline-form, .rename-form { display: flex; gap: 8px; align-items: center; }

.actions { margin: 0 var(--gap) 20px; }
.actions-row { display: flex; gap: 8px; }
.actions-row .btn-wide { width: auto; flex: 1 1 0; }
.in-telegram .fallback-only { display: none !important; }
/* A Telegram client without the secondary button uses the buttons of the page. */
.in-telegram .html-buttons .actions-row.fallback-only { display: flex !important; }

.select-all { user-select: all; -webkit-user-select: all; word-break: break-all; display: block; }
.invite { display: flex; flex-direction: column; gap: 12px; }

/* endregion */

/* region chips and pills */

.chips { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.chip {
  display: inline-block; padding: 2px 8px; border-radius: 6px;
  background: var(--soft); color: var(--text); font-size: 12px; line-height: 18px;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.keep-icon { display: inline-block; vertical-align: -2px; color: var(--hint); }
.chip .keep-icon { vertical-align: -3px; }
.chip-warn { color: var(--st-retry); }
.chip-muted { color: var(--hint); background: none; padding-left: 0; }
.chip-link { color: var(--link); }

.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 8px; border-radius: 10px;
  font-size: 12px; font-weight: 600; line-height: 18px;
  color: #ffffff;
}
.pill.st-queued { background: var(--st-queued); }
.pill.st-download { background: var(--st-download); }
.pill.st-encode { background: var(--st-encode); }
.pill.st-upload { background: var(--st-upload); }
.pill.st-retry { background: var(--st-retry); }
.pill.st-done { background: var(--st-done); }
.pill.st-failed { background: var(--st-failed); }

/* endregion */

/* region progress */

.bar {
  display: flex; height: 8px; border-radius: 4px; overflow: hidden;
  background: var(--soft); margin: 8px 0;
}
.bar-part { height: 100%; transition: width 0.4s ease; }
.bar-part + .bar-part { box-shadow: -1px 0 0 var(--card); }
.st-queued.bar-part, .dot.st-queued { background: var(--st-queued); }
.st-download.bar-part, .dot.st-download { background: var(--st-download); }
.st-encode.bar-part, .dot.st-encode { background: var(--st-encode); }
.st-upload.bar-part, .dot.st-upload { background: var(--st-upload); }
.st-retry.bar-part, .dot.st-retry { background: var(--st-retry); }
.st-done.bar-part, .dot.st-done { background: var(--st-done); }
.st-failed.bar-part, .dot.st-failed { background: var(--st-failed); }

/* The parts that are in progress move. */
.bar-part.st-download, .bar-part.st-encode, .bar-part.st-upload {
  background-image: linear-gradient(-45deg, rgba(255, 255, 255, 0.25) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.25) 50%, rgba(255, 255, 255, 0.25) 75%, transparent 75%);
  background-size: 16px 16px;
  animation: stripes 1s linear infinite;
}
@keyframes stripes { to { background-position: 16px 0; } }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex: none; }

.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--sub); }
.legend li { display: inline-flex; align-items: center; gap: 6px; }

.summary-numbers { display: flex; align-items: baseline; gap: 8px; }
.big { font-size: 34px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.big .of { font-size: 18px; font-weight: 500; color: var(--hint); }
.summary-label { color: var(--hint); }
.feeds-edit { padding: 0 !important; }
.feeds-edit > summary {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  padding: 12px var(--gap); cursor: pointer; list-style: none;
}
.feeds-edit > summary::-webkit-details-marker { display: none; }
.feeds-edit > summary .hint { margin: 0; }
.feeds-edit .edit-toggle { margin-left: auto; }
.feeds-edit .when-open, .feeds-edit[open] .when-closed { display: none; }
.feeds-edit[open] .when-open { display: inline; }
.feeds-edit > .list { border-top: 0.5px solid var(--separator); }

.row-text > .bar { margin: 6px 0 4px; }

/* The steps of an episode: Download, Encode, Upload, Ready. */
.steps { list-style: none; display: flex; margin: 8px 0 4px; padding: 0; }
.step { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; position: relative; font-size: 11px; color: var(--hint); }
.step::before {
  content: ""; position: absolute; top: 5px; right: 50%; width: 100%; height: 2px;
  background: var(--soft); z-index: 0;
}
.step:first-child::before { display: none; }
.step-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--soft); position: relative; z-index: 1; }
.step-done .step-dot, .step-done::before { background: var(--st-done); }
.step-now .step-dot { background: var(--st-download); box-shadow: 0 0 0 4px rgba(47, 128, 237, 0.25); animation: pulse 1.4s ease-in-out infinite; }
.step-now, .step-retry, .step-failed { color: var(--text); font-weight: 600; }
.step-now::before, .step-retry::before, .step-failed::before { background: var(--st-done); }
.step-retry .step-dot { background: var(--st-retry); animation: pulse 1.4s ease-in-out infinite; }
.step-failed .step-dot { background: var(--st-failed); }
@keyframes pulse { 50% { transform: scale(1.25); } }

.ep-body .steps { margin: 6px 0 4px; }

.status-card .steps { margin-top: 4px; }
.status-line { display: flex; align-items: center; gap: 8px; margin: 8px 0 0; font-size: 14px; color: var(--sub); }
.ep-error { display: block; font-size: 13px; color: var(--danger); white-space: pre-wrap; }

.history { margin-top: 12px; }
.history summary { cursor: pointer; list-style: none; padding: 4px 0; justify-content: flex-start; }
.history summary::-webkit-details-marker { display: none; }
.history summary::after { content: " ▾"; }
.timeline { list-style: none; margin: 0; padding: 4px 0 !important; }
.timeline li { display: flex; align-items: baseline; gap: 10px; padding: 6px var(--gap); font-size: 14px; }
.timeline .time { width: 56px; flex: none; color: var(--hint); font-variant-numeric: tabular-nums; text-align: right; }
.timeline .dot { position: relative; top: -1px; }

.player { padding: 8px !important; }
.player audio { width: 100%; display: block; }

/* endregion */

/* region episodes */

.ep-row { display: flex; align-items: stretch; }
.ep-row .row-link { flex: 1; min-width: 0; }
.row-link.with-thumb { gap: 12px; }
.row-link.with-thumb.top { align-items: flex-start; }
.ep-body { display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 0; }

/* The covers of the episodes. */
.thumb { flex: none; width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: var(--soft); }
.thumb-empty { display: grid; place-items: center; color: var(--hint); }
.cover {
  display: block; width: min(220px, 60vw); aspect-ratio: 1; object-fit: cover;
  margin: 4px auto 16px; border-radius: 14px; background: var(--soft);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}
.ep-row.with-action .row-link { padding-right: 0; }
.ep-row.with-action .icon-btn { align-self: center; }
.ep-title { font-size: 15px; font-weight: 500; }
.ep-num { color: var(--hint); font-weight: 400; font-variant-numeric: tabular-nums; }
.ep-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; font-size: 13px; color: var(--sub); }
.ep-feeds { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }

.selectable-row .check { display: flex; align-items: center; padding-left: var(--gap); cursor: pointer; }
.selectable-row .row-link { padding-left: 12px; }

.tabs { display: flex; gap: 6px; margin: 0 var(--gap) 12px; overflow-x: auto; scrollbar-width: none; }
.tab {
  flex: none; padding: 6px 14px; border-radius: 16px;
  background: var(--card); color: var(--text); font-size: 14px;
}
.tab-active { background: var(--button); color: var(--button-text); }

.selection-bar {
  position: sticky; bottom: calc(12px + var(--tg-safe-area-inset-bottom, 0px));
  display: flex; align-items: center; gap: 16px;
  margin: 12px var(--gap) 0; padding: 10px var(--gap);
  border-radius: var(--radius); background: var(--card);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}
.selection-bar > span { flex: 1; }

.files { list-style: none; margin: 8px 0 0; padding: 0; color: var(--sub); }
.files li { padding: 2px 0; word-break: break-all; }

/* endregion */

/* region file tree */

.tree { padding: 4px 0 !important; }
.tree-file, .tree-folder > summary {
  display: flex; align-items: center; gap: 10px;
  min-height: 40px; padding: 6px var(--gap);
  cursor: pointer;
}
.tree-folder > summary { list-style: none; }
.tree-folder > summary::-webkit-details-marker { display: none; }
.tree-folder > summary::after { content: "▸"; color: var(--hint); margin-left: 4px; transition: transform 0.15s; }
.tree-folder[open] > summary::after { transform: rotate(90deg); }
.tree-children { padding-left: 20px; border-left: 1px solid var(--separator); margin-left: calc(var(--gap) + 10px); }
.tree-children .tree-file, .tree-children .tree-folder > summary { padding-left: 8px; }
.tree-name { flex: 1; min-width: 0; font-size: 15px; }
.tree-actions { display: flex; flex-wrap: wrap; gap: 4px 16px; padding: 6px var(--gap) 4px; font-size: 14px; }
.tree-children .tree-actions { padding-left: 8px; }
.order summary { cursor: pointer; margin-top: 2px; color: var(--link); }
.order-list { margin: 6px 0 0; padding: 8px var(--gap) 8px 40px !important; font-size: 13px; color: var(--sub); }
.order-list li { padding: 2px 0; word-break: break-all; }
.tree-meta { flex: none; font-size: 12px; color: var(--hint); }
.tree-picked { flex: none; font-size: 12px; font-weight: 600; color: var(--link); }

.radio-row, .check-row, .switch-row { cursor: pointer; }

/* endregion */

/* region states */

.loading { display: flex; justify-content: center; padding: 64px 0; }
.loading-card { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 32px var(--gap) !important; text-align: center; }
.loading-card p { margin: 0; }
.loading-row { justify-content: center; }
.spinner {
  width: 24px; height: 24px; border-radius: 50%;
  border: 3px solid var(--soft); border-top-color: var(--button);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.htmx-request.btn, .htmx-request .btn { opacity: 0.6; }

.empty { text-align: center; padding: 32px var(--gap); }
.empty.small { padding: 20px var(--gap); }
.empty p { color: var(--hint); margin: 4px 0 12px; }
.empty h2 { font-size: 18px; margin: 0; }
.empty-icon { font-size: 40px; margin-bottom: 8px; }

.toast {
  position: fixed; left: var(--gap); right: var(--gap);
  bottom: calc(16px + var(--tg-safe-area-inset-bottom, 0px));
  max-width: 560px; margin: 0 auto; padding: 12px var(--gap);
  border-radius: var(--radius);
  background: rgba(30, 30, 32, 0.94); color: #ffffff; font-size: 14px;
  transform: translateY(150%); opacity: 0;
  transition: transform 0.25s ease, opacity 0.25s ease;
  pointer-events: none; z-index: 10;
}
.toast-visible { transform: none; opacity: 1; }
.toast-error { background: var(--st-failed); }

/* endregion */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
