:root {
  --reader-bg: #f6f8f6;
  --reader-surface: rgba(255, 255, 255, 0.98);
  --reader-surface-soft: #f7fbf8;
  --reader-line: #dfe8e2;
  --reader-line-strong: #bfd3c6;
  --reader-text: var(--text, #0f172a);
  --reader-muted: var(--muted, #64748b);
  --reader-primary: var(--ok, #16a34a);
  --reader-primary-strong: #047857;
  --reader-primary-soft: var(--ok-bg, rgba(22, 163, 74, 0.08));
  --reader-cyan: #0f766e;
  --reader-green: var(--ok-text, #15803d);
  --reader-amber: #a16207;
  --reader-red: var(--danger-text, #b91c1c);
  --reader-progress-red: #dc2626;
  --reader-shadow: 0 12px 34px rgba(15, 23, 42, 0.07);
  --reader-shadow-soft: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 22px rgba(15, 23, 42, 0.06);
}

html:has(body.reader-page),
body.reader-page,
.reader-page .app-shell,
.reader-page .app-body {
  background: var(--reader-bg);
}

html:has(body.reader-page),
body.reader-page {
  height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
}

.reader-page .app-shell,
.reader-page .app-body {
  overflow-x: clip;
}

.reader-page .app-shell {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow-y: hidden;
}

.reader-page .app-body {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.reader-page .footer {
  background: var(--reader-bg);
  border-top: 1px solid var(--reader-line);
  color: var(--reader-muted);
  flex: 0 0 auto;
  font-family: var(--font-ui, sans-serif);
  font-size: 0.78rem;
  margin: auto 0 0;
  padding: 10px clamp(18px, 2.4vw, 34px) calc(10px + env(safe-area-inset-bottom));
}

.reader-page .startup-loader-card .startup-splash-loader {
  animation: reader-startup-spin 1.4s linear infinite;
  border: 3px solid rgba(148, 163, 184, 0.35);
  border-top-color: var(--accent);
  height: 38px;
  width: 38px;
}

@keyframes reader-startup-spin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

.page-topbar:has(.reader-section-tabs) {
  gap: 12px;
  min-height: 64px;
}

.page-topbar:has(.reader-section-tabs) .page-topbar-title {
  flex: 0 0 auto;
}

.page-topbar:has(.reader-section-tabs) .page-topbar-actions {
  gap: 10px;
  margin-left: auto;
}

.reader-layout {
  background: var(--reader-bg);
  color: var(--reader-text);
  display: grid;
  flex: 0 0 auto;
  gap: 14px;
  min-height: 0;
  padding: 16px clamp(18px, 2.4vw, 34px) 28px;
}

.reader-layout .sr-only {
  border: 0;
  clip: rect(0 0 0 0);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

.reader-head {
  align-items: end;
  display: flex;
  gap: 18px;
  justify-content: space-between;
}

.reader-kicker {
  color: var(--reader-cyan);
  font-size: 0.68rem;
  font-weight: 900;
  letter-spacing: 0;
  margin: 0 0 6px;
  text-transform: uppercase;
}

.reader-head h2,
.reader-panel h2,
.reader-player-shell h2 {
  color: var(--reader-text);
  line-height: 1.12;
  margin: 0;
}

.reader-head h2 {
  font-size: clamp(1.55rem, 2.2vw, 2.2rem);
  max-width: 780px;
}

.reader-copy {
  color: var(--reader-muted);
  font-size: 0.95rem;
  line-height: 1.55;
  margin: 7px 0 0;
  max-width: 700px;
}

.reader-actions {
  align-items: end;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: flex-end;
  min-width: min(460px, 100%);
}

.field,
.search-field {
  display: grid;
  gap: 7px;
}

.field span {
  color: var(--reader-text);
  font-size: 0.86rem;
  font-weight: 800;
}

.field input,
.field select,
.search-field input {
  background: #fff;
  border: 1px solid var(--reader-line);
  border-radius: 12px;
  color: var(--reader-text);
  min-height: 40px;
  min-width: 0;
  padding: 0 12px;
}

.field input:focus,
.field select:focus,
.search-field input:focus,
.reader-dropzone:focus-within,
.reader-tab:focus-visible,
.reader-icon-btn:focus-visible,
.reader-play-btn:focus-visible,
.book-select:focus-visible,
.chapter-play-btn:focus-visible,
.btn:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--reader-primary) 24%, transparent);
  outline-offset: 2px;
}

.voice-field {
  min-width: min(310px, 100%);
}

.reader-generate-btn {
  align-items: center;
  display: inline-flex;
  gap: 8px;
  min-height: 36px;
  padding-inline: 14px;
  white-space: nowrap;
}

.reader-action-icon,
.reader-tab-icon {
  display: inline-flex;
  fill: none;
  flex: 0 0 auto;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.2;
}

.reader-action-icon {
  height: 1.18rem;
  width: 1.18rem;
}

.reader-status,
.reader-alert {
  border-radius: 12px;
  font-size: 0.94rem;
  line-height: 1.45;
  margin: 0;
  padding: 11px 14px;
}

.reader-status {
  background: color-mix(in srgb, var(--reader-primary) 8%, white 92%);
  color: var(--reader-primary-strong);
}

.reader-status:empty {
  display: none;
}

.reader-alert {
  background: #fff1f2;
  color: var(--reader-red);
  font-weight: 800;
}

.reader-layout .btn.primary {
  background: var(--reader-primary);
  border-color: var(--reader-primary);
  box-shadow: 0 8px 18px color-mix(in srgb, var(--reader-primary) 22%, transparent);
  color: #fff;
}

.reader-layout .btn.primary:hover:not(:disabled) {
  background: var(--reader-primary-strong);
  border-color: var(--reader-primary-strong);
}

.reader-section-tabs {
  align-items: center;
  background: transparent;
  border: 1px solid var(--reader-line);
  border-radius: 999px;
  display: flex;
  flex: 0 1 auto;
  gap: 8px;
  justify-self: center;
  margin-left: clamp(8px, 2vw, 22px);
  max-width: min(100%, 560px);
  overflow-x: auto;
  padding: 5px;
  scrollbar-width: none;
  width: max-content;
}

.reader-section-tabs::-webkit-scrollbar {
  display: none;
}

.reader-tab {
  align-items: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--reader-muted);
  cursor: pointer;
  flex: 0 0 auto;
  display: inline-flex;
  gap: 8px;
  min-height: 40px;
  padding: 0 16px;
  text-align: center;
  transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}

.reader-tab:hover:not(.active) {
  background: var(--reader-primary-soft);
  color: var(--reader-primary-strong);
}

.reader-tab.active {
  background: var(--reader-primary);
  border-color: var(--reader-primary);
  color: #fff;
  box-shadow: 0 6px 16px color-mix(in srgb, var(--reader-primary) 22%, transparent);
}

.reader-tab-label {
  font-size: 0.9rem;
  font-weight: 900;
  line-height: 1.1;
}

.reader-tab-icon {
  height: 1.05rem;
  width: 1.05rem;
}

.reader-view {
  display: none;
}

.reader-view.active {
  display: grid;
  gap: 14px;
}

.reader-player-shell {
  align-items: start;
  background: var(--reader-surface);
  border: 1px solid var(--reader-line);
  border-radius: 16px;
  box-shadow: var(--reader-shadow);
  display: grid;
  gap: clamp(16px, 2vw, 24px);
  grid-template-columns: minmax(116px, 148px) 1fr;
  min-width: 0;
  padding: clamp(16px, 2vw, 24px);
}

.reader-cover {
  align-items: stretch;
  align-self: start;
  aspect-ratio: 0.76;
  background: linear-gradient(180deg, #f3fbf5, #eef8f1);
  border: 1px solid color-mix(in srgb, var(--reader-primary) 18%, var(--reader-line));
  border-radius: 16px;
  color: var(--reader-primary);
  display: grid;
  grid-template-rows: auto 1fr auto;
  justify-items: stretch;
  overflow: hidden;
  padding: 12px;
  width: 100%;
}

.reader-cover::after {
  border-top: 4px solid currentColor;
  content: "";
  display: block;
  opacity: 0.8;
}

.reader-cover.type-pdf {
  background: linear-gradient(180deg, #fff8f6, #fff1ec);
  border-color: #ffd6d6;
  color: #c2410c;
}

.reader-cover.type-docx {
  background: linear-gradient(180deg, #f3fbf5, #eef8f1);
  border-color: color-mix(in srgb, var(--reader-primary) 18%, var(--reader-line));
  color: var(--reader-primary-strong);
}

.reader-cover.type-txt {
  background: #f1fbf6;
  border-color: #cfeedd;
  color: var(--reader-green);
}

.reader-cover svg {
  align-self: center;
  fill: none;
  height: 42px;
  justify-self: center;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
  width: 42px;
}

.reader-cover-type {
  align-items: center;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid currentColor;
  border-radius: 999px;
  display: inline-flex;
  font-size: 0.64rem;
  font-weight: 900;
  justify-self: start;
  min-height: 24px;
  padding: 0 8px;
}

.reader-cover-initials {
  align-self: end;
  color: currentColor;
  font-size: clamp(1rem, 1.6vw, 1.25rem);
  font-weight: 900;
  letter-spacing: 0;
  line-height: 1;
  opacity: 0.9;
}

.player-main {
  align-content: start;
  display: grid;
  gap: 10px;
  min-width: 0;
}

.reader-panel-head {
  align-items: center;
  display: flex;
  gap: 14px;
  justify-content: space-between;
  min-width: 0;
}

.player-head {
  align-items: start;
}

.player-head-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.player-voice-field {
  min-width: min(230px, 42vw);
}

.player-voice-field select {
  min-height: 36px;
}

.selected-title {
  color: var(--reader-text);
  font-size: clamp(1.18rem, 1.9vw, 1.65rem);
  font-weight: 900;
  line-height: 1.12;
  margin: 0;
  overflow-wrap: anywhere;
}

.segment-title {
  color: var(--reader-muted);
  font-size: 0.92rem;
  font-weight: 700;
  margin: 0;
}

.player-time-row {
  color: var(--reader-muted);
  display: flex;
  font-size: 0.88rem;
  font-weight: 800;
  justify-content: space-between;
  margin-top: 2px;
}

.progress-field {
  gap: 0;
  min-height: 22px;
  width: 100%;
}

#progressRange,
.progress-field input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  accent-color: var(--reader-progress-red);
  background: linear-gradient(
    to right,
    var(--reader-progress-red) 0%,
    var(--reader-progress-red) var(--reader-progress, 0%),
    var(--reader-line) var(--reader-progress, 0%),
    var(--reader-line) 100%
  );
  border-radius: 999px;
  border: 0;
  cursor: pointer;
  height: 8px;
  max-width: none;
  min-height: 8px;
  padding: 0;
  width: 100%;
}

#progressRange::-webkit-slider-runnable-track,
.progress-field input[type="range"]::-webkit-slider-runnable-track,
#miniProgressRange::-webkit-slider-runnable-track {
  background: transparent;
  border: 0;
  height: 8px;
}

#progressRange::-webkit-slider-thumb,
.progress-field input[type="range"]::-webkit-slider-thumb,
#miniProgressRange::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  background: var(--reader-progress-red);
  border: 3px solid #fff;
  border-radius: 999px;
  box-shadow: 0 4px 12px rgba(220, 38, 38, 0.34);
  height: 20px;
  margin-top: -6px;
  width: 20px;
}

#progressRange::-moz-range-thumb,
.progress-field input[type="range"]::-moz-range-thumb,
#miniProgressRange::-moz-range-thumb {
  background: var(--reader-progress-red);
  border: 3px solid #fff;
  border-radius: 999px;
  box-shadow: 0 4px 12px rgba(220, 38, 38, 0.34);
  height: 20px;
  width: 20px;
}

#progressRange::-moz-range-progress,
.progress-field input[type="range"]::-moz-range-progress,
#miniProgressRange::-moz-range-progress {
  background: var(--reader-progress-red);
}

#progressRange::-moz-range-track,
.progress-field input[type="range"]::-moz-range-track,
#miniProgressRange::-moz-range-track {
  background: var(--reader-line);
}

