:root {
    color-scheme: light;
    --page: #f8f3ea;
    --surface: #fffbf5;
    --ink: #25221e;
    --muted: #65594d;
    --line: #dcd0bd;
    --accent: #953545;
    --action: #8b2d3b;
    --on-action: #fff9f2;
    --story-size: 1.3125rem;
    --gutter: clamp(1rem, 4vw, 2.5rem);
    --book-font: "PT Serif", Georgia, serif;
    font-family: Inter, system-ui, sans-serif;
}

html[data-theme="dark"] {
    color-scheme: dark;
    --page: #1c1917;
    --surface: #27221f;
    --ink: #f5ebdc;
    --muted: #c7b8a6;
    --line: #51453d;
    --accent: #f3a3ae;
    --action: #f3a3ae;
    --on-action: #301d1c;
}

html[data-size="large"] { --story-size: 1.5625rem; }
html[data-size="largest"] { --story-size: 1.875rem; }

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--page);
    color: var(--ink);
}

a { color: inherit; }

a:focus-visible,
button:focus-visible,
select:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 4px;
}

[hidden] { display: none !important; }

.skip {
    position: absolute;
    z-index: 2;
    inset: .5rem auto auto .5rem;
    padding: .75rem;
    background: var(--surface);
    color: var(--ink);
    transform: translateY(calc(-100% - 1rem));
}

.skip:focus { transform: none; }

.site-header {
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}

.header-inner {
    width: min(70rem, 100% - 2 * var(--gutter));
    min-height: 4.5rem;
    margin-inline: auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .625rem;
}

.brand {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    min-width: 0;
    text-decoration: none;
}

.brand-visual {
    --label-start: 24.5%;
    position: relative;
    display: grid;
    width: clamp(7rem, 36vw, 9.625rem);
    border-radius: .375rem;
    background: #fff;
}

.brand-visual::before {
    content: "";
    aspect-ratio: 5 / 1;
}

.brand-wordmark {
    position: absolute;
    inset: 0 0 auto;
    aspect-ratio: 10 / 3;
    background: url("zvistka-wordmark-light.webp") center / 150% auto no-repeat;
    clip-path: polygon(0 0, 100% 0, 100% 67%, var(--label-start) 67%, var(--label-start) 100%, 0 100%);
}

.brand-section {
    position: relative;
    display: flex;
    align-items: center;
    gap: .25rem;
    margin-inline-start: var(--label-start);
    padding: .125rem 0 .25rem;
    color: var(--accent);
    font-size: .8125rem;
    font-weight: 700;
    line-height: 1.1;
}

html[data-theme="dark"] .brand-visual {
    --label-start: 22.5%;
    background: transparent;
}

html[data-theme="dark"] .brand-wordmark {
    background: url("zvistka-wordmark-dark.webp") center / contain no-repeat;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: clamp(.375rem, 2vw, .75rem);
}

.outline,
.theme-toggle,
.text-size select {
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink);
    font: inherit;
}

.outline,
.theme-toggle {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    text-decoration: none;
}

.outline {
    padding: .45rem .875rem;
    font-size: .8125rem;
    font-weight: 650;
    white-space: nowrap;
}

.theme-toggle {
    width: 44px;
    padding: 0;
    cursor: pointer;
}

.theme-sun { display: none; }
html[data-theme="dark"] .theme-sun { display: block; }
html[data-theme="dark"] .theme-moon { display: none; }

.catalogue,
.reader {
    width: calc(100% - 2 * var(--gutter));
    margin-inline: auto;
    padding-block: clamp(1.375rem, 5vw, 3.375rem) 3rem;
}

.catalogue { max-width: 66rem; }
.reader { max-width: 43rem; }

.catalogue h1,
.reader h1,
.story-card h2 {
    margin: 0;
    font-family: var(--book-font);
    font-weight: 700;
    text-wrap: balance;
    line-height: 1.12;
}

.catalogue h1 { font-size: clamp(2.125rem, 6.6vw, 4.375rem); }
.reader h1 { font-size: clamp(2.25rem, 7vw, 4rem); }

.intro,
.story-subtitle {
    margin: .625rem 0 0;
    color: var(--muted);
    line-height: 1.5;
}

.intro { font-size: clamp(.9375rem, 2.5vw, 1.0625rem); }
.story-subtitle { font-size: .9375rem; }

.shelf {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: clamp(1rem, 3vw, 1.75rem);
    margin-block-start: clamp(1.125rem, 3.5vw, 2rem);
}

.story-card {
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 1.125rem;
    text-decoration: none;
}

.story-card img,
.story-text img {
    display: block;
    width: 100%;
    height: auto;
}

.story-card img {
    aspect-ratio: 3 / 2;
    object-fit: cover;
}

.story-card h2 { font-size: clamp(1.625rem, 4.4vw, 2.3rem); }

.story-card-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: start;
    gap: .625rem;
    padding: clamp(.9375rem, 3vw, 1.5rem);
}

.story-card-body p {
    margin: 0 0 .2rem;
    color: var(--muted);
    line-height: 1.55;
    font-size: .9375rem;
}

.read-button {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    margin-block-start: auto;
    padding: .55rem .9rem;
    background: var(--action);
    color: var(--on-action);
    border-radius: .625rem;
    font-size: .875rem;
    font-weight: 700;
}

