:root {
  --bg: #f4f4f2;
  --panel: #ffffff;
  --ink: #1d1f23;
  --ink-2: #4a4f57;
  --muted: #8b9098;
  --faint: #a4a9b0;
  --line: #e4e4e0;
  --accent: #3b5bdb;
  --accent-soft: #edf2ff;
  --viewer-bg: #5f6368;
  --hover: rgba(59, 91, 219, .22);
  --linked: #e7ecff;
  font-family: "Pretendard Variable", Pretendard, "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
button, select, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }

/* ---------------- library ---------------- */
#library { min-height: 100%; display: flex; justify-content: center; padding: 64px 16px; }
.lib-inner { width: 100%; max-width: 760px; }
#library h1 { font-size: 32px; margin: 0 0 6px; letter-spacing: -.02em; }
.logo { color: var(--accent); }
.lib-sub { color: var(--ink-2); margin: 0 0 28px; }
.drop {
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
  border: 2px dashed #c9ccd2; border-radius: 14px; padding: 44px 20px; background: var(--panel);
  cursor: pointer; transition: .15s;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop-icon { font-size: 28px; color: var(--accent); }
.drop.busy { pointer-events: none; opacity: .6; }
.lib-h { font-size: 15px; color: var(--muted); font-weight: 600; margin: 36px 0 10px; }
#doclist { list-style: none; padding: 0; margin: 0; }
#doclist li {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; cursor: pointer;
}
#doclist li:hover { border-color: var(--accent); }
#doclist .name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#doclist .del { border: 0; background: none; color: var(--faint); cursor: pointer; font-size: 16px; }
#doclist .del:hover { color: #e03131; }