.transport {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 0;
}

.reader-icon-btn,
.reader-play-btn,
.chapter-play-btn {
  align-items: center;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  font-weight: 900;
  justify-content: center;
  min-height: 42px;
  padding: 0;
  transition: background 160ms ease, border-color 160ms ease, box-shadow 160ms ease, color 160ms ease, transform 160ms ease;
}

.control-icon {
  align-items: center;
  background: transparent;
  border-radius: 999px;
  display: inline-flex;
  justify-content: center;
  margin-right: 0;
  min-height: 22px;
  min-width: 22px;
}

.control-icon svg {
  fill: none;
  height: 16px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.4;
  width: 16px;
}

.reader-play-btn .control-icon svg path {
  fill: currentColor;
  stroke: currentColor;
}

.reader-play-btn .reader-action-icon path,
.chapter-play-btn .reader-action-icon path,
.mini-play-btn .reader-action-icon path {
  fill: currentColor;
  stroke: currentColor;
}

.control-text {
  min-width: 0;
}

.reader-icon-btn {
  background: #fff;
  border: 1px solid var(--reader-line);
  color: var(--reader-text);
  width: 44px;
}

.reader-play-btn {
  background: var(--reader-primary);
  border: 1px solid var(--reader-primary);
  box-shadow: 0 12px 24px color-mix(in srgb, var(--reader-primary) 26%, transparent);
  color: #fff;
  min-height: 54px;
  width: 54px;
}

