:root{
  --bg: #FBF0D9;
  --text: #5F4B32;
  --paper-edge: #E8D9B5;
  --accent: #A8461F;
  --accent-soft: #D9A876;
  --ui-bg: #F4E7C9;
  --ui-border: #D9C79C;
  --font-ui: 'Be Vietnam Pro', system-ui, sans-serif;
  --font-body: 'Lora', Georgia, serif;
}
:root.dark{
  --bg: #1E1E1E;
  --text: #D4D4D4;
  --paper-edge: #171717;
  --accent: #E0894A;
  --accent-soft: #6B4A2E;
  --ui-bg: #262624;
  --ui-border: #3A3A38;
}

*{ box-sizing: border-box; }
html,body{ margin:0; height:100%; }
body{
  font-family: var(--font-ui);
  background: var(--paper-edge);
  color: var(--text);
  display:flex; flex-direction:column; height:100vh;
  transition: background .25s ease, color .25s ease;
}

/* ── Toolbar ── */
.toolbar{
  display:flex; align-items:center; gap:14px;
  padding:10px 16px;
  background: var(--ui-bg);
  border-bottom:1px solid var(--ui-border);
  flex-wrap:wrap;
}
.toolbar-brand{ display:flex; align-items:center; gap:10px; margin-right:6px; }
.brand-mark{
  font-size:22px; color:var(--accent); font-family: var(--font-body);
  border:1px solid var(--accent-soft); border-radius:6px;
  width:32px; height:32px; display:flex; align-items:center; justify-content:center;
}
.brand-text strong{ display:block; font-size:13.5px; letter-spacing:.2px; }
.brand-text small{ display:block; font-size:11px; opacity:.65; }

.toolbar-group{ display:flex; align-items:center; gap:6px; }
.toolbar-group.grow{ flex:1; min-width:220px; }

.tbtn{
  font-family: var(--font-ui);
  border:1px solid var(--ui-border);
  background: var(--bg);
  color: var(--text);
  padding:6px 10px;
  border-radius:7px;
  font-size:13px;
  cursor:pointer;
  white-space:nowrap;
  transition: filter .15s ease, transform .05s ease;
}
.tbtn:hover{ filter:brightness(0.95); }
.tbtn:active{ transform: translateY(1px); }
.tbtn.icon{ width:34px; padding:6px 0; text-align:center; font-weight:600; }
.tbtn.ai{ border-color: var(--accent-soft); color: var(--accent); font-weight:600; }

#search-input{
  font-family: var(--font-ui);
  flex:1; min-width:120px;
  padding:6px 10px;
  border:1px solid var(--ui-border);
  border-radius:7px;
  background: var(--bg);
  color: var(--text);
  font-size:13px;
}
#search-input:focus{ outline:2px solid var(--accent-soft); outline-offset:1px; }

/* ── Reader ── */
#reader-wrap{
  flex:1; overflow-y:auto;
  background: var(--paper-edge);
  display:flex; justify-content:center;
  padding: 32px 16px 80px;
}
.paper{
  max-width: 760px; width:100%;
  background: var(--bg);
  color: var(--text);
  padding: 40px 48px;
  border-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,.15), 0 12px 32px rgba(0,0,0,.12);
  font-family: var(--font-body);
  font-size: 18px;
  line-height: 1.85;
  white-space: pre-wrap;
  min-height: 60vh;
}
.paper .cadao-block{
  margin-bottom: 22px;
  padding-bottom: 20px;
  border-bottom: 1px dashed var(--paper-edge);
}
.paper .cadao-block:last-child{ border-bottom:none; }
.paper mark{
  background: #FFE066;
  color: #2A1F0F;
  padding: 0 2px;
  border-radius:2px;
}
:root.dark .paper mark{ background:#7A5B1E; color:#FFE9C2; }
.paper mark.current{ background: var(--accent); color:#fff; box-shadow:0 0 0 2px var(--accent); }
.paper .empty-hint{
  font-family: var(--font-ui);
  font-size: 14.5px;
  opacity:.75;
}
.paper .empty-hint h2{ font-family: var(--font-body); font-size:22px; }
.paper .empty-hint ul{ padding-left:20px; }

/* ── Modals ── */
.modal-overlay{
  position:fixed; inset:0; background: rgba(20,15,8,.45);
  display:flex; align-items:center; justify-content:center;
  z-index: 50;
}
.modal-overlay.hidden{ display:none; }
.modal{
  background: var(--bg); color: var(--text);
  border-radius: 10px; padding: 24px 26px;
  width: 420px; max-width: 92vw;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
  font-family: var(--font-ui);
}
.modal.wide{ width: 640px; max-height: 80vh; display:flex; flex-direction:column; }
.modal h3{ margin:0 0 10px; font-family: var(--font-body); font-size:19px; }
.modal .muted{ opacity:.75; font-size:13.5px; }
.modal .hint{ font-size:12px; opacity:.6; margin: 10px 0 16px; }
.modal .row{ display:flex; gap:14px; align-items:center; margin:10px 0; flex-wrap:wrap; }
.modal .row.right{ justify-content:flex-end; }
.modal label{ font-size:13px; display:flex; align-items:center; gap:6px; }
.modal input[type=number]{
  width:70px; padding:5px 7px; border-radius:6px; border:1px solid var(--ui-border);
  background: var(--ui-bg); color: var(--text);
}

.progress-bar{
  height:8px; border-radius:5px; background: var(--ui-bg);
  overflow:hidden; margin:10px 0;
}
#progress-fill{ height:100%; width:0%; background: var(--accent); transition: width .2s ease; }

.results{ overflow-y:auto; margin-top:8px; padding-right:4px; }
.result-item{
  margin-bottom:14px; padding:12px 14px;
  border-left: 4px solid var(--accent-soft);
  background: var(--ui-bg);
  border-radius: 0 6px 6px 0;
  font-family: var(--font-body);
  white-space: pre-wrap;
}
.result-item .meta{
  font-family: var(--font-ui); font-size:11px; opacity:.7; margin-bottom:4px;
}
.result-item .badge{
  display:inline-block; font-family: var(--font-ui); font-size:10.5px;
  padding:1px 7px; border-radius:9px; color:#fff; margin-right:6px;
  background: var(--accent);
}
.result-item .text{ font-style: italic; font-size:15px; }
.results .empty{ opacity:.7; font-style:italic; padding:20px 4px; }

.hidden{ display:none !important; }

.toast{
  position:fixed; bottom:22px; left:50%; transform:translateX(-50%);
  background:#2A1F0F; color:#F4E7C9; padding:10px 18px; border-radius:8px;
  font-family: var(--font-ui); font-size:13.5px; z-index:100;
  box-shadow: 0 8px 24px rgba(0,0,0,.3);
}

@media (max-width: 720px){
  .paper{ padding: 26px 20px; font-size:16.5px; }
  .toolbar{ gap:8px; }
  .toolbar-group.grow{ order:5; width:100%; }
}
