:root {
  --bg: #f6f5f1; --surface: #ffffff; --surface-2: #efede7; --border: #dedad0;
  --ink: #1c1b19; --ink-2: #55524b; --muted: #8a867c;
  --accent: #1f5fa8; --accent-soft: #dce8f6; --on-accent: #fff;
  --keep: #2e7d4f; --skip: #b5473a; --mark: #ffe58a; --mark-ink: #1c1b19;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 6px 20px rgb(0 0 0 / .07);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121315; --surface: #1c1d20; --surface-2: #26272b; --border: #33343a;
    --ink: #ecebe7; --ink-2: #b9b6ae; --muted: #85837c;
    --accent: #7fb0ea; --accent-soft: #1d2c40; --on-accent: #0d1520;
    --keep: #5cc28a; --skip: #e2766a; --mark: #6b5a17; --mark-ink: #fff4c8;
    --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 6px 20px rgb(0 0 0 / .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: grid; grid-template-rows: auto 1fr auto; min-height: 100dvh;
}
a { color: var(--accent); }
code { background: var(--surface-2); padding: 0 .3em; border-radius: 4px; font-size: .9em; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.grow { flex: 1; }
.right { margin-left: auto; }
.ok { color: var(--keep); font-weight: 600; }
mark { background: var(--mark); color: var(--mark-ink); border-radius: 3px; padding: 0 .1em; }

header {
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; letter-spacing: -.02em; color: var(--ink); text-decoration: none; font-size: 1.1rem; }
main { width: 100%; max-width: 760px; margin: 0 auto; padding: 12px 16px 24px; overflow-x: hidden; }

nav {
  display: none; position: sticky; bottom: 0;
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
body.signed-in nav { display: flex; }
nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 8px 0; text-decoration: none; color: var(--muted); font-size: .75rem;
}
nav a .ico { font-size: 1.25rem; line-height: 1; }
nav a.active { color: var(--accent); font-weight: 600; }

button, .ghost {
  font: inherit; border: 0; border-radius: 10px; padding: 8px 16px; cursor: pointer;
  background: var(--accent); color: var(--on-accent); font-weight: 600;
}
button:disabled { opacity: .5; cursor: progress; }
.ghost { background: transparent; color: var(--ink-2); padding: 6px 10px; text-decoration: none; font-weight: 500; }
.ghost:hover { background: var(--surface-2); }
input, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; width: 100%;
}
input[type=checkbox] { width: auto; accent-color: var(--accent); }
input[type=number] { width: 5em; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.toolbar input[type=search] { flex: 1; }
.toolbar > .ghost:last-child, .toolbar > button:last-child { margin-left: auto; }
.toggle { display: flex; align-items: center; gap: 6px; font-size: .85rem; color: var(--ink-2); white-space: nowrap; }

.empty { text-align: center; padding: 15vh 0; }
.empty .big { font-size: 3rem; }
.signin h1 { font-size: 2rem; letter-spacing: -.03em; }
.signin button { margin-top: 16px; }

/* ---------- triage ---------- */
.triage { display: flex; flex-direction: column; height: calc(100dvh - 160px); min-height: 420px; }
.stack { position: relative; flex: 1; }
.card {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 18px; overflow: hidden;
  touch-action: pan-y; user-select: none; transition: transform .18s ease, opacity .18s ease;
  --keep: 0; --skip: 0;
}
.card.under { transform: scale(.96) translateY(10px); opacity: .6; pointer-events: none; }
.card.dragging { transition: none; cursor: grabbing; }
.card.fly-right { transform: translateX(120%) rotate(12deg); opacity: 0; }
.card.fly-left { transform: translateX(-120%) rotate(-12deg); opacity: 0; }
.card h2 { font-size: 1.15rem; }
.card .authors { color: var(--ink-2); font-size: .88rem; margin: 0 0 10px; }
.card .abstract { flex: 1; overflow-y: auto; font-size: .92rem; color: var(--ink); padding-right: 4px; user-select: text; }
.card .links { display: flex; gap: 14px; padding-top: 10px; border-top: 1px solid var(--border); margin-top: 10px; }
.meta-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 8px; }
.chip { font-size: .75rem; padding: 1px 8px; border-radius: 99px; background: var(--surface-2); color: var(--ink-2); }
.chip.kw { background: var(--mark); color: var(--mark-ink); }
.stamp {
  position: absolute; top: 18px; padding: 2px 10px; border: 3px solid; border-radius: 8px;
  font-weight: 800; letter-spacing: .1em; pointer-events: none; z-index: 2; background: var(--surface);
}
.stamp.keep { left: 18px; color: var(--keep); opacity: var(--keep); transform: rotate(-12deg); }
.stamp.skip { right: 18px; color: var(--skip); opacity: var(--skip); transform: rotate(12deg); }
.actions { display: flex; justify-content: center; gap: 22px; padding-top: 14px; }
.round { width: 58px; height: 58px; border-radius: 50%; padding: 0; font-size: 1.4rem; background: var(--surface); box-shadow: var(--shadow); border: 1px solid var(--border); }
.round.keep { color: var(--keep); }
.round.skip { color: var(--skip); }
.round.undo { width: 44px; height: 44px; align-self: center; font-size: 1.1rem; color: var(--ink-2); }

/* ---------- reading list ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.item.read h3 a { color: var(--muted); }
.item-head { display: flex; gap: 10px; align-items: flex-start; }
.item-head h3 { margin: 0; font-size: .98rem; }
.item-head h3 a { color: var(--ink); text-decoration: none; }
.item-head p { margin: 2px 0 0; }
.item-actions { display: flex; }
.check { padding-top: 2px; }
.item details { margin: 6px 0; }
.item .note { margin-top: 4px; resize: vertical; background: var(--surface-2); border-color: transparent; }

/* ---------- citations ---------- */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.tile .num { font-size: 1.8rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.tile .lbl { color: var(--muted); font-size: .8rem; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.panel.new { border-color: var(--accent); background: linear-gradient(var(--accent-soft), var(--surface) 80px); }
.panel-head { display: flex; justify-content: space-between; align-items: center; }
.cite { padding: 8px 0; border-top: 1px solid var(--border); }
.cite:first-of-type { border-top: 0; }
.cite > a { color: var(--ink); text-decoration: none; font-weight: 500; }
.cite .cites { color: var(--ink-2); margin-top: 2px; }
.cite .cites span { font-style: italic; }
table.papers { width: 100%; border-collapse: collapse; font-size: .88rem; }
.papers th { text-align: left; color: var(--muted); font-weight: 500; font-size: .8rem; border-bottom: 1px solid var(--border); padding: 4px; }
.papers td { padding: 6px 4px; border-bottom: 1px solid var(--border); vertical-align: top; }
.papers td a { color: var(--ink); text-decoration: none; }
.papers .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.chart { position: relative; }
.chart svg { width: 100%; height: auto; display: block; touch-action: pan-y; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.chart .area { fill: var(--accent); opacity: .1; }
.chart .cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .tip {
  position: absolute; width: 110px; pointer-events: none; font-size: .8rem; line-height: 1.3;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; box-shadow: var(--shadow);
}

/* ---------- settings ---------- */
.settings textarea { font-family: ui-monospace, monospace; font-size: .88rem; }
.checks { display: grid; gap: 4px; margin-bottom: 10px; }
.checks label { display: flex; gap: 8px; align-items: baseline; font-size: .9rem; }
.row { display: flex; gap: 8px; align-items: center; font-size: .9rem; }
.stack-label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; margin-top: 8px; }
.save-row { display: flex; align-items: center; gap: 10px; }

#toast {
  position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 8px 16px; border-radius: 99px; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100vw - 32px); z-index: 10;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--skip); color: #fff; }

@media (max-width: 420px) {
  .tile .num { font-size: 1.4rem; }
  .card { padding: 14px; }
}