.reader-play-btn .control-icon {
  background: rgba(255, 255, 255, 0.18);
}

.reader-icon-btn:hover:not(:disabled),
.chapter-play-btn:hover:not(:disabled),
.book-select:hover {
  border-color: var(--reader-primary);
  color: var(--reader-primary-strong);
  transform: translateY(-1px);
}

.reader-play-btn:hover:not(:disabled) {
  background: var(--reader-primary-strong);
}

.reader-icon-btn:disabled,
.reader-play-btn:disabled,
.chapter-play-btn:disabled,
.btn:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.player-options {
  align-items: end;
  border-top: 1px solid var(--reader-line);
  display: flex;
  gap: 14px;
  justify-content: space-between;
  margin-top: 6px;
  padding-top: 12px;
}

.compact-field {
  min-width: 140px;
}

.player-hint {
  color: var(--reader-muted);
  font-weight: 700;
  line-height: 1.35;
  text-align: right;
}

.reader-main-grid,
.reader-support-grid {
  align-items: start;
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(440px, 1.05fr) minmax(360px, 0.95fr);
}

.reader-support-grid {
  grid-template-columns: minmax(300px, 0.78fr) minmax(380px, 1.22fr);
}

.reader-panel {
  align-content: start;
  background: var(--reader-surface);
  border: 1px solid var(--reader-line);
  border-radius: 16px;
  display: grid;
  gap: 14px;
  min-width: 0;
  padding: 18px;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.reader-panel:hover {
  border-color: color-mix(in srgb, var(--reader-primary) 22%, var(--reader-line));
  box-shadow: var(--reader-shadow-soft);
}

.library-full-panel,
.playlist-full-panel {
  max-width: none;
  width: 100%;
}

.upload-panel {
  max-width: 760px;
  width: 100%;
}

.reader-panel h2 {
  font-size: 1rem;
}

.panel-note {
  color: var(--reader-muted);
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.5;
  margin: -6px 0 0;
  max-width: 860px;
}

.search-field {
  min-width: min(260px, 100%);
}

.reader-count,
.status-badge {
  align-items: center;
  border-radius: 999px;
  display: inline-flex;
  font-size: 0.74rem;
  font-weight: 900;
  min-height: 30px;
  padding: 0 11px;
  white-space: nowrap;
}

.reader-count,
.status-badge.neutral {
  background: #eef2f7;
  color: #475569;
}

.status-badge.ready {
  background: var(--reader-primary-soft);
  color: var(--reader-green);
}

.status-badge.processing,
.status-badge.pending {
  background: #fff7df;
  color: var(--reader-amber);
}

.status-badge.failed {
  background: #fff1f2;
  color: var(--reader-red);
}

.reader-dropzone {
  align-items: center;
  background: var(--reader-surface-soft);
  border: 1.5px dashed var(--reader-line-strong);
  border-radius: 16px;
  cursor: pointer;
  display: grid;
  gap: 8px;
  min-height: 104px;
  padding: 20px;
  text-align: center;
  transition: background 160ms ease, border-color 160ms ease;
}

.reader-dropzone.dragging {
  background: var(--reader-primary-soft);
  border-color: var(--reader-primary);
}

.reader-dropzone span {
  color: var(--reader-text);
  font-weight: 900;
}

.reader-dropzone small,
.reader-count,
.book-meta,
.chapter-preview,
.chapter-meta,
.empty-state {
  color: var(--reader-muted);
}

#readerFileInput {
  border: 0;
  clip: rect(0 0 0 0);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

.reader-list,
.segments {
  --reader-visible-rows: 5;
  --reader-row-size: 76px;
  display: grid;
  gap: 0;
  grid-auto-rows: var(--reader-row-size);
  max-height: calc(var(--reader-visible-rows) * var(--reader-row-size));
  overflow-x: hidden;
  overflow-y: auto;
  padding-right: 2px;
  overscroll-behavior: contain;
  scroll-padding-block: 4px;
}

.reader-list:has(.empty-state),
.segments:has(.empty-state) {
  grid-auto-rows: auto;
  max-height: none;
  overflow: visible;
  padding-right: 0;
}

.library-list-large {
  max-height: calc(var(--reader-visible-rows) * var(--reader-row-size));
}

.chapter-panel .segments {
  --reader-row-size: 82px;
}

.library-panel .reader-list {
  min-height: 0;
  --reader-row-size: 78px;
}

.book-row,
.segment-row {
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--reader-line);
  border-radius: 0;
  color: var(--reader-text);
  min-width: 0;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.segment-row {
  min-height: 0;
}

.book-row {
  align-items: center;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) auto;
  height: 100%;
  min-height: 0;
  padding: 10px;
  text-align: left;
  width: 100%;
}

