/*
 * BookHunter UI. One stylesheet, phone first: every rule outside a media
 * query describes the narrow layout, and the wide layout is added on top.
 * Colours come only from the tokens below, so light and dark stay in step.
 */

/* ---- Tokens ------------------------------------------------------------ */
:root {
    --bg: #f6f3ee;
    --surface: #ffffff;
    --surface-2: #efeae2;
    --line: #e0d8cb;
    --text: #1d1a16;
    --muted: #645b50;
    --faint: #8b8276;
    --accent: #7a4a21;
    --on-accent: #ffffff;
    --good: #1c7449;
    --good-bg: #e2f2e9;
    --bad: #b03a2e;
    --bad-bg: #fae9e6;
    --warn: #8a5d00;
    --warn-bg: #fdf1d3;
    --info: #2a5b93;
    --info-bg: #e5eef9;
    --gold: #a16c10;
    --gold-bg: #fbefcf;
    --shadow: 0 1px 2px rgba(40, 30, 15, .06), 0 6px 20px rgba(40, 30, 15, .06);
    --radius: 14px;
    --nav-h: 60px;
    --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
    color-scheme: light;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #14120f; --surface: #1e1b17; --surface-2: #29251f; --line: #3a342b;
        --text: #ece7df; --muted: #aaa194; --faint: #82796d;
        --accent: #dba56b; --on-accent: #1a140c;
        --good: #55c890; --good-bg: #15301f; --bad: #f08376; --bad-bg: #3a1d19;
        --warn: #e4b552; --warn-bg: #352a10; --info: #86b5ea; --info-bg: #17283d;
        --gold: #e7b755; --gold-bg: #33290f;
        --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
        color-scheme: dark;
    }
}
:root[data-theme="dark"] {
    --bg: #14120f; --surface: #1e1b17; --surface-2: #29251f; --line: #3a342b;
    --text: #ece7df; --muted: #aaa194; --faint: #82796d;
    --accent: #dba56b; --on-accent: #1a140c;
    --good: #55c890; --good-bg: #15301f; --bad: #f08376; --bad-bg: #3a1d19;
    --warn: #e4b552; --warn-bg: #352a10; --info: #86b5ea; --info-bg: #17283d;
    --gold: #e7b755; --gold-bg: #33290f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
}

