:root {
    --ink: #2b1c18;
    --muted: #79655d;
    --line: #eadbd2;
    --paper: #faf6f1;
    --card: #ffffff;
    --accent: #a84f24;
    --accent-2: #c56a35;
    --accent-soft: #f8e6d8;
    --warm: #8f3027;
    --shadow: 0 18px 50px rgba(91, 46, 28, .12);
    --radius: 20px;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; color: var(--ink); background: var(--paper); font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.eyebrow { margin: 0 0 7px; color: var(--accent); font-size: .73rem; font-weight: 800; letter-spacing: .15em; }

.login-page { min-height: 100vh; background: radial-gradient(circle at 20% 10%, #f4d7bd 0, transparent 33%), radial-gradient(circle at 90% 85%, #edc9c1 0, transparent 30%), #f7eee5; }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 28px; }
.login-card { width: min(460px, 100%); padding: 48px; background: rgba(255,252,249,.92); border: 1px solid rgba(255,255,255,.9); border-radius: 30px; box-shadow: 0 30px 90px rgba(90,44,29,.18); backdrop-filter: blur(18px); }
.brand-mark { width: 64px; height: 64px; display: grid; place-items: center; margin-bottom: 30px; color: white; background: var(--accent); border-radius: 20px; font-size: 2.2rem; box-shadow: 0 12px 30px rgba(168,79,36,.3); }
.brand-mark.small { width: 42px; height: 42px; margin: 0; border-radius: 13px; font-size: 1.5rem; }
.brand-mark img { display: block; width: 76%; height: 76%; object-fit: contain; filter: brightness(0) invert(1); }
.brand-mark.small img { width: 74%; height: 74%; }
.login-brand { display: flex; align-items: center; gap: 20px; margin-bottom: 30px; }
.login-brand .brand-mark { flex: 0 0 64px; margin: 0; }
.login-brand .eyebrow { margin-bottom: 6px; }
.login-card h1 { margin: 0; font-family: Georgia, serif; font-size: clamp(2rem, 6vw, 2.7rem); line-height: 1.05; }
.login-intro { margin: 14px 0 30px; color: var(--muted); line-height: 1.6; }
.login-form { display: grid; gap: 11px; }
.login-form label { font-size: .85rem; font-weight: 700; }
.secret-field { position: relative; }
.secret-field input { width: 100%; padding: 16px 52px 16px 16px; border: 1px solid var(--line); border-radius: 13px; outline: none; background: #fffaf6; }
.secret-field input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.icon-button { position: absolute; right: 8px; top: 8px; width: 38px; height: 38px; border: 0; background: transparent; color: var(--muted); }
.primary-button { display: flex; justify-content: space-between; margin-top: 8px; padding: 16px 18px; color: white; border: 0; border-radius: 13px; background: var(--accent); font-weight: 750; }
.primary-button:hover { background: #873b1c; }
.login-footnote { margin: 24px 0 0; color: #9a8278; font-size: .78rem; text-align: center; }
.alert { margin-bottom: 18px; padding: 12px 14px; border-radius: 11px; font-size: .9rem; }
.alert-error { color: #8c2d28; background: #fbe8e6; }

.app-shell { min-height: 100vh; }
.topbar { height: 76px; display: flex; align-items: center; gap: 30px; padding: 0 32px; background: rgba(255,255,255,.94); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; backdrop-filter: blur(16px); }
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand strong, .brand small { display: block; }
.brand strong { font-family: Georgia, serif; font-size: 1.25rem; }
.brand small { margin-top: 2px; color: var(--muted); font-size: .7rem; }
.library-stats { margin-left: auto; display: flex; align-items: center; gap: 13px; color: var(--muted); font-size: .82rem; }
.library-stats strong { color: var(--ink); }
.library-stats i { width: 4px; height: 4px; background: #bba69b; border-radius: 50%; }
.quiet-button { padding: 9px 13px; color: var(--ink); background: white; border: 1px solid var(--line); border-radius: 10px; font-weight: 650; }
.quiet-button:hover { border-color: #c8a999; background: #fff8f3; }
.main-nav { display: flex; gap: 5px; padding: 14px 32px 0; background: white; }
.nav-tab { padding: 12px 17px; color: var(--muted); border: 0; border-bottom: 3px solid transparent; background: transparent; font-weight: 700; }
.nav-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.app-view { display: none; }
.app-view.active { display: block; }

.search-hero { padding: 42px max(32px, calc((100vw - 1460px)/2)); background: linear-gradient(135deg, #fffaf5, #f6e8dc 58%, #f2ddd5); border-bottom: 1px solid var(--line); }
.search-hero > div:first-child { max-width: 720px; }
.search-hero h1, .catalog-header h1 { margin: 0; font-family: Georgia, serif; font-size: clamp(2rem, 4vw, 3.3rem); font-weight: 500; letter-spacing: -.025em; }
.search-hero > div > p:last-child, .catalog-header p:last-child { color: var(--muted); }
.search-form { max-width: 1160px; margin-top: 28px; }
.search-input-wrap { display: flex; align-items: center; gap: 12px; padding: 10px 10px 10px 20px; background: white; border: 1px solid #e5d2c6; border-radius: 18px; box-shadow: var(--shadow); }
.search-input-wrap > span { color: var(--accent); font-size: 1.5rem; }
.search-input-wrap textarea { flex: 1; min-width: 0; resize: none; padding: 10px 0; border: 0; outline: 0; font-size: 1.05rem; background: transparent; }
.search-submit { padding: 14px 18px; color: white; border: 0; border-radius: 12px; background: var(--accent); font-weight: 750; }
.search-options { display: flex; align-items: end; gap: 22px; margin-top: 18px; }
.segmented { display: flex; padding: 3px; margin: 0; border: 0; border-radius: 11px; background: #efdfd4; }
.segmented legend { float: left; margin: 8px 10px 0 0; color: var(--muted); font-size: .78rem; font-weight: 700; }
.segmented label input { position: absolute; opacity: 0; }
.segmented label span { display: block; padding: 8px 12px; border-radius: 8px; color: var(--muted); font-size: .82rem; font-weight: 700; cursor: pointer; }
.segmented input:checked + span { color: var(--accent); background: white; box-shadow: 0 2px 6px rgba(91,46,28,.12); }
.result-count, .filter-bar label { display: grid; gap: 5px; color: var(--muted); font-size: .75rem; font-weight: 700; }
select { padding: 8px 32px 8px 10px; border: 1px solid var(--line); border-radius: 9px; background: white; }
.empty-state { min-height: 420px; display: grid; justify-items: center; align-content: center; padding: 50px 24px; text-align: center; }
.empty-state h2 { margin: 18px 0 6px; font-family: Georgia, serif; font-size: 1.8rem; }
.empty-state p { max-width: 580px; color: var(--muted); line-height: 1.65; }
.personal-notice { width: min(760px, 100%); padding: 30px 32px; text-align: left; background: rgba(255,255,255,.58); border: 1px solid rgba(121,101,93,.18); border-radius: 14px; }
.personal-notice h2 { margin: 0 0 18px; color: var(--ink); font-family: inherit; font-size: .78rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.personal-notice p { max-width: none; margin: 0; }
.personal-notice p + p { margin-top: 14px; }
.personal-notice .notice-signature { margin-top: 20px; color: var(--ink); font-size: .82rem; font-weight: 700; }

.workspace { display: grid; grid-template-columns: minmax(320px, 38%) 1fr; min-height: calc(100vh - 260px); background: white; }
.result-panel { min-width: 0; border-right: 1px solid var(--line); background: #faf6f2; }
.panel-heading { display: flex; justify-content: space-between; align-items: center; padding: 22px; border-bottom: 1px solid var(--line); }
.panel-heading h2 { margin: 0; font-family: Georgia, serif; font-size: 1.35rem; }
.count-badge { min-width: 34px; padding: 6px 9px; text-align: center; color: var(--accent); background: var(--accent-soft); border-radius: 20px; font-size: .8rem; font-weight: 800; }
.result-list { max-height: calc(100vh - 275px); overflow: auto; }
.result-item { display: block; width: 100%; padding: 18px 22px; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: transparent; }
.result-item:hover { background: #f8ebe2; }
.result-item.active { background: white; box-shadow: inset 4px 0 var(--accent); }
.result-item h3 { margin: 0 0 5px; font-family: Georgia, serif; font-size: 1.08rem; }
.result-item .author { color: var(--muted); font-size: .84rem; }
.result-item .excerpt { display: -webkit-box; margin: 10px 0 0; overflow: hidden; color: #66544c; line-height: 1.45; font-size: .86rem; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.result-meta { display: flex; justify-content: space-between; gap: 10px; margin-top: 10px; color: var(--accent); font-size: .72rem; font-weight: 700; }
.detail-panel { min-width: 0; padding: clamp(28px, 4vw, 64px); background: white; overflow: auto; }
.detail-panel h1 { margin: 0; font-family: Georgia, serif; font-size: clamp(2rem, 4vw, 3.2rem); font-weight: 500; line-height: 1.1; }
.detail-author { margin: 10px 0 24px; color: var(--muted); font-size: 1.15rem; }
.detail-tags { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0; }
.tag { padding: 7px 10px; color: #6c4a3c; background: #f6e8df; border-radius: 20px; font-size: .76rem; font-weight: 700; }
.paragraph-text { margin: 30px 0; font-family: Georgia, serif; font-size: clamp(1.08rem, 1.5vw, 1.3rem); line-height: 1.85; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 26px; }
.action-button, .audio-button { padding: 11px 15px; color: white; border: 0; border-radius: 10px; background: var(--accent); font-weight: 750; }
.action-button.secondary { color: var(--accent); border: 1px solid #dfb8a1; background: white; }
.book-description { margin: 26px 0; color: #5e4940; line-height: 1.75; }
.info-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 1px; margin-top: 28px; overflow: hidden; border: 1px solid var(--line); border-radius: 15px; background: var(--line); }
.info-grid div { padding: 13px 15px; background: #fcf8f5; }
.info-grid dt { color: var(--muted); font-size: .72rem; font-weight: 700; text-transform: uppercase; }
.info-grid dd { margin: 5px 0 0; overflow-wrap: anywhere; }
.detail-placeholder { min-height: 430px; display: grid; place-items: center; align-content: center; color: var(--muted); text-align: center; }
.detail-placeholder span { font-size: 3rem; color: #d3ad98; }
.detail-placeholder h2 { margin-bottom: 3px; color: var(--ink); font-family: Georgia, serif; }

.catalog-header { display: flex; justify-content: space-between; align-items: center; padding: 32px; background: white; border-bottom: 1px solid var(--line); }
.catalog-header h1 { font-size: 2.3rem; }
.filter-bar { display: grid; grid-template-columns: minmax(220px,1.4fr) repeat(3,minmax(150px,1fr)); gap: 14px; padding: 16px 32px; background: #fcf7f3; border-bottom: 1px solid var(--line); }
.filter-bar input, .filter-bar select { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: white; outline: none; }
.filter-search { align-self: end; position: relative; }
.filter-search span { position: absolute; left: 12px; bottom: 10px; color: var(--muted); }
.filter-search input { padding-left: 34px; }
.catalog-workspace { min-height: calc(100vh - 250px); }
.book-list { max-height: calc(100vh - 320px); }
.pagination { display: flex; justify-content: space-between; align-items: center; padding: 13px; border-top: 1px solid var(--line); background: white; font-size: .8rem; }

.context-dialog { width: min(1500px, 96vw); height: min(900px, 94vh); padding: 0; border: 0; border-radius: 24px; box-shadow: 0 30px 100px rgba(0,0,0,.3); }
.context-dialog::backdrop { background: rgba(48,25,19,.58); backdrop-filter: blur(5px); }
.dialog-shell { height: 100%; display: grid; grid-template-rows: auto auto 1fr; overflow: hidden; }
.dialog-header { display: flex; justify-content: space-between; gap: 25px; padding: 24px 28px; border-bottom: 1px solid var(--line); }
.dialog-header h2 { margin: 0; font-family: Georgia, serif; font-size: 1.7rem; }
.dialog-header p:last-child { margin: 5px 0 0; color: var(--muted); }
.dialog-controls { display: flex; align-items: center; gap: 15px; }
.dialog-controls label { color: var(--muted); font-size: .78rem; font-weight: 700; }
.dialog-controls input { width: 54px; margin-left: 5px; padding: 7px; border: 1px solid var(--line); border-radius: 8px; }
.dialog-close { width: 40px; height: 40px; border: 0; border-radius: 50%; background: #f6e9e1; font-size: 1.5rem; }
.paragraph-slider { display: flex; align-items: center; gap: 15px; padding: 13px 28px; background: #faf5f1; border-bottom: 1px solid var(--line); }
.paragraph-slider input { flex: 1; accent-color: var(--accent); }
.paragraph-slider output { min-width: 42px; padding: 5px 8px; text-align: center; color: white; background: var(--accent); border-radius: 8px; font-weight: 700; }
.context-columns { display: grid; grid-template-columns: 1fr 1fr; min-height: 0; }
.context-columns > section { min-width: 0; overflow: auto; }
.context-columns > section:first-child { border-right: 1px solid var(--line); }
.summary-column { background: #fdf9f6; }
.section-title { position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center; padding: 16px 24px; background: rgba(255,255,255,.94); border-bottom: 1px solid var(--line); backdrop-filter: blur(10px); font-weight: 800; z-index: 2; }
.section-title small { color: var(--muted); font-weight: 500; }
.context-content { padding: 24px; }
.context-paragraph { margin-bottom: 18px; padding: 18px; border: 1px solid var(--line); border-radius: 14px; background: white; font-family: Georgia, serif; line-height: 1.65; }
.context-paragraph.central { border-color: #d59673; background: var(--accent-soft); }
.context-paragraph strong { display: block; margin-bottom: 8px; color: var(--accent); font-family: Inter, sans-serif; font-size: .75rem; text-transform: uppercase; }
.summary-text { font-family: Georgia, serif; font-size: 1.15rem; line-height: 1.8; }

.loading-overlay { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; align-content: center; color: white; background: rgba(53,27,20,.58); backdrop-filter: blur(5px); }
.loader { width: 44px; height: 44px; border: 4px solid rgba(255,255,255,.3); border-top-color: white; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 110; max-width: 430px; padding: 13px 17px; color: white; background: #523126; border-radius: 12px; box-shadow: var(--shadow); opacity: 0; transform: translateY(15px); pointer-events: none; transition: .2s; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #8d3831; }
.audio-dock { position: fixed; left: 24px; bottom: 24px; z-index: 105; display: flex; align-items: center; gap: 14px; width: min(620px, calc(100vw - 48px)); padding: 12px 14px 12px 18px; background: rgba(255, 250, 246, .96); border: 1px solid #e2c5b4; border-radius: 17px; box-shadow: 0 20px 60px rgba(68, 32, 22, .22); backdrop-filter: blur(16px); }
.audio-dock[hidden] { display: none; }
.audio-dock > div { min-width: 105px; }
.audio-dock strong, .audio-dock small { display: block; }
.audio-dock strong { font-size: .8rem; }
.audio-dock small { margin-top: 3px; color: var(--muted); font-size: .7rem; }
.audio-dock audio { flex: 1; min-width: 180px; height: 38px; }
.audio-dock button { width: 34px; height: 34px; flex: 0 0 auto; border: 0; border-radius: 50%; background: #f4e4da; color: var(--ink); font-size: 1.2rem; }

@media (max-width: 900px) {
    .workspace { grid-template-columns: 1fr; }
    .result-panel { border-right: 0; }
    .result-list, .book-list { max-height: 480px; }
    .filter-bar { grid-template-columns: 1fr 1fr; }
    .context-columns { grid-template-columns: 1fr; overflow: auto; }
    .context-columns > section { overflow: visible; }
    .context-columns > section:first-child { border-right: 0; border-bottom: 1px solid var(--line); }
    .dialog-controls { flex-wrap: wrap; justify-content: end; }
}
@media (max-width: 640px) {
    .topbar { height: auto; padding: 12px 16px; flex-wrap: wrap; }
    .brand small, .library-stats i { display: none; }
    .library-stats { order: 3; width: 100%; justify-content: center; }
    .main-nav { padding: 8px 12px 0; }
    .nav-tab { flex: 1; padding: 10px 5px; font-size: .8rem; }
    .search-hero, .catalog-header { padding: 28px 18px; }
    .search-input-wrap { align-items: stretch; flex-wrap: wrap; }
    .search-input-wrap textarea { width: calc(100% - 40px); }
    .search-submit { width: 100%; }
    .search-options { align-items: stretch; flex-direction: column; gap: 10px; }
    .segmented { justify-content: center; }
    .filter-bar { grid-template-columns: 1fr; padding: 14px 18px; }
    .detail-panel { padding: 24px 18px; }
    .info-grid { grid-template-columns: 1fr; }
    .dialog-header { padding: 18px; flex-direction: column; }
    .dialog-controls { justify-content: space-between; }
    .context-dialog { width: 100vw; height: 100vh; max-width: none; max-height: none; border-radius: 0; }
    .audio-dock { left: 12px; bottom: 12px; width: calc(100vw - 24px); flex-wrap: wrap; }
    .audio-dock > div { flex: 1; }
    .audio-dock audio { order: 3; width: 100%; flex-basis: 100%; }
}
