:root {
  --bg: var(--tg-theme-bg-color, #f6f3ec);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --surface-muted: rgba(120, 100, 75, 0.08);
  --text: var(--tg-theme-text-color, #1e1b18);
  --text-muted: var(--tg-theme-hint-color, #6f675f);
  --accent: var(--tg-theme-button-color, #7c3f23);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --border: rgba(120, 100, 75, 0.16);
  --shadow: 0 8px 24px rgba(30, 20, 10, 0.08);
  --radius-lg: 18px;
  --radius-md: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-bg-color, #151412);
    --surface: var(--tg-theme-secondary-bg-color, #211f1c);
    --surface-muted: rgba(255, 245, 230, 0.07);
    --text: var(--tg-theme-text-color, #f3ede4);
    --text-muted: var(--tg-theme-hint-color, #a79e94);
    --accent: var(--tg-theme-button-color, #d08b5b);
    --accent-text: var(--tg-theme-button-text-color, #191410);
    --border: rgba(255, 240, 220, 0.12);
    --shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Vazirmatn", "Segoe UI", Tahoma, sans-serif;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
  color: inherit;
}

.app-shell {
  max-width: 960px;
  margin-inline: auto;
  padding-inline: 14px;
  padding-block-start: 14px;
  padding-block-end: calc(88px + var(--safe-bottom));
}

.top-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-block-end: 16px;
}

.brand-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.eyebrow {
  margin: 0;
  font-size: 0.78rem;
  color: var(--accent);
  font-weight: 700;
}

.app-title {
  margin: 2px 0 0;
  font-size: clamp(1.2rem, 3.8vw, 1.65rem);
  font-weight: 800;
  line-height: 1.3;
}

.stats-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.catalog-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding-inline: 12px;
  box-shadow: var(--shadow);
}

.search-box input {
  width: 100%;
  border: 0;
  background: transparent;
  padding-block: 11px;
  outline: none;
  font-size: 0.94rem;
}

.search-icon {
  color: var(--text-muted);
  font-size: 1.15rem;
}

.filter-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-block-end: 4px;
  scrollbar-width: none;
}

.filter-bar::-webkit-scrollbar {
  display: none;
}

.filter-chip {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, background-color 0.15s ease, color 0.15s ease;
}

.filter-chip.is-active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
}

.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(164px, 1fr));
  gap: 12px;
}

.book-card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
  text-align: start;
  padding: 0;
  transition: transform 0.14s ease;
}

.book-card:active {
  transform: scale(0.985);
}

.cover-wrap {
  position: relative;
  aspect-ratio: 3 / 4;
  background: linear-gradient(145deg, #4b2b1f, #201815);
  overflow: hidden;
}

.cover-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.cover-placeholder {
  width: 100%;
  height: 100%;
  padding: 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  color: #f6efe4;
  background: linear-gradient(155deg, #5a2e1d 0%, #2a211c 100%);
}

.cover-placeholder-ep {
  font-size: 0.75rem;
  opacity: 0.85;
}

.cover-placeholder-title {
  font-size: 0.96rem;
  font-weight: 700;
  line-height: 1.45;
}

.cover-placeholder-author {
  font-size: 0.76rem;
  opacity: 0.82;
}

.ep-badge {
  position: absolute;
  inset-block-start: 8px;
  inset-inline-start: 8px;
  background: rgba(15, 12, 10, 0.74);
  color: #fff;
  backdrop-filter: blur(6px);
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 0.72rem;
  font-weight: 700;
}

.status-badge {
  position: absolute;
  inset-block-end: 8px;
  inset-inline-end: 8px;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.68rem;
  font-weight: 700;
}

.status-badge.is-ready {
  background: #1f7a4c;
  color: #fff;
}

.status-badge.is-upcoming {
  background: rgba(25, 22, 19, 0.78);
  color: #e9dfd1;
}

.card-body {
  padding: 10px 11px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.card-title {
  margin: 0;
  font-size: 0.93rem;
  font-weight: 700;
  line-height: 1.38;
}

.card-author {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.card-tags {
  margin-top: auto;
  padding-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.tag {
  font-size: 0.68rem;
  background: var(--surface-muted);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 2px 6px;
  font-weight: 600;
}

.tag.is-pdf {
  color: var(--accent);
}

/* Detail View */
.detail-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.detail-nav-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.btn {
  border: 1px solid var(--border);
  background: var(--surface-muted);
  color: var(--text);
  border-radius: var(--radius-md);
  padding: 8px 13px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
}

.detail-hero {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 14px;
  align-items: start;
}

@media (max-width: 480px) {
  .detail-hero {
    grid-template-columns: 96px 1fr;
  }
}

.detail-cover {
  border-radius: var(--radius-md);
  overflow: hidden;
  aspect-ratio: 3 / 4;
  border: 1px solid var(--border);
}

.detail-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.detail-title {
  margin: 4px 0 4px;
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1.35;
}

.detail-subtitle {
  margin: 0 0 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.meta-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.player-panel {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.player-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.play-main-btn {
  min-width: 112px;
  padding: 9px 16px;
  border-radius: 999px;
  border: 0;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
  cursor: pointer;
}

.seek-row {
  display: flex;
  align-items: center;
  gap: 10px;
  direction: ltr;
}

.seek-slider {
  flex: 1;
  accent-color: var(--accent);
}

.time-label {
  font-size: 0.76rem;
  color: var(--text-muted);
  min-width: 42px;
  text-align: center;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.story-text {
  font-size: 0.98rem;
  line-height: 2;
  white-space: pre-line;
  margin: 0;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 36px 12px;
}

/* Sticky Mini Player */
.mini-player {
  position: fixed;
  inset-block-end: calc(10px + var(--safe-bottom));
  inset-inline: 14px;
  max-width: 932px;
  margin-inline: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 40;
}

.mini-play-btn {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 0;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
  cursor: pointer;
  flex: 0 0 auto;
}

.mini-meta {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  text-align: start;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  padding: 0;
}

.mini-title {
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mini-sub {
  font-size: 0.74rem;
  color: var(--text-muted);
}

.mini-time {
  font-size: 0.76rem;
  color: var(--text-muted);
  direction: ltr;
}
