/* Bukvica — Apple iBooks-inspired design */
:root {
    --bg: #FFFDF7;
    --text: #1C1C1E;
    --text-muted: #8E8E93;
    --primary: #FF6B35;
    --primary-hover: #E85D2C;
    --surface: #F5F0E8;
    --border: #E8E0D4;
    --radius: 12px;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
    --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', sans-serif;
    --font-serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
    --chrome-bg: rgba(255,253,247,0.92);
    --chrome-bg-soft: rgba(255,253,247,0.88);
    color-scheme: light;
}

.theme-dark {
    --bg: #1C1C1E;
    --text: #F2F2F7;
    --text-muted: #98989D;
    --surface: #2C2C2E;
    --border: #3A3A3C;
    --shadow: 0 2px 8px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
    --chrome-bg: rgba(28,28,30,0.92);
    --chrome-bg-soft: rgba(28,28,30,0.88);
    color-scheme: dark;
}

.theme-sepia {
    --bg: #F8F1E3;
    --text: #3B2F2F;
    --text-muted: #7A6B5D;
    --surface: #EFE6D5;
    --border: #DDD2BE;
    --chrome-bg: rgba(248,241,227,0.92);
    --chrome-bg-soft: rgba(248,241,227,0.88);
}

.theme-contrast {
    --bg: #05070A;
    --text: #F8FAFC;
    --text-muted: #CBD5E1;
    --primary: #60A5FA;
    --primary-hover: #93C5FD;
    --surface: #111827;
    --border: #334155;
    --shadow: 0 2px 10px rgba(0,0,0,0.45);
    --shadow-lg: 0 10px 36px rgba(0,0,0,0.5);
    --chrome-bg: rgba(5,7,10,0.96);
    --chrome-bg-soft: rgba(17,24,39,0.94);
    color-scheme: dark;
}

.font-serif { --font: 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif; --font-serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif; }
.font-mono { --font: 'SF Mono', 'Fira Code', 'Courier New', monospace; --font-serif: 'SF Mono', 'Fira Code', 'Courier New', monospace; }

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; scroll-behavior: smooth; overflow-x: hidden; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100dvh;
    overflow-x: hidden;
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; transition: color 0.2s; }
a:hover { color: var(--primary-hover); }
img { max-width: 100%; height: auto; display: block; }

/* Header — clean Apple-style nav bar */
.header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 0.5px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--chrome-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: 100;
}
.header__back {
    display: flex; align-items: center; justify-content: center;
    min-width: 48px; min-height: 48px;
    color: var(--primary); border-radius: 12px;
    -webkit-tap-highlight-color: transparent;
}
.header__back:active { background: var(--surface); }
.header__back svg { flex-shrink: 0; }
.header__back-title {
    flex: 1 1 auto; min-width: 0;
    display: flex; align-items: center; gap: 12px;
    color: var(--text);
    border-radius: 12px;
    -webkit-tap-highlight-color: transparent;
}
.header__back-title:active .header__back { background: var(--surface); }
.header__back-title:hover { color: var(--text); }
.header__back-title .header__back { flex: 0 0 48px; }
.header__title {
    flex: 1; min-width: 0; font-size: 1.0625rem; font-weight: 600;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    letter-spacing: -0.02em;
}
.header__search {
    display: flex; align-items: center; justify-content: center;
    min-width: 48px; min-height: 48px;
    font-size: 1.25rem; color: var(--primary);
    border-radius: 12px;
}
.header__search:active { background: var(--surface); }
.header__btn { background: none; border: none; color: var(--primary); cursor: pointer; font-size: 0.9375rem; font-weight: 500; }
.logo { flex: 1; min-width: 0; }
.brand-logo {
    display: inline-flex; align-items: center; gap: 10px;
    min-height: 48px; color: var(--text);
}
.brand-logo:hover { color: var(--text); }
.brand-logo__mark {
    position: relative;
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px; border-radius: 9px;
    background: var(--primary); color: #fff;
    font-family: var(--font-serif); font-size: 1.25rem; font-weight: 800;
    line-height: 1; box-shadow: 0 4px 14px rgba(255,107,53,0.28);
}
.brand-logo__mark::after {
    content: ""; position: absolute; right: 6px; top: 6px;
    width: 7px; height: 14px; border-right: 2px solid rgba(255,255,255,0.82);
    border-top: 2px solid rgba(255,255,255,0.82); border-radius: 0 4px 0 0;
}
.brand-logo__text {
    font-size: 1.35rem; font-weight: 800; letter-spacing: 0;
    color: var(--primary);
}

/* Main container */
.main { padding: 20px 16px; max-width: 500px; margin: 0 auto; padding-bottom: calc(72px + var(--safe-bottom)); }

/* Section titles */
.section { margin-bottom: 32px; }
.section--compact { margin-bottom: 24px; }
.section-title {
    font-size: 1.375rem; font-weight: 700; margin-bottom: 16px;
    letter-spacing: -0.02em;
}
.section-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; margin-bottom: 16px;
}
.section-head .section-title { margin-bottom: 0; }
.section-link {
    flex: 0 0 auto; min-height: 44px; display: inline-flex; align-items: center;
    color: var(--primary); font-size: 0.875rem; font-weight: 700;
}

