:root {
    --bg: #faf8f5;
    --surface: #ffffff;
    --text: #22201c;
    --muted: #6b665e;
    --border: #e3ded6;
    --accent: #8b1e2d;
    --accent-text: #ffffff;
    --mark: #ffe7a3;
    --link: #7a1a28;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #17181b;
        --surface: #202226;
        --text: #e8e6e3;
        --muted: #9b978f;
        --border: #34363b;
        --accent: #c9485b;
        --accent-text: #ffffff;
        --mark: #6b5310;
        --link: #ef8a98;
        color-scheme: dark;
    }
}

* { 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(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

.bar {
    display: flex;
    flex-wrap: wrap;
    gap: .25rem 1.25rem;
    align-items: baseline;
    padding: .75rem 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.bar .home { font-weight: 700; font-size: 1.1rem; color: var(--accent); }
.crumbs { color: var(--muted); overflow-wrap: anywhere; }

main { max-width: 72rem; margin: 0 auto; padding: 1.25rem; }

/* search */
.search-box { display: flex; gap: .5rem; flex-wrap: wrap; }
.search-box input {
    flex: 1 1 18rem;
    min-width: 0;
    padding: .65rem .85rem;
    font: inherit;
    color: inherit;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: .5rem;
}
.search-box input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.modes { display: inline-flex; border: 1px solid var(--border); border-radius: .5rem; overflow: hidden; }
.modes button {
    font: inherit;
    padding: .5rem .8rem;
    border: 0;
    background: var(--surface);
    color: var(--muted);
    cursor: pointer;
}
.modes button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }
.search-scope { color: var(--muted); font-size: .85rem; margin: .4rem 0 0; }

.results { margin-top: 1rem; }
.results[hidden] { display: none; }
.notice { color: var(--muted); font-style: italic; margin: .5rem 0; }
.summary { color: var(--muted); font-size: .9rem; margin-bottom: .5rem; }
.hit {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: .5rem;
    padding: .75rem 1rem;
    margin-bottom: .6rem;
}
.hit .title { font-weight: 600; font-size: 1.02rem; overflow-wrap: anywhere; }
.hit .path { font-size: .82rem; color: var(--muted); overflow-wrap: anywhere; }
.hit .path a { color: var(--muted); }
.hit .snippet { margin-top: .35rem; overflow-wrap: anywhere; }
.hit mark { background: var(--mark); color: inherit; border-radius: 2px; padding: 0 1px; }
.hit img.preview { max-height: 140px; max-width: 100%; margin-top: .4rem; border-radius: .25rem; display: block; }
.snippet.tags, .tile .tags { color: var(--muted); font-size: .85rem; }

.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(10.5rem, 1fr));
    gap: .75rem;
}
.tile {
    margin: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: .5rem;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.tile img {
    display: block;
    width: 100%;
    aspect-ratio: 1;
    object-fit: contain;
    background: #fff;
}
.tile figcaption { padding: .4rem .55rem .55rem; min-width: 0; }
.tile .name {
    display: block;
    font-size: .85rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tile .tags { font-size: .78rem; margin-top: .15rem; overflow-wrap: anywhere; }
.badge {
    display: inline-block;
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 0 .45rem;
    margin-left: .4rem;
    vertical-align: middle;
}

.pager { display: flex; flex-wrap: wrap; gap: .3rem; justify-content: center; margin: 1rem 0; }
.pager button {
    font: inherit;
    min-width: 2.2rem;
    padding: .3rem .6rem;
    border: 1px solid var(--border);
    border-radius: .35rem;
    background: var(--surface);
    color: inherit;
    cursor: pointer;
}
.pager button[aria-current="page"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.pager button:disabled { opacity: .4; cursor: default; }

/* home page */
.systems {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
    gap: 1rem;
    margin-top: 2rem;
}
.systems a {
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 4 / 3;
    padding: 1rem;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: .5rem;
}
.systems img { max-width: 100%; max-height: 100%; object-fit: contain; }

.status {
    margin-top: 2rem;
    padding: .75rem 1rem;
    border: 1px solid var(--border);
    border-radius: .5rem;
    background: var(--surface);
    color: var(--muted);
    font-size: .88rem;
}
.status:empty { display: none; }
.status .row { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; margin: .2rem 0; }
.status strong { color: var(--text); }
.status button {
    font: inherit;
    font-size: .82rem;
    padding: .2rem .6rem;
    border: 1px solid var(--border);
    border-radius: .35rem;
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
}
.status progress { width: 10rem; accent-color: var(--accent); }

/* directory listing */
table.listing { width: 100%; border-collapse: collapse; margin-top: 1rem; }
.listing th { text-align: left; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--border); padding: .4rem; }
.listing td { padding: .3rem .4rem; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
.listing .size { text-align: right; white-space: nowrap; }
.listing td:last-child { white-space: nowrap; color: var(--muted); }
.listing a.dir { font-weight: 600; }

@media (max-width: 40rem) {
    .listing th:last-child, .listing td:last-child { display: none; }
    main { padding: 1rem; }
}
