:root {
    color-scheme: light;
    --bg: #f6f3ee;
    --panel: #ffffff;
    --ink: #202124;
    --muted: #6b655d;
    --line: #ded8cf;
    --accent: #12665c;
    --accent-strong: #0b4d45;
    --wish: #9a3d51;
    --danger: #a32828;
    --shadow: 0 16px 40px rgba(31, 27, 21, 0.10);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
    cursor: pointer;
}

.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 28px clamp(18px, 5vw, 64px);
    background: #fffaf2;
    border-bottom: 1px solid var(--line);
}

h1,
h2,
h3,
p {
    margin: 0;
}

h1 {
    font-size: clamp(2rem, 4vw, 4rem);
    line-height: 1;
}

h2 {
    font-size: 1.35rem;
}

h3 {
    font-size: 1rem;
    line-height: 1.25;
}

main {
    width: min(1180px, calc(100% - 32px));
    margin: 24px auto 56px;
}

.eyebrow {
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.toolbar,
.admin-panel,
.list-section {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.toolbar {
    display: flex;
    align-items: end;
    gap: 12px;
    padding: 14px;
    margin-bottom: 20px;
}

.search-box {
    flex: 1;
    min-width: 180px;
}

label {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
}

input,
textarea,
select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 11px 12px;
    color: var(--ink);
    background: #fff;
    text-transform: none;
}

textarea {
    resize: vertical;
}

.primary-button,
.secondary-button,
.ghost-button,
.small-button,
.icon-button {
    border: 0;
    border-radius: 8px;
    font-weight: 800;
}

.primary-button {
    padding: 12px 16px;
    color: #fff;
    background: var(--accent);
}

.primary-button:hover {
    background: var(--accent-strong);
}

.secondary-button,
.ghost-button {
    padding: 11px 14px;
    color: var(--accent-strong);
    background: #e6f0ed;
}

.ghost-button {
    background: transparent;
    border: 1px solid var(--line);
}

.icon-button {
    width: 36px;
    height: 36px;
    color: var(--muted);
    background: #f3f0eb;
}

.admin-panel {
    padding: 18px;
    margin-bottom: 20px;
}

.panel-heading,
.section-heading {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 16px;
}

.lookup-row {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) auto auto;
    gap: 10px;
    align-items: end;
}

.scanner {
    margin: 14px 0;
}

.scanner video {
    width: min(420px, 100%);
    aspect-ratio: 4 / 3;
    display: block;
    margin-bottom: 10px;
    border-radius: 8px;
    background: #111;
}

.lookup-results {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 10px;
    margin: 16px 0;
}

.lookup-result {
    display: grid;
    grid-template-columns: 46px 1fr;
    gap: 10px;
    min-height: 68px;
    padding: 8px;
    text-align: left;
    color: var(--ink);
    background: #faf8f4;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.lookup-result small {
    display: block;
    margin-top: 3px;
    color: var(--muted);
}

.lookup-cover,
.cover-preview {
    display: grid;
    place-items: center;
    overflow: hidden;
    background: #efe9de;
    color: var(--muted);
}

.lookup-cover {
    width: 46px;
    height: 58px;
    border-radius: 6px;
}

.lookup-cover img,
.cover-preview img,
.book-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.book-form {
    display: grid;
    grid-template-columns: 128px 1fr;
    gap: 16px;
    align-items: start;
}

.cover-preview {
    width: 128px;
    aspect-ratio: 2 / 3;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 0.85rem;
    text-align: center;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.form-grid .wide {
    grid-column: 1 / -1;
}

.book-form .primary-button {
    grid-column: 2;
    width: fit-content;
}

.lists-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.list-section {
    padding: 18px;
    min-width: 0;
}

.wishlist-section {
    border-top: 4px solid var(--wish);
}

.count-pill {
    min-width: 36px;
    padding: 6px 10px;
    color: #fff;
    text-align: center;
    border-radius: 999px;
    background: var(--accent);
    font-weight: 800;
}

.wishlist-section .count-pill {
    background: var(--wish);
}

.book-grid {
    display: grid;
    gap: 12px;
}

.book-card {
    display: grid;
    grid-template-columns: 82px 1fr;
    gap: 12px;
    min-width: 0;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fffdf9;
}

.book-cover {
    width: 82px;
    aspect-ratio: 2 / 3;
    overflow: hidden;
    border-radius: 7px;
    background: #ece4d8;
}

.missing-cover {
    display: grid;
    place-items: center;
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 800;
}

.book-body {
    min-width: 0;
}

.muted,
.isbn,
.notes {
    margin-top: 5px;
    color: var(--muted);
    font-size: 0.88rem;
}

.isbn {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.notes {
    color: var(--ink);
}

.book-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.small-button {
    padding: 8px 10px;
    color: var(--accent-strong);
    background: #e6f0ed;
    font-size: 0.82rem;
}

.small-button.danger {
    color: #fff;
    background: var(--danger);
}

.empty-state {
    padding: 16px;
    color: var(--muted);
    border: 1px dashed var(--line);
    border-radius: 8px;
    background: #fbfaf7;
}

dialog {
    width: min(420px, calc(100% - 32px));
    padding: 0;
    border: 0;
    border-radius: 8px;
    box-shadow: var(--shadow);
}

dialog::backdrop {
    background: rgba(20, 18, 15, 0.36);
}

.login-form {
    display: grid;
    gap: 14px;
    padding: 18px;
}

.toast {
    position: fixed;
    right: 18px;
    bottom: 18px;
    transform: translateY(16px);
    max-width: min(360px, calc(100% - 36px));
    padding: 12px 14px;
    color: #fff;
    background: #222;
    border-radius: 8px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 160ms ease, transform 160ms ease;
}

.toast.visible {
    opacity: 1;
    transform: translateY(0);
}

[hidden] {
    display: none !important;
}

@media (max-width: 820px) {
    .site-header,
    .toolbar,
    .lookup-row {
        align-items: stretch;
        flex-direction: column;
    }

    .toolbar {
        display: grid;
    }

    .lookup-row,
    .lists-grid,
    .book-form,
    .form-grid {
        grid-template-columns: 1fr;
    }

    .book-form .primary-button {
        grid-column: 1;
    }
}

@media (max-width: 520px) {
    main {
        width: min(100% - 20px, 1180px);
        margin-top: 14px;
    }

    .site-header {
        padding: 20px 14px;
    }

    .book-card {
        grid-template-columns: 66px 1fr;
    }

    .book-cover {
        width: 66px;
    }
}
