

:root {
    --ink: #edf3ef;
    --muted: #a8b5ae;
    --paper: #0c1210;
    --paper-deep: #121b18;
    --green: #286554;
    --green-soft: #3d806d;
    --wine: #e19aa7;
    --wine-strong: #994554;
    --gold: #e7c47f;
    --gold-soft: #252115;
    --line: #293630;
    --white: #17211d;
    --on-solid: #f7fbf8;
    --header-bg: rgba(12, 18, 16, .88);
    --hero-start: #111c18;
    --hero-end: #0c1210;
    --badge-bg: rgba(18, 27, 24, .92);
    --focus: rgba(88, 178, 150, .34);
    --shadow: 0 20px 60px rgba(0, 0, 0, .36);
    --radius: 18px;
}

:root[data-theme="light"] {
    --ink: #192421;
    --muted: #66736e;
    --paper: #fbfaf6;
    --paper-deep: #f0eee7;
    --green: #18342f;
    --green-soft: #285047;
    --wine: #8b3541;
    --wine-strong: #8b3541;
    --gold: #b58a4a;
    --gold-soft: #fff8e8;
    --line: #dcd9d0;
    --white: #fff;
    --on-solid: #fff;
    --header-bg: rgba(251, 250, 246, .90);
    --hero-start: #f7f3e8;
    --hero-end: #fbfaf6;
    --badge-bg: rgba(251,250,246,.92);
    --focus: rgba(40,80,71,.18);
    --shadow: 0 18px 50px rgba(24, 52, 47, .10);
    --radius: 18px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; background: var(--paper); }
body {
    margin: 0;
    color: var(--ink);
    background: var(--paper);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    text-rendering: optimizeLegibility;
}
button, input, select { font: inherit; color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}
.hidden { display: none !important; }