/* Home discovery */
.home-hero {
    margin-bottom: 24px; padding: 18px 16px 16px;
    border: 1px solid var(--border); border-radius: 18px;
    background: linear-gradient(180deg, var(--surface), var(--bg));
}
.home-hero__eyebrow {
    margin-bottom: 6px; color: var(--primary);
    font-size: 0.8125rem; font-weight: 800; text-transform: uppercase;
}
.home-hero__title {
    max-width: 680px; margin-bottom: 8px;
    color: var(--text); font-size: 1.75rem; line-height: 1.12; font-weight: 800;
}
.home-hero__text {
    max-width: 680px; margin-bottom: 16px;
    color: var(--text-muted); font-size: 0.9375rem; line-height: 1.55;
}
.home-search {
    display: grid; grid-template-columns: 20px 1fr auto; align-items: center; gap: 10px;
    min-height: 52px; padding: 0 6px 0 16px;
    border: 1.5px solid var(--border); border-radius: 16px;
    background: var(--bg); color: var(--text-muted);
}
.home-search input {
    min-width: 0; height: 48px; border: none; outline: none;
    background: transparent; color: var(--text); font-size: 1rem;
}
.home-search button {
    min-height: 40px; padding: 0 14px; border: none; border-radius: 12px;
    background: var(--primary); color: #fff; font-weight: 600; cursor: pointer;
}
.home-actions {
    display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px;
}
.home-actions a {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: 42px; padding: 0 13px;
    border: 1px solid var(--border); border-radius: 12px;
    background: var(--bg); color: var(--text);
    font-size: 0.875rem; font-weight: 750;
}
.home-actions__primary {
    border-color: transparent !important;
    background: var(--primary) !important;
    color: #fff !important;
}
.continue-card {
    display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; gap: 14px; align-items: center;
    padding: 12px; border-radius: 16px; background: var(--surface);
    color: var(--text); box-shadow: var(--shadow);
}
.continue-card img,
.continue-card__cover {
    width: 56px; height: 84px; object-fit: cover; border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.14);
}
.continue-card__cover {
    display: flex; align-items: center; justify-content: center; padding: 6px;
    background: linear-gradient(145deg, var(--surface), var(--border));
    color: var(--text-muted); font-size: 0.6875rem; text-align: center;
}
.continue-card__body { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.continue-card__title { font-weight: 700; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.continue-card__meta { color: var(--text-muted); font-size: 0.8125rem; }
.continue-card__action { color: var(--primary); font-weight: 700; font-size: 0.875rem; }

.home-genres { margin-top: 28px; }
.genre-quick-grid {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px; margin-bottom: 18px;
}
.genre-quick-card {
    display: flex; flex-direction: column; justify-content: space-between;
    min-height: 86px; padding: 13px 14px; border: 1px solid var(--border);
    border-radius: 14px; background: var(--surface); color: var(--text);
}
.genre-quick-card:active { transform: scale(0.98); }
.genre-quick-card__name {
    font-size: 0.9375rem; line-height: 1.25; font-weight: 750;
}
.genre-quick-card__count {
    margin-top: 10px; color: var(--text-muted); font-size: 0.8125rem; line-height: 1.2;
}
.genre-groups {
    display: grid; gap: 12px;
}
.genre-group {
    padding: 14px; border: 1px solid var(--border);
    border-radius: 14px; background: var(--bg);
}
.genre-group__title {
    margin-bottom: 10px; color: var(--text);
    font-size: 1rem; line-height: 1.25; font-weight: 800;
}
.genre-group__links {
    display: flex; flex-wrap: wrap; gap: 8px;
}
.genre-group__link {
    display: inline-flex; align-items: center; min-height: 38px;
    padding: 6px 11px; border-radius: 999px; background: var(--surface);
    color: var(--text); font-size: 0.8125rem; font-weight: 650;
}
.genre-group__link:active { background: var(--border); }
.home-seo {
    margin: 34px 0 8px; padding: 18px;
    border: 1px solid var(--border); border-radius: 14px;
    background: var(--surface);
}
.home-seo h2 {
    margin-bottom: 10px; color: var(--text);
    font-size: 1.125rem; line-height: 1.3; font-weight: 800;
}
.home-seo p {
    color: var(--text-muted); font-size: 0.9375rem; line-height: 1.65;
}
.home-seo p + p { margin-top: 10px; }

/* Book shelf grid */
.book-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
.book-card {
    display: flex; flex-direction: column; text-align: center;
    min-width: 0;
    color: var(--text); transition: transform 0.2s;
}
.book-card:active { transform: scale(0.96); }
.book-card__cover-wrap {
    position: relative; display: block; width: 100%; aspect-ratio: 2/3;
}
.book-card img {
    width: 100%; aspect-ratio: 2/3; object-fit: cover;
    border-radius: 4px;
    box-shadow: 0 3px 10px rgba(0,0,0,0.15), 0 1px 3px rgba(0,0,0,0.1);
    background: var(--surface);
}
.book-cover-placeholder {
    display: flex; align-items: center; justify-content: center;
    width: 100%; aspect-ratio: 2/3; padding: 12px;
    border-radius: 6px; background: linear-gradient(145deg, var(--surface), var(--border));
    color: var(--text-muted); font-size: 0.8125rem; line-height: 1.3; text-align: center;
    box-shadow: 0 3px 10px rgba(0,0,0,0.12);
}
.book-card__badges {
    position: absolute; left: 6px; right: 6px; bottom: 6px;
    display: flex; flex-wrap: wrap; gap: 4px; justify-content: center;
    pointer-events: none;
}
.book-card__badge {
    display: inline-flex; align-items: center; min-height: 22px; max-width: 100%;
    padding: 0 7px; border-radius: 999px;
    background: rgba(28,28,30,0.78); color: #fff;
    font-size: 0.6875rem; font-weight: 800; line-height: 1;
    box-shadow: 0 2px 8px rgba(0,0,0,0.16);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.book-card__badge--favorite { background: rgba(255,107,53,0.92); }
.book-card__title {
    font-size: 0.8125rem; font-weight: 500; margin-top: 8px;
    min-height: calc(0.8125rem * 1.3 * 2);
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
    line-height: 1.3; overflow-wrap: anywhere;
}
.book-card__author {
    min-height: calc(0.75rem * 1.25 * 2);
    margin-top: 2px;
    color: var(--text-muted);
    font-size: 0.75rem;
    line-height: 1.25;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    overflow-wrap: anywhere;
}
.book-card__year { font-size: 0.71875rem; color: var(--text-muted); margin-top: 1px; }

/* Book detail — hero section */
.book-hero {
    display: flex; flex-direction: column; align-items: center;
    width: 100%; min-width: 0;
    text-align: center; margin-bottom: 28px; padding-top: 8px;
}
.book-hero__cover-wrap {
    position: relative;
    width: 160px;
    height: 240px;
    margin-bottom: 20px;
}
.book-hero__cover {
    width: 160px; height: 240px; object-fit: cover;
    border-radius: 6px;
    box-shadow: var(--shadow-lg), 0 2px 4px rgba(0,0,0,0.1);
}
.book-hero__favorite {
    position: absolute; right: 10px; top: 10px;
    display: inline-flex; align-items: center; justify-content: center;
    width: 44px; height: 44px;
    border: 1px solid rgba(255,255,255,0.7); border-radius: 50%;
    background: rgba(5,7,10,0.58); color: #fff;
    box-shadow: 0 6px 18px rgba(0,0,0,0.24);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    cursor: pointer;
}
.book-hero__favorite.active {
    background: var(--primary);
    border-color: var(--primary);
}
.book-hero__favorite.active svg { fill: currentColor; }
.book-hero__favorite:active { transform: scale(0.96); }
.book-actions__audio {
    flex-direction: column;
    gap: 2px;
}
.book-actions__audio small {
    display: block;
    max-width: 100%;
    color: currentColor;
    opacity: 0.76;
    font-size: 0.6875rem;
    line-height: 1.15;
    font-weight: 650;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.book-actions__audio small:empty { display: none; }
.book-hero__info {
    display: flex; flex-direction: column; gap: 4px; align-items: center;
    width: 100%; max-width: 100%; min-width: 0;
}
.book-hero__title {
    width: 100%; max-width: 100%; min-width: 0;
    font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2;
    overflow-wrap: anywhere;
}
.book-hero__authors { color: var(--primary); font-size: 1rem; font-weight: 500; }
.book-hero__author-link {
    display: inline-flex; align-items: center;
    min-height: 32px; color: var(--primary); text-decoration: none;
    border-bottom: 1px solid color-mix(in srgb, var(--primary) 35%, transparent);
}
.book-hero__author-link:active { opacity: 0.7; }
.book-hero__year { color: var(--text-muted); font-size: 0.875rem; }
.book-hero__meta {
    display: flex; gap: 12px; color: var(--text-muted); font-size: 0.8125rem;
    margin-top: 8px; padding: 8px 16px;
    background: var(--surface); border-radius: 20px;
}

.book-state {
    width: 100%; min-width: 0;
    margin: 20px 0 24px;
    position: relative;
}
.book-state__toggle {
    width: 100%; min-height: 56px;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 9px 13px 9px 15px;
    border: 1.5px solid var(--border); border-radius: 14px;
    background: var(--surface); color: var(--text);
    box-shadow: var(--shadow);
    cursor: pointer; font: inherit; text-align: left;
}
.book-state__toggle-copy {
    min-width: 0; display: flex; flex-direction: column; gap: 2px;
}
.book-state__title {
    color: var(--text-muted); font-size: 0.8125rem; line-height: 1.2; font-weight: 700;
}
.book-state__toggle strong {
    min-width: 0; color: var(--text);
    font-size: 0.984375rem; line-height: 1.25; font-weight: 800;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.book-state__chevron {
    flex: 0 0 20px; color: var(--text-muted);
    transition: transform 0.18s ease;
}
.book-state--open .book-state__chevron { transform: rotate(180deg); }
.book-state--has-value .book-state__toggle {
    border-color: color-mix(in srgb, var(--primary) 48%, var(--border));
}
.book-state__menu {
    position: absolute; left: 0; right: 0; top: 64px;
    z-index: 260;
    max-height: min(420px, calc(100dvh - 160px));
    overflow: auto;
    padding: 10px;
    border: 1px solid var(--border); border-radius: 14px;
    background: var(--bg);
    box-shadow: var(--shadow-lg);
}
.book-state__menu-title {
    padding: 12px 4px 8px;
    color: var(--text-muted); font-size: 0.8125rem; line-height: 1.2; font-weight: 750;
}
.book-state__statuses button,
.book-state__clear {
    min-height: 44px; border: 1.5px solid var(--border); border-radius: 12px;
    background: var(--bg); color: var(--text); cursor: pointer;
    font: inherit; font-size: 0.875rem; font-weight: 600;
}
.book-state__statuses {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px;
}
.book-state__statuses button { min-width: 0; }
.book-state__statuses button.active {
    border-color: var(--primary); background: var(--primary); color: #fff;
}
.book-state__clear {
    width: 100%; margin-top: 8px; color: var(--text-muted); background: transparent;
}
.book-state__meta { margin-top: 8px; font-size: 0.8125rem; color: var(--text-muted); }

/* Buttons — iOS-style rounded */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 14px 28px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 14px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    letter-spacing: -0.01em;
    transition: transform 0.1s, background 0.2s;
    box-shadow: 0 2px 12px rgba(255,107,53,0.3);
}
.btn:hover { background: var(--primary-hover); color: #fff; }
.btn:active { transform: scale(0.97); }
.btn--full { display: flex; width: 100%; }
.btn--secondary {
    background: var(--surface); color: var(--text); box-shadow: none;
}
.btn--secondary:hover { background: var(--border); color: var(--text); }
.book-actions {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px;
    width: 100%; min-width: 0;
}
.book-actions .btn {
    min-width: 0; padding-left: 10px; padding-right: 10px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.book-actions__primary { min-width: 0; }

/* Bottom nav — frosted glass */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    background: var(--chrome-bg-soft);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 0.5px solid var(--border);
    padding: 8px 0 calc(8px + var(--safe-bottom));
    z-index: 100;
}
.bottom-nav__item {
    appearance: none;
    border: 0;
    background: transparent;
    font: inherit;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    min-width: 0;
    font-size: 0.625rem; color: var(--text-muted); padding: 4px 2px;
    gap: 2px; font-weight: 500;
}
.bottom-nav__item svg { width: 24px; height: 24px; }
.bottom-nav__item span { max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bottom-nav__item.active { color: var(--primary); }
.bottom-nav__item--button { cursor: pointer; }
.bottom-nav__item--button:active { transform: scale(0.94); }

/* Pagination */
.pagination { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 24px; }
.pagination__btn {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: 44px; padding: 10px 20px; background: var(--surface); border-radius: 10px;
    color: var(--text); font-weight: 500; font-size: 0.875rem;
    transition: background 0.2s;
}
.pagination__btn:hover { background: var(--border); }
.pagination__info { font-size: 0.875rem; color: var(--text-muted); }

/* Hub description */
.hub-description { font-size: 0.9rem; line-height: 1.6; color: var(--text-muted); margin: 0 0 20px; padding: 12px 16px; background: var(--surface); border-radius: 12px; }

/* Catalog filters */
.catalog-filter {
    display: grid; gap: 12px; margin-bottom: 22px; padding: 14px;
    border: 1px solid var(--border); border-radius: 16px; background: var(--surface);
    position: relative; z-index: 20;
}
.catalog-filter__field,
.catalog-filter__dropdown {
    display: flex; flex-direction: column; gap: 6px; min-width: 0;
}
.catalog-filter__field > span,
.catalog-filter__dropdown summary > span {
    color: var(--text-muted); font-size: 0.8125rem; font-weight: 650;
}
.catalog-filter__field select {
    width: 100%; min-height: 50px; padding: 0 38px 0 13px;
    border: 1px solid var(--border); border-radius: 12px;
    background: var(--bg); color: var(--text); font: inherit;
    font-size: 0.9375rem;
}
.catalog-filter__dropdown {
    position: relative; z-index: 1;
}
.catalog-filter__dropdown[open] { z-index: 30; }
.catalog-filter__dropdown summary {
    display: flex; flex-direction: column; justify-content: center; gap: 5px;
    min-height: 62px; padding: 10px 38px 10px 13px;
    border: 1px solid var(--border); border-radius: 12px;
    background: var(--bg); color: var(--text); cursor: pointer; list-style: none;
    touch-action: manipulation;
}
.catalog-filter__dropdown summary::-webkit-details-marker { display: none; }
.catalog-filter__dropdown summary::after {
    content: "⌄"; position: absolute; right: 15px; top: 34px;
    color: var(--text-muted); font-size: 1.1rem; line-height: 1;
}
.catalog-filter__dropdown[open] summary::after { transform: rotate(180deg); }
.catalog-filter__dropdown[open] summary {
    border-color: rgba(255,107,53,0.55);
    box-shadow: 0 0 0 3px rgba(255,107,53,0.12);
}
.catalog-filter__dropdown summary strong {
    color: var(--text); font-size: 0.9375rem; font-weight: 700; line-height: 1.2;
}
.catalog-filter__checks {
    position: absolute; left: 0; right: 0; top: calc(100% + 8px);
    max-height: min(430px, calc(100dvh - 210px)); overflow: hidden; margin: 0;
    border: 1px solid var(--border); border-radius: 12px;
    background: var(--bg);
    box-shadow: var(--shadow-lg);
    overscroll-behavior: contain;
    z-index: 40;
}
.catalog-filter__options {
    max-height: min(350px, calc(100dvh - 300px));
    overflow: auto;
    overscroll-behavior: contain;
}
.catalog-filter__tri {
    display: grid; grid-template-columns: 22px minmax(0, 1fr) auto;
    width: 100%; border: none; background: var(--bg); font: inherit; text-align: left;
    align-items: center; gap: 10px; min-height: 48px;
    padding: 9px 12px; border-bottom: 1px solid var(--border);
    color: var(--text); cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.catalog-filter__tri:active { background: var(--surface); }
.catalog-filter__tri[hidden] { display: none; }
.catalog-filter__box {
    width: 19px; height: 19px; border-radius: 5px;
    border: 1.5px solid var(--border); background: var(--bg);
    display: inline-flex; align-items: center; justify-content: center;
    color: #fff; font-size: 0.875rem; line-height: 1; font-weight: 900;
}
.catalog-filter__tri.is-include .catalog-filter__box {
    border-color: var(--primary); background: var(--primary);
}
.catalog-filter__tri.is-include .catalog-filter__box::before { content: "✓"; }
.catalog-filter__tri.is-exclude .catalog-filter__box {
    border-color: #EF4444; background: #EF4444;
}
.catalog-filter__tri.is-exclude .catalog-filter__box::before { content: "−"; }
.catalog-filter__tri span {
    min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-size: 0.9375rem; line-height: 1.25; font-weight: 550;
}
.catalog-filter__tri em {
    color: var(--text-muted); font-size: 0.8125rem; font-style: normal;
}
.catalog-filter__tri.is-exclude span { color: #B91C1C; }
.catalog-filter__quick {
    position: sticky; bottom: 0; display: grid; gap: 6px;
    padding: 10px; border-top: 1px solid var(--border);
    background: var(--bg);
}
.catalog-filter__quick span {
    color: var(--text-muted); font-size: 0.75rem; font-weight: 650;
}
.catalog-filter__quick input {
    width: 100%; min-height: 42px; padding: 0 12px;
    border: 1px solid var(--border); border-radius: 10px;
    background: var(--surface); color: var(--text); font: inherit;
    font-size: 0.9375rem; outline: none;
}
.catalog-filter__quick input:focus {
    border-color: rgba(255,107,53,0.55);
    box-shadow: 0 0 0 3px rgba(255,107,53,0.12);
}
.catalog-filter__actions {
    display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: center;
}
.catalog-filter__actions button,
.catalog-filter__actions a {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: 44px; border-radius: 12px; font-weight: 750; font-size: 0.875rem;
}
.catalog-filter__actions button {
    border: none; background: var(--primary); color: #fff; cursor: pointer;
}
.catalog-filter__actions a {
    border: 1px solid var(--border); background: var(--bg); color: var(--text);
}

/* Genre/Author list */
.genre-list { display: flex; flex-direction: column; gap: 1px; background: var(--border); border-radius: 12px; overflow: hidden; }
.genre-item { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; background: var(--bg); text-decoration: none; color: var(--text); }
.genre-item:active { background: var(--surface); }
.genre-item__name { font-size: 0.95rem; }
.genre-item__count { font-size: 0.8rem; color: var(--text-muted); background: var(--surface); padding: 2px 8px; border-radius: 10px; }

/* Tags — pill style */
.tags { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.tag {
    display: inline-flex; align-items: center;
    min-height: 44px; padding: 6px 14px; background: var(--surface);
    border-radius: 20px; font-size: 0.8125rem; color: var(--text);
    font-weight: 500; transition: background 0.2s;
}
.tag:hover { background: var(--border); }

/* TOC — clean list */
.toc { list-style: none; padding: 0; }
.toc li {
    padding: 0; border-bottom: 0.5px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
}
.toc a { display: flex; align-items: center; min-height: 48px; color: var(--text); font-size: 0.9375rem; flex: 1; }
.toc li::after { content: "›"; color: var(--text-muted); font-size: 1.25rem; font-weight: 300; }

/* Book annotation */
.book-annotation {
    font-family: var(--font-serif);
    font-size: 1rem; line-height: 1.75; color: var(--text);
    margin: 0; padding: 18px;
    background: var(--surface); border-radius: var(--radius);
}
.book-annotation-wrap {
    background: var(--surface); border-radius: var(--radius);
    margin: 12px 0 20px; overflow: hidden;
}

/* Reader — immersive paper feel */
.reader {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    padding-top: calc(60px + var(--safe-top));
    background: var(--bg);
}
.reader__header {
    display: flex; align-items: center; gap: 6px;
    min-height: calc(58px + var(--safe-top));
    padding: calc(6px + var(--safe-top)) 10px 6px;
    border-bottom: 0.5px solid var(--border);
    position: fixed; left: 0; right: 0; top: 0;
    background: var(--chrome-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: 120;
    transition: transform 0.3s ease, opacity 0.3s ease;
}
.reader__top-progress {
    position: fixed;
    left: 0;
    right: 0;
    top: calc(58px + var(--safe-top));
    z-index: 119;
    height: 2px;
    background: transparent;
    transition: transform 0.24s ease, opacity 0.18s ease;
}
.reader--chrome-hidden:not(.reader--paged) .reader__header {
    transform: translateY(-100%);
    opacity: 0;
    pointer-events: none;
}
.reader--chrome-hidden:not(.reader--paged) .reader__top-progress {
    transform: translateY(calc(-58px - var(--safe-top)));
    opacity: 0;
}
.reader__back {
    display: flex; align-items: center; justify-content: center;
    width: 44px; height: 44px; flex: 0 0 44px;
    color: var(--primary); border-radius: 50%;
    -webkit-tap-highlight-color: transparent;
}
.reader__back:active { background: var(--surface); }
.reader__back svg { flex-shrink: 0; }
.reader__heading { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.reader__book,
.reader__title { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader__book { color: var(--text); font-size: 0.875rem; font-weight: 700; line-height: 1.2; }
.reader__title { font-size: 0.75rem; line-height: 1.25; color: var(--text-muted); }
.reader__icon-btn {
    display: flex; align-items: center; justify-content: center;
    width: 44px; height: 44px; flex: 0 0 44px;
    border: none; background: transparent; color: var(--primary);
    border-radius: 50%; cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.reader__icon-btn:active { background: var(--surface); }
.reader__bookmark-btn.active {
    color: #fff;
    background: var(--primary);
}
.reader__bookmark-btn.active svg { fill: currentColor; }
.reader__aa {
    font-family: var(--font-serif);
    font-size: 1rem;
    font-weight: 700;
    line-height: 1;
}
.reader__settings-btn {
    display: flex; align-items: center; justify-content: center;
    min-width: 48px; min-height: 48px;
    border: none; background: none; color: var(--primary);
    font-size: 1.0625rem; font-weight: 600; cursor: pointer;
    border-radius: 12px; font-family: var(--font-serif);
    -webkit-tap-highlight-color: transparent;
}
.reader__settings-btn:active { background: var(--surface); }
.reader__progress {
    display: none;
    min-width: 42px;
    padding: 0 2px;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* Settings panel */
.reader__settings {
    display: none; padding: 16px 20px;
    background: var(--surface); border-bottom: 0.5px solid var(--border);
    position: sticky; top: 64px; z-index: 9;
}
.reader__settings.open { display: block; }
.reader__settings-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.reader__settings-row + .reader__settings-row { margin-top: 16px; }
.reader__settings-label { font-size: 0.8125rem; color: var(--text-muted); font-weight: 500; }
.reader__font-controls { display: flex; gap: 8px; }
.reader__font-btn {
    display: flex; align-items: center; justify-content: center;
    min-width: 48px; min-height: 48px;
    border: 1.5px solid var(--border); border-radius: 12px;
    background: var(--bg); color: var(--text);
    cursor: pointer; font-family: var(--font-serif);
    -webkit-tap-highlight-color: transparent;
}
.reader__font-btn[data-size="16"] { font-size: 0.8125rem; }
.reader__font-btn[data-size="18"] { font-size: 1.0625rem; }
.reader__font-btn[data-size="21"] { font-size: 1.375rem; }
.reader__font-btn.active { border-color: var(--primary); background: var(--primary); color: #fff; }
.reader__theme-controls { display: flex; gap: 8px; }
.reader__theme-btn {
    width: 48px; height: 48px; border-radius: 50%; cursor: pointer;
    border: 2.5px solid var(--border);
    -webkit-tap-highlight-color: transparent;
}
.reader__theme-btn--light { background: #FFFDF7; }
.reader__theme-btn--sepia { background: #F8F1E3; }
.reader__theme-btn--dark { background: #1C1C1E; }
.reader__theme-btn.active { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary); }

.reader__content {
    flex: 1;
    padding: 28px 22px 40px;
    max-width: 680px;
    margin: 0 auto;
    width: 100%;
    font-family: var(--font-serif); font-size: 1.125rem; line-height: 1.88;
    color: var(--text); transition: font-size 0.2s ease;
}
.reader__chapter-head { margin: 0 0 30px; text-align: center; }
.reader__chapter-kicker {
    display: block;
    margin-bottom: 8px;
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 0.8125rem;
    font-weight: 600;
}
.reader__chapter-head h1 {
    margin: 0;
    color: var(--text);
    font-family: var(--font);
    font-size: clamp(1.35rem, 6vw, 2rem);
    line-height: 1.2;
    letter-spacing: 0;
    text-indent: 0;
}
.reader__content p { margin-bottom: 1.2em; text-indent: 1.45em; }
.reader__content p,
.reader__content li {
    overflow-wrap: anywhere;
}
.reader__content p:first-child { text-indent: 0; }
.reader__content h1, .reader__content h2, .reader__content h3 {
    margin: 2em 0 0.75em; font-family: var(--font); letter-spacing: 0;
    text-indent: 0;
}
.reader--paged {
    min-height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: manipulation;
    padding-top: 0;
}
.reader--paged .reader__header {
    position: fixed; left: 0; right: 0; top: 0;
}
.reader--paged .reader__top-progress {
    position: fixed; left: 0; right: 0;
}
.reader--paged .reader__content {
    box-sizing: border-box;
    position: fixed;
    left: 0;
    right: 0;
    top: var(--reader-content-top, 66px);
    bottom: var(--reader-content-bottom, 0px);
    z-index: 1;
    display: block;
    max-width: none;
    width: 100%;
    margin: 0;
    padding: 20px 22px 28px;
    overflow: hidden;
    line-height: 1.62 !important;
    user-select: text;
    -webkit-user-select: text;
    touch-action: pan-y pinch-zoom;
    column-width: auto;
    column-gap: 0;
    column-fill: auto;
    scroll-behavior: auto;
}
.reader--paged .reader__content p { margin-bottom: 0.72em; }
.reader__footer {
    width: min(740px, calc(100% - 44px));
    margin: 0 auto;
    padding: 8px 0 calc(28px + var(--safe-bottom));
    border-top: 1px solid var(--border);
    transition: transform 0.3s ease, opacity 0.3s ease;
}
.reader--paged .reader__footer {
    position: fixed; left: 0; right: 0; bottom: 0;
    width: auto;
    margin: 0;
    background: var(--chrome-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 0.5px solid var(--border);
    padding: 5px 12px calc(5px + var(--safe-bottom));
    z-index: 120;
}
.reader__nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.reader__nav-btn {
    display: inline-flex; align-items: center; gap: 4px;
    min-width: 48px; min-height: 48px;
    padding: 8px 16px; border-radius: 12px;
    font-size: 0.9375rem; color: var(--primary); font-weight: 500;
    -webkit-tap-highlight-color: transparent;
}
.reader__nav-btn:active { background: var(--surface); }
.reader__nav-btn svg { flex-shrink: 0; }
.reader__nav-btn--disabled { color: var(--text-muted); pointer-events: none; }
.reader__chapter-num {
    flex: 1;
    font-size: 0.8125rem;
    color: var(--text-muted);
    text-align: center;
    font-variant-numeric: tabular-nums;
}
.reader__progress-bar { height: 2px; background: var(--border); border-radius: 1px; margin-top: 8px; }
.reader__progress-fill { height: 100%; background: var(--primary); border-radius: 0 1px 1px 0; width: 0; transition: width 0.3s ease; }
.reader-selection-toolbar {
    position: fixed;
    left: 50%;
    top: 50%;
    z-index: 700;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--chrome-bg);
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    transform: translate(-50%, -12px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.16s ease, transform 0.16s ease;
}
.reader-selection-toolbar.open {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, 0);
}
.reader-selection-toolbar button {
    min-height: 40px;
    padding: 0 10px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 0.8125rem;
    font-weight: 700;
    cursor: pointer;
}
.reader-selection-toolbar button:active { background: var(--surface); }
.reader-toast {
    position: fixed;
    left: 50%;
    bottom: calc(22px + var(--safe-bottom));
    z-index: 800;
    max-width: min(360px, calc(100vw - 32px));
    padding: 12px 16px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--text) 92%, transparent);
    color: var(--bg);
    font-size: 0.875rem;
    font-weight: 700;
    line-height: 1.3;
    text-align: center;
    box-shadow: var(--shadow-lg);
    transform: translate(-50%, 18px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease, transform 0.18s ease;
}
.reader-toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

/* Search */
.search-form { margin-bottom: 20px; }
.search-input {
    width: 100%; padding: 14px 18px; border: none;
    border-radius: 12px; font-size: 1rem; background: var(--surface);
    color: var(--text); outline: none;
    transition: box-shadow 0.2s;
}
.search-input:focus { box-shadow: 0 0 0 3px rgba(255,107,53,0.2); }
.search-results { list-style: none; }
.search-result { padding: 14px 0; border-bottom: 0.5px solid var(--border); }
.search-result a { display: block; color: var(--text); font-weight: 500; }
.search-result__author { display: block; font-size: 0.8125rem; color: var(--text-muted); margin-top: 2px; }
.search-result__year { display: block; font-size: 0.78125rem; color: var(--text-muted); margin-top: 2px; }
.search-result__badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.search-result__badges .book-card__badge { background: var(--surface); color: var(--text-muted); box-shadow: none; }
.search-result__badges .book-card__badge--favorite { color: var(--primary); }
.empty { text-align: center; color: var(--text-muted); padding: 60px 0; font-size: 1.0625rem; }

/* Login / Desktop landing */
.login-page {
    position: relative;
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; min-height: 80dvh; padding: 20px;
    width: 100%;
}
.auth-back {
    position: absolute;
    top: max(12px, var(--safe-top));
    left: 16px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 44px;
    padding: 0 12px;
    border-radius: 12px;
    color: var(--primary);
    font-size: 0.9375rem;
    font-weight: 600;
    -webkit-tap-highlight-color: transparent;
}
.auth-back:active { background: var(--surface); }
.login-page__title { font-size: 2.5rem; color: var(--primary); margin-bottom: 4px; font-weight: 700; letter-spacing: -0.03em; }
.login-page__subtitle { color: var(--text-muted); margin-bottom: 32px; font-size: 1.0625rem; }
.login-page__error { color: #FF3B30; margin-bottom: 12px; font-size: 0.875rem; }
.login-form { width: 100%; max-width: 320px; display: flex; flex-direction: column; gap: 14px; }
.login-form__input {
    padding: 14px 18px; border: none; border-radius: 12px;
    font-size: 1rem; background: var(--surface); color: var(--text);
}
.login-page__message {
    width: 100%; max-width: 320px;
    color: #34C759; margin-bottom: 12px; font-size: 0.875rem;
    text-align: center; overflow-wrap: anywhere;
}
.login-page > .btn--full { max-width: 320px; }
.login-page__link { margin-top: 16px; font-size: 0.875rem; color: var(--text-muted); }
.login-page__link a { color: var(--primary); text-decoration: none; font-weight: 500; }
.profile-info { width: 100%; max-width: 320px; display: flex; flex-direction: column; gap: 12px; margin-top: 24px; }
.profile-info__item { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; background: var(--surface); border-radius: 12px; }
.profile-info__label { font-size: 0.875rem; color: var(--text-muted); }
.profile-info__value { font-size: 1rem; font-weight: 600; color: var(--text); }
.profile-page { max-width: 620px; }
.profile-page__head { margin-bottom: 20px; }
.profile-page__title { font-size: 1.75rem; font-weight: 800; letter-spacing: -0.02em; }
.profile-page__subtitle { margin-top: 4px; color: var(--text-muted); font-size: 0.9375rem; }
.profile-stats {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px;
    margin: 16px 0 24px;
}
.profile-stat {
    min-width: 0; padding: 12px 8px; border-radius: 14px;
    background: var(--surface); text-align: center;
}
.profile-stat__value { display: block; font-size: 1.25rem; font-weight: 800; color: var(--text); }
.profile-stat__label { display: block; margin-top: 2px; font-size: 0.75rem; color: var(--text-muted); }
.profile-stat:last-child { grid-column: 1 / -1; }
.profile-list { display: flex; flex-direction: column; gap: 10px; }
.profile-book {
    display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 12px; align-items: center;
    padding: 10px; border-radius: 14px; background: var(--surface); color: var(--text);
}
.profile-book--actionable { grid-template-columns: minmax(0, 1fr) auto; }
.profile-book__link {
    min-width: 0;
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr);
    gap: 12px;
    align-items: center;
    color: var(--text);
}
.profile-book__cover {
    width: 44px; height: 66px; object-fit: cover; border-radius: 4px;
    background: var(--border); box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}
.profile-book__body { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.profile-book__title { font-weight: 700; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-book__meta { display: flex; flex-wrap: wrap; gap: 6px; font-size: 0.75rem; color: var(--text-muted); }
.profile-pill {
    display: inline-flex; align-items: center; min-height: 24px; padding: 0 8px;
    border-radius: 999px; background: var(--bg); color: var(--text-muted); font-weight: 700;
}
.profile-pill--primary { color: var(--primary); }
.profile-empty {
    padding: 18px; border-radius: 14px; background: var(--surface);
    color: var(--text-muted); font-size: 0.9375rem; line-height: 1.5;
}
.profile-book__delete-form { display: flex; align-items: center; }
.profile-delete-btn {
    min-height: 40px;
    padding: 0 10px;
    border: none;
    border-radius: 10px;
    background: var(--bg);
    color: #B42318;
    font: inherit;
    font-size: 0.8125rem;
    font-weight: 800;
    cursor: pointer;
}
.profile-delete-btn:active { opacity: 0.72; }
.profile-account { margin-top: 28px; }
.profile-account__form { max-width: none; }
.profile-danger {
    margin-top: 14px;
    padding: 14px;
    border: 1px solid rgba(180,35,24,0.26);
    border-radius: 14px;
    background: color-mix(in srgb, #B42318 7%, var(--bg));
}
.profile-danger__confirm {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    font-size: 0.875rem;
    line-height: 1.45;
}
.profile-danger__confirm input { margin-top: 2px; }
.profile-danger__btn {
    width: 100%;
    min-height: 48px;
    margin-top: 12px;
    border: none;
    border-radius: 12px;
    background: #B42318;
    color: #fff;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
}
.profile-danger__btn:active { opacity: 0.82; }

/* Admin */
.admin-table { width: 100%; border-collapse: collapse; font-size: 0.8125rem; margin-top: 16px; }
.admin-table th, .admin-table td { padding: 10px 8px; border-bottom: 0.5px solid var(--border); text-align: left; }
.admin-table th { font-weight: 600; background: var(--surface); }

/* Global Settings Panel */
.g-settings-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.4);
    z-index: 300; opacity: 0; pointer-events: none;
    transition: opacity 0.3s;
}
.g-settings-overlay.open { opacity: 1; pointer-events: auto; }
.g-settings {
    position: fixed; bottom: 0; left: 0; right: 0;
    background: var(--bg); border-radius: 20px 20px 0 0;
    padding: 20px 20px calc(20px + var(--safe-bottom));
    z-index: 301; transform: translateY(100%);
    transition: transform 0.3s ease;
    max-height: 80dvh; overflow-y: auto;
    box-shadow: 0 -4px 32px rgba(0,0,0,0.15);
}
.g-settings.open { transform: translateY(0); }
.g-settings__header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.g-settings__title { font-size: 1.125rem; font-weight: 700; color: var(--text); }
.g-settings__close {
    width: 44px; height: 44px; border-radius: 50%;
    background: var(--surface); border: none; color: var(--text-muted);
    font-size: 1rem; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.g-settings__section { margin-bottom: 20px; }
.g-settings__label { display: block; font-size: 0.8125rem; color: var(--text-muted); font-weight: 500; margin-bottom: 10px; }
.g-settings__hint { font-size: 0.75rem; color: var(--text-muted); margin-top: 6px; display: block; }
.g-settings__row { display: flex; gap: 10px; }
.g-reading-mode { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-reading-mode-btn {
    min-height: 44px; border: 1px solid var(--border); border-radius: 12px;
    background: var(--surface); color: var(--text); font-weight: 600; cursor: pointer;
}
.g-reading-mode-btn.active { border-color: var(--primary); background: var(--primary); color: #fff; }

/* Theme buttons */
.g-theme-btn {
    width: 48px; height: 48px; border-radius: 50%; cursor: pointer;
    border: 2.5px solid var(--border);
    -webkit-tap-highlight-color: transparent;
}
.g-theme-btn--light { background: #FFFDF7; }
.g-theme-btn--sepia { background: #F8F1E3; }
.g-theme-btn--dark { background: #1C1C1E; }
.g-theme-btn--contrast { background: #05070A; box-shadow: inset 0 0 0 6px #05070A, inset 0 0 0 8px #60A5FA, inset 0 0 0 14px #F8FAFC; }
.g-theme-btn.active { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary); }
.g-theme-btn--contrast.active { border-color: #60A5FA; box-shadow: 0 0 0 2px #60A5FA; }

/* Font family buttons */
.g-font-family-btn {
    flex: 1; min-height: 48px; border: 1.5px solid var(--border);
    border-radius: 12px; background: var(--bg); color: var(--text);
    font-size: 1rem; font-weight: 500; cursor: pointer;
    font-family: var(--font);
    -webkit-tap-highlight-color: transparent;
}
.g-font-family-btn--serif { font-family: Georgia, 'Palatino Linotype', serif; }
.g-font-family-btn--mono { font-family: 'SF Mono', 'Fira Code', 'Courier New', monospace; font-size: 0.875rem; }
.g-font-family-btn.active { border-color: var(--primary); background: var(--primary); color: #fff; }

/* Range slider */
.g-range {
    -webkit-appearance: none; width: 100%; height: 4px;
    background: var(--border); border-radius: 2px; outline: none;
}
.g-range::-webkit-slider-thumb {
    -webkit-appearance: none; width: 28px; height: 28px;
    background: var(--primary); border-radius: 50%; cursor: pointer;
    border: 3px solid var(--bg); box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

/* Toggle switch */
.g-toggle {
    display: flex; align-items: center; gap: 12px; cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.g-toggle input { display: none; }
.g-toggle__slider {
    width: 48px; height: 28px; background: var(--border);
    border-radius: 14px; position: relative; transition: background 0.2s; flex-shrink: 0;
}
.g-toggle__slider::after {
    content: ''; position: absolute; top: 3px; left: 3px;
    width: 22px; height: 22px; background: #fff;
    border-radius: 50%; transition: transform 0.2s; box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}
.g-toggle input:checked + .g-toggle__slider { background: var(--primary); }
.g-toggle input:checked + .g-toggle__slider::after { transform: translateX(20px); }
.g-toggle__label { font-size: 0.9375rem; color: var(--text); font-weight: 500; }

/* Bionic reading */
.bionic-active .reader__content b,
.bionic-active .book-annotation b { font-weight: 700; }

/* AI summary */
.ai-summary-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 10px 20px; border: 1.5px solid var(--primary);
    border-radius: 12px; background: transparent;
    color: var(--primary); font-size: 0.875rem; font-weight: 500;
    cursor: pointer; margin-top: 16px;
    -webkit-tap-highlight-color: transparent;
}
.ai-summary-btn:active { background: var(--surface); }
.ai-summary-btn svg { flex-shrink: 0; }
.ai-summary {
    margin-top: 12px; padding: 16px;
    background: var(--surface); border-radius: 12px;
    font-size: 0.9375rem; line-height: 1.65; color: var(--text);
}
.ai-summary--loading { text-align: center; color: var(--text-muted); }

/* Reading time */
.reader__time {
    font-size: 0.75rem; color: var(--text-muted);
    text-align: center; padding: 8px 0; opacity: 0.7;
}
.reader--paged .reader__time { display: none; }

/* Reader toolbar */
.reader__toolbar {
    display: flex; justify-content: center; gap: 6px;
    padding: 2px 0 6px;
    border-bottom: 0.5px solid var(--border); margin-bottom: 6px;
}
.reader:not(.reader--paged) .reader__toolbar { display: none; }
.reader__tool-btn {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    flex: 0 1 112px; min-width: 0; height: 46px; border: none; background: none;
    color: var(--text-muted); cursor: pointer; border-radius: 10px;
    font-size: 0.6875rem; font-weight: 600;
    -webkit-tap-highlight-color: transparent;
}
.reader__tool-btn svg { width: 20px; height: 20px; }
.reader__tool-btn:active { background: var(--surface); }
.reader__tool-btn.active { color: var(--primary); }

.r-state-panel {
    padding: 12px 0 14px;
    border-bottom: 0.5px solid var(--border);
    margin-bottom: 4px;
}
.r-state-panel__head {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    margin-bottom: 10px; font-size: 0.875rem; font-weight: 700;
}
.r-state-panel__favorite,
.r-state-panel__statuses button {
    min-height: 40px; border: 1.5px solid var(--border); border-radius: 12px;
    background: var(--bg); color: var(--text); cursor: pointer;
    font: inherit; font-size: 0.8125rem; font-weight: 600;
}
.r-state-panel__favorite { padding: 0 12px; color: var(--text-muted); }
.r-state-panel__favorite.active {
    color: var(--primary); border-color: var(--primary); background: color-mix(in srgb, var(--primary) 10%, var(--bg));
}
.r-state-panel__statuses {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px;
}
.r-state-panel__statuses button.active {
    border-color: var(--primary); background: var(--primary); color: #fff;
}

/* Reader overlays (sheets) */
.r-overlay {
    position: fixed; inset: 0; z-index: 500;
    background: rgba(0,0,0,0.45);
    opacity: 0; pointer-events: none; transition: opacity 0.25s;
}
.r-overlay.open { opacity: 1; pointer-events: auto; }
.r-sheet {
    position: absolute; bottom: 0; left: 0; right: 0;
    background: var(--bg); border-radius: 20px 20px 0 0;
    max-height: 75dvh; display: flex; flex-direction: column;
    transform: translateY(100%); transition: transform 0.3s ease;
    box-shadow: 0 -4px 24px rgba(0,0,0,0.12);
}
.r-overlay.open .r-sheet { transform: translateY(0); }
.r-sheet--sm { max-height: 50dvh; }
.r-sheet__header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 20px; font-weight: 700; font-size: 1rem; color: var(--text);
    border-bottom: 0.5px solid var(--border); flex-shrink: 0;
}
.r-sheet__close {
    width: 44px; height: 44px; border-radius: 50%;
    background: var(--surface); border: none; color: var(--text-muted);
    font-size: 0.875rem; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.r-sheet__body { padding: 16px 20px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.auth-required { z-index: 900; }
.auth-required__body p {
    margin: 0 0 16px;
    color: var(--text);
    font-size: 0.9375rem;
    line-height: 1.55;
}
.auth-required__actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}
.auth-required__actions .btn {
    min-height: 48px;
    padding-left: 14px;
    padding-right: 14px;
}

/* TOC items */
.r-toc-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px 0; border-bottom: 0.5px solid var(--border);
    color: var(--text); font-size: 0.9375rem;
}
.r-toc-item--active { color: var(--primary); font-weight: 600; }
.r-toc-item__num { color: var(--text-muted); font-size: 0.8125rem; }

/* Sound grid */
.r-sound-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.r-sound-btn {
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    padding: 16px 8px; border: 1.5px solid var(--border); border-radius: 14px;
    background: var(--bg); font-size: 0.75rem; color: var(--text-muted);
    cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.r-sound-btn span { font-size: 0.6875rem; }
.r-sound-btn.active { border-color: var(--primary); background: var(--surface); color: var(--primary); }
.r-sound-vol { display: flex; align-items: center; gap: 12px; font-size: 0.8125rem; color: var(--text-muted); }
.r-sound-vol .g-range { flex: 1; }

/* TTS controls */
.r-tts-controls { display: flex; flex-direction: column; gap: 16px; }
.r-control { display: flex; flex-direction: column; gap: 8px; }
.r-control__label { font-size: 0.8125rem; color: var(--text-muted); font-weight: 500; }
.r-select {
    width: 100%; min-height: 48px; padding: 0 12px;
    border: 1.5px solid var(--border); border-radius: 12px;
    background: var(--bg); color: var(--text); font-size: 0.9375rem;
}
.r-tts-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.r-tts-btn {
    min-height: 48px; border: 1.5px solid var(--border); border-radius: 12px;
    background: var(--bg); color: var(--text); font-size: 0.9375rem;
    font-weight: 600; cursor: pointer;
}
.r-tts-btn--primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.r-tts-btn:disabled { opacity: 0.45; cursor: default; }
.r-tts-progress {
    display: grid; gap: 8px;
    padding: 12px;
    border: 1px solid var(--border); border-radius: 12px;
    background: var(--surface);
}
.r-tts-progress__head {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    font-size: 0.8125rem;
}
.r-tts-progress__head span { color: var(--text-muted); font-weight: 650; }
.r-tts-progress__head strong {
    min-width: 0; color: var(--text); font-weight: 800;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.r-tts-progress__bar {
    height: 6px; overflow: hidden; border-radius: 999px; background: var(--border);
}
.r-tts-progress__bar span {
    display: block; width: 0; height: 100%;
    border-radius: inherit; background: var(--primary);
    transition: width 0.2s ease;
}
.r-tts-status { font-size: 0.8125rem; color: var(--text-muted); min-height: 20px; }

/* AI panel */
.r-ai-btn {
    display: block; width: 100%; padding: 14px 16px; margin-bottom: 8px;
    border: 1.5px solid var(--border); border-radius: 12px;
    background: var(--bg); color: var(--text); font-size: 0.9375rem;
    text-align: left; cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.r-ai-btn:active { background: var(--surface); }
.r-ai-result {
    margin-top: 12px; padding: 14px; background: var(--surface);
    border-radius: 12px; font-size: 0.875rem; line-height: 1.65;
    color: var(--text); white-space: pre-wrap; display: none;
}
.r-ai-result.show { display: block; }

/* More menu buttons */
.r-more-btn {
    display: flex; align-items: center; gap: 12px; width: 100%;
    padding: 14px 0; border: none; background: none;
    color: var(--text); font-size: 0.9375rem; cursor: pointer;
    border-bottom: 0.5px solid var(--border);
    -webkit-tap-highlight-color: transparent;
}
.r-more-btn:last-child { border-bottom: none; }
.r-more-btn:active { opacity: 0.6; }
.r-more-btn.active { color: var(--primary); }
.r-more-btn svg { color: var(--text-muted); flex-shrink: 0; }
.r-more-btn.active svg { color: var(--primary); }

/* RSVP screen */
.r-rsvp {
    position: absolute; inset: 0; display: flex;
    flex-direction: column; align-items: center; justify-content: center;
    background: var(--bg); gap: 32px;
}
.r-rsvp__close {
    position: absolute; top: 16px; right: 16px;
    width: 44px; height: 44px; border-radius: 50%;
    background: var(--surface); border: none; color: var(--text);
    font-size: 1.125rem; cursor: pointer;
}
.r-rsvp__word {
    font-size: 2.5rem; font-weight: 700; color: var(--text);
    min-height: 56px; text-align: center; font-family: var(--font-serif);
}
.r-rsvp__controls { display: flex; align-items: center; gap: 20px; }
.r-rsvp__btn {
    width: 48px; height: 48px; border-radius: 50%;
    border: 1.5px solid var(--border); background: var(--bg);
    color: var(--text); font-size: 1.25rem; cursor: pointer;
}
.r-rsvp__wpm { font-size: 0.875rem; color: var(--text-muted); min-width: 80px; text-align: center; }
.r-rsvp__play {
    padding: 14px 40px; border-radius: 14px;
    background: var(--primary); color: #fff; border: none;
    font-size: 1rem; font-weight: 600; cursor: pointer;
}

/* Search in book results */
#book-search-results { margin-top: 12px; }
.r-search-hit {
    display: block; padding: 12px 0; border-bottom: 0.5px solid var(--border);
    color: var(--text); font-size: 0.875rem; line-height: 1.5;
}
.r-search-hit__ch { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 4px; }
.r-search-hit mark { background: rgba(255,107,53,0.2); color: var(--primary); border-radius: 2px; }

/* Bookmarks list */
.r-bookmarks-list { display: flex; flex-direction: column; gap: 1px; }
.r-bookmark {
    display: flex; align-items: stretch; gap: 10px;
    border-bottom: 0.5px solid var(--border);
}
.r-bookmark__link {
    flex: 1; display: flex; flex-direction: column; gap: 4px;
    padding: 12px 0; color: var(--text); min-width: 0;
}
.r-bookmark__chapter { font-size: 0.75rem; color: var(--text-muted); }
.r-bookmark__meta { font-size: 0.75rem; color: var(--primary); }
.r-bookmark__text {
    font-size: 0.875rem; line-height: 1.5;
    display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
    overflow: hidden;
}
.r-bookmark__delete {
    align-self: center; width: 44px; height: 44px; border-radius: 50%;
    border: none; background: var(--surface); color: var(--text-muted);
    cursor: pointer; font-size: 0.875rem;
}
.r-bookmarks-empty { padding: 32px 0; }

/* Desktop adaptation */
@media (min-width: 900px) {
    .main {
        max-width: 1120px;
        padding: 28px 32px calc(88px + var(--safe-bottom));
    }
    .book-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 24px;
    }
    .book-card__title { font-size: 0.9rem; }
    .book-card__author { font-size: 0.8125rem; }
    .home-hero {
        padding: 28px; margin-bottom: 32px;
    }
    .home-hero__title {
        font-size: 2.25rem;
    }
    .home-hero__text {
        font-size: 1rem;
    }
    .genre-quick-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 12px;
    }
    .genre-groups {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .catalog-filter {
        grid-template-columns: minmax(280px, 2fr) minmax(190px, 1fr) auto;
        align-items: end;
        padding: 16px;
    }
    .catalog-filter__dropdown--genres .catalog-filter__checks {
        width: min(560px, 90vw);
        right: auto;
    }
    .catalog-filter__actions {
        min-width: 210px;
    }
    .book-hero {
        display: grid;
        grid-template-columns: 220px minmax(0, 1fr);
        align-items: start;
        gap: 32px;
        text-align: left;
        max-width: 840px;
        margin-left: auto;
        margin-right: auto;
    }
    .book-hero__cover-wrap,
    .book-hero__cover {
        width: 220px;
        height: 330px;
    }
    .book-hero__cover-wrap {
        margin-bottom: 0;
    }
    .book-hero__info { align-items: flex-start; padding-top: 10px; }
    .book-hero__title { font-size: 2rem; }
    .book-actions,
    .book-hero + .btn {
        max-width: 840px;
        margin-left: auto;
        margin-right: auto;
    }
    .book-actions { grid-template-columns: 1.35fr 1fr 1fr 1fr; }
    .book-actions__primary { grid-column: auto; }
    .book-state {
        max-width: 840px;
        margin-left: auto;
        margin-right: auto;
    }
    .book-annotation {
        max-width: 840px;
        margin-left: auto;
        margin-right: auto;
    }
    .toc {
        max-width: 840px;
        margin-left: auto;
        margin-right: auto;
    }
    .reader__header {
        padding-left: max(22px, calc((100vw - 860px) / 2));
        padding-right: max(22px, calc((100vw - 860px) / 2));
    }
    .reader__content { max-width: 740px; padding-left: 34px; padding-right: 34px; }
    .reader__progress { display: inline-block; }
    .reader__toolbar,
    .reader__nav,
    .reader__progress-bar {
        max-width: 740px;
        margin-left: auto;
        margin-right: auto;
    }
    .g-settings {
        left: auto;
        right: 24px;
        bottom: 24px;
        width: 420px;
        border-radius: 20px;
        padding-bottom: 20px;
        transform: translateY(calc(100% + 32px));
    }
    .g-settings.open { transform: translateY(0); }
    .r-sheet {
        left: 50%;
        right: auto;
        width: min(760px, calc(100vw - 48px));
        border-radius: 20px 20px 0 0;
        transform: translate(-50%, 100%);
    }
    .r-sheet--sm { width: min(460px, calc(100vw - 48px)); }
    .r-overlay.open .r-sheet { transform: translate(-50%, 0); }
}

@media (max-width: 420px) {
    .reader__header { gap: 2px; padding-left: 6px; padding-right: 6px; }
    .reader__back,
    .reader__icon-btn {
        width: 40px;
        height: 40px;
        flex-basis: 40px;
    }
    .reader__book { font-size: 0.8125rem; }
    .reader__title { font-size: 0.6875rem; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .reader__progress-fill { transition: none; }
    .book-card { transition: none; }
    .btn { transition: none; }
    .g-settings, .g-settings-overlay, .r-overlay, .r-sheet { transition: none; }
}

/* Auto dark mode */
@media (prefers-color-scheme: dark) {
    body.theme-auto {
        --bg: #1C1C1E; --text: #F2F2F7; --text-muted: #98989D;
        --surface: #2C2C2E; --border: #3A3A3C;
        --shadow: 0 2px 8px rgba(0,0,0,0.3); --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
        --chrome-bg: rgba(28,28,30,0.92);
        --chrome-bg-soft: rgba(28,28,30,0.88);
        color-scheme: dark;
    }
}
