/* Design system: Apple — see DESIGN.md.
   - Single accent: Action Blue #0066cc
   - SF Pro Display + SF Pro Text via -apple-system stack
   - Body 17px (not 16) с negative letter-spacing на display-размерах
   - Pill radius для primary CTAs, search, sticky-bar; rounded.lg (18px) для utility cards
   - Один drop-shadow — только под обложку (мы используем под product-tile imagery суррогат)
   - Tile alternation: canvas / canvas-parchment / surface-tile вместо границ
*/

:root {
  /* Colors — Apple */
  --primary: #0066cc;
  --primary-focus: #0071e3;
  --primary-on-dark: #2997ff;
  --ink: #1d1d1f;
  --ink-muted-80: #333333;
  --ink-muted-48: #7a7a7a;
  --body-muted: #cccccc;
  --hairline: #e0e0e0;
  --divider-soft: #f0f0f0;
  --canvas: #ffffff;
  --canvas-parchment: #f5f5f7;
  --surface-pearl: #fafafc;
  --surface-tile-1: #272729;
  --surface-tile-2: #2a2a2c;
  --surface-tile-3: #252527;
  --surface-black: #000000;
  --surface-chip-translucent: rgba(210, 210, 215, 0.64);
  --on-dark: #ffffff;

  /* Spacing */
  --sp-xxs: 4px;
  --sp-xs: 8px;
  --sp-sm: 12px;
  --sp-md: 17px;
  --sp-lg: 24px;
  --sp-xl: 32px;
  --sp-xxl: 48px;
  --sp-section: 80px;

  /* Radii */
  --r-xs: 5px;
  --r-sm: 8px;
  --r-md: 11px;
  --r-lg: 18px;
  --r-pill: 9999px;

  /* The single shadow — for cover/product imagery only */
  --shadow-product: rgba(0, 0, 0, 0.22) 3px 5px 30px 0;
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text",
               "SF Pro Display", system-ui, "Helvetica Neue", Arial, sans-serif;
  font-size: 17px;
  font-weight: 400;
  line-height: 1.47;
  letter-spacing: -0.374px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body { min-height: 100dvh; }
body.has-player { padding-bottom: 220px; }

a {
  color: var(--primary);
  text-decoration: none;
  transition: color .15s ease;
}
a:hover { text-decoration: underline; }

button {
  font: inherit;
  letter-spacing: inherit;
  cursor: pointer;
  border: 0;
  background: none;
  color: inherit;
}
button:active { transform: scale(0.95); }

/* === GLOBAL NAV === */

.global-nav {
  position: sticky;
  top: 0;
  z-index: 50;
  height: 44px;
  background: var(--surface-black);
  color: var(--on-dark);
  display: flex;
  align-items: center;
  padding: 0 var(--sp-lg);
}
.global-nav .brand {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  font-size: 12px;
  font-weight: 400;
  letter-spacing: -0.12px;
  color: var(--on-dark);
  text-decoration: none;
}
.global-nav .brand:hover { text-decoration: none; opacity: 0.85; }

/* === SUB-NAV (frosted) === */

.sub-nav {
  position: sticky;
  top: 44px;
  z-index: 49;
  height: 52px;
  background: rgba(245, 245, 247, 0.8);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid rgba(0, 0, 0, 0.04);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sp-lg);
  gap: var(--sp-md);
}
.sub-nav .nav-cover {
  width: 36px;
  height: 36px;
  border-radius: var(--r-sm);
  object-fit: cover;
  flex-shrink: 0;
  /* Mini-shadow — приглушённая версия под small thumbnail */
  box-shadow: rgba(0, 0, 0, 0.18) 1px 2px 8px 0;
}

.sub-nav .nav-left {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  min-width: 0;
  flex: 1;
}

