:root {
    --bg: #faf7f2;
    --surface: #ffffff;
    --text: #2b2420;
    --muted: #7a6f66;
    --border: #e8e0d6;
    --accent: #b5462d;
    --accent-text: #ffffff;
    --shadow: 0 1px 2px rgba(43, 36, 32, .06), 0 4px 14px rgba(43, 36, 32, .06);
    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #17130f;
        --surface: #221c17;
        --text: #f0e9e1;
        --muted: #a89c90;
        --border: #3a312a;
        --accent: #e07a5a;
        --accent-text: #17130f;
        --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }

/* Top bar */
.topbar {
    position: sticky; top: 0; z-index: 10;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.topbar-inner {
    display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
    padding-top: 12px; padding-bottom: 12px;
}
.brand { font-weight: 700; font-size: 18px; color: var(--text); }
.brand span { color: var(--accent); }
.nav { display: flex; gap: 16px; }
.nav a { color: var(--muted); font-weight: 500; }
.nav a:hover { color: var(--text); text-decoration: none; }

input[type=search], select {
    font: inherit; color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    min-width: 0;
}
input[type=search]:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

button {
    font: inherit; cursor: pointer;
    border: 0; border-radius: 8px;
    padding: 8px 14px;
    background: var(--accent); color: var(--accent-text); font-weight: 600;
}

.search { display: flex; gap: 8px; margin-left: auto; flex: 1 1 260px; max-width: 380px; }
.search input { flex: 1; }

/* Page header */
.page-head {
    display: flex; align-items: flex-end; justify-content: space-between;
    gap: 16px; flex-wrap: wrap;
    margin: 24px 0 16px;
}
.page-head h1 { margin: 0; font-size: 26px; line-height: 1.2; }
.page-head p { margin: 4px 0 0; }
.filter { width: 260px; max-width: 100%; }

.crumbs { margin-top: 20px; font-size: 14px; color: var(--muted); }

.scoped-search { display: flex; gap: 8px; max-width: 420px; margin-bottom: 20px; }
.scoped-search input { flex: 1; }

/* Grid + cards */
.grid { display: grid; gap: 16px; }
.categories { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.products { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }

.card {
    display: flex; flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow);
    color: inherit;
    transition: transform .15s ease, box-shadow .15s ease;
}
.card:hover { transform: translateY(-2px); text-decoration: none; }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

button.card {
    padding: 0; text-align: left; font-weight: normal;
    background: var(--surface); color: inherit;
}

.thumb {
    position: relative;
    aspect-ratio: 1;
    background: var(--bg);
    display: grid; place-items: center;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.no-image { color: var(--muted); font-size: 13px; }
.badge {
    position: absolute; top: 8px; right: 8px;
    background: rgba(0, 0, 0, .65); color: #fff;
    font-size: 11px; font-weight: 600;
    padding: 2px 8px; border-radius: 99px;
}

.card-body { padding: 10px 12px 12px; }
.card-body h2 {
    margin: 0 0 4px; font-size: 14px; font-weight: 600;
    overflow-wrap: anywhere;
}
.category-card .card-body span { font-size: 13px; }
.meta { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.meta .muted { font-size: 12px; text-align: right; }

/* Pager */
.pager {
    display: flex; justify-content: center; align-items: center; gap: 20px;
    margin: 28px 0 40px;
}
.pager a {
    padding: 8px 14px; border: 1px solid var(--border); border-radius: 8px;
    background: var(--surface);
}

.empty, .empty-filter { padding: 40px 0; text-align: center; }
.message { padding: 60px 0; text-align: center; }

main { padding-bottom: 40px; }

/* Product dialog */
.product-dialog {
    width: min(720px, calc(100vw - 32px));
    max-height: calc(100vh - 32px);
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    color: var(--text);
}
.product-dialog::backdrop { background: rgba(0, 0, 0, .6); }
.dialog-close {
    position: absolute; top: 8px; right: 8px; z-index: 1;
    width: 36px; height: 36px; padding: 0;
    border-radius: 50%; font-size: 22px; line-height: 1;
    background: rgba(0, 0, 0, .55); color: #fff;
}
.dialog-media { background: var(--bg); }
.dialog-media img, .dialog-media video {
    display: block; width: 100%; max-height: 65vh; object-fit: contain;
}
.dialog-thumbs { display: flex; gap: 8px; padding: 10px 16px 0; }
.dialog-thumbs button {
    width: 56px; height: 56px; padding: 0; overflow: hidden;
    background: var(--bg); border: 2px solid transparent;
}
.dialog-thumbs button[aria-current=true] { border-color: var(--accent); }
.dialog-thumbs img { width: 100%; height: 100%; object-fit: cover; }
.dialog-info { padding: 14px 16px 18px; }
.dialog-info h2 { margin: 0 0 6px; font-size: 20px; overflow-wrap: anywhere; }
.dialog-info dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; margin: 0; }
.dialog-info dt { color: var(--muted); }
.dialog-info dd { margin: 0; }

@media (max-width: 600px) {
    .search { max-width: none; margin-left: 0; flex-basis: 100%; }
    .products { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .categories { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .filter { width: 100%; }
}
