:root {
  --bg: #f6f3ee; --surface: #ffffff; --ink: #1f1d1a; --muted: #6b665e; --line: #e4ddd2;
  --accent: #c2410c; --accent-soft: rgba(194,65,12,.14); --sent-soft: rgba(37,99,235,.12);
  --shadow: 0 8px 30px rgba(0,0,0,.12);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg:#16151a; --surface:#222128; --ink:#ece9e4; --muted:#a19c94; --line:#34323b; --accent:#fb923c; --accent-soft:rgba(251,146,60,.2); --sent-soft:rgba(96,165,250,.18); }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.topbar { display:flex; align-items:center; gap:8px; padding:10px 16px; border-bottom:1px solid var(--line); background:var(--surface); position:sticky; top:0; z-index:5; }
.brand { font-weight:700; color:var(--ink); text-decoration:none; letter-spacing:.2px; }
.spacer { flex:1; }
.iconbtn { border:1px solid var(--line); background:var(--surface); border-radius:10px; min-width:36px; height:36px; padding:0 10px; display:inline-flex; align-items:center; justify-content:center; cursor:pointer; text-decoration:none; color:var(--ink); font-size:18px; }
.iconbtn:hover { border-color: var(--accent); }
.iconbtn:disabled { opacity:.4; cursor:default; }

.library { max-width: 960px; margin: 0 auto; padding: 24px 16px 60px; }
.library h1 { font-size: 24px; margin: 8px 0 4px; }
.hint { color: var(--muted); margin: 0 0 24px; }
.grid { display:grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 20px; }
.card { background:var(--surface); border:1px solid var(--line); border-radius:14px; overflow:hidden; text-decoration:none; color:var(--ink); display:flex; flex-direction:column; transition: transform .15s, box-shadow .15s; }
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.card .cover { aspect-ratio: 3/4; background:#ddd center/cover no-repeat; }
.card .meta { padding: 10px 12px 12px; }
.card .t { font-weight:600; font-size:15px; }
.card .s { color:var(--muted); font-size:13px; margin-top:2px; }
.card .resume { color:var(--accent); font-size:12px; margin-top:6px; }

.readerbar { display:flex; align-items:center; gap:8px; padding:8px 16px; background:var(--surface); border-bottom:1px solid var(--line); position:sticky; top:57px; z-index:4; }
.booktitle { font-weight:600; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; min-width:0; }
.pagejump { display:inline-flex; align-items:center; gap:4px; color:var(--muted); font-size:14px; }
.pagejump input { width: 56px; height:32px; border:1px solid var(--line); border-radius:8px; text-align:center; background:var(--bg); color:var(--ink); font:inherit; }
.status { text-align:center; font-size:13px; color:var(--muted); min-height: 20px; padding: 6px 16px 0; }
.stage { padding: 8px 16px 220px; display:flex; justify-content:center; }
.page { position:relative; width: 100%; max-width: 900px; box-shadow: var(--shadow); background:#fff; border-radius:4px; overflow:hidden; }
.page img { display:block; width:100%; height:auto; user-select:none; -webkit-user-drag:none; }
.overlay { position:absolute; inset:0; }
.w { position:absolute; border-radius:3px; cursor:pointer; }
.w:hover, .overlay.boxes .w { background: var(--accent-soft); outline: 1px solid rgba(194,65,12,.35); }
.w.sent { background: var(--sent-soft); }
.w.active { background: rgba(194,65,12,.32); outline: 2px solid var(--accent); }

.drawer { position:fixed; left:50%; transform:translateX(-50%); bottom:16px; width:min(720px, calc(100% - 32px)); max-height: 45vh; overflow:auto; background:var(--surface); border:1px solid var(--line); border-radius:16px; box-shadow: var(--shadow); padding: 14px 18px 16px; z-index: 10; }
.drawer .close { position:absolute; top:8px; right:10px; border:0; background:none; font-size:24px; cursor:pointer; color:var(--muted); }
.entry + .entry { border-top:1px solid var(--line); margin-top:12px; padding-top:12px; }
.label { font-size:11px; text-transform:uppercase; letter-spacing:.08em; color:var(--muted); margin-bottom:4px; }
.row { display:flex; align-items:flex-start; gap:10px; padding-right: 28px; }
.ko { font-size: 22px; font-weight:600; line-height:1.35; }
.ko.sentence { font-size: 17px; font-weight:500; flex:1; outline:none; border-radius:6px; }
.ko.sentence:focus { box-shadow: 0 0 0 2px var(--accent-soft); }
.speak { flex:none; border:1px solid var(--line); background:var(--bg); border-radius:999px; width:38px; height:38px; cursor:pointer; font-size:17px; }
.speak:hover { border-color: var(--accent); }
.speak.playing { background: var(--accent-soft); border-color: var(--accent); }
.ko[contenteditable="true"] { outline:none; border-radius:6px; }
.ko[contenteditable="true"]:focus { box-shadow: 0 0 0 2px var(--accent-soft); }
.fixbar { display:flex; align-items:center; gap:8px; flex-wrap:wrap; margin-top:8px; }
.chip { border:1px solid var(--line); background:var(--bg); border-radius:999px; padding:4px 12px; font-size:13px; cursor:pointer; }
.chip:hover:not(:disabled) { border-color: var(--accent); }
.chip:disabled { opacity:.4; cursor:default; }
.fixhint { font-size:12px; color:var(--muted); }
.en { margin-top:6px; font-size:16px; color:var(--ink); line-height:1.4; }
.en.loading { color: var(--muted); font-style: italic; }
.links { margin-top:6px; display:flex; gap:12px; flex-wrap:wrap; font-size:13px; }
.links a { color: var(--accent); }

dialog { border:1px solid var(--line); border-radius:16px; background:var(--surface); color:var(--ink); width:min(420px, calc(100% - 32px)); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog h2 { margin: 0 0 12px; font-size: 18px; }
dialog label { display:flex; align-items:center; gap:8px; margin: 10px 0; }
dialog select { flex:1; min-width:0; }
dialog .small { color: var(--muted); font-size: 13px; }
dialog menu { display:flex; justify-content:flex-end; padding:0; margin:12px 0 0; }
dialog menu button, .ghost { border:1px solid var(--line); background:var(--bg); border-radius:10px; padding:8px 14px; cursor:pointer; }

@media (max-width: 600px) {
  .readerbar { padding: 8px 10px; gap:6px; }
  .booktitle { display:none; }
  .stage { padding: 8px 0 240px; }
  .page { border-radius:0; }
  .drawer { bottom: 0; width: 100%; border-radius: 16px 16px 0 0; }
}