.sub-nav .category {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", system-ui, sans-serif;
  font-size: 21px;
  font-weight: 600;
  line-height: 1.19;
  letter-spacing: 0.231px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sub-nav .back-link {
  font-size: 14px;
  font-weight: 400;
  letter-spacing: -0.224px;
  color: var(--primary);
  flex-shrink: 0;
}

/* === HERO (для index) === */

.hero {
  text-align: center;
  padding: var(--sp-section) var(--sp-lg) calc(var(--sp-section) - 16px);
}
.hero h1 {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", system-ui, sans-serif;
  font-size: 56px;
  font-weight: 600;
  line-height: 1.07;
  letter-spacing: -0.28px;
  margin: 0;
}
.hero .subtitle {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", system-ui, sans-serif;
  font-size: 28px;
  font-weight: 400;
  line-height: 1.14;
  letter-spacing: 0.196px;
  color: var(--ink-muted-80);
  margin: var(--sp-md) 0 0;
}

/* === PRODUCT TILES (book list) === */

.tiles { list-style: none; margin: 0; padding: 0; }

.tile {
  padding: var(--sp-section) var(--sp-lg);
  text-align: center;
}
.tile.light { background: var(--canvas); color: var(--ink); }
.tile.parchment { background: var(--canvas-parchment); color: var(--ink); }
.tile.dark { background: var(--surface-tile-1); color: var(--on-dark); }
.tile.dark-2 { background: var(--surface-tile-2); color: var(--on-dark); }
.tile.dark-3 { background: var(--surface-tile-3); color: var(--on-dark); }

.tile-link {
  display: block;
  color: inherit;
  text-decoration: none;
  max-width: 980px;
  margin: 0 auto;
}
.tile-link:hover { text-decoration: none; }

.cover-frame {
  position: relative;
  width: 320px;
  max-width: 100%;
  margin: 0 auto var(--sp-xl);
}
.cover-link { display: block; }

.tile-cover {
  display: block;
  width: 320px;
  height: 320px;
  max-width: 100%;
  border-radius: var(--r-sm);
  /* Единственный allowed shadow — под product imagery (Apple-spec) */
  box-shadow: var(--shadow-product);
  object-fit: cover;
  background: var(--canvas-parchment);
}

/* === COVER OVERLAY BADGES (Apple-style frosted-glass) === */

.cover-stats {
  position: absolute;
  bottom: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.cover-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: var(--r-pill);
  background: rgba(255, 255, 255, 0.65);
  backdrop-filter: saturate(160%) blur(18px);
  -webkit-backdrop-filter: saturate(160%) blur(18px);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: -0.12px;
  color: var(--ink-muted-80);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  border: 0;
}
.cover-badge svg {
  flex-shrink: 0;
  color: var(--ink-muted-48);
  transition: color .15s ease, transform .15s ease;
}

.cover-plays {
  text-decoration: none;
  cursor: pointer;
  transition: background .15s ease;
}
.cover-plays:hover { background: rgba(255, 255, 255, 0.8); text-decoration: none; }
.cover-plays:hover svg { transform: scale(1.1); }
.cover-plays:focus-visible { outline: 2px solid var(--primary-focus); outline-offset: 2px; }

.cover-like {
  cursor: pointer;
  transition: background .15s ease;
}
.cover-like:hover { background: rgba(255, 255, 255, 0.8); }
.cover-like:hover svg { transform: scale(1.1); }
.cover-like.liked svg { color: #e0245e; fill: #e0245e; }
.cover-like:focus-visible { outline: 2px solid var(--primary-focus); outline-offset: 2px; }

.tile h2 {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", system-ui, sans-serif;
  font-size: 40px;
  font-weight: 600;
  line-height: 1.10;
  letter-spacing: -0.374px;
  margin: 0;
}

.tile .tile-tagline {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", system-ui, sans-serif;
  font-size: 21px;
  font-weight: 600;
  line-height: 1.19;
  letter-spacing: 0.231px;
  color: var(--ink-muted-80);
  margin: var(--sp-sm) 0 0;
}
.tile.dark .tile-tagline,
.tile.dark-2 .tile-tagline,
.tile.dark-3 .tile-tagline { color: var(--body-muted); }

.tile .tile-status {
  font-size: 14px;
  font-weight: 400;
  line-height: 1.43;
  letter-spacing: -0.224px;
  color: var(--ink-muted-48);
  margin: var(--sp-md) 0 var(--sp-lg);
}
.tile.dark .tile-status,
.tile.dark-2 .tile-status,
.tile.dark-3 .tile-status { color: var(--body-muted); }

.tile-cta-row {
  margin-top: var(--sp-md);
  display: flex;
  gap: var(--sp-md);
  justify-content: center;
  flex-wrap: wrap;
}

/* === BOOK META (book detail page: «142 слушают · ♡ 38 лайков») === */

.book-meta {
  margin: 0 0 var(--sp-xl);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--sp-sm);
  font-size: 14px;
  letter-spacing: -0.224px;
  color: var(--ink-muted-48);
  font-variant-numeric: tabular-nums;
}
.book-meta > * + *::before {
  content: "·";
  margin-right: var(--sp-sm);
  color: var(--ink-muted-48);
  opacity: 0.5;
}
#book-plays:empty { display: none; }

.like-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 0;
  padding: 4px 6px;
  margin: -4px -6px; /* визуально не съезжает в строке */
  border-radius: var(--r-sm);
  font: inherit;
  font-size: 14px;
  letter-spacing: -0.224px;
  color: var(--ink-muted-48);
  cursor: pointer;
  transition: color .15s ease, background .15s ease;
}
.like-action svg { transition: color .15s ease, transform .15s ease; }
.like-action:hover { background: rgba(0, 0, 0, 0.04); color: var(--ink); }
.like-action:hover svg { transform: scale(1.08); }
.like-action.liked { color: var(--ink); }
.like-action.liked svg { color: #e0245e; }
.like-action:focus-visible { outline: 2px solid var(--primary-focus); outline-offset: 2px; }

/* === BUTTONS === */

.btn-primary,
.btn-secondary,
.btn-utility {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: var(--on-dark);
  border-radius: var(--r-pill);
  padding: 11px 22px;
  font-size: 17px;
  font-weight: 400;
  letter-spacing: -0.374px;
}
.btn-primary:hover { text-decoration: none; filter: brightness(1.03); }
.btn-primary:focus-visible { outline: 2px solid var(--primary-focus); outline-offset: 2px; }

.btn-secondary {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
  border-radius: var(--r-pill);
  padding: 10px 21px;
  font-size: 17px;
  font-weight: 400;
  letter-spacing: -0.374px;
}
.btn-secondary:hover { background: rgba(0, 102, 204, 0.06); text-decoration: none; }

.tile.dark .btn-secondary,
.tile.dark-2 .btn-secondary,
.tile.dark-3 .btn-secondary {
  color: var(--primary-on-dark);
  border-color: var(--primary-on-dark);
}
.tile.dark .btn-secondary:hover,
.tile.dark-2 .btn-secondary:hover,
.tile.dark-3 .btn-secondary:hover { background: rgba(41, 151, 255, 0.1); }

.btn-utility {
  background: var(--ink);
  color: var(--on-dark);
  border-radius: var(--r-sm);
  padding: 8px 15px;
  font-size: 14px;
  font-weight: 400;
  letter-spacing: -0.224px;
}
.btn-utility:hover { text-decoration: none; opacity: 0.92; }

/* Compact circular icon button — для контролов плеера на тёмном/полу-прозрачном фоне */
.btn-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--r-pill);
  background: var(--surface-chip-translucent);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
}
.btn-icon:hover { filter: brightness(1.05); }