/* ---------------- top bar ---------------- */
#reader { height: 100%; display: flex; flex-direction: column; }
#topbar {
  display: flex; align-items: center; gap: 10px; padding: 6px 12px; background: var(--panel);
  border-bottom: 1px solid var(--line); flex-wrap: wrap; min-height: 50px;
}
.doc-title { font-weight: 700; flex: 1; min-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.group { display: flex; align-items: center; gap: 4px; }
.sep { width: 1px; height: 20px; background: var(--line); margin: 0 6px; }
.icon-btn, .tool, .text-btn {
  border: 1px solid transparent; background: none; border-radius: 7px; height: 32px; min-width: 32px;
  cursor: pointer; font-size: 15px;
}
.icon-btn:hover, .tool:hover, .text-btn:hover { background: #f0f1f3; }
.text-btn { font-size: 13px; padding: 0 8px; }
.tool.active { background: var(--accent-soft); border-color: #c5d0fa; }
#page-input { width: 38px; text-align: center; border: 1px solid var(--line); border-radius: 6px; height: 28px; }
#swatches { display: flex; gap: 5px; }
.swatch { width: 20px; height: 20px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px #c7c9ce; cursor: pointer; padding: 0; }
.swatch.active { box-shadow: 0 0 0 2px var(--ink); }
select { height: 32px; border: 1px solid var(--line); border-radius: 7px; background: #fff; padding: 0 6px; }
.chk { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--ink-2); cursor: pointer; user-select: none; }
.primary {
  height: 32px; padding: 0 14px; border-radius: 7px; border: 1px solid var(--accent);
  background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; font-size: 13px;
}
.primary:hover { filter: brightness(1.08); }
.primary.ghost { background: #fff; color: var(--accent); }
.primary:disabled { opacity: .5; cursor: default; }
#progress { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-2); }
.bar { width: 110px; height: 6px; background: #e9eaee; border-radius: 3px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .4s; }
.bar.indet i { width: 35%; animation: indet 1.2s infinite ease-in-out; }
@keyframes indet { from { margin-left: -35%; } to { margin-left: 100%; } }

/* ---------------- split ---------------- */
#split { flex: 1; display: flex; min-height: 0; }
#viewer { width: 52%; overflow: auto; background: var(--viewer-bg); position: relative; }
#pages { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 16px 20px 40px; width: max-content; min-width: 100%; }
#divider { width: 6px; cursor: col-resize; background: var(--line); flex: none; }
#divider:hover, #divider.drag { background: var(--accent); }
#side { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--panel); }

/* ---------------- pages ---------------- */
.page { position: relative; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.35); flex: none; user-select: none; }
.page img { position: absolute; inset: 0; width: 100%; height: 100%; }
.page .layer { position: absolute; inset: 0; pointer-events: none; }
.page.tool-mark, .page.tool-erase { cursor: text; }
.page.tool-erase { cursor: cell; }
.hl { position: absolute; mix-blend-mode: multiply; border-radius: 1px; }
.hv { position: absolute; background: var(--hover); border-radius: 2px; outline: 1px solid rgba(59,91,219,.45); }
.hv.soft { background: rgba(59, 91, 219, .10); outline: none; }
.sel { position: absolute; background: rgba(59, 91, 219, .28); }
.hv.flash { animation: flash 1.2s ease-out; }
@keyframes flash { 0%, 40% { background: rgba(255, 170, 0, .55); } 100% { background: var(--hover); } }
.pno { position: absolute; bottom: -18px; right: 0; font-size: 11px; color: #d6d8db; }

/* ---------------- side ---------------- */
#tabs { display: flex; align-items: center; gap: 2px; padding: 0 12px; border-bottom: 1px solid var(--line); flex: none; }
#tabs > button {
  border: 0; background: none; padding: 12px 12px 10px; font-weight: 600; color: var(--muted);
  border-bottom: 2px solid transparent; cursor: pointer; font-size: 14px;
}
#tabs > button.active { color: var(--ink); border-bottom-color: var(--ink); }
.tab-opts { margin-left: auto; display: flex; gap: 12px; }
.pane { flex: 1; overflow: auto; padding: 22px 28px 120px; }

.empty { color: var(--muted); text-align: center; margin-top: 80px; line-height: 1.7; }

/* ---------------- overview ---------------- */
.ov { max-width: 780px; margin: 0 auto; }
.ov-title { font-size: 22px; font-weight: 800; line-height: 1.35; margin: 0; letter-spacing: -.015em; }
.ov-title-en { color: var(--muted); margin: 4px 0 8px; font-size: 14px; }
.ov-meta { font-size: 13px; color: var(--ink-2); }
.tldr { margin: 20px 0; background: var(--accent-soft); border-left: 4px solid var(--accent); padding: 14px 16px; border-radius: 0 10px 10px 0; line-height: 1.75; }
.tldr b { display: block; font-size: 12px; color: var(--accent); margin-bottom: 4px; letter-spacing: .04em; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12px; background: #f1f3f5; border-radius: 999px; padding: 3px 10px; color: var(--ink-2); }
.ov h3 { font-size: 15px; margin: 30px 0 10px; display: flex; gap: 8px; align-items: center; }
.ov h3 .n { font-size: 11px; background: var(--ink); color: #fff; border-radius: 5px; padding: 1px 6px; }
.ov p, .ov li { line-height: 1.75; font-size: 14.5px; }
.ov ul { padding-left: 20px; margin: 6px 0; }
.comp { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin: 8px 0; }
.comp b { display: block; margin-bottom: 2px; }
.comp span { font-size: 14px; color: var(--ink-2); line-height: 1.65; }
.kv { display: grid; grid-template-columns: 90px 1fr; gap: 8px 12px; align-items: start; font-size: 14px; }
.kv > div:nth-child(odd) { color: var(--muted); font-size: 13px; padding-top: 3px; }
.secmap { list-style: none; padding: 0 !important; }
.secmap li { padding: 9px 12px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
.secmap li:hover { background: #f8f9fa; border-color: var(--line); }
.secmap .st { font-weight: 700; font-size: 14px; }
.secmap .st small { color: var(--muted); font-weight: 400; margin-left: 6px; }
.secmap .ss { font-size: 13.5px; color: var(--ink-2); line-height: 1.6; }
table.gloss { border-collapse: collapse; width: 100%; font-size: 13.5px; }
table.gloss td { border-bottom: 1px solid var(--line); padding: 6px 8px; }
table.gloss td:first-child { color: var(--ink-2); width: 50%; }

/* ---------------- translation ---------------- */
#trans { font-size: 15.5px; }
.tr { max-width: 780px; margin: 0 auto; }
.pg-sep { font-size: 11px; color: var(--faint); text-align: center; margin: 26px 0 12px; letter-spacing: .1em; display: flex; align-items: center; gap: 10px; }
.pg-sep::before, .pg-sep::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.blk { margin: 0 0 18px; padding: 2px 8px; border-radius: 8px; border-left: 3px solid transparent; }
.blk.focus { border-left-color: var(--accent); background: #fafbff; }
.blk p { margin: 0; line-height: 1.85; word-break: keep-all; overflow-wrap: anywhere; }
.blk h2 { font-size: 18px; margin: 26px 0 2px; }
.blk.meta p { font-size: 13px; color: var(--muted); line-height: 1.6; }
.blk.caption p { font-size: 14px; color: var(--ink-2); }
.blk.list p { padding-left: 4px; }
.blk.frag p, .blk.pending p { color: var(--faint); font-size: 13px; font-style: italic; line-height: 1.6; }
.blk.pending p::before { content: "번역 대기 · "; font-style: normal; color: var(--muted); }
.sum { margin-top: 6px; color: #9aa0a8; font-size: 13.5px; line-height: 1.6; }
.sum::before { content: "해설 "; font-size: 11px; font-weight: 700; color: #b6bac0; margin-right: 2px; }
.orig { margin-top: 6px; color: #9aa0a8; font-size: 13px; line-height: 1.55; font-family: Georgia, "Times New Roman", serif; }
.h-orig { color: var(--faint); font-size: 12px; font-weight: 400; }
.s { border-radius: 3px; transition: background .1s; }
.s:hover, .s.linked { background: var(--linked); }
.s.m { box-decoration-break: clone; -webkit-box-decoration-break: clone; }
#trans.tool-erase .s.m, #trans.tool-erase .s.u { cursor: cell; }
.refs { color: var(--muted); font-size: 13px; border: 1px dashed var(--line); border-radius: 8px; padding: 10px 14px; margin: 18px 0; }

#toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: #25272b; color: #fff; padding: 9px 16px; border-radius: 8px; font-size: 13px; transition: .25s; pointer-events: none;
  max-width: 80vw;
}
#toast.show { opacity: 1; transform: translateX(-50%); }

/* ---------------- figure / equation cards ---------------- */
.vcard { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin: 22px 0; background: #fff; }
.vcard:hover { border-color: #c5d0fa; }
.vimg { text-align: center; background: #fff; }
.vimg img { max-width: 100%; max-height: 520px; border-radius: 4px; cursor: zoom-in; }
.vimg.big img { max-height: none; cursor: zoom-out; }
.vimg.eq img { max-height: 160px; cursor: default; }
.vlabel { display: inline-block; margin: 12px 0 4px; font-size: 11px; font-weight: 700; letter-spacing: .04em; color: var(--accent); background: var(--accent-soft); border-radius: 5px; padding: 2px 7px; }
.vcap { margin: 0; font-size: 14.5px; line-height: 1.75; color: var(--ink-2); word-break: keep-all; }
.vex { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); color: #8a9099; font-size: 13.5px; line-height: 1.7; }
.vex > b { display: block; font-size: 11px; color: #b0b5bc; margin-bottom: 3px; letter-spacing: .03em; }
.vex ul { margin: 6px 0 0; padding-left: 18px; }
.vex.wait { font-style: italic; color: var(--faint); }
.vmath { overflow-x: auto; overflow-y: hidden; padding: 4px 0; font-size: 1.05em; }
.vorig { margin-top: 6px; font-size: 12px; color: var(--faint); }
.vorig summary { cursor: pointer; }
.vorig img { display: block; max-width: 100%; margin-top: 6px; border: 1px solid var(--line); }
.syms { display: grid; grid-template-columns: max-content 1fr; gap: 3px 14px; margin: 8px 0 0; align-items: baseline; }
.syms dt { color: var(--ink-2); }
.syms dd { margin: 0; }
.s .katex { font-size: 1.02em; }
.hv.region { outline: 2px solid rgba(59, 91, 219, .55); background: rgba(59, 91, 219, .06); }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.gcard { border: 1px solid var(--line); border-radius: 10px; padding: 8px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; }
.gcard:hover { border-color: var(--accent); }
.gcard img { width: 100%; height: 110px; object-fit: contain; background: #fafafa; border-radius: 6px; }
.gcard b { font-size: 12px; color: var(--accent); }
.gcard span { font-size: 12px; color: var(--ink-2); line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
/* keep \tag{n} after the formula instead of overlapping it when the formula is wider than the pane */
.vmath .katex-display > .katex > .katex-html > .tag { position: relative !important; right: auto !important; margin-left: 1.2em; }
.vmath .katex-display > .katex > .katex-html { white-space: nowrap; }
.vcard.bare { border: 0; padding: 0; margin: 6px 0; text-align: left; } .vcard.bare .vimg { text-align: left; } .vcard.bare img { max-height: 40px; }
.s.wait { color: var(--faint); font-style: italic; }
.lim { display: inline-block; width: 1.1em; color: var(--muted); }
.vex.eqx { padding-top: 6px; }
.vex.eqx > summary { cursor: pointer; font-size: 12px; font-weight: 600; color: #a0a5ad; list-style: none; user-select: none; }
.vex.eqx > summary::-webkit-details-marker { display: none; }
.vex.eqx > summary::before { content: "▸ "; }
.vex.eqx[open] > summary::before { content: "▾ "; }
.vex.eqx[open] > summary { margin-bottom: 6px; }

/* ---------------- export menu ---------------- */
.export-wrap { position: relative; }
#export-menu {
  position: absolute; right: 0; top: 38px; z-index: 20; width: 250px; background: #fff; border: 1px solid var(--line);
  border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: 6px; display: flex; flex-direction: column;
}
#export-menu[hidden] { display: none; }
#export-menu button { border: 0; background: none; text-align: left; padding: 8px 10px; border-radius: 7px; cursor: pointer; display: flex; flex-direction: column; gap: 1px; }
#export-menu button:hover { background: var(--accent-soft); }
#export-menu b { font-size: 13.5px; }
#export-menu small { font-size: 11.5px; color: var(--muted); }

/* ---------------- print layout (used for 개요 / 번역·해설 PDF export) ---------------- */
body.printing, body.printing #reader, body.printing #split, body.printing #side { display: block; height: auto; background: #fff; }
body.printing #topbar, body.printing #viewer, body.printing #divider, body.printing #tabs, body.printing #toast { display: none !important; }
body.printing .pane { overflow: visible; padding: 0; }
body.printing.print-all #trans { break-before: page; }
body.printing .ov, body.printing .tr { max-width: none; }
body.printing .vcard, body.printing .comp, body.printing .gcard, body.printing .secmap li, body.printing .tldr, body.printing h3 { break-inside: avoid; }
body.printing h2, body.printing h3 { break-after: avoid; }
body.printing .vimg img { max-height: 420px; }
body.printing .vmath { overflow: visible; }
body.printing .s.linked, body.printing .blk.focus { background: none; }
.print-title { font-size: 22px; font-weight: 800; margin: 0; line-height: 1.35; }
.print-sub { color: var(--muted); font-size: 13px; margin: 4px 0 18px; }
/* KaTeX's hidden MathML still widens the printable area, which makes the browser shrink every page */
body.printing .katex-mathml { display: none; }
body.printing .vmath { overflow: hidden; }

/* ---------------- AI chat ---------------- */
.ai-btn {
  height: 30px; padding: 0 10px; margin-left: 4px; border-radius: 7px; cursor: pointer; font-size: 13px; font-weight: 700;
  border: 1px solid #c5d0fa; background: linear-gradient(135deg, #edf2ff, #f3e8ff); color: #4c3fb3;
}
.ai-btn:hover { filter: brightness(.97); border-color: var(--accent); }
#ask-chip {
  position: fixed; z-index: 40; border: 0; border-radius: 999px; padding: 6px 12px; font-size: 12.5px; font-weight: 700;
  background: #4c3fb3; color: #fff; box-shadow: 0 4px 14px rgba(76,63,179,.35); cursor: pointer;
}
#ask-chip:hover { filter: brightness(1.1); }
#chat {
  position: fixed; top: 58px; right: 16px; z-index: 30; width: 430px; height: min(640px, calc(100vh - 80px));
  display: flex; flex-direction: column; background: #fff; border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0,0,0,.18); overflow: hidden; resize: both; min-width: 320px; min-height: 320px;
}
#chat[hidden] { display: none; }
#chat-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: move; user-select: none; background: #fafaff; }
#chat-head b { font-size: 14px; }
#chat-head small { color: var(--muted); font-size: 11.5px; flex: 1; }
#chat-head select { font-size: 11.5px; padding: 2px 4px; border: 1px solid var(--line); border-radius: 6px; background: #fff; max-width: 170px; }
#chat-head button { border: 0; background: none; cursor: pointer; color: var(--ink-2); font-size: 12.5px; padding: 4px 6px; border-radius: 6px; }
#chat-head button:hover { background: #eef0f4; }
#chat-log { flex: 1; overflow: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.chat-empty { color: var(--muted); font-size: 13px; line-height: 1.7; text-align: center; margin: auto 10px; }
.cm { max-width: 92%; }
.cm.user { align-self: flex-end; }
.cm.ai { align-self: flex-start; }
.cm .cb { padding: 9px 12px; border-radius: 12px; font-size: 14px; line-height: 1.7; word-break: keep-all; overflow-wrap: anywhere; }
.cm.user .cb { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.cm.ai .cb { background: #f4f5f7; border-bottom-left-radius: 4px; }
.cm.ai .cb p { margin: 0 0 6px; } .cm.ai .cb p:last-child { margin-bottom: 0; }
.cm.ai .cb ul, .cm.ai .cb ol { margin: 4px 0 6px; padding-left: 18px; }
.cm.ai .cb .ch { font-weight: 700; margin-top: 6px; }
.cm.ai .cb code { background: #e6e8ec; border-radius: 4px; padding: 0 4px; font-size: 12.5px; }
.cmath { overflow-x: auto; margin: 4px 0; }
.cq { font-size: 11.5px; color: var(--muted); margin: 0 4px 4px; text-align: right; }
.cerr { color: #e03131; font-size: 12px; margin-top: 4px; }
.typing { color: var(--muted); font-style: italic; }
#chat-ctx { margin: 0 12px; padding: 8px 10px; border-left: 3px solid #7c6ff0; background: #f5f3ff; border-radius: 0 8px 8px 0; font-size: 12.5px; }
#chat-ctx[hidden] { display: none; }
.ctx-h { display: flex; justify-content: space-between; color: #4c3fb3; font-weight: 700; font-size: 11.5px; margin-bottom: 3px; }
.ctx-h button { border: 0; background: none; cursor: pointer; color: var(--muted); }
.ctx-t { color: var(--ink-2); max-height: 64px; overflow: auto; line-height: 1.5; }
#chat-form { display: flex; gap: 8px; padding: 10px 12px 12px; }
#chat-input { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; font-size: 13.5px; line-height: 1.5; }
#chat-input:focus { outline: 2px solid #c5d0fa; border-color: var(--accent); }
#chat-send { border: 0; border-radius: 9px; padding: 0 14px; background: #4c3fb3; color: #fff; font-weight: 700; cursor: pointer; }
body.printing #chat, body.printing #ask-chip { display: none !important; }
#chat-input, #chat-send { font: inherit; } #chat-input { font-size: 13.5px; }

/* ---------------- Drag AI toggle / right-side AI button ---------------- */
.dragai {
  height: 30px; padding: 0 8px 0 10px; margin-left: 4px; border-radius: 7px; cursor: pointer; font-size: 12.5px; font-weight: 700;
  border: 1px solid var(--line); background: #fff; color: var(--muted); display: inline-flex; align-items: center; gap: 6px;
}
.dragai .sw { width: 26px; height: 15px; border-radius: 999px; background: #d4d6db; position: relative; transition: .15s; }
.dragai .sw::after { content: ""; position: absolute; top: 2px; left: 2px; width: 11px; height: 11px; border-radius: 50%; background: #fff; transition: .15s; }
.dragai.on { color: #4c3fb3; border-color: #c5d0fa; background: linear-gradient(135deg, #edf2ff, #f3e8ff); }
.dragai.on .sw { background: #4c3fb3; }
.dragai.on .sw::after { left: 13px; }
#side { position: relative; }
.ask-fab {
  position: absolute; right: 22px; bottom: 22px; z-index: 5; border: 0; border-radius: 999px; padding: 11px 18px;
  font: inherit; font-size: 14px; font-weight: 700; color: #fff; cursor: pointer;
  background: linear-gradient(135deg, #5b4fd6, #4c3fb3); box-shadow: 0 6px 20px rgba(76,63,179,.35);
}
.ask-fab:hover { filter: brightness(1.08); transform: translateY(-1px); }
body.printing .ask-fab, body.printing #note-editor { display: none !important; }

/* ---------------- notes (주석) ---------------- */
#note-editor {
  position: fixed; z-index: 45; width: 340px; background: #fff; border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 12px 36px rgba(0,0,0,.18); padding: 12px; display: flex; flex-direction: column; gap: 8px;
}
#note-editor[hidden] { display: none; }
.ne-h { font-weight: 700; font-size: 13.5px; }
.ne-h small { color: var(--muted); font-weight: 400; margin-left: 4px; }
.ne-q { font-size: 12.5px; color: var(--ink-2); border-left: 3px solid var(--line); padding-left: 8px; max-height: 60px; overflow: auto; line-height: 1.5; }
#ne-text { font: inherit; font-size: 13.5px; line-height: 1.5; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; resize: vertical; }
#ne-text:focus { outline: 2px solid #c5d0fa; border-color: var(--accent); }
.ne-b { display: flex; gap: 6px; align-items: center; }
.ne-b span { flex: 1; }
.ne-b button { font: inherit; font-size: 12.5px; border: 1px solid var(--line); background: #fff; border-radius: 7px; padding: 5px 12px; cursor: pointer; }
#ne-save { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.ne-danger { color: #e03131; }
.ne-danger[hidden] { display: none; }
.note-pin {
  position: absolute; pointer-events: auto; cursor: pointer; font-size: 13px; line-height: 1; transform: translate(-2px, -60%);
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.35));
}
.note-pin:hover { transform: translate(-2px, -60%) scale(1.25); }
.note-cap {
  margin: 8px 0 2px; padding: 7px 10px 7px 12px; border-left: 4px solid #ffe066; border-radius: 0 8px 8px 0;
  background: #fffbea; font-size: 13.5px; line-height: 1.6; color: var(--ink); cursor: pointer;
}
.note-cap:hover { background: #fff6cc; }
.nc-i { display: block; font-size: 11px; font-weight: 700; color: #b08800; margin-bottom: 2px; }
/* library rows: paper title, with the file name underneath */
#doclist .name { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
#doclist .name b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#doclist .name small { font-weight: 400; font-size: 11.5px; color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* library: Task + keyword boxes on the right of each paper */
.lib-inner { max-width: 1180px; }
#doclist li { gap: 14px; }
#doclist .name { flex: 1 1 auto; }
#doclist .meta { white-space: nowrap; font-size: 13px; }
.tags { display: flex; gap: 6px; flex: 0 1 auto; flex-wrap: wrap; justify-content: flex-end; max-width: 52%; }
.tag {
  font-size: 11.5px; line-height: 1; padding: 6px 9px; border-radius: 7px; white-space: nowrap;
  background: #f4f5f7; border: 1px solid #e4e6ea; color: var(--ink-2);
}
.tag.task { background: #eef1ff; border-color: #c9d3fb; color: #3b4fc4; font-weight: 700; }
.tag.wait { color: var(--faint); font-style: italic; background: #fafafa; }
.tag.none { color: var(--faint); background: transparent; border-style: dashed; }
/* one tidy line of boxes; long keywords shrink with an ellipsis instead of wrapping */
.tags { flex-wrap: nowrap; max-width: 56%; min-width: 0; overflow: hidden; }
.tag { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; max-width: 190px; }
.tag.task { flex-shrink: 0; max-width: 230px; }
#doclist .name { flex: 1 1 200px; }

/* library rows as a fixed-column grid: icon | title | Task | keyword | keyword | pages·date | delete */
#doclist li {
  display: grid; grid-template-columns: 20px minmax(0, 1fr) 230px 165px 165px 118px 22px;
  column-gap: 10px; align-items: center;
}
#doclist .name { flex: none; }
#doclist li .tag { max-width: none; width: 100%; box-sizing: border-box; text-align: center; }
#doclist li .tag.span3 { grid-column: span 3; text-align: center; }
#doclist .meta { text-align: right; }
#doclist li.muted { display: block; }
@media (max-width: 1080px) {
  #doclist li { grid-template-columns: 20px minmax(0, 1fr) 200px 140px 118px 22px; }
  #doclist li .tag.span3 { grid-column: span 2; }
}
@media (max-width: 760px) {
  #doclist li { grid-template-columns: 20px minmax(0, 1fr) 22px; }
  #doclist li .tag, #doclist li .tag-empty, #doclist .meta { display: none; }
}

/* overview: Task badge + keywords */
.ov-kw { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.ov-task {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 700; color: #3b4fc4;
  background: #eef1ff; border: 1px solid #c9d3fb; border-radius: 7px; padding: 4px 10px;
}
.ov-task small { font-size: 10.5px; font-weight: 700; color: #7f8fd8; letter-spacing: .04em; }
.chip.core { background: #f3f0ff; color: #4c3fb3; border: 1px solid #ddd6fe; font-weight: 600; }

/* library: Field | Task | main keyword, each with its own look */
#doclist li { grid-template-columns: 20px minmax(0, 1fr) 104px 230px 175px 118px 22px; }
.tag.field {
  background: var(--fc); border-color: var(--fc); color: #fff; font-weight: 800; letter-spacing: .02em;
  border-radius: 999px; text-transform: none;
}
#doclist li .tag.task { background: #fff; border: 1.5px solid #c9d3fb; color: #3b4fc4; }
#doclist li .tag.kw { background: #f4f5f7; border: 1px solid transparent; color: var(--ink-2); font-style: italic; }
.ov-kw .tag.field { font-size: 12px; padding: 5px 11px; }
@media (max-width: 1080px) {
  #doclist li { grid-template-columns: 20px minmax(0, 1fr) 96px 200px 118px 22px; }
  #doclist li .tag.kw { display: none; }                        /* keep Field + Task */
}

/* library: drop zone + arXiv import side by side */
.add-row { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 14px; align-items: stretch; }
.add-row .drop { padding: 34px 20px; }
.arxiv {
  display: flex; flex-direction: column; justify-content: center; gap: 9px; padding: 20px 20px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
}
.arxiv-h { font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.arxiv-logo { background: #b31b1b; color: #fff; font-weight: 800; font-size: 12px; padding: 3px 7px; border-radius: 5px; letter-spacing: .02em; }
#arxiv-url { font: inherit; font-size: 13.5px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; }
#arxiv-url:focus { outline: 2px solid #c5d0fa; border-color: var(--accent); }
#arxiv-go { font: inherit; font-weight: 700; font-size: 13.5px; padding: 9px; border: 0; border-radius: 8px; background: #b31b1b; color: #fff; cursor: pointer; }
#arxiv-go:hover { filter: brightness(1.1); }
#arxiv-go:disabled { opacity: .6; cursor: default; }
.arxiv-help { font-size: 11.5px; }
@media (max-width: 760px) { .add-row { grid-template-columns: 1fr; } }

/* overview: highlights and notes */
mark.om { color: inherit; border-radius: 3px; padding: 1px 0; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
#overview .note-cap { margin-top: 8px; }
.secmap li .note-cap, .comp .note-cap { cursor: pointer; }
.ou { border-radius: 3px; }

/* ---------------- accounts: login screen, account chip/menu, modal, admin user table ---------------- */
#auth { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card {
  width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 28px 28px 22px; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 2px 14px rgba(0,0,0,.06);
}
.auth-card h1 { margin: 0; font-size: 26px; letter-spacing: -.02em; }
.auth-sub { margin: -8px 0 4px; font-size: 13px; }
#auth-pw-block { display: flex; flex-direction: column; gap: 14px; }
#auth-pw-block[hidden] { display: none; }
.google-btn { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); font-weight: 700; text-decoration: none; }
.google-btn:hover { background: #f6f7f9; }
.google-btn[hidden] { display: none; }
#auth-tabs { display: flex; background: #f0f1f3; border-radius: 9px; padding: 3px; }
#auth-tabs button { flex: 1; border: 0; background: none; padding: 7px; border-radius: 7px; cursor: pointer; font-weight: 600; color: var(--muted); }
#auth-tabs button.active { background: var(--panel); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.auth-card label, .mform label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.auth-card input, .mform input, .mform select {
  font-size: 14px; font-weight: 400; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.auth-card input:focus, .mform input:focus { outline: 2px solid #c5d0fa; border-color: var(--accent); }
.auth-card .primary, .mform .primary { padding: 10px; font-weight: 700; border-radius: 8px; }
#auth-hint { font-size: 12.5px; margin: 0; text-align: center; }
.merr { color: #e03131; font-size: 13px; min-height: 1em; }
.merr .ok { color: #2b8a3e; }
.merr code { background: #f1f3f5; padding: 1px 6px; border-radius: 4px; color: var(--ink); user-select: all; }

.lib-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.user-chip {
  display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--panel);
  border-radius: 999px; padding: 4px 12px 4px 4px; cursor: pointer; font-size: 13px; font-weight: 600; max-width: 220px;
}
.user-chip:hover { border-color: var(--accent); }
.user-chip .avatar {
  width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff; display: inline-flex;
  align-items: center; justify-content: center; font-size: 12.5px; font-weight: 800; flex: none;
}
.user-chip .uname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip.compact { padding: 3px; border-color: transparent; }
.user-chip.compact .uname { display: none; }
#user-menu {
  position: fixed; z-index: 60; min-width: 220px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: 0 8px 28px rgba(0,0,0,.14); padding: 6px; display: flex; flex-direction: column;
}
#user-menu .um-h { padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; display: flex; flex-direction: column; gap: 2px; }
#user-menu .um-h small { color: var(--muted); }
#user-menu button { text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 7px; cursor: pointer; font-size: 13.5px; }
#user-menu button:hover { background: #f0f1f3; }
#user-menu button.danger { color: #e03131; }
.role { align-self: flex-start; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; margin-top: 4px; background: #f1f3f5; color: var(--ink-2); }
.role.admin { background: #fff4e6; color: #d9480f; }

#modal { position: fixed; inset: 0; z-index: 70; background: rgba(20,22,26,.38); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-box { width: 100%; max-width: 380px; max-height: calc(100vh - 32px); overflow: auto; background: var(--panel); border-radius: 12px; box-shadow: 0 16px 48px rgba(0,0,0,.2); }
.modal-box.wide { max-width: 920px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-close { border: 0; background: none; cursor: pointer; font-size: 16px; color: var(--muted); }
.modal-body { padding: 16px 18px 18px; }
.mform { display: flex; flex-direction: column; gap: 12px; }
.mform.inline { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.mform.inline input { flex: 1 1 160px; }
.notice { background: #fff9db; border: 1px solid #ffe066; border-radius: 8px; padding: 8px 12px; font-size: 13px; margin-bottom: 12px; }
table.users { width: 100%; border-collapse: collapse; font-size: 13px; }
table.users th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.users td { padding: 7px 8px; border-bottom: 1px solid #f1f1ee; vertical-align: middle; }
table.users tr.pending td { background: #fffbeb; }
table.users tr.disabled td { color: var(--faint); }
table.users select { font-size: 12.5px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.small { font-size: 12px !important; padding: 4px 9px !important; height: auto !important; }
@media (max-width: 760px) { table.users th:nth-child(5), table.users td:nth-child(5) { display: none; } }

/* library rows: wider meta column for the uploader's name; blank cell where delete is not allowed */
#doclist li { grid-template-columns: 20px minmax(0, 1fr) 104px 230px 175px 170px 22px; }
#doclist .meta { overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 1080px) { #doclist li { grid-template-columns: 20px minmax(0, 1fr) 96px 200px 150px 22px; } }
@media (max-width: 760px) { #doclist li { grid-template-columns: 20px minmax(0, 1fr) 22px; } }
.printing .user-chip { display: none !important; }

/* ---------------- feedback bubble (feedback.js) ---------------- */
#fb-bubble {
  position: fixed; left: 18px; bottom: 18px; z-index: 80; width: 46px; height: 46px; border-radius: 50%;
  border: 0; background: #fab005; color: #fff; font-size: 21px; cursor: grab; touch-action: none;
  box-shadow: 0 4px 14px rgba(0,0,0,.22); transition: transform .12s;
}
#fb-bubble:hover { transform: scale(1.08); }
#fb-bubble.dragging { cursor: grabbing; transform: scale(1.15); opacity: .9; transition: none; }
#fb-outline {
  position: fixed; z-index: 78; pointer-events: none; border: 2px dashed #f08c00; border-radius: 4px;
  background: rgba(250, 176, 5, .08);
}
#fb-pin {
  position: fixed; z-index: 79; width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50%;
  background: #f08c00; border: 2px solid #fff; box-shadow: 0 0 0 4px rgba(240,140,0,.3); pointer-events: none;
}
#fb-box {
  position: fixed; z-index: 81; width: 320px; max-width: calc(100vw - 16px); background: var(--panel);
  border: 1px solid #ffd43b; border-radius: 10px; box-shadow: 0 10px 32px rgba(0,0,0,.18); padding: 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.fb-h { font-weight: 700; font-size: 13.5px; display: flex; flex-direction: column; gap: 2px; }
.fb-h small { font-weight: 400; color: var(--muted); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#fb-text { font: inherit; font-size: 13.5px; resize: vertical; padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; }
#fb-text:focus { outline: 2px solid #ffe8a1; border-color: #fab005; }
.fb-b { display: flex; justify-content: flex-end; gap: 6px; }
.fb-b button { border-radius: 7px; padding: 6px 12px; cursor: pointer; }
.fb-b button:not(.primary) { border: 1px solid var(--line); background: #fff; }
.fb-b .primary { border: 0; }
.printing #fb-bubble, .printing #fb-box { display: none !important; }
.fb-filter { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.fb-filter button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 4px 11px; font-size: 12.5px; cursor: pointer; }
.fb-filter button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.fb-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.fb-list li { border: 1px solid var(--line); border-left: 4px solid #fab005; border-radius: 8px; padding: 10px 12px; }
.fb-list li.done { border-left-color: #40c057; }
.fb-list li.doing { border-left-color: var(--accent); }
.fb-list li.wontfix { border-left-color: var(--faint); opacity: .75; }
.fb-meta { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.fb-meta select { margin-left: auto; font-size: 12.5px; padding: 3px 6px; border: 1px solid var(--line); border-radius: 6px; }
.fb-st { margin-left: auto; font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: #f1f3f5; }
.fb-text { margin: 6px 0; font-size: 14px; line-height: 1.55; }
.fb-where { font-size: 12px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.fb-empty { padding: 20px 0; text-align: center; }
.add-row.single { grid-template-columns: 1fr; }