.compact-book-row .book-actions {
  display: none;
}

.book-row[aria-current="true"] {
  background: var(--reader-primary-soft);
  border-color: color-mix(in srgb, var(--reader-primary) 44%, var(--reader-line));
}

.book-row:hover,
.segment-row:hover {
  background: var(--reader-surface-soft);
}

.book-select {
  align-items: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 12px;
  color: var(--reader-text);
  cursor: pointer;
  display: grid;
  gap: 12px;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  min-width: 0;
  padding: 0;
  text-align: left;
  width: 100%;
}

.compact-book-row .book-select {
  grid-template-columns: 44px minmax(0, 1fr);
}

.compact-book-row .book-status {
  display: none;
}

.book-icon {
  align-items: center;
  background: var(--reader-primary-soft);
  border: 1px solid color-mix(in srgb, var(--reader-primary) 22%, var(--reader-line));
  border-radius: 12px;
  color: var(--reader-primary-strong);
  display: inline-flex;
  font-weight: 900;
  height: 44px;
  justify-content: center;
  width: 44px;
}

.book-icon.type-pdf {
  background: #fff5f5;
  border-color: #ffd6d6;
  color: #c2410c;
}

.book-icon.type-txt {
  background: #f1fbf6;
  border-color: #cfeedd;
  color: var(--reader-green);
}