/* === BOOK PAGE: chapter cards === */

main.content {
  max-width: 1024px;
  margin: 0 auto;
  padding: var(--sp-xxl) var(--sp-lg);
}

.section-head {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", system-ui, sans-serif;
  font-size: 34px;
  font-weight: 600;
  line-height: 1.47;
  letter-spacing: -0.374px;
  margin: 0 0 var(--sp-xl);
  color: var(--ink);
}

.chapter-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: var(--sp-lg);
}

.chapter-card {
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  padding: var(--sp-lg);
  /* Доп.отступ справа сверху, чтобы заголовок не уезжал под кнопку «прослушано» */
  padding-right: calc(var(--sp-lg) + 32px);
  display: flex;
  flex-direction: column;
  gap: var(--sp-sm);
  transition: border-color .15s ease, transform .15s ease;
  position: relative;
}
.chapter-card:hover { border-color: var(--ink-muted-48); }
.chapter-card.done { border-left: 3px solid var(--primary); padding-left: calc(var(--sp-lg) - 2px); }
.chapter-card.in-progress { border-left: 3px solid var(--primary); padding-left: calc(var(--sp-lg) - 2px); }

.mark-done {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 28px;
  height: 28px;
  border-radius: var(--r-pill);
  border: 1.5px solid var(--hairline);
  background: var(--canvas);
  color: var(--ink-muted-48);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
  padding: 0;
  flex-shrink: 0;
}
.mark-done svg { opacity: 0; transition: opacity .15s ease; }
.mark-done:hover { border-color: var(--primary); color: var(--primary); }
.mark-done:hover svg { opacity: 0.4; }
.mark-done:focus-visible { outline: 2px solid var(--primary-focus); outline-offset: 2px; }
.chapter-card.done .mark-done {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-dark);
}
.chapter-card.done .mark-done svg { opacity: 1; }
.chapter-card.done .mark-done:hover { filter: brightness(1.05); }