/* ---- Base -------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0; background: var(--bg); color: var(--text);
    font: 16px/1.5 var(--sans); -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
    /* A faint paper grain (self-contained SVG noise, no image request) so
       flat panels read as something closer to paper than a generic app
       background. Low enough opacity to never fight with text contrast. */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");
}
h1, h2, h3, p, ul, dl, dd { margin: 0; padding: 0; }
ul { list-style: none; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; display: block; }
code { font: .9em ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; overflow-wrap: anywhere; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.ic { width: 1.2em; height: 1.2em; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: -.22em; }
.ic-gold { color: var(--gold); }
.muted { color: var(--muted); }
.fine { color: var(--faint); font-size: 13px; line-height: 1.45; }
.fine.is-bad, .is-bad { color: var(--bad); }

/* ---- Navigation: bottom bar on a phone, side rail on a wide screen ------ */
.nav {
    position: fixed; z-index: 30; left: 0; right: 0; bottom: 0;
    height: calc(var(--nav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface); border-top: 1px solid var(--line);
}
.nav-brand {
    display: flex; align-items: center; gap: 9px;
    font: 700 20px/1.1 var(--serif); letter-spacing: .01em; color: var(--text);
}
.nav-brand span { color: var(--accent); }
.nav-brand:hover { text-decoration: none; }
.logo-mark { width: 34px; height: 34px; flex: none; color: var(--accent); }
.nav .nav-brand { display: none; }
.nav-links { display: grid; grid-template-columns: repeat(5, 1fr); height: var(--nav-h); }
.nav-link {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    border: 0; background: none; color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: .02em;
}
.nav-link .ic { width: 24px; height: 24px; }
.nav-link:hover { text-decoration: none; color: var(--text); }
.nav-link.is-active { color: var(--accent); }
.nav-foot { display: none; }

.main { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px); min-height: 100dvh; }
.main-bare { padding-bottom: 0; }
.page { max-width: 1240px; margin: 0 auto; padding: 16px 16px 8px; }
.page-narrow { max-width: 780px; }
.page-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; margin-bottom: 14px; }
.page-head h1 { font: 700 28px/1.15 var(--serif); }
.status { color: var(--muted); font-size: 14px; display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; }
a.status:hover { text-decoration: none; color: var(--text); }
.status-next { color: var(--faint); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--faint); flex: none; display: inline-block; }
.dot.is-ok { background: var(--good); }
.dot.is-warn { background: var(--warn); }
.dot.is-bad { background: var(--bad); }
.dot.is-busy { background: var(--info); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.crumb { margin-bottom: 10px; font-size: 14px; }

@media (min-width: 960px) {
    .nav {
        top: 0; right: auto; bottom: 0; width: 216px; height: auto; padding: 22px 12px 14px;
        border-top: 0; border-right: 1px solid var(--line);
        display: flex; flex-direction: column; gap: 22px;
    }
    .nav .nav-brand { display: flex; padding: 0 10px; }
    .nav-links { display: flex; flex-direction: column; gap: 2px; height: auto; }
    .nav-link {
        flex-direction: row; justify-content: flex-start; gap: 12px; width: 100%;
        padding: 10px; border-radius: 10px; font-size: 15px; font-weight: 550; letter-spacing: 0;
    }
    .nav-link .ic { width: 20px; height: 20px; }
    .nav-link:hover { background: var(--surface-2); }
    .nav-link.is-active { background: var(--surface-2); color: var(--text); }
    .nav-link.is-active .ic { color: var(--accent); }
    .nav-foot { display: block; margin-top: auto; }
    .main { margin-left: 216px; padding-bottom: 40px; }
    .main-bare { margin-left: 0; }
    .page { padding: 28px 36px 8px; }
    .page-head h1 { font-size: 32px; }
}

/* ---- Buttons, inputs, chips ------------------------------------------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 44px; padding: 0 16px; border-radius: 12px;
    border: 1px solid var(--line); background: var(--surface); color: var(--text);
    font-weight: 600; font-size: 15px; white-space: nowrap;
}
.btn:hover { text-decoration: none; border-color: var(--faint); }
.btn:disabled { opacity: .5; cursor: default; }
/* A soft gilt highlight rather than a flat fill — leather-and-gold-leaf is
   literally how a fine old book is decorated, so the primary action borrows
   that rather than a generic flat brand-color button. */
.btn-primary {
    background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 88%, white 12%), var(--accent));
    border-color: var(--accent); color: var(--on-accent);
    box-shadow: inset 0 1px 0 color-mix(in srgb, var(--gold) 55%, transparent);
}
.btn-primary:hover { filter: brightness(1.08); border-color: var(--accent); }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn-block { width: 100%; }
.btn .count { background: var(--accent); color: var(--on-accent); border-radius: 99px; font-size: 12px; min-width: 20px; padding: 1px 6px; }
.icon-btn {
    display: inline-grid; place-items: center; width: 44px; height: 44px; flex: none;
    border: 0; border-radius: 12px; background: none; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.link-btn { border: 0; background: none; padding: 6px 0; color: var(--accent); font-size: 14px; font-weight: 550; display: inline-flex; align-items: center; gap: 6px; }
.link-btn:hover { text-decoration: underline; }
.link-btn.is-on { color: var(--bad); }

input[type="text"], input[type="search"], input[type="url"], input[type="number"], input[type="email"],
input[type="password"], .select, select {
    width: 100%; min-height: 44px; padding: 8px 12px; border-radius: 12px;
    border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.select, select { appearance: none; padding-right: 34px;
    background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.search { position: relative; flex: 1 1 100%; min-width: 0; }
.search .ic { position: absolute; left: 12px; top: 50%; translate: 0 -50%; color: var(--faint); }
.search input { padding-left: 38px; }
.inline-form { display: flex; gap: 8px; margin: 12px 0; }
.inline-form > input { flex: 1; min-width: 0; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 16px 10px; margin: 0 -16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
    display: inline-flex; align-items: center; gap: 6px; flex: none; min-height: 36px; padding: 0 13px;
    border-radius: 99px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
    font-size: 14px; font-weight: 550; white-space: nowrap;
}
.chip:hover { text-decoration: none; border-color: var(--faint); }
.chip small { color: var(--faint); font-weight: 500; }
.chip.is-on { background: var(--text); border-color: var(--text); color: var(--bg); }
.chip.is-removable .ic { width: 14px; height: 14px; }

.tags { display: flex; flex-wrap: wrap; gap: 5px; }
.tag { font-size: 12px; font-weight: 600; line-height: 1; padding: 4px 7px; border-radius: 6px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.tag.is-warn { background: var(--warn-bg); color: var(--warn); }
.tag.is-good { background: var(--good-bg); color: var(--good); }
.tag.is-info { background: var(--info-bg); color: var(--info); }
.tag.is-gold { background: var(--gold-bg); color: var(--gold); }
.tag.is-muted { color: var(--faint); }
.tags-lg .tag { font-size: 13px; padding: 5px 9px; }
.ai-badge { font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--faint); border: 1px solid var(--line); border-radius: 5px; padding: 1px 4px; white-space: nowrap; }

.score {
    display: inline-grid; place-items: center; min-width: 40px; height: 28px; padding: 0 8px; border-radius: 8px;
    font-weight: 750; font-size: 14px; font-variant-numeric: tabular-nums; background: var(--surface-2); color: var(--muted);
}
.score-high { background: var(--good-bg); color: var(--good); }
.score-mid { background: var(--warn-bg); color: var(--warn); }
.score-rated { background: var(--accent); color: var(--on-accent); }
.est { font-size: 13px; color: var(--muted); white-space: nowrap; }
.est b { font-weight: 700; }
.est.is-good b { color: var(--good); }
.est.is-bad b { color: var(--bad); }

/* ---- Book cards: a row on a phone, a tile on a wide screen ------------- */
.section { margin: 0 0 28px; }
.section-head { margin-bottom: 10px; }
.section-head h2 { font: 700 20px/1.2 var(--serif); }
.section-head p { color: var(--muted); font-size: 14px; }
.bk-list { display: grid; gap: 10px; }
.bk {
    display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 12px; padding: 10px;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.bk.is-gone { opacity: .72; }
.bk-cover { position: relative; display: block; aspect-ratio: 3 / 4; border-radius: 8px; overflow: hidden; background: var(--surface-2); align-self: start; }
.bk-cover img, .rate-cover img { width: 100%; height: 100%; object-fit: contain; }
.cover-none { display: grid; place-items: center; align-content: center; gap: 6px; width: 100%; height: 100%; color: var(--faint); }
.cover-none .ic { width: 30px; height: 30px; }
.ribbon {
    position: absolute; left: 0; top: 8px; display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 8px 3px 6px; border-radius: 0 8px 8px 0; font-size: 11px; font-weight: 700; line-height: 1.2;
    box-shadow: 0 2px 5px rgba(0, 0, 0, .28);
}
.ribbon .ic { width: 12px; height: 12px; }
.ribbon-find { background: var(--gold); color: var(--surface); }
.ribbon-stock { background: var(--info); color: var(--surface); }
.bk-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.bk-title { font: 600 16px/1.25 var(--serif); display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.bk-title a { color: var(--text); }
.bk-by { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bk-price { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; }
.bk-price strong { font-size: 17px; font-weight: 750; }
.price-note { font-size: 12.5px; font-weight: 600; color: var(--warn); }
.bk .tags { max-height: 46px; overflow: hidden; }
.bk-foot { display: flex; align-items: center; gap: 8px; margin-top: auto; padding-top: 4px; }
.bk-shop { color: var(--faint); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1; }
.bk-ext { display: grid; place-items: center; width: 36px; height: 36px; margin: -6px -6px -6px 0; border-radius: 10px; color: var(--muted); }
.bk-ext:hover { background: var(--surface-2); color: var(--text); }
.bk-save { display: grid; place-items: center; width: 36px; height: 36px; margin: -6px -4px; border: 0; border-radius: 10px; background: none; color: var(--muted); }
.bk-save:hover { background: var(--surface-2); color: var(--text); }
.bk-save.is-on, .detail-save.is-on { color: var(--accent); }
.bk-save.is-on .ic, .detail-save.is-on .ic { fill: currentColor; }

@media (min-width: 700px) {
    .bk-list { grid-template-columns: repeat(auto-fill, minmax(208px, 1fr)); gap: 16px; }
    .bk { grid-template-columns: minmax(0, 1fr); gap: 0; padding: 0; overflow: hidden; transition: box-shadow .15s, border-color .15s; }
    .bk:hover { box-shadow: var(--shadow); border-color: var(--faint); }
    .bk-cover { aspect-ratio: 4 / 5; border-radius: 0; }
    .bk-body { padding: 12px; gap: 5px; }
}

.cta {
    display: flex; align-items: center; gap: 14px; padding: 14px 16px; margin: 0 0 28px;
    background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent);
    border-radius: var(--radius); color: var(--text);
}
.cta:hover { text-decoration: none; border-color: var(--accent); }
.cta span { flex: 1; display: grid; }
.cta small { color: var(--muted); font-size: 13px; }
.cta > .ic:first-child { width: 26px; height: 26px; color: var(--accent); }
.empty { padding: 36px 16px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }

/* ---- Saved ------------------------------------------------------------- */
.saved-shop h2 { overflow-wrap: anywhere; }
.saved-item {
    display: flex; flex-direction: column; min-width: 0;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.saved-item > .bk { flex: 1; border: 0; border-radius: 0; }
.saved-item > .bk:hover { box-shadow: none; }
.saved-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 0 10px 10px; }
.saved-tools .saved-note { flex: 1 1 100%; min-height: 38px; font-size: 14px; }
.saved-meta { flex: 1; min-width: 0; color: var(--faint); font-size: 12px; }
.saved-bought summary { cursor: pointer; list-style: none; }
.saved-bought summary::-webkit-details-marker { display: none; }
.saved-bought summary h2::after { content: " ›"; color: var(--faint); }
.saved-bought[open] summary h2::after { content: " ⌄"; }
.saved-log { list-style: none; display: grid; gap: 2px; }
.saved-log li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.saved-log a { flex: 1 1 100%; color: var(--text); font-weight: 600; }
@media (min-width: 700px) {
    .saved-tools { padding: 0 12px 12px; }
    .saved-meta { flex-basis: 100%; order: -1; }  /* the cards are narrow here: its own line, above the note */
    .saved-tools .btn { flex: 1; }
}

/* ---- Browse ------------------------------------------------------------ */
.browse-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.browse-bar .btn, .browse-bar > .select { flex: 1 1 0; }
.result-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.result-line strong { color: var(--text); }
.result-line .chip { min-height: 30px; font-size: 13px; padding: 0 10px; }
.pager { display: flex; justify-content: center; align-items: center; gap: 12px; margin: 22px 0 8px; }
.pager-pos { color: var(--muted); font-size: 14px; }
@media (min-width: 700px) {
    .browse-bar { flex-wrap: nowrap; }
    .browse-bar .search { flex: 1 1 auto; }
    .browse-bar .btn, .browse-bar > .select { flex: 0 0 auto; width: auto; }
    .chips { flex-wrap: wrap; overflow: visible; }
}

/* ---- Sheets (native <dialog>) ------------------------------------------ */
.sheet {
    position: fixed; inset: auto 0 0 0; width: 100%; max-width: none; height: calc(100dvh - 20px); max-height: none;
    margin: 0; padding: 0; border: 0; border-radius: 18px 18px 0 0;
    background: var(--bg); color: var(--text); box-shadow: var(--shadow); overflow: hidden;
}
.sheet[open] { display: flex; flex-direction: column; animation: sheet-up .18s ease-out; }
.sheet::backdrop { background: rgba(15, 10, 5, .5); }
@keyframes sheet-up { from { translate: 0 24px; opacity: 0; } }
.sheet-bar { display: flex; align-items: center; gap: 2px; padding: 6px 8px; border-bottom: 1px solid var(--line); background: var(--surface); flex: none; }
.sheet-bar strong { padding-left: 8px; font-size: 17px; }
.sheet-bar [data-sheet-close], .sheet-bar [data-close-filters] { margin-left: auto; }
.sheet-pos { color: var(--faint); font-size: 13px; padding-left: 6px; }
.sheet-body { overflow-y: auto; overscroll-behavior: contain; padding: 16px; flex: 1; -webkit-overflow-scrolling: touch; }
.sheet-actions { display: flex; gap: 8px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--surface); flex: none; }
.sheet-actions .btn { flex: 1; }
.sheet-filters { height: auto; max-height: calc(100dvh - 20px); }
.filters { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field > span, .field > label { font-size: 13px; font-weight: 650; color: var(--muted); }
.field-check { grid-template-columns: auto 1fr; align-items: center; column-gap: 12px; }
.field-check > label { order: 2; font-size: 15px; font-weight: 550; color: var(--text); }
.field-check > .fine { grid-column: 2; order: 3; }
.range { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
@media (min-width: 700px) {
    .sheet { inset: 0 0 0 auto; width: min(600px, 100vw); height: 100dvh; border-radius: 0; border-left: 1px solid var(--line); }
    @keyframes sheet-up { from { translate: 24px 0; opacity: 0; } }
    .sheet-filters { inset: 0; margin: auto; width: min(520px, 94vw); height: fit-content; max-height: 90dvh; border: 1px solid var(--line); border-radius: 18px; }
}

/* ---- One book ---------------------------------------------------------- */
.detail { display: grid; gap: 16px; }
.detail-top { display: grid; grid-template-columns: 116px minmax(0, 1fr); gap: 14px; align-items: start; }
.detail-cover { border-radius: 10px; overflow: hidden; background: var(--surface-2); aspect-ratio: 3 / 4; }
.detail-cover a { display: block; width: 100%; height: 100%; }
.detail-cover img { width: 100%; height: 100%; object-fit: contain; }
.detail-head { display: grid; gap: 8px; min-width: 0; }
.detail-title { font: 700 21px/1.2 var(--serif); overflow-wrap: anywhere; }
.detail-by { color: var(--muted); }
.price-block { display: grid; gap: 2px; }
.price-ask { font-size: 26px; font-weight: 780; line-height: 1.1; }
.price-est { font-size: 14px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 0 8px; }
.price-est.is-good b { color: var(--good); }
.price-est.is-bad b { color: var(--bad); }
.detail-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 18px; margin-top: -8px; }
.detail-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; padding-top: 4px; border-top: 1px solid var(--line); }
.note { font-size: 15px; color: var(--muted); }
.block { display: grid; gap: 8px; padding-top: 14px; border-top: 1px solid var(--line); }
.block h3 { font: 700 17px/1.2 var(--serif); display: flex; align-items: center; gap: 8px; }
.desc { white-space: pre-line; overflow-wrap: anywhere; font-size: 15px; line-height: 1.5; }
/* Six lines by max-height, not -webkit-line-clamp: mobile Safari didn't
   re-lay-out a line-clamp switched off by a class change, so "Show all" only
   flipped its label. A max-height toggle re-lays-out everywhere. */
.desc[data-clamp] { max-height: 9em; overflow: hidden; }
.desc[data-clamp].is-open { max-height: none; }
.block > .link-btn, .rate-card > .link-btn { justify-self: start; }
@media (min-width: 700px) {
    .detail-top { grid-template-columns: 180px minmax(0, 1fr); gap: 18px; }
    .detail-title { font-size: 24px; }
}

.rating { container-type: inline-size; display: grid; gap: 8px; padding: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.rating-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.rating-label { font-weight: 700; }
.rating.is-rated .rating-label { color: var(--accent); }
.rating-hint { color: var(--faint); font-size: 12px; white-space: nowrap; }
.rating-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
@container (min-width: 470px) { .rating-grid { grid-template-columns: repeat(10, 1fr); } }
.rate-btn {
    min-height: 48px; border-radius: 10px; border: 1px solid var(--line); border-bottom-width: 3px;
    background: var(--bg); font-weight: 750; font-size: 17px; font-variant-numeric: tabular-nums;
}
.rate-btn:nth-child(-n+3) { border-bottom-color: color-mix(in srgb, var(--bad) 55%, var(--line)); }
.rate-btn:nth-child(n+8) { border-bottom-color: color-mix(in srgb, var(--good) 60%, var(--line)); }
.rate-btn:hover { border-color: var(--accent); }
.rate-btn:active { scale: .96; }
.rate-btn.is-on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.rate-btn:disabled { opacity: .5; }

.why { display: grid; gap: 8px; }
.why-row { display: grid; grid-template-columns: minmax(0, 1fr) 76px 42px; align-items: center; gap: 10px; font-size: 14px; }
.why-label { font-weight: 600; min-width: 0; }
.why-label small { display: block; font-weight: 400; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.why-bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.why-bar i { display: block; height: 100%; border-radius: 99px; background: var(--good); }
.why-row.is-down .why-bar i { background: var(--bad); margin-left: auto; }
.why-val { text-align: right; font-weight: 750; font-variant-numeric: tabular-nums; color: var(--good); }
.why-row.is-down .why-val { color: var(--bad); }

.comps { display: grid; gap: 8px; }
.comp { display: grid; grid-template-columns: 38px minmax(0, 1fr) auto; align-items: center; gap: 10px; font-size: 14px; }
.comp-cover { width: 38px; height: 50px; border-radius: 5px; background: var(--surface-2); overflow: hidden; }
.comp-cover img { width: 100%; height: 100%; object-fit: cover; }
.comp-main { min-width: 0; display: grid; }
.comp-title { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; line-height: 1.3; }
.comp-main small { color: var(--faint); font-size: 12px; }
.comp-price { white-space: nowrap; }
.facts { display: grid; grid-template-columns: minmax(0, auto) minmax(0, 1fr); gap: 6px 16px; font-size: 14px; }
.facts dt { color: var(--muted); }
.facts dd { overflow-wrap: anywhere; }
.copies { display: grid; gap: 6px; font-size: 14px; }
.copies li { display: flex; justify-content: space-between; gap: 12px; }

.ai-thread { display: grid; gap: 8px; }
.ai-thread:empty { display: none; }
.ai-msg { padding: 10px 12px; border-radius: 12px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; line-height: 1.5; }
.ai-user { justify-self: end; max-width: 88%; background: var(--accent); color: var(--on-accent); border-bottom-right-radius: 4px; }
.ai-assistant { background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.ai-assistant.is-waiting::after { content: "▍"; animation: pulse 1s steps(2) infinite; color: var(--faint); }
.ai-assistant.is-error { border-color: var(--bad); color: var(--bad); }
.ai-suggest { display: flex; flex-wrap: wrap; gap: 6px; }
.ai-suggest .chip { white-space: normal; text-align: left; min-height: 34px; padding: 5px 12px; font-size: 13px; }
.ai-form { display: flex; gap: 6px; }
.ai-form input { flex: 1; min-width: 0; }
.ai-form .icon-btn { background: var(--accent); color: var(--on-accent); }

/* ---- Rate -------------------------------------------------------------- */
.progress { height: 4px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-bottom: 16px; }
.progress i { display: block; height: 100%; background: var(--accent); transition: width .2s; }
.rate-card { display: grid; gap: 12px; padding-bottom: 12px; }
.rate-top { display: grid; grid-template-columns: 132px minmax(0, 1fr); gap: 14px; align-items: start; }
.rate-cover { display: block; aspect-ratio: 3 / 4; border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.rate-head { display: grid; gap: 7px; min-width: 0; }
.rate-dock {
    position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 8px); z-index: 5;
    display: grid; gap: 8px; margin-top: 8px;
}
.rate-dock .rating { box-shadow: var(--shadow); }
.rate-dock-actions { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.rate-keys { display: none; }
.rate-done { text-align: center; padding: 40px 12px; }
.rate-done h2 { font: 700 24px/1.2 var(--serif); margin-bottom: 8px; }
@media (min-width: 960px) {
    .rate-top { grid-template-columns: 220px minmax(0, 1fr); gap: 22px; }
    .rate-dock { bottom: 16px; }
    .rate-keys { display: inline; }
}

/* ---- System pages ------------------------------------------------------ */
.tabs { display: flex; gap: 4px; margin: 0 0 16px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tab { padding: 10px 12px; color: var(--muted); font-weight: 600; font-size: 15px; border-bottom: 3px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { text-decoration: none; color: var(--text); }
.tab.is-active { color: var(--text); border-bottom-color: var(--accent); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; display: grid; gap: 12px; }
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 12px; }
.card h2 { font: 700 19px/1.2 var(--serif); display: flex; align-items: center; gap: 8px; }
.card h3 { font-size: 14px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-top: 4px; }
.card p.muted { font-size: 15px; }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.stat { background: var(--bg); border-radius: 10px; padding: 10px 12px; display: grid; }
.stat b { font-size: 22px; font-weight: 780; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat span { color: var(--muted); font-size: 13px; line-height: 1.3; }
.stat.is-bad b { color: var(--bad); }
@media (min-width: 700px) { .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; white-space: nowrap; }
.table th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 6px 10px 6px 0; border-bottom: 1px solid var(--line); }
.table td { padding: 8px 10px 8px 0; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.table .num { text-align: right; }
.table-note td { white-space: normal; color: var(--bad); font-size: 13px; padding-top: 0; }
.rows { display: grid; }
.row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); min-width: 0; }
.row:first-child { border-top: 0; }
.row-main { flex: 1; min-width: 0; display: grid; gap: 1px; overflow-wrap: anywhere; }
.row-main > a { font-weight: 600; color: var(--text); }
.row-main small { color: var(--muted); font-size: 13px; line-height: 1.4; }
.row-actions { display: flex; align-items: center; gap: 2px; flex: none; }
.row-input { min-height: 40px; border-color: transparent; background: transparent; padding-left: 0; font-weight: 600; }
.row-input:hover { border-color: var(--line); padding-left: 10px; }
.row-input:focus { background: var(--surface); padding-left: 10px; }
.shop.is-paused .row-main { opacity: .6; }
.meters { display: grid; gap: 8px; font-size: 14px; }
.meters li { display: grid; grid-template-columns: minmax(0, 1fr) 84px 44px; align-items: center; gap: 10px; }
.meter { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.meters b { text-align: right; font-variant-numeric: tabular-nums; }
.settings .field { padding: 10px 0; border-top: 1px solid var(--line); }
.settings .field > label { font-size: 15px; font-weight: 600; color: var(--text); }
.settings .field input:not([type="checkbox"]), .settings .field select { max-width: 380px; }
.save-bar { position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 8px); display: flex; justify-content: flex-end; margin-bottom: 16px; z-index: 5; }
.save-bar .btn { box-shadow: var(--shadow); }
@media (min-width: 960px) { .save-bar { bottom: 16px; } }

/* ---- Messages ---------------------------------------------------------- */
.flash { max-width: 780px; margin: 0 auto; padding: 12px 16px 0; display: grid; gap: 8px; }
.flash-item { padding: 10px 14px; border-radius: 12px; background: var(--info-bg); color: var(--info); font-size: 15px; }
.flash-item.is-success { background: var(--good-bg); color: var(--good); }
.flash-item.is-error { background: var(--bad-bg); color: var(--bad); }
.toasts { position: fixed; z-index: 60; left: 0; right: 0; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px); display: grid; justify-items: center; gap: 8px; pointer-events: none; padding: 0 12px; }
.toast {
    pointer-events: auto; display: flex; align-items: center; gap: 12px; max-width: 100%;
    padding: 10px 16px; border-radius: 12px; background: var(--text); color: var(--bg); font-size: 15px; font-weight: 550;
    box-shadow: var(--shadow); animation: sheet-up .18s ease-out;
}
.toast.is-error { background: var(--bad); color: #fff; }
.toast button { border: 0; background: none; color: inherit; font-weight: 750; text-decoration: underline; padding: 4px 0; }
@media (min-width: 960px) { .toasts { bottom: 20px; left: 216px; } }

/* ---- Login ------------------------------------------------------------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(380px, 100%); gap: 16px; padding: 24px; }
.login-card .nav-brand { display: flex; justify-content: center; font-size: 26px; }
.login-brand .logo-mark { width: 56px; height: 56px; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