.site-header {
    min-height: 76px;
    display: grid;
    grid-template-columns: minmax(210px, 1fr) minmax(260px, 560px) minmax(310px, 1fr);
    align-items: center;
    gap: 28px;
    padding: 12px clamp(20px, 5vw, 72px);
    border-bottom: 1px solid var(--line);
    background: var(--header-bg);
    backdrop-filter: blur(18px) saturate(140%);
    position: sticky;
    top: 0;
    z-index: 30;
}
.brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    color: var(--ink);
    text-decoration: none;
    min-width: max-content;
}
.brand-mark {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 12px 4px 12px 4px;
    background: var(--green);
    color: #f7e9c5;
    font: 700 25px/1 system-ui, -apple-system, "Segoe UI", sans-serif;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.15);
}
.brand strong { display: block; font: 700 20px/1.1 system-ui, -apple-system, "Segoe UI", sans-serif; letter-spacing: .02em; }
.brand small { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.header-search { display: flex; height: 44px; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--white); }
.header-search:focus-within { border-color: var(--green-soft); box-shadow: 0 0 0 3px var(--focus); }
.header-search input { flex: 1; min-width: 0; border: 0; outline: 0; padding: 0 18px; background: transparent; color: var(--ink); }
.header-search button { border: 0; background: var(--green); color: var(--on-solid); padding: 0 20px; }
.main-nav { display: flex; justify-content: flex-end; align-items: center; gap: 8px; }
.nav-link, .account-button, .theme-toggle { border: 0; background: transparent; color: var(--muted); padding: 10px 12px; border-radius: 10px; white-space: nowrap; }
.nav-link:hover, .nav-link.active { color: var(--ink); background: var(--paper-deep); }
.account-button { background: var(--wine-strong); color: var(--on-solid); font-weight: 750; min-height: 42px; }
.theme-toggle { width: 42px; height: 42px; display: grid; place-items: center; padding: 0; border: 1px solid var(--line); background: var(--white); }
.theme-toggle:hover { color: var(--ink); border-color: var(--green-soft); }
.theme-icon { grid-area: 1/1; width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; transition: transform .25s ease, opacity .2s ease; }
.theme-icon-sun { opacity: 0; transform: rotate(-45deg) scale(.65); }
.theme-icon-moon { opacity: 1; transform: rotate(0) scale(1); }
:root:not([data-theme="light"]) .theme-icon-sun { opacity: 1; transform: rotate(0) scale(1); }
:root:not([data-theme="light"]) .theme-icon-moon { opacity: 0; transform: rotate(35deg) scale(.65); }
.auth-actions { min-width: 190px; min-height: 42px; display: flex; justify-content: flex-end; align-items: center; }
.telegram-login.header-login { min-height: 42px; margin: 0; display: flex; align-items: center; justify-content: flex-end; }
.telegram-login.header-login.loading { min-width: 190px; border: 1px solid var(--line); border-radius: 11px; background: var(--white); color: var(--muted); font-size: 12px; }
.telegram-direct-button { min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 9px; padding: 9px 15px; border-radius: 11px; background: #2a8bd6; color: #fff; font-size: 14px; font-weight: 750; text-decoration: none; white-space: nowrap; box-shadow: 0 8px 24px rgba(42,139,214,.18); transition: transform .18s ease, background .18s ease; }
.telegram-direct-button:hover { background: #2180ca; transform: translateY(-1px); }
.telegram-direct-button svg { width: 20px; height: 20px; fill: currentColor; flex: 0 0 auto; }
.auth-actions.login-attention { animation: login-attention 1.1s ease; }
@keyframes login-attention { 35%, 75% { transform: translateY(-2px); filter: drop-shadow(0 0 8px var(--focus)); } }


main { min-height: 70vh; }
.hero {
    max-width: 1450px;
    margin: 0 auto;
    padding: clamp(58px, 9vw, 120px) clamp(20px, 6vw, 90px);
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(300px, .75fr);
    gap: clamp(48px, 8vw, 120px);
    align-items: center;
    background:
        radial-gradient(circle at 90% 10%, color-mix(in srgb, var(--gold) 18%, transparent), transparent 32%),
        linear-gradient(135deg, var(--hero-start), var(--hero-end) 58%);
    border-bottom: 1px solid var(--line);
}
.eyebrow { margin: 0 0 10px; color: var(--wine); font-size: 12px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.hero h1, .page-shell h1 {
    max-width: 780px;
    margin: 0;
    font: 700 clamp(42px, 5.7vw, 72px)/1.08 system-ui, -apple-system, "Segoe UI", sans-serif;
    letter-spacing: -.032em;
    font-synthesis: none;
    font-optical-sizing: auto;
}
.hero-copy > p:not(.eyebrow) { max-width: 680px; margin: 24px 0 0; color: var(--muted); font-size: clamp(17px, 2vw, 20px); line-height: 1.75; }
.hero-actions, .button-row { display: flex; gap: 12px; margin-top: 30px; flex-wrap: wrap; }
.button { min-height: 44px; border: 1px solid transparent; border-radius: 12px; padding: 10px 18px; font-weight: 750; transition: transform .18s ease, background .18s ease; text-decoration: none; text-align: center; }
.button:hover { transform: translateY(-1px); }
.button.primary { background: var(--green); color: var(--on-solid); }
.button.ghost { border-color: var(--line); background: var(--white); color: var(--ink); }
.button.full { width: 100%; display: block; margin-top: 16px; }
.hero-panel { border-radius: var(--radius); background: var(--green); color: var(--on-solid); padding: 16px 32px; box-shadow: var(--shadow); }
.hero-panel div { display: grid; grid-template-columns: 70px 1fr; gap: 18px; align-items: center; padding: 24px 0; border-bottom: 1px solid rgba(255,255,255,.14); }
.hero-panel div:last-child { border-bottom: 0; }
.hero-panel strong { color: #f4d59e; font: 700 38px/1 system-ui, -apple-system, "Segoe UI", sans-serif; }
.hero-panel span { line-height: 1.5; color: rgba(255,255,255,.8); }

.continue-section, .catalog-layout, .page-shell { max-width: 1450px; margin: 0 auto; padding: 54px clamp(20px, 5vw, 72px); }
.continue-section { padding-bottom: 0; }
.section-heading { display: flex; justify-content: space-between; gap: 20px; align-items: end; margin-bottom: 22px; }
.section-heading h2 { margin: 0; font: 700 clamp(28px, 4vw, 42px)/1.1 system-ui, -apple-system, "Segoe UI", sans-serif; }
.section-heading select { border: 1px solid var(--line); background: var(--white); border-radius: 10px; padding: 10px 14px; color: var(--ink); }
.continue-row { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(260px, 360px); gap: 14px; overflow-x: auto; padding-bottom: 8px; }
.continue-card { display: grid; grid-template-columns: 70px 1fr; gap: 16px; align-items: center; border: 1px solid var(--line); background: var(--white); border-radius: 14px; padding: 12px; cursor: pointer; text-align: left; }
.continue-card img, .mini-cover { width: 70px; aspect-ratio: 3/4; border-radius: 8px; object-fit: cover; background: var(--paper-deep); }
.continue-card strong, .library-card h3 { display: block; font-family: system-ui, -apple-system, "Segoe UI", sans-serif; }
.continue-card small { color: var(--muted); display: block; margin-top: 6px; }
.catalog-layout { display: grid; grid-template-columns: minmax(0, 1fr) 310px; gap: 54px; }
.story-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 22px; }
.story-card { background: var(--white); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; transition: transform .2s ease, box-shadow .2s ease; cursor: pointer; }
.story-card:hover { transform: translateY(-4px); box-shadow: var(--shadow); }
.story-cover { aspect-ratio: 4/5; background: linear-gradient(145deg, var(--green), #37695e); position: relative; overflow: hidden; }
.story-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-placeholder { width: 100%; height: 100%; display: grid; place-items: center; padding: 20px; color: #f4d59e; font: 700 30px/1.2 system-ui, -apple-system, "Segoe UI", sans-serif; text-align: center; }
.story-badge { position: absolute; top: 12px; left: 12px; padding: 6px 9px; border-radius: 999px; background: var(--badge-bg); color: var(--ink); font-size: 11px; font-weight: 800; backdrop-filter: blur(8px); }
.story-card-body { padding: 18px; }
.story-card h3 { margin: 0; font: 700 20px/1.3 system-ui, -apple-system, "Segoe UI", sans-serif; }
.story-author { color: var(--muted); margin: 7px 0 14px; font-size: 13px; }
.story-card-tags { display: flex; flex-wrap: wrap; gap: 5px; min-height: 23px; margin: -5px 0 12px; }
.story-card-tags span, .tag-filter button { border: 1px solid var(--line); border-radius: 999px; background: var(--paper-deep); color: var(--green); font-size: 11px; font-weight: 750; }
.story-card-tags span { padding: 4px 8px; }
.tag-filter { display: flex; flex-wrap: wrap; gap: 8px; margin: -14px 0 22px; }
.tag-filter button { min-height: 34px; padding: 6px 12px; cursor: pointer; }
.tag-filter button.active { background: var(--green); color: var(--on-solid); border-color: var(--green); }
.story-price-row { display: flex; justify-content: space-between; gap: 8px; padding-top: 13px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.story-price-row strong { display: block; color: var(--wine); font-size: 15px; }
.catalog-aside { position: sticky; top: 150px; align-self: start; padding: 28px; border-radius: var(--radius); background: var(--paper-deep); border: 1px solid var(--line); }
.catalog-aside h3 { margin: 0; font: 700 28px/1.25 Georgia, serif; }
.catalog-aside > p:not(.eyebrow), .catalog-aside li { color: var(--muted); line-height: 1.65; }
.catalog-aside ul { padding-left: 18px; }
.pagination { display: flex; justify-content: center; gap: 8px; margin-top: 30px; }
.pagination button { min-width: 40px; min-height: 40px; border: 1px solid var(--line); background: var(--white); border-radius: 9px; }
.pagination button.active { background: var(--green); color: var(--on-solid); }

.page-shell { padding-top: 72px; }
.page-shell h1 { font-size: clamp(40px, 6vw, 68px); }
.library-header { display: flex; justify-content: space-between; gap: 30px; align-items: end; margin-bottom: 42px; }
.library-header p:not(.eyebrow) { color: var(--muted); }
.balance-card { min-width: 180px; background: var(--green); color: var(--on-solid); padding: 20px; border-radius: 14px; }
.balance-card span { display: block; color: rgba(255,255,255,.7); font-size: 12px; }
.balance-card strong { display: block; margin-top: 5px; font: 700 25px/1 Georgia, serif; }
.balance-card strong span { display: inline; color: inherit; font-size: inherit; }
.library-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.library-card { display: grid; grid-template-columns: 92px 1fr; gap: 16px; border: 1px solid var(--line); background: var(--white); padding: 14px; border-radius: 15px; }
.library-card .mini-cover { width: 92px; }
.library-card h3 { margin: 4px 0; font-size: 19px; }
.library-card p { margin: 6px 0; color: var(--muted); font-size: 13px; }
.library-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.library-actions .button { min-height: 36px; padding: 7px 11px; font-size: 12px; }
.empty-state { grid-column: 1/-1; padding: 56px 24px; border: 1px dashed var(--line); border-radius: 16px; color: var(--muted); text-align: center; }

footer { margin-top: 50px; min-height: 170px; display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 40px clamp(20px, 5vw, 72px); background: var(--green); color: rgba(255,255,255,.78); }
.footer-brand, .footer-brand small { color: var(--on-solid); }
.footer-brand .brand-mark { background: #f3d39a; color: var(--green); }

.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 18px; background: color-mix(in srgb, var(--paper-deep) 68%, transparent); backdrop-filter: blur(5px); }
.modal-card { width: min(100%, 1000px); max-height: 92vh; overflow: auto; background: var(--paper); border-radius: 22px; box-shadow: 0 28px 90px rgba(0,0,0,.3); position: relative; }
.modal-card.compact { width: min(100%, 480px); padding: 32px; }
.modal-card h2 { margin: 0 0 10px; font: 700 32px/1.15 Georgia, serif; }
.modal-card p { color: var(--muted); line-height: 1.65; }
.modal-close { position: absolute; top: 14px; right: 14px; z-index: 2; width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 50%; background: var(--white); color: var(--ink); font-size: 22px; }
.story-detail-card { display: grid; grid-template-columns: 38% 62%; overflow: hidden; }
.detail-cover { min-height: 620px; background: linear-gradient(145deg, var(--green), #37695e); }
.detail-cover img { width: 100%; height: 100%; object-fit: cover; }
.detail-body { padding: clamp(30px, 5vw, 62px); }
.detail-body h2 { font-size: clamp(38px, 6vw, 62px); letter-spacing: -.03em; }
.genre-pill { display: inline-flex; width: fit-content; margin: 0 0 14px; padding: 7px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--paper-deep); color: var(--green); font-size: 12px; font-weight: 800; }
.detail-author { font-weight: 700; }
.detail-description { max-height: 190px; overflow: auto; }
.story-notices { display: grid; gap: 9px; margin: 16px 0; }
.story-notices p { margin: 0; padding: 12px 14px; border: 1px solid var(--line); border-left: 3px solid var(--gold); border-radius: 10px; background: var(--paper-deep); color: var(--ink); font-size: 12px; line-height: 1.65; white-space: pre-line; }
.story-notices p:last-child { border-left-color: var(--wine); font-weight: 700; }
.purchase-notices { margin: 16px 0; }
.detail-meta { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0; }
.detail-meta span { background: var(--paper-deep); border-radius: 999px; padding: 7px 10px; color: var(--muted); font-size: 12px; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 22px 0; }
.plan-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.plan-grid article { border: 1px solid var(--line); background: var(--white); padding: 16px; border-radius: 13px; }
.plan-grid article.featured { border-color: var(--gold); background: var(--gold-soft); }
.plan-grid span, .plan-grid small { display: block; color: var(--muted); font-size: 12px; }
.plan-grid strong { display: block; margin: 5px 0; font-size: 22px; color: var(--wine); }
.field-label { display: grid; gap: 7px; margin: 18px 0; font-size: 13px; font-weight: 750; }
.field-label select { height: 46px; border: 1px solid var(--line); background: var(--white); border-radius: 10px; padding: 0 12px; }
.order-summary { margin: 20px 0; padding: 18px; background: var(--paper-deep); border-radius: 12px; line-height: 1.8; }
.order-summary div { display: flex; justify-content: space-between; gap: 12px; }
.policy-note { font-size: 13px; padding-left: 12px; border-left: 3px solid var(--wine); }
.telegram-login { min-height: 52px; display: grid; place-items: center; margin: 20px 0; }
.payment-card { text-align: center; }
.payment-card img { width: min(100%, 300px); border-radius: 14px; margin: 12px auto; display: block; }
.payment-card > strong { display: block; color: var(--wine); font-size: 24px; }
.payment-choice-hint { min-height: 1.25em; margin: -6px 0 14px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.payment-details { margin: 16px 0; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); text-align: left; }
.payment-details > p { margin: 0 0 10px; font-size: 13px; }
.payment-details dl { display: grid; gap: 9px; margin: 0; }
.payment-details dl > div { display: flex; justify-content: space-between; gap: 14px; }
.payment-details dt { color: var(--muted); }
.payment-details dd { margin: 0; text-align: right; font-weight: 750; overflow-wrap: anywhere; }
.download-options { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin: 18px 0; }
.download-options a { border: 1px solid var(--line); background: var(--white); border-radius: 10px; padding: 14px 8px; text-align: center; color: var(--ink); text-decoration: none; font-weight: 800; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 200; max-width: min(420px, calc(100vw - 40px)); padding: 13px 18px; border-radius: 11px; background: var(--green); color: var(--on-solid); box-shadow: var(--shadow); transform: translateY(120px); opacity: 0; transition: .25s ease; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { background: var(--wine); }

@media (max-width: 1350px) {
    .site-header { grid-template-columns: 1fr auto; }
    .header-search { grid-column: 1/-1; grid-row: 2; }
}
@media (max-width: 1100px) {
    .story-grid, .library-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
    .catalog-layout { grid-template-columns: minmax(0,1fr) 270px; gap: 28px; }
}
@media (max-width: 760px) {
    .site-header { position: relative; padding: 12px 16px; gap: 12px; }
    .brand small { display: none; }
    .brand-mark { width: 38px; height: 38px; }
    .nav-link { display: none; }
    .main-nav { gap: 6px; }
    .theme-toggle { display: grid; width: 38px; height: 38px; }
    .auth-actions { min-width: 154px; }
    .telegram-login.header-login.loading { min-width: 154px; }
    .account-button { padding: 9px 11px; font-size: 12px; }
    .hero { grid-template-columns: 1fr; padding-top: 58px; gap: 38px; }
    .hero h1 { font-size: clamp(42px, 13vw, 64px); }
    .hero-panel { padding: 8px 22px; }
    .catalog-layout { display: block; padding-top: 38px; }
    .catalog-aside { position: static; margin-top: 35px; }
    .story-grid { gap: 12px; }
    .story-card-body { padding: 13px; }
    .story-card h3 { font-size: 17px; }
    .story-price-row { display: block; }
    .story-price-row span + span { display: none; }
    .library-header { display: block; }
    .balance-card { margin-top: 20px; }
    .library-grid { grid-template-columns: 1fr; }
    footer { display: block; }
    footer > p { margin-top: 24px; }
    .story-detail-card { display: block; }
    .detail-cover { min-height: 330px; max-height: 42vh; }
    .detail-body { padding: 28px 22px; }
    .detail-body h2 { font-size: 38px; }
    .detail-actions { flex-direction: column; }
    .detail-actions .button { width: 100%; }
    .plan-grid { grid-template-columns: 1fr; }
}
@media (max-width: 460px) {
    .site-header { grid-template-columns: auto 1fr; }
    .site-header .brand > span { display: none; }
    .auth-actions { min-width: 0; }
    .telegram-login.header-login.loading { min-width: 148px; }
    .header-search { height: 42px; }
    .story-grid { grid-template-columns: 1fr 1fr; }
    .story-cover { aspect-ratio: 3/4; }
    .story-card-body { padding: 11px; }
    .story-author { display: none; }
    .library-card { grid-template-columns: 72px 1fr; }
    .library-card .mini-cover { width: 72px; }
    .modal-card.compact { padding: 28px 20px; }
}
@media (prefers-reduced-motion: reduce) {
    * { scroll-behavior: auto !important; transition: none !important; }
}