.story-card:hover,
.outline:hover,
.theme-toggle:hover {
    border-color: var(--accent);
}

.reader-heading { margin-block-end: 1.25rem; }

.text-size {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .375rem .75rem;
    margin-block-start: 1rem;
    color: var(--muted);
    font-size: .875rem;
    font-weight: 600;
}

.text-size select {
    max-width: 100%;
    min-height: 44px;
    border-radius: .625rem;
    padding: .4rem .5rem;
    font-size: 1rem;
}

.story-text {
    font: 400 var(--story-size) / 1.68 var(--book-font);
    overflow-wrap: break-word;
}

.story-text p { margin: 0 0 1em; }

.story-text figure {
    margin: 1.15em 0;
    overflow: hidden;
    border-radius: 1rem;
    background: var(--surface);
    border: 1px solid var(--line);
}

.story-text figure.archival-vignette {
    width: fit-content;
    max-width: 100%;
    margin-inline: auto;
}

.archival-vignette img { width: auto; max-width: 100%; }

.story-source {
    display: grid;
    justify-items: start;
    margin-block: 1.75rem;
    font-size: .875rem;
    color: var(--muted);
}

.story-source a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    color: var(--accent);
    font-weight: 650;
    text-decoration: none;
}

.story-source a:hover { color: var(--ink); }

@media (max-width: 55rem) {
    .shelf { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.reader-nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: .75rem;
    padding-block-start: .5rem;
}

@media (max-width: 38.75rem) {
    .shelf { grid-template-columns: 1fr; }
}

@media (forced-colors: active) {
    .brand-wordmark { display: none; }
    .brand-visual::before { content: "ЗВІСТКА"; font-weight: 700; aspect-ratio: auto; }
    .brand-section { margin-inline-start: 0; color: LinkText; }
    .read-button { border: 1px solid ButtonText; }
}

.catalogue-nav {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    margin-block: 1.125rem 1.75rem;
}

.catalogue-nav a[aria-current="page"] {
    color: var(--on-action);
    background: var(--action);
    border-color: var(--action);
}

.library h2,
.featured-stories h2 {
    margin: 0;
    font: 700 clamp(1.4rem, 4vw, 1.9rem) / 1.25 var(--book-font);
}

.library-controls {
    display: grid;
    grid-template-columns: minmax(13rem, 1fr) repeat(2, minmax(0, 13rem));
    align-items: end;
    gap: .65rem;
    margin-block: .9rem .75rem;
}

.library-controls label {
    min-width: 0;
    display: grid;
    gap: .35rem;
    color: var(--muted);
    font-size: .8125rem;
    font-weight: 600;
}

.library-controls input,
.library-controls select {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    padding: .55rem .65rem;
    border: 1px solid var(--line);
    border-radius: .625rem;
    background: var(--surface);
    color: var(--ink);
    font: 400 .9375rem / 1.35 Inter, system-ui, sans-serif;
}

.library-controls input::placeholder { color: var(--muted); }

.library-controls input:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

.library-status {
    margin: .65rem 0;
    color: var(--muted);
    font-size: .875rem;
    line-height: 1.5;
}

.featured-stories {
    margin-block: 1.25rem 1.55rem;
}

.featured-stories .shelf { margin-block-start: .75rem; }

.library-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .5rem;
    padding: 0;
    margin: 1rem 0;
    list-style: none;
}

.library-entry { min-width: 0; }

.library-entry a {
    display: grid;
    grid-template-columns: 2.75rem minmax(0, 1fr);
    align-items: center;
    gap: .75rem;
    min-height: 64px;
    padding: .6rem .75rem;
    height: 100%;
    border: 1px solid var(--line);
    border-radius: .625rem;
    background: var(--surface);
    text-decoration: none;
}

.library-entry a:hover { border-color: var(--accent); }

.library-entry-cover {
    display: grid;
    place-items: center;
    width: 2.75rem;
    aspect-ratio: 4 / 5;
    overflow: hidden;
    border-radius: .3rem .4rem .4rem .3rem;
    background-color: var(--cover-color, #843b48);
    box-shadow: inset 3px 0 0 rgb(0 0 0 / 17%);
    color: #fff8ee;
    font: 700 1.5rem / 1 var(--book-font);
}

[data-category="world-folk"] { --cover-color: #375951; }
[data-category="ukrainian-authors"] { --cover-color: #785135; }
[data-category="world-authors"] { --cover-color: #52486e; }

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

.library-entry-label {
    display: grid;
    gap: .2rem;
    min-width: 0;
}

.library-entry-title {
    overflow-wrap: anywhere;
    font-weight: 650;
}

.library-entry-meta {
    color: var(--muted);
    font-size: .8125rem;
    line-height: 1.35;
}

.library-entry-description {
    color: var(--muted);
    font-size: .875rem;
    line-height: 1.45;
    overflow-wrap: anywhere;
}

.library-pagination {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
    gap: .5rem;
    margin: 1.2rem 0 .75rem;
    font-size: .875rem;
}

.library-pagination button { cursor: pointer; }
.library-pagination button:disabled { cursor: default; opacity: .55; }

@media (max-width: 40rem) {
    .library-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .library-query,
    .library-controls [data-group-control] { grid-column: 1 / -1; }
    .library-list { grid-template-columns: 1fr; }
    .catalogue-nav .outline { white-space: normal; }
}