.chapter-btn {
  display: contents;
  text-align: left;
}
.chapter-btn:focus-visible {
  outline: 2px solid var(--primary-focus);
  outline-offset: 2px;
}

.chapter-num {
  font-size: 14px;
  font-weight: 400;
  letter-spacing: -0.224px;
  color: var(--ink-muted-48);
  font-variant-numeric: tabular-nums;
}

.chapter-title {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", system-ui, sans-serif;
  font-size: 21px;
  font-weight: 600;
  line-height: 1.19;
  letter-spacing: 0.231px;
  color: var(--ink);
  margin: 0;
}

.chapter-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-sm);
  margin-top: auto;
  padding-top: var(--sp-sm);
}

.chapter-dur {
  font-size: 14px;
  font-weight: 400;
  letter-spacing: -0.224px;
  color: var(--ink-muted-48);
  font-variant-numeric: tabular-nums;
}

.chapter-state {
  font-size: 14px;
  font-weight: 400;
  letter-spacing: -0.224px;
  color: var(--primary);
}
.chapter-card.done .chapter-state::before { content: "✓ "; }

.loading, .error {
  padding: var(--sp-lg);
  color: var(--ink-muted-48);
  font-style: italic;
}
.error { color: #b3261e; }

/* === PLAYER (floating sticky bar — frosted) === */

.player {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 100;
  background: rgba(245, 245, 247, 0.85);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid rgba(0, 0, 0, 0.04);
  padding: var(--sp-md) var(--sp-xl);
  user-select: none;
  -webkit-user-select: none;
}
.player.hidden { display: none; }

.player-row {
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  margin-bottom: var(--sp-xs);
  max-width: 1024px;
  margin-left: auto;
  margin-right: auto;
}

.player-meta { flex: 1; min-width: 0; }
.player-chapter {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.374px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink);
}
.player-book {
  font-size: 14px;
  font-weight: 400;
  letter-spacing: -0.224px;
  color: var(--ink-muted-48);
  margin-top: 2px;
}

audio { display: none; }

.progress-row {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  max-width: 1024px;
  margin: var(--sp-xs) auto;
}

.time {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  letter-spacing: -0.12px;
  color: var(--ink-muted-48);
  flex-shrink: 0;
  min-width: 40px;
  text-align: center;
}

#seek {
  flex: 1;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--hairline);
  border-radius: var(--r-pill);
  outline: none;
  cursor: pointer;
}
#seek:focus-visible { outline: 2px solid var(--primary-focus); outline-offset: 4px; }
#seek::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: var(--primary);
  border-radius: var(--r-pill);
  cursor: pointer;
  border: 0;
}
#seek::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: var(--primary);
  border-radius: var(--r-pill);
  cursor: pointer;
  border: 0;
}

