button, a[href], input[type="range"] {
  touch-action: manipulation;
}

* {
  box-sizing: border-box;
}
html {
  background: var(--ui-page, #080809);
}
body {
  margin: 0;
  color: var(--ui-text, #f8f7f4);
  font:
    16px/1.5 -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    "PingFang SC",
    sans-serif;
  background: var(--ui-page, #101011);
  min-height: 100dvh;
}
main {
  max-width: 780px;
  margin: auto;
  --gutter: clamp(16px, 3vw, 24px);
  padding: calc(env(safe-area-inset-top) + 8px) max(var(--gutter), env(safe-area-inset-right)) calc(104px + env(safe-area-inset-bottom)) max(var(--gutter), env(safe-area-inset-left));
}
.library-controls { display: flex; align-items: center; gap: 2px; }
.order-control { position: relative; }
#order-toggle {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ui-muted, #ccc8c4);
}
#library-order {
  position: absolute;
  z-index: 5;
  inset-inline-end: 0;
  top: 100%;
  width: max-content;
  padding: 3px;
  background: var(--ui-surface, #242426);
  border: 1px solid var(--ui-line, #ffffff26);
  border-radius: 10px;
  box-shadow: 0 6px 18px #0005;
}
#library-order button {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 44px;
  padding: 0 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  font-size: 14px;
  white-space: nowrap;
}
#library-order button::before {
  content: "";
  width: 10px;
  height: 6px;
  box-sizing: border-box;
}
#library-order [aria-checked="true"]::before {
  border-left: 2px solid var(--ui-accent, #ffd65a);
  border-bottom: 2px solid var(--ui-accent, #ffd65a);
  transform: translateY(-1px) rotate(-45deg);
}
#library-order button:focus-visible { outline-offset: -2px; }
@media (hover: hover) and (pointer: fine) {
  #order-toggle:hover, #library-order button:hover, #settings-open:hover { background: var(--ui-hover, #ffffff0d); }
}
#settings-open { display: grid; place-items: center; background: transparent; border: 0; color: var(--ui-muted, #ccc8c4); min-height: 44px; min-width: 44px; padding: 0 6px; font-size: 14px; }
header {
  margin-bottom: 4px;
  border-bottom: 1px solid var(--ui-line, #ffffff1a);
}
header,
.brand,
.dialog-head,
.row,
.check {
  display: flex;
  align-items: center;
}
header,
.dialog-head {
  justify-content: space-between;
  gap: 12px;
}
.brand {
  margin: 0;
  font-size: 18px;
  font-weight: 650;
  letter-spacing: 0;
  gap: 9px;
}
.brand img {
  width: 28px;
  height: 28px;
  border-radius: 10px;
}
button,
a {
  font: inherit;
  cursor: pointer;
}
button,
#action-list a {
  color: inherit;
  background: var(--ui-control, #262629);
  border: 1px solid var(--ui-line, #ffffff17);
  border-radius: 11px;
  padding: 8px 13px;
}
button:hover,
#action-list a:hover {
  background: var(--ui-hover, #353538);
}
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--ui-accent, #ffd65a);
  outline-offset: 3px;
}
button:disabled {
  opacity: 0.5;
}
.primary {
  background: #ffd65a;
  color: #201d16;
  font-weight: 650;
}
.primary:hover {
  background: #ffe28a;
}
#new-open {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 1;
  display: grid;
  place-content: center;
  width: 56px;
  height: 56px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  font: 400 32px/1 sans-serif;
}
.hint,
label,
#status,
.meta,
.empty,
.job small {
  color: var(--ui-muted, #aaa7a6);
  font-size: 14px;
}
#library,
#jobs {
  display: grid;
  gap: 12px;
}
.job {
  border: 1px solid var(--ui-line, #ffffff13);
  background: var(--ui-surface, #171719);
  border-radius: 18px;
  padding: 16px;
}
#library { gap: 0; }
main:has(#library-loading:not([hidden])) {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}
#library-loading {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 20px 0;
  color: var(--ui-muted, #aaa7a6);
  font-size: 14px;
}
#library-loading::before {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid var(--ui-line, #444);
  border-top-color: currentColor;
  border-radius: 50%;
}
@media (prefers-reduced-motion: no-preference) {
  #library-loading::before { animation: library-spin 900ms linear infinite; }
}
@keyframes library-spin { to { transform: rotate(1turn); } }
.card + .card { border-top: 1px solid var(--ui-line, #ffffff0e); }
.row-front {
  flex: 0 0 100%;
  min-width: 0;
  position: relative;
  z-index: 1;
  background: var(--ui-page, #101011);
  touch-action: pan-y pinch-zoom;
  transition: transform 160ms ease-out;
  padding: 12px 0;
  display: flex;
  align-items: center;
  gap: 14px;
}
.cover {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  flex: none;
  border-radius: 12px;
  background: linear-gradient(145deg, #564a3e, #302a25);
}
.cover.ted { background: linear-gradient(145deg, #903f3b, #51292b); }
.cover.url { background: linear-gradient(145deg, #34555c, #223438); }
.cover.image { background: linear-gradient(145deg, #575070, #332f40); }
.cover-play {
  display: grid;
  place-items: center;
  width: 29px;
  height: 29px;
  border-radius: 50%;
  background: rgb(20 20 20 / 16%);
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 16%);
}
.cover-play::after {
  content: "";
  border-left: 10px solid rgb(255 255 255 / 75%);
  border-block: 6px solid transparent;
  margin-left: 2px;
}
@media (hover: hover) and (pointer: fine) {
  .cover:hover .cover-play { background: rgb(20 20 20 / 28%); }
  .book:hover strong { text-decoration: underline; text-underline-offset: 3px; }
}
.cover:active .cover-play, #new-open:active { scale: .96; }
.book {
  min-width: 0;
  flex: 1;
  color: inherit;
  text-decoration: none;
}
.book strong {
  display: block;
  font-size: 18px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}
.sub {
  display: block;
  color: var(--ui-muted, #c2bfba);
  font-size: 14px;
  margin: 3px 0;
}
.meta {
  display: block;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}
.card progress,
.job progress {
  display: block;
  height: 3px;
  width: 100%;
  margin-top: 9px;
  accent-color: var(--ui-accent, #ffd65a);
  border: 0;
  border-radius: 9px;
  overflow: hidden;
}
progress::-webkit-progress-bar {
  background: var(--ui-hover, #353536);
}
progress::-webkit-progress-value {
  background: #ffd65a;
}
.job {
  overflow-wrap: anywhere;
  margin-bottom: 10px;
}
.job small {
  display: block;
}
.empty {
  padding: 24px;
  border: 1px dashed var(--ui-line, #444);
  border-radius: 15px;
}
.error {
  color: var(--ui-danger, #ffae9d);
}
#status {
  margin-bottom: 12px;
}
#demo {
  margin-bottom: 15px;
}
dialog {
  width: min(480px, calc(100% - 24px));
  max-height: 88dvh;
  border: 1px solid var(--ui-line, #424244);
  border-radius: 20px;
  padding: 22px;
  background: var(--ui-surface, #19191b);
  color: var(--ui-text, white);
}
dialog::backdrop {
  background: #000b;
  backdrop-filter: blur(4px);
}
h2 {
  font-size: 22px;
  margin: 0;
}
.dialog-head {
  margin-bottom: 15px;
}
.close {
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 22px;
}
label {
  display: grid;
  gap: 5px;
  margin: 12px 0;
}
input,
textarea,
select {
  min-width: 0;
  width: 100%;
  background: var(--ui-page, #101011);
  color: var(--ui-text, white);
  border: 1px solid var(--ui-line, #48484b);
  border-radius: 9px;
  padding: 10px;
  font: inherit;
}
.check input {
  width: auto;
}
.check {
  gap: 8px;
}
.hint {
  margin-top: -5px;
}
.error:empty {
  display: none;
}
nav {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
nav button {
  font-size: 13px;
  padding: 6px 9px;
}
nav button[aria-pressed="true"] {
  color: var(--ui-accent, #ffda79);
  border-color: var(--ui-accent, #a98e4e);
}
#previews {
  padding: 0;
}
#previews li {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 6px 0;
}
#previews li span {
  flex: 1;
  overflow-wrap: anywhere;
  font-size: 12px;
}
#previews img {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 5px;
}
#action-list {
  display: grid;
  gap: 8px;
}
#action-list a {
  text-decoration: none;
  text-align: center;
}
[hidden] {
  display: none !important;
}
@media (max-width: 500px) {
  .row-front {
    gap: 10px;
  }
  .cover {
    width: 48px;
    height: 48px;
  }
  .book strong {
    font-size: 16px;
  }
}

#action-list { gap: 0; }
#action-list > :is(a, button) {
  min-height: 44px;
  padding: 10px 4px;
  border: 0;
  border-radius: 0;
  border-bottom: 1px solid var(--ui-line, #ffffff12);
  background: transparent;
  text-align: start;
}
#action-list > :last-child { border: 0; }
#action-list .destructive { color: var(--ui-danger, #ffafa6); }
@media (max-width: 500px) {
  #actions {
    margin: auto 0 0;
    width: 100%;
    max-width: 100%;
    padding: 16px 20px calc(14px + env(safe-area-inset-bottom));
    border-radius: 20px 20px 0 0;
  }
  #actions .close { min-width: 44px; min-height: 44px; }
  #actions .dialog-head { margin-bottom: 4px; }
}

#filter-toggle {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  background: transparent;
  color: var(--ui-muted, #ccc8c4);
}
#filter-toggle[aria-expanded="true"] { color: var(--ui-accent, #ffd65a); }
#library-filters { padding: 10px 0 4px; }
.filter-options, .filter-options label { display: flex; align-items: center; }
.filter-options { justify-content: space-between; }
.filter-options label { gap: 8px; min-height: 44px; margin: 0; color: inherit; }
#offline-only { width: 16px; height: 16px; accent-color: var(--ui-accent, #ffd65a); }
#clear-filters { min-height: 44px; border: 0; background: transparent; font-size: 14px; }
#filter-result { margin: 0; color: var(--ui-muted, #aaa7a6); font-size: 14px; }

#library { grid-template-columns: minmax(0, 1fr); }
.card { position: relative; overflow: hidden; }
.dragging .row-front { transition: none; }
.row-open .row-front { transform: translateX(calc(-1 * var(--rail-width))); }
.row-actions {
  position: absolute;
  inset: 0 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding-left: 12px;
  visibility: hidden;
}
.row-open .row-actions, .dragging .row-actions { visibility: visible; }
@media (prefers-reduced-motion: reduce) {
  .row-front { transition: none; }
}
.row-actions button { min-height: 44px; }
.cover { position: relative; overflow: hidden; isolation: isolate; text-decoration: none; }
.row-front :focus-visible { outline-offset: -2px; }
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cover-initial { font: 600 24px/1 system-ui, sans-serif; color: #fff; }
.cover .cover-play { position: absolute; inset: 0; margin: auto; }
.cover-play::after { border-left-width: 6px; border-block-width: 4px; }
#create-fields { margin: 0; padding: 0; border: 0; min-width: 0; }
#create-fields:disabled { opacity: .58; }
#admin-unlock { border-bottom: 1px solid var(--ui-line, #ffffff24); padding-bottom: 14px; margin-bottom: 18px; }