.book-main,
.chapter-main {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.book-title,
.chapter-title {
  color: var(--reader-text);
  font-weight: 900;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-meta,
.chapter-meta,
.chapter-preview {
  font-size: 0.84rem;
  line-height: 1.35;
  margin: 0;
}

.chapter-preview {
  display: -webkit-box;
  max-width: 100%;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
}

.book-status {
  justify-self: end;
}

.book-actions,
.playlist-item-actions,
.playlist-manage-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.btn.danger {
  background: #fff1f2;
  border-color: rgba(185, 28, 28, 0.22);
  color: var(--reader-red);
}

.btn.danger:hover:not(:disabled) {
  background: #ffe4e6;
  border-color: rgba(185, 28, 28, 0.48);
}

.small-btn {
  min-height: 34px;
  padding-inline: 12px;
}

.icon-action {
  align-items: center;
  background: #fff;
  border: 1px solid var(--reader-line);
  border-radius: 999px;
  color: var(--reader-muted);
  cursor: pointer;
  display: inline-flex;
  height: 38px;
  justify-content: center;
  padding: 0;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
  width: 38px;
}

.icon-action:hover:not(:disabled) {
  background: var(--reader-primary-soft);
  border-color: color-mix(in srgb, var(--reader-primary) 34%, var(--reader-line));
  color: var(--reader-primary-strong);
  transform: translateY(-1px);
}

.icon-action.danger {
  background: var(--danger-bg, #fff1f2);
  border-color: var(--danger-border, rgba(185, 28, 28, 0.22));
  color: var(--reader-red);
}

.icon-action.danger:hover:not(:disabled) {
  background: var(--btn-danger-bg-hover, #ffe4e6);
  border-color: var(--danger-border, rgba(185, 28, 28, 0.32));
  color: var(--reader-red);
}

.book-actions .btn.danger {
  border-style: dashed;
}

.segment-row {
  align-items: center;
  display: grid;
  gap: 12px;
  grid-template-columns: 30px minmax(0, 1fr) 62px 78px auto;
  height: 100%;
  min-height: 0;
  padding: 9px 10px;
}

.segment-row[aria-current="true"] {
  background: var(--reader-primary-soft);
}

.chapter-index {
  color: var(--reader-muted);
  font-size: 0.9rem;
  font-weight: 900;
  text-align: center;
}

.chapter-play-btn {
  background: var(--reader-primary);
  border: 1px solid var(--reader-primary);
  color: #fff;
  min-width: 0;
  width: 38px;
}

.chapter-duration {
  color: var(--reader-muted);
  font-size: 0.86rem;
  font-weight: 900;
  text-align: right;
}

.chapter-status {
  justify-self: start;
}

.playlist-form {
  align-items: end;
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr auto;
}

.playlist-manage {
  background: var(--reader-surface-soft);
  border: 1px solid var(--reader-line);
  border-radius: 14px;
  display: grid;
  gap: 10px;
  padding: 14px;
}

.playlist-items {
  display: grid;
  gap: 8px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.playlist-items li {
  align-items: center;
  background: transparent;
  border-bottom: 1px solid var(--reader-line);
  border-radius: 0;
  display: grid;
  gap: 10px;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  min-height: 56px;
  padding: 10px 4px;
}

.playlist-items li:hover {
  background: var(--reader-surface-soft);
}

.playlist-items li.empty-state {
  border: 1px dashed var(--reader-line);
  border-radius: 14px;
  grid-template-columns: 1fr;
  padding: 16px;
}

.playlist-track-index {
  color: var(--reader-muted);
  font-weight: 900;
  text-align: center;
}

.playlist-track-title {
  color: var(--reader-text);
  font-weight: 900;
}

.playlist-items span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.playlist-items button {
  flex: 0 0 auto;
}

.reader-mini-player {
  align-items: center;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--reader-line);
  border-radius: 18px;
  bottom: 0;
  box-shadow: 0 18px 42px rgba(15, 23, 42, 0.1);
  display: grid;
  gap: 14px;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  padding: 12px;
  position: sticky;
  z-index: 4;
}

.mini-cover {
  align-items: center;
  background: #f3f7ff;
  border: 1px solid #d7e2f3;
  border-radius: 12px;
  color: var(--reader-primary);
  display: inline-flex;
  font-size: 0.7rem;
  font-weight: 900;
  height: 48px;
  justify-content: center;
  width: 48px;
}

.reader-mini-player.type-pdf .mini-cover {
  background: #fff5f5;
  border-color: #ffd6d6;
  color: #c2410c;
}

.reader-mini-player.type-txt .mini-cover {
  background: #f1fbf6;
  border-color: #cfeedd;
  color: var(--reader-green);
}

.mini-now-playing {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.mini-now-playing strong,
.mini-now-playing span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-now-playing strong {
  color: var(--reader-text);
  font-size: 0.95rem;
}

.mini-now-playing span {
  color: var(--reader-muted);
  font-size: 0.82rem;
  font-weight: 700;
}

#miniProgressRange {
  -webkit-appearance: none;
  appearance: none;
  accent-color: var(--reader-progress-red);
  background: linear-gradient(
    to right,
    var(--reader-progress-red) 0%,
    var(--reader-progress-red) var(--reader-progress, 0%),
    var(--reader-line) var(--reader-progress, 0%),
    var(--reader-line) 100%
  );
  border-radius: 999px;
  border: 0;
  height: 8px;
  min-height: 8px;
  width: 100%;
}

.mini-controls {
  display: flex;
  gap: 6px;
}

.mini-control-btn,
.mini-play-btn {
  align-items: center;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  font-weight: 900;
  height: 38px;
  justify-content: center;
  min-height: 38px;
  padding: 0;
  width: 38px;
}

.mini-control-btn {
  background: #fff;
  border: 1px solid var(--reader-line);
  color: var(--reader-text);
}

.mini-play-btn {
  background: var(--reader-primary);
  border: 1px solid var(--reader-primary);
  color: #fff;
}

.mini-control-btn:disabled,
.mini-play-btn:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.empty-state {
  background: var(--reader-surface-soft);
  border: 1px dashed var(--reader-line);
  border-radius: 16px;
  margin: 0;
  padding: 16px;
}

.empty-state-action {
  display: grid;
  gap: 6px;
}

.empty-state-action strong {
  color: var(--reader-text);
  font-size: 0.98rem;
}

.empty-state-action span {
  color: var(--reader-muted);
  line-height: 1.45;
}

.empty-state-featured {
  align-items: start;
  min-height: 220px;
  padding: 28px;
}

.empty-state-btn {
  justify-self: start;
  margin-top: 8px;
}

.hidden {
  display: none !important;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 1180px) {
  .page-topbar:has(.reader-section-tabs) {
    flex-wrap: wrap;
    height: auto;
    padding-block: 8px;
  }

  .page-topbar:has(.reader-section-tabs) .page-topbar-title {
    flex: 1 1 auto;
  }

  .reader-section-tabs {
    flex: 0 1 auto;
    justify-content: flex-start;
    margin-left: 0;
    max-width: calc(100vw - 36px);
    order: 3;
    width: max-content;
  }

  .transport {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 980px) {
  .page-topbar:has(.reader-section-tabs) .page-topbar-actions {
    margin-left: 0;
  }

  .reader-layout {
    padding: 18px;
  }

  .reader-head,
  .reader-panel-head,
  .player-head-actions,
  .player-options {
    align-items: stretch;
    flex-direction: column;
  }

  .reader-actions {
    align-items: stretch;
    min-width: 0;
  }

  .reader-player-shell,
  .reader-main-grid,
  .reader-support-grid,
  .playlist-form {
    grid-template-columns: 1fr;
  }

  .segment-row {
    grid-template-columns: 30px minmax(0, 1fr) 58px 74px auto;
  }
  .reader-cover {
    min-height: 132px;
    max-width: 240px;
  }

  .player-hint {
    text-align: left;
  }

  .reader-mini-player {
    grid-template-columns: 42px minmax(0, 1fr);
  }

  .mini-controls {
    grid-column: 1 / -1;
  }
}

@media (max-width: 620px) {
  .reader-page .page-topbar {
    padding-inline: 12px;
  }

  .page-topbar:has(.reader-section-tabs) {
    gap: 8px;
  }

  .reader-layout {
    gap: 12px;
    padding: 12px;
  }

  .reader-panel,
  .reader-player-shell {
    border-radius: 18px;
  }

  .reader-panel {
    padding: 16px;
  }

  .reader-panel-head {
    gap: 10px;
  }

  .reader-panel-head .search-field {
    width: 100%;
  }

  .search-field input,
  .field input,
  .field select {
    min-height: 44px;
  }

  .panel-note {
    display: none;
  }

  .reader-tab {
    gap: 7px;
    min-height: 42px;
    padding: 0 14px;
  }

  .transport {
    grid-template-columns: 1fr 1fr;
  }

  .reader-player-shell {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .reader-cover {
    display: none;
  }

  .player-card-head {
    gap: 10px;
  }

  .player-head-actions {
    align-items: stretch;
    width: 100%;
  }

  .player-voice-field,
  .reader-generate-btn {
    width: 100%;
  }

  .selected-title {
    font-size: 1.25rem;
  }

  .segment-title {
    font-size: 0.92rem;
  }

  .reader-icon-btn,
  .reader-play-btn {
    min-height: 46px;
    width: 46px;
  }

  .reader-play-btn {
    min-height: 58px;
    width: 58px;
  }

  .reader-list,
  .segments {
    padding-right: 0;
  }

  .chapter-panel .segments {
    --reader-row-size: 76px;
    max-height: calc(var(--reader-visible-rows) * var(--reader-row-size));
  }

  .library-panel .reader-list {
    --reader-row-size: 92px;
    max-height: calc(var(--reader-visible-rows) * var(--reader-row-size));
  }

  .library-list-large {
    --reader-row-size: 96px;
    max-height: calc(var(--reader-visible-rows) * var(--reader-row-size));
  }

  .book-row {
    gap: 8px;
    grid-template-columns: minmax(0, 1fr) 44px;
    padding: 8px 0;
  }

  .book-select {
    gap: 10px;
    grid-template-columns: 46px minmax(0, 1fr);
  }

  .book-icon {
    border-radius: 14px;
    font-size: 0.76rem;
    height: 46px;
    width: 46px;
  }

  .book-main {
    gap: 3px;
  }

  .book-title {
    font-size: 0.95rem;
  }

  .book-meta {
    display: -webkit-box;
    font-size: 0.88rem;
    line-height: 1.3;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .book-status {
    display: none;
  }

  .book-actions {
    align-self: center;
    grid-column: 2;
    grid-row: 1;
    justify-content: center;
  }

  .compact-book-row {
    grid-template-columns: 1fr;
  }

  .compact-book-row .book-select {
    grid-template-columns: 46px minmax(0, 1fr);
  }

  .segment-row {
    gap: 8px;
    grid-template-columns: 24px minmax(0, 1fr) 44px;
    padding: 8px 0;
  }

  .segment-row .chapter-duration {
    grid-column: 2;
    text-align: left;
  }

  .segment-row .chapter-status {
    display: none;
  }

  .segment-row .chapter-play-btn {
    grid-column: 3;
    grid-row: 1 / span 2;
  }

  .chapter-title {
    font-size: 0.95rem;
  }

  .chapter-preview {
    display: none;
  }

  .chapter-duration,
  .chapter-meta {
    font-size: 0.78rem;
  }

  .chapter-play-btn {
    height: 42px;
    width: 42px;
  }

  .playlist-form,
  .playlist-manage {
    grid-template-columns: 1fr;
  }

  .playlist-items li {
    grid-template-columns: 28px minmax(0, 1fr);
  }

  .playlist-item-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
    padding-left: 38px;
  }

  .book-status {
    grid-column: 1 / -1;
    justify-self: start;
  }

  .reader-mini-player {
    border-radius: 16px;
    gap: 10px;
    padding: 10px;
  }

  .mini-cover {
    height: 42px;
    width: 42px;
  }

  .mini-controls {
    justify-content: space-between;
    width: 100%;
  }
}

@media (max-width: 520px) {
  .page-topbar:has(.reader-section-tabs) {
    align-items: center;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .page-topbar:has(.reader-section-tabs) .page-topbar-title {
    min-width: 0;
  }

  .reader-section-tabs {
    grid-column: 1 / -1;
    max-width: calc(100vw - 24px);
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    overflow: visible;
    padding: 4px;
    width: 100%;
  }

  .reader-tab {
    gap: 5px;
    justify-content: center;
    min-height: 40px;
    padding: 0 4px;
    width: 100%;
  }

  .reader-tab-label {
    font-size: 0.78rem;
  }

  .reader-tab-icon {
    height: 0.92rem;
    width: 0.92rem;
  }

  .reader-panel-head h2,
  .reader-player-shell h2 {
    font-size: 1.15rem;
  }

  .reader-kicker {
    font-size: 0.62rem;
  }

  .reader-player-shell {
    gap: 14px;
  }

  .reader-cover {
    aspect-ratio: 1.22;
    min-height: 112px;
    max-width: 170px;
    padding: 10px;
  }

  .reader-cover svg {
    height: 32px;
    width: 32px;
  }

  .reader-mini-player {
    grid-template-columns: minmax(0, 1fr);
  }

  .reader-mini-player .mini-cover {
    display: none;
  }
}
