:root {
    --bg: #f4f1ea;
    --panel: #fffaf0;
    --ink: #1f2a24;
    --muted: #657069;
    --line: #d8d0c2;
    --accent: #8f1f2d;
    --accent-strong: #6d1722;
    --forest: #244b36;
    --shadow: 0 18px 50px rgba(31, 42, 36, 0.14);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background: var(--bg);
    font-family: Arial, Helvetica, sans-serif;
}

button,
input,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

.app-shell {
    display: grid;
    grid-template-columns: 360px minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 22px;
    background: var(--panel);
    border-right: 1px solid var(--line);
    min-height: 100vh;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 46px;
    height: 46px;
    border-radius: 8px;
    color: white;
    background: var(--accent);
    font-weight: 700;
}

.brand h1 {
    margin: 0;
    font-size: 18px;
    line-height: 1.25;
}

.brand p {
    margin: 3px 0 0;
    color: var(--muted);
}

.field,
.search-box {
    display: grid;
    gap: 8px;
}

.field span,
.search-box label {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

select,
input[type="search"],
input[type="number"] {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 11px 12px;
    color: var(--ink);
    background: white;
    outline: none;
}

select:focus,
input:focus {
    border-color: var(--forest);
    box-shadow: 0 0 0 3px rgba(36, 75, 54, 0.14);
}

.search-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
}

.search-row button,
.results-head button,
.reader-toolbar button {
    border: 0;
    border-radius: 8px;
    padding: 10px 14px;
    color: white;
    background: var(--forest);
}

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

.results-head button {
    color: var(--accent);
    background: transparent;
    padding: 6px 0;
}

.results {
    display: grid;
    gap: 10px;
    overflow: auto;
    padding-right: 4px;
}

.result-item {
    display: grid;
    gap: 6px;
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    text-align: left;
    color: var(--ink);
    background: white;
}

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

.result-item span,
.muted {
    color: var(--muted);
    font-size: 13px;
}

.result-item strong {
    font-size: 14px;
    line-height: 1.45;
    font-weight: 500;
}

.reader {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    min-width: 0;
    min-height: 100vh;
}

.reader-toolbar {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    background: rgba(244, 241, 234, 0.94);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(10px);
}

.reader-toolbar button {
    min-width: 42px;
    height: 42px;
    padding: 0 12px;
    font-size: 22px;
    line-height: 1;
}

.reader-toolbar button:disabled {
    opacity: 0.35;
    cursor: default;
}

.page-control {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 128px;
}

.page-control input {
    width: 78px;
    text-align: center;
}

.toolbar-spacer {
    flex: 1;
}

#zoomValue {
    min-width: 50px;
    text-align: center;
}

.page-stage {
    overflow: auto;
    padding: 28px;
    text-align: center;
}

.page-stage img {
    display: block;
    width: 100%;
    max-width: 980px;
    min-width: 420px;
    margin: 0 auto;
    border-radius: 4px;
    box-shadow: var(--shadow);
    user-select: none;
    -webkit-user-drag: none;
}

.empty-state {
    max-width: 620px;
    margin: 12vh auto;
    padding: 28px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

.empty-state h2 {
    margin: 0 0 10px;
}

.empty-state code {
    display: inline-block;
    padding: 8px 10px;
    border-radius: 6px;
    background: #efe6d6;
}

@media (max-width: 860px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        min-height: auto;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .reader {
        min-height: 70vh;
    }

    .page-stage {
        padding: 16px;
    }
}

@media (max-width: 540px) {
    .reader-toolbar {
        gap: 7px;
        padding: 10px;
    }

    .page-control {
        min-width: 108px;
    }

    .toolbar-spacer {
        display: none;
    }

    .page-stage img {
        min-width: 320px;
    }
}
