/* Naše knihovna - all styles. Mobile and desktop are equal citizens:
   the sidebar is a permanent column from 900px up and a slide-in drawer below. */

:root {
    --bg: #f7f5f1;
    --surface: #ffffff;
    --surface-2: #f0ece5;
    --text: #23201c;
    --text-dim: #6d665c;
    --line: #ddd7cc;
    --accent: #7a4b2a;
    --accent-soft: #f0e3d8;
    --good: #2f7a4d;
    --warn: #9a6b1f;
    --danger: #a3402e;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(35, 32, 28, .06), 0 4px 16px rgba(35, 32, 28, .06);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #171614;
        --surface: #201e1b;
        --surface-2: #2a2724;
        --text: #eae6df;
        --text-dim: #a49c90;
        --line: #38342f;
        --accent: #d79a6c;
        --accent-soft: #3a2c22;
        --good: #6fbf8d;
        --warn: #d5a94f;
        --danger: #e0806c;
        --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .3);
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    font-size: 16px;
    line-height: 1.5;
}

h1, h2, h3 { margin: 0; font-weight: 600; }

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

.sr-only {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* ---------- topbar ---------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    flex-wrap: wrap;
}

.brand h1 { font-size: 19px; letter-spacing: -.01em; }

.subtitle {
    margin: 2px 0 0;
    font-size: 13px;
    color: var(--text-dim);
}

.search-wrap {
    position: relative;
    flex: 1 1 260px;
    min-width: 200px;
}

#search {
    width: 100%;
    padding: 9px 34px 9px 13px;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 999px;
    outline: none;
}

#search:focus { border-color: var(--accent); }

.search-clear {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 26px; height: 26px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-dim);
    font-size: 19px;
    line-height: 1;
    cursor: pointer;
}

.filters-toggle {
    display: none;
    align-items: center;
    gap: 6px;
    padding: 9px 15px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 999px;
    cursor: pointer;
}

.badge {
    min-width: 19px;
    padding: 0 5px;
    background: var(--accent);
    color: #fff;
    border-radius: 999px;
    font-size: 12px;
    text-align: center;
}

/* ---------- layout ---------- */

.layout {
    display: grid;
    grid-template-columns: 264px minmax(0, 1fr);
    gap: 28px;
    max-width: 1440px;
    margin: 0 auto;
    padding: 24px 20px 64px;
}

.sidebar { position: relative; }

.sidebar-inner {
    position: sticky;
    top: 84px;
    max-height: calc(100vh - 108px);
    overflow-y: auto;
    padding-right: 4px;
}

.fblock { margin-bottom: 24px; }

.fblock h2 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--text-dim);
    margin-bottom: 9px;
}

.fblock h3 {
    font-size: 12px;
    color: var(--text-dim);
    margin: 14px 0 7px;
    font-weight: 500;
}

/* ---------- controls ---------- */

.segmented {
    display: flex;
    background: var(--surface-2);
    border-radius: 8px;
    padding: 3px;
}

.segmented button {
    flex: 1;
    padding: 6px 4px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-dim);
    font-size: 14px;
    cursor: pointer;
}

.segmented button.on {
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 1px 2px rgba(0, 0, 0, .08);
}

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

.chips + .chips { margin-top: 8px; }

.chip {
    display: inline-flex;
    align-items: baseline;
    gap: 5px;
    padding: 4px 10px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 999px;
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
}

.chip:hover { border-color: var(--accent); }

.chip.on {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
    font-weight: 500;
}

.chip .n {
    font-size: 11px;
    color: var(--text-dim);
    font-variant-numeric: tabular-nums;
}

.chip.on .n { color: var(--accent); }

/* Nothing behind it in the current view - still clickable, just quiet. */
.chip.zero { opacity: .38; }
.chip.zero:hover { border-color: var(--line); }

.hint-text {
    margin: 8px 0 0;
    font-size: 12px;
    color: var(--text-dim);
}

.reset {
    width: 100%;
    padding: 9px;
    background: none;
    border: 1px dashed var(--line);
    border-radius: 8px;
    color: var(--text-dim);
    cursor: pointer;
}

.reset:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- results ---------- */

.results-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.count { margin: 0; font-size: 14px; color: var(--text-dim); }

#sort {
    padding: 6px 10px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    cursor: pointer;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
    gap: 20px 18px;
}

.card {
    display: flex;
    flex-direction: column;
    gap: 7px;
    background: none;
    border: none;
    padding: 0;
    text-align: left;
    cursor: pointer;
    color: inherit;
}

.card-cover {
    position: relative;
    aspect-ratio: 2 / 3;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--surface-2);
    box-shadow: var(--shadow);
    transition: transform .15s ease;
}

.card:hover .card-cover { transform: translateY(-3px); }

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

/* Cover stand-in: the app icon's shelf, drawn as one muted SVG. No generated
   image files, stays sharp at any size, and the motif ties the grid to the icon
   on the home screen. The title is deliberately not repeated here - it already
   sits under the card and beside it in the detail. */
.cover-fallback {
    height: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-2) url('../icons/cover-placeholder.svg')
                no-repeat center / 78% auto;
}

.card-score {
    position: absolute;
    left: 7px;
    bottom: 7px;
    padding: 2px 7px;
    border-radius: 999px;
    background: rgba(25, 22, 19, .82);
    color: #fff;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    backdrop-filter: blur(3px);
}