.controls-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-sm);
  max-width: 1024px;
  margin: 0 auto;
  flex-wrap: wrap;
}

#play {
  background: var(--primary);
  color: var(--on-dark);
  border-radius: var(--r-pill);
  padding: 0;
  width: 64px;
  height: 64px;
  font-size: 22px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
#play:hover { filter: brightness(1.03); }

#back-15, #fwd-15 {
  background: var(--canvas);
  color: var(--ink);
  border: 1px solid var(--hairline);
  border-radius: var(--r-pill);
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 400;
  letter-spacing: -0.224px;
}
#back-15:hover, #fwd-15:hover { border-color: var(--ink-muted-48); }

#player-close {
  background: var(--canvas);
  color: var(--ink-muted-48);
  border: 1px solid var(--hairline);
  border-radius: var(--r-pill);
  width: 32px;
  height: 32px;
  font-size: 18px;
  line-height: 1;
  padding: 0;
  flex-shrink: 0;
}
#player-close:hover { color: var(--ink); border-color: var(--ink-muted-48); }

select {
  background: var(--canvas);
  color: var(--ink);
  border: 1px solid var(--hairline);
  border-radius: var(--r-pill);
  padding: 8px 28px 8px 14px;
  font: inherit;
  font-size: 14px;
  letter-spacing: -0.224px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' stroke='%231d1d1f' stroke-width='1.5' fill='none' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
select:hover { border-color: var(--ink-muted-48); }
select:focus-visible { outline: 2px solid var(--primary-focus); outline-offset: 2px; }

.sleep-status {
  margin-top: var(--sp-xs);
  text-align: center;
  font-size: 12px;
  letter-spacing: -0.12px;
  color: var(--ink-muted-48);
  font-variant-numeric: tabular-nums;
  min-height: 1em;
  max-width: 1024px;
  margin-left: auto;
  margin-right: auto;
}

/* === FOOTER === */

.site-footer {
  background: var(--canvas-parchment);
  color: var(--ink-muted-80);
  padding: var(--sp-xxl) var(--sp-lg);
  text-align: center;
  font-size: 12px;
  letter-spacing: -0.12px;
}

/* === RESPONSIVE === */

@media (max-width: 833px) {
  .hero { padding: 56px var(--sp-lg) 40px; }
  .hero h1 { font-size: 40px; }
  .hero .subtitle { font-size: 21px; }
  .tile { padding: var(--sp-xxl) var(--sp-lg); }
  .cover-frame { width: 240px; }
  .tile-cover { width: 240px; height: 240px; }
  .tile h2 { font-size: 34px; }
  .tile .tile-tagline { font-size: 17px; }
  .chapter-list { grid-template-columns: 1fr; }
  .player { padding: var(--sp-sm) var(--sp-md); }
  .controls-row { gap: var(--sp-xs); }
}

@media (max-width: 640px) {
  /* Плеер: одна строка контролов на мобильном.
     Скрываем текстовый label у play, ужимаем паддинги и шрифты. */
  .controls-row {
    flex-wrap: nowrap;
    gap: 6px;
    justify-content: space-between;
  }
  #play {
    width: 56px;
    height: 56px;
    font-size: 18px;
  }
  #back-15, #fwd-15 {
    padding: 8px 10px;
    font-size: 13px;
    flex-shrink: 0;
  }
  select {
    padding: 7px 22px 7px 10px;
    font-size: 13px;
    background-position: right 6px center;
    flex-shrink: 1;
    min-width: 0;
  }
  .player-row { gap: var(--sp-sm); }
  .progress-row { gap: var(--sp-xs); }
  .time { min-width: 36px; font-size: 11px; }
}

@media (max-width: 480px) {
  .hero h1 { font-size: 28px; line-height: 1.14; }
  .hero .subtitle { font-size: 17px; }
  .tile h2 { font-size: 28px; }
  .section-head { font-size: 24px; }
  body.has-player { padding-bottom: 200px; }
  .player { padding: 10px var(--sp-sm); }
  .player-chapter { font-size: 15px; }
  .player-book { font-size: 12px; }
}
