[data-theme="default"] {
  --bg: #f6f7f9; --card: #ffffff; --ink: #1c2330; --muted: #6b7480; --line: #e3e7ec;
  --brand: #2f6df0; --brand-d: #1a4fa8; --ok: #1f9d57; --warn: #c0392b;
  --a: #1f9d57; --b: #2f6df0; --c: #8a93a0;
  --hover-bg: #eef2fb; --hover-border: #d6e0f7; --ink-light: #38404d;
  --ok-bg: #e3f6ea; --warn-bg: #fdecea; --brand-bg: #dbe4f7;
  --topbar-bg: #ffffff;
}
[data-theme="warm"] {
  --bg: #f0dfc8; --card: #ffffff; --ink: #2c2018; --muted: #8a705a; --line: #dcc4ac;
  --brand: #bf6b4a; --brand-d: #9a4f30; --ok: #7dab7d; --warn: #c95848;
  --a: #7dab7d; --b: #bf6b4a; --c: #b89c84;
  --hover-bg: #e8d4bc; --hover-border: #d4bca4; --ink-light: #4a3424;
  --ok-bg: #e4f0e4; --warn-bg: #f5e4dc; --brand-bg: #f0dcc8;
  --topbar-bg: #f0dfc8;
}
[data-theme="lavender"] {
  --bg: #e4d6f0; --card: #ffffff; --ink: #241c38; --muted: #7a688a; --line: #ccbcd8;
  --brand: #7a4dba; --brand-d: #5a309a; --ok: #7ab07a; --warn: #c95870;
  --a: #7ab07a; --b: #7a4dba; --c: #ac98b4;
  --hover-bg: #d8c8e8; --hover-border: #c0acd0; --ink-light: #403050;
  --ok-bg: #e4f0e4; --warn-bg: #f5e4e8; --brand-bg: #e0d4f0;
  --topbar-bg: #e4d6f0;
}
[data-theme="blush"] {
  --bg: #f7e0de; --card: #ffffff; --ink: #2c1e22; --muted: #8a6870; --line: #dcbeba;
  --brand: #c96a84; --brand-d: #a84864; --ok: #7db07d; --warn: #c95860;
  --a: #7db07d; --b: #c96a84; --c: #b89ca0;
  --hover-bg: #f0d2d0; --hover-border: #dcb8b4; --ink-light: #4a3038;
  --ok-bg: #e4f0e4; --warn-bg: #f5e4e0; --brand-bg: #f0d8dc;
  --topbar-bg: #f7e0de;
}
[data-theme="green"] {
  --bg: #dce8d8; --card: #ffffff; --ink: #1c281e; --muted: #5a7a5e; --line: #b8ccb4;
  --brand: #4a9a6a; --brand-d: #2e7a4a; --ok: #3d8a5d; --warn: #c95848;
  --a: #4a9a6a; --b: #5a8aaa; --c: #8aaa8a;
  --hover-bg: #c8dcc4; --hover-border: #a8c0a4; --ink-light: #2a4432;
  --ok-bg: #d8ecd8; --warn-bg: #f5e4dc; --brand-bg: #d0e4d0;
  --topbar-bg: #dce8d8;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px; background: var(--topbar-bg);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 18px; color: var(--brand); }
.nav { display: flex; gap: 4px; }
.userbox { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.email { color: var(--muted); font-size: 13px; }
main { max-width: 100%; margin: 0 16px; padding: 16px 0; }

.btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.primary:hover { background: var(--brand-d); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.tab {
  border: none; background: transparent; padding: 8px 12px; cursor: pointer;
  font-size: 14px; color: var(--muted); border-radius: 8px;
}
.tab.active, .tab:hover { background: var(--hover-bg); color: var(--brand); }

.auth-wrap { display: flex; justify-content: center; align-items: flex-start; gap: 28px; margin-top: 48px; flex-wrap: wrap; }
.auth-card { width: 340px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 20px; }
.auth-info { max-width: 380px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 22px 24px; }
.auth-info h1 { margin: 0 0 8px; font-size: 24px; color: var(--brand); }
.auth-info h3 { margin: 16px 0 6px; font-size: 15px; }
.auth-info p { font-size: 13px; line-height: 1.5; color: var(--ink-light); }
.auth-info ol { margin: 6px 0; padding-left: 18px; }
.auth-info li { font-size: 13px; line-height: 1.5; margin-bottom: 4px; }
.demo-box { margin-top: 14px; padding: 10px 12px; background: var(--hover-bg); border: 1px solid var(--hover-border); border-radius: 8px; font-size: 13px; line-height: 1.6; }
.demo-box code { background: #fff; padding: 1px 6px; border-radius: 4px; border: 1px solid var(--line); }
.auth-tabs { display: flex; gap: 4px; margin-bottom: 14px; }
.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.form input, .form select { padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; }
.msg { font-size: 13px; min-height: 16px; }
.msg.err { color: var(--warn); }
.msg.ok { color: var(--ok); }

.search-form { display: flex; flex-direction: column; gap: 12px; }
.search-row { display: flex; gap: 8px; }
.search-row input[type=text] { flex: 1; padding: 12px; font-size: 16px; border: 1px solid var(--line); border-radius: 10px; }
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.filters label { display: flex; flex-direction: row; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); }
.filters input, .filters select { padding: 7px 8px; border: 1px solid var(--line); border-radius: 8px; }
.filters input[type=number] { width: 80px; }
.filters .check { flex-direction: row; align-items: center; gap: 6px; white-space: nowrap; }
.search-controls { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.source-checks { display: flex; flex-wrap: wrap; gap: 8px 14px; }
.source-checks label { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); cursor: move; }
.source-checks label[draggable=true] { padding: 2px 4px; border-radius: 4px; }
.source-checks label[draggable=true]:hover { background: var(--hover-bg); }
.source-checks .tag { font-size: 10px; padding: 1px 5px; }

.status { color: var(--muted); font-size: 13px; margin: 12px 0; }
.results { display: flex; flex-direction: column; gap: 14px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px; position: relative;
}
.card h3 { margin: 0 0 6px; font-size: 16px; line-height: 1.35; }
.meta { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.badge {
  display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px;
  border-radius: 999px; margin-right: 6px; color: #fff; vertical-align: middle;
}
.rank-a { background: var(--a); }
.rank-b { background: var(--b); }
.rank-c { background: var(--c); }
.rank-unknown { background: #444; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip { background: var(--hover-bg); color: var(--brand-d); font-size: 11px; padding: 2px 8px; border-radius: 999px; }
.abstract { font-size: 13px; color: var(--ink-light); margin: 8px 0; }
.abstract.collapsed { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.actions { display: flex; gap: 8px; margin-top: 10px; }
.links a { color: var(--brand); text-decoration: none; font-size: 13px; }
.links a:hover { text-decoration: underline; }
.save-btn { position: absolute; top: 14px; right: 14px; }

.settings-list { display: flex; flex-direction: column; gap: 12px; }
.setting-row {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 14px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.setting-row .info { flex: 1; min-width: 220px; }
.setting-row .name { font-weight: 600; }
.setting-row .desc { font-size: 12px; color: var(--muted); }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 999px; }
.tag.on { background: var(--ok-bg); color: var(--ok); }
.tag.off { background: var(--warn-bg); color: var(--warn); }
.muted { color: var(--muted); font-size: 13px; }
h2 { font-size: 18px; }
.pub-badge {
  display: inline-block; font-size: 10px; font-weight: 600; padding: 1px 5px;
  border-radius: 4px; margin-right: 5px;   background: var(--brand-bg); color: var(--brand);
  vertical-align: middle; text-transform: uppercase;
}

/* ---------- 2-pane layout ---------- */
.panes { display: flex; min-height: 60vh; position: relative; }
.pane-left { flex: 0 0 50%; position: sticky; top: 68px; align-self: start; max-height: calc(100vh - 88px); overflow-y: auto; min-width: 200px; }
.pane-right { flex: 1; position: sticky; top: 68px; align-self: start; max-height: calc(100vh - 88px); overflow-y: auto; min-width: 200px; }
.divider {
  width: 5px; cursor: col-resize; background: transparent;
  flex-shrink: 0; position: relative; z-index: 5;
}
.divider:hover, .divider:active { background: var(--brand); }

.compact-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; cursor: pointer; transition: border-color .15s, background .15s;
}
.compact-card:hover { border-color: var(--brand); }
.compact-card.active { border-color: var(--brand); background: var(--hover-bg); }
.compact-card h4 { margin: 0 0 3px; font-size: 14px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.compact-card .meta { font-size: 12px; margin: 0; }
.compact-card .badge { font-size: 10px; padding: 1px 6px; margin-right: 4px; }

.detail-empty {
  text-align: center; padding: 60px 20px; color: var(--muted); font-size: 14px;
}
.detail-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 20px;
}
.detail-card h2 { margin: 0 0 10px; font-size: 20px; line-height: 1.35; }
.detail-card .meta { font-size: 14px; margin-bottom: 12px; }
.detail-card .abstract { font-size: 14px; line-height: 1.55; margin: 12px 0; }
.detail-card .abstract.collapsed { -webkit-line-clamp: unset; display: block; overflow: visible; }
.detail-card .badge { font-size: 13px; padding: 3px 10px; vertical-align: middle; }
.detail-card .chips { margin: 10px 0; }

/* ---------- source info button ---------- */
.btn-info {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: 50%;
  border: 1px solid var(--muted); background: transparent;
  color: var(--muted); font-size: 10px; font-weight: 700;
  cursor: pointer; padding: 0; line-height: 1;
  font-family: serif; font-style: italic; vertical-align: middle;
}
.btn-info:hover { border-color: var(--brand); color: var(--brand); }

/* ---------- source detail modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.modal-card {
  background: var(--card); border-radius: 12px; padding: 24px;
  max-width: 480px; width: 90%; box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-header h3 { margin: 0; font-size: 18px; }
.modal-close {
  border: none; background: transparent; font-size: 22px; cursor: pointer;
  color: var(--muted); line-height: 1; padding: 0 4px;
}
.modal-close:hover { color: var(--ink); }
.modal-desc { font-size: 14px; color: var(--ink-light); line-height: 1.5; margin: 0 0 14px; }
.modal-tags { display: flex; gap: 8px; margin-bottom: 12px; }
.modal-quotas { font-size: 13px; }
.modal-section { margin-bottom: 14px; }
.modal-section h4 { margin: 0 0 4px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.modal-section p { margin: 0; font-size: 14px; line-height: 1.5; color: var(--ink-light); }
.modal-section a { color: var(--brand); word-break: break-all; }

/* ---------- theme selector ---------- */
.theme-picker { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.theme-opt {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; border: 2px solid var(--line); border-radius: 10px;
  cursor: pointer; font-size: 13px; background: var(--card);
  transition: border-color .15s;
}
.theme-opt:hover { border-color: var(--brand); }
.theme-opt.active { border-color: var(--brand); background: var(--hover-bg); }
.theme-swatch {
  display: inline-block; width: 14px; height: 14px; border-radius: 50%;
  border: 1px solid var(--line); flex-shrink: 0;
}
html { transition: background .2s, color .2s; }
html *, html *:before, html *:after { transition: background-color .2s, border-color .2s, color .2s; }

/* narrow screens: stack */
@media (max-width: 800px) {
  .panes { flex-direction: column; }
  .pane-left, .pane-right { flex: none; position: static; max-height: none; overflow: visible; }
  .pane-left { order: 1; }
  .divider { display: none; }
  .pane-right { order: 2; }
}