.card-score.thin { background: rgba(25, 22, 19, .45); }

.card-flag {
    position: absolute;
    right: 7px;
    top: 7px;
    padding: 2px 7px;
    border-radius: 999px;
    font-size: 11px;
    background: var(--surface);
    border: 1px solid var(--line);
}

.card-flag.ask { background: var(--warn); border-color: var(--warn); color: #fff; }
.card-flag.cull { background: var(--danger); border-color: var(--danger); color: #fff; }

.card-title {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.3;
}

.card-authors { font-size: 12.5px; color: var(--text-dim); }

.card-line {
    font-size: 12.5px;
    color: var(--text-dim);
    font-style: italic;
    line-height: 1.35;
}

.empty { color: var(--text-dim); }

/* ---------- detail ---------- */

.detail-overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 24px 16px;
    background: rgba(25, 22, 19, .5);
    overflow-y: auto;
    backdrop-filter: blur(2px);
}

/* `display: flex` above outranks the browser's [hidden] rule - put it back. */
.detail-overlay[hidden] { display: none; }

.detail-card {
    position: relative;
    width: min(760px, 100%);
    background: var(--surface);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 28px;
}

.detail-close {
    position: absolute;
    right: 12px;
    top: 10px;
    width: 34px; height: 34px;
    border: none;
    border-radius: 50%;
    background: var(--surface-2);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
}

.d-head {
    display: grid;
    grid-template-columns: 132px minmax(0, 1fr);
    gap: 20px;
    margin-bottom: 20px;
}

.d-cover { border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.d-cover img { width: 100%; display: block; }

.d-title { font-size: 23px; line-height: 1.2; }
.d-sub { margin: 3px 0 0; color: var(--text-dim); }
.d-authors { margin: 8px 0 0; font-size: 15px; }
.d-meta { margin: 10px 0 0; font-size: 13px; color: var(--text-dim); }

.d-isbn {
    margin: 10px 0 0;
    font-size: 13px;
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 8px;
    color: var(--text-dim);
}

.d-isbn code {
    font-size: 14px;
    letter-spacing: .02em;
    color: var(--text);
    background: var(--surface-2);
    padding: 2px 7px;
    border-radius: 5px;
    user-select: all;
}

.isbn-mark {
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 11.5px;
}

.isbn-mark.ok { background: var(--accent-soft); color: var(--good); }
.isbn-mark.todo { background: var(--surface-2); color: var(--warn); }

.d-oneliner {
    margin: 14px 0 0;
    font-size: 16px;
    font-style: italic;
    color: var(--accent);
}

.d-section { margin-top: 22px; }

.d-section h3 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--text-dim);
    margin-bottom: 8px;
}

.d-why { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }

@media (max-width: 620px) { .d-why { grid-template-columns: 1fr; } }

.d-why ul { margin: 0; padding-left: 18px; }
.d-why li { margin-bottom: 5px; }
.d-why .yes h3 { color: var(--good); }
.d-why .no h3 { color: var(--danger); }

.d-tags { display: flex; flex-wrap: wrap; gap: 6px; }

.tag-pill {
    padding: 3px 9px;
    background: var(--surface-2);
    border-radius: 999px;
    font-size: 12.5px;
}

.d-ratings { display: grid; gap: 8px; }

.rating-row {
    display: flex;
    align-items: baseline;
    gap: 10px;
    font-size: 14px;
}

.rating-row .score {
    min-width: 46px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.rating-row .meta { color: var(--text-dim); font-size: 12.5px; }
.rating-row a { color: var(--accent); }

.callout {
    padding: 13px 15px;
    border-radius: var(--radius);
    border-left: 3px solid var(--line);
    background: var(--surface-2);
    font-size: 14px;
}

.callout.ask { border-left-color: var(--warn); }
.callout.cull { border-left-color: var(--danger); }
.callout h4 { margin: 0 0 5px; font-size: 13px; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; font-size: 14px; }
.kv dt { color: var(--text-dim); }
.kv dd { margin: 0; }

.provenance summary {
    cursor: pointer;
    font-size: 12px;
    color: var(--text-dim);
}

.provenance .body {
    margin-top: 8px;
    font-size: 12.5px;
    color: var(--text-dim);
}

.provenance code {
    background: var(--surface-2);
    padding: 1px 5px;
    border-radius: 4px;
}

/* ---------- mobile ---------- */

@media (max-width: 900px) {
    .topbar { padding: 10px 14px; gap: 10px; }
    .brand { flex: 1 1 100%; }
    .filters-toggle { display: inline-flex; }

    .layout {
        grid-template-columns: minmax(0, 1fr);
        padding: 16px 14px 48px;
        gap: 0;
    }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 40;
        width: min(310px, 86vw);
        background: var(--surface);
        border-right: 1px solid var(--line);
        transform: translateX(-102%);
        transition: transform .2s ease;
    }

    .sidebar.open { transform: none; }

    .sidebar-inner {
        position: static;
        max-height: none;
        height: 100%;
        overflow-y: auto;
        padding: 18px 16px 40px;
    }

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

    .detail-card { padding: 20px 16px; }
    .d-head { grid-template-columns: 96px minmax(0, 1fr); gap: 14px; }
    .d-title { font-size: 20px; }
}

.scrim {
    position: fixed;
    inset: 0;
    z-index: 35;
    background: rgba(25, 22, 19, .4);
}
