:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1b2330;
  --muted: #657085;
  --line: #e2e6ec;
  --accent: #0b6e99;
  --accent-soft: #e3f1f8;
  --star: #d98e04;
  --star-soft: #fff4dc;
  --danger: #b42318;
  --conflict: #fde7e5;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 2px 8px rgba(20, 30, 50, .05);
  --mark: #ffe58a; --ok: #1a7f4b; --warn: #a15c00;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11151b; --panel: #1a2029; --ink: #e6eaf0; --muted: #98a3b5; --line: #2a323e;
    --accent: #4fb3e0; --accent-soft: #15303f; --star: #f2b23a; --star-soft: #3a2d10;
    --danger: #ff7a6e; --conflict: #3d1d1b; --shadow: none; --mark: #6b5a12; --ok: #5fcf8a; --warn: #f2b23a; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #11151b; --panel: #1a2029; --ink: #e6eaf0; --muted: #98a3b5; --line: #2a323e;
    --accent: #4fb3e0; --accent-soft: #15303f; --star: #f2b23a; --star-soft: #3a2d10;
    --danger: #ff7a6e; --conflict: #3d1d1b; --shadow: none; --mark: #6b5a12; --ok: #5fcf8a; --warn: #f2b23a; color-scheme: dark;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, select, input { font: inherit; color: inherit; }
button, .btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px;
  padding: 6px 12px; cursor: pointer;
}
button:hover, .btn:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--danger); }
a { color: var(--accent); }

/* header */
.top {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 10; display: flex; align-items: center; gap: 24px;
  padding-block: 10px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand small { display: block; color: var(--muted); font-size: 12px; }
.logo {
  width: 34px; height: 34px; border-radius: 8px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700;
}
.tabs { display: flex; gap: 4px; }
.tabs button { border: none; background: none; padding: 8px 14px; border-radius: 8px; color: var(--muted); }
.tabs button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.pill { background: var(--star); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 12px; }

main { max-width: 1100px; margin: 0 auto; padding-block: 16px 60px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.view { display: none; }
.view.active { display: block; }

/* search */
.searchbar { display: flex; gap: 10px; }
#q {
  flex: 1; padding: 12px 14px; font-size: 16px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--panel); outline: none;
}
#q:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: none; border-radius: 0; background: var(--panel); padding: 0 16px; }
.seg button.active { background: var(--accent); color: #fff; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 12px 0 4px; }
.filters select { padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); max-width: 280px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border-radius: 999px; padding: 4px 12px; font-size: 13px; }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chk { font-size: 13px; color: var(--muted); display: flex; gap: 4px; align-items: center; }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }

/* cards */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; margin: 10px 0; box-shadow: var(--shadow);
}
.card.saved { border-left: 4px solid var(--star); }
.card.conflict { background: var(--conflict); }
.row { display: flex; gap: 12px; align-items: flex-start; }
.row .grow { flex: 1; min-width: 0; }
.meta { color: var(--muted); font-size: 13px; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.meta b { color: var(--ink); font-weight: 600; }
.title { font-weight: 600; margin: 2px 0; cursor: pointer; }
.title:hover { color: var(--accent); }
.authors { font-size: 13.5px; margin-top: 2px; }
.authors b { cursor: pointer; }
.authors b:hover { text-decoration: underline; color: var(--accent); }
.snippet { font-size: 13px; color: var(--muted); margin-top: 4px; }
mark { background: var(--mark); color: inherit; border-radius: 2px; padding: 0 1px; }
.tag { display: inline-block; font-size: 11.5px; padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.star {
  border: 1px solid var(--line); border-radius: 8px; min-width: 38px; height: 34px;
  font-size: 18px; line-height: 1; color: var(--muted); background: var(--panel); padding: 0 8px;
  white-space: nowrap;
}
.star small { font-size: 12px; }
.star.on { color: var(--star); background: var(--star-soft); border-color: var(--star); }
.talks { margin-top: 10px; border-top: 1px dashed var(--line); }
.talk { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--line); align-items: flex-start; }
.talk:last-child { border-bottom: none; }
.talk .time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; width: 92px; flex: none; padding-top: 2px; }
.talk .grow { flex: 1; min-width: 0; }
.talk.withdrawn { opacity: .5; text-decoration: line-through; }
.linkbtn { border: none; background: none; color: var(--accent); padding: 0; font-size: 13px; cursor: pointer; }
.more { display: block; margin: 16px auto; }
.dayhead { margin: 24px 0 4px; font-size: 18px; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(10, 15, 25, .5); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal[hidden] { display: none; }
.modal-card {
  background: var(--panel); border-radius: 14px; max-width: 760px; width: 100%;
  max-height: 88vh; overflow: auto; padding: 20px 24px; position: relative;
}
.modal-card h2 { margin: 4px 36px 8px 0; font-size: 20px; }
.modal-card .abstract { margin-top: 14px; font-size: 14.5px; }
.close { position: absolute; right: 14px; top: 12px; font-size: 22px; border: none; background: none; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* calendar */
.cal { display: grid; grid-template-columns: 54px 1fr; position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.cal .hours { position: relative; border-right: 1px solid var(--line); }
.cal .hour { position: absolute; right: 6px; font-size: 11px; color: var(--muted); transform: translateY(-50%); }
.cal .lane { position: relative; }
.cal .gridline { position: absolute; left: 0; right: 0; border-top: 1px solid var(--line); }
.ev {
  position: absolute; border-radius: 6px; padding: 3px 6px; font-size: 12px; overflow: hidden;
  background: var(--accent-soft); border-left: 3px solid var(--accent); cursor: pointer; line-height: 1.25;
}
.ev.paper { background: var(--star-soft); border-left-color: var(--star); }
.ev.clash { outline: 2px solid var(--danger); outline-offset: -2px; }
.ev .t { font-weight: 600; }
.ev .m { color: var(--muted); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--panel); padding: 8px 16px; border-radius: 8px; z-index: 60; font-size: 14px; }

@media (max-width: 720px) {
  .top { flex-direction: column; align-items: stretch; gap: 8px; padding-block: 8px; }
  .sync { margin-left: 0; }
  .tabs { justify-content: space-between; }
  .searchbar { flex-direction: column; }
  .seg { align-self: flex-start; height: 34px; }
  .talk .time { width: 70px; }
}
#q { min-width: 0; width: 100%; }
.hint code { white-space: normal; word-break: break-word; }
@media (max-width: 720px) {
  .filters select { flex: 1 1 140px; min-width: 0; max-width: none; }
  .tabs button { padding: 8px 8px; }
  .modal { padding: 0; }
  .modal-card { max-height: 100vh; height: 100%; border-radius: 0; padding: 16px; }
}
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--panel); }
.sync { margin-left: auto; font-size: 12.5px; color: var(--muted); }
.sync.ok { color: var(--ok); }
.sync.ok::before { content: "● "; }
.sync.warn { color: var(--warn); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.toast { bottom: calc(20px + env(safe-area-inset-bottom, 0px)); max-width: calc(100vw - 32px); text-align: center; }
.devicebox { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; background: var(--accent-soft); border-radius: 10px; padding: 10px 14px; margin: 8px 0; font-size: 14px; }
.devicebox > div { flex: 1 1 260px; min-width: 0; }
.linkrow { display: flex; gap: 8px; margin-top: 8px; }
.linkrow input { flex: 1; min-width: 0; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.qr { background: #fff; padding: 10px; width: max-content; border-radius: 8px; margin: 12px 0; }
.acct { white-space: nowrap; }
.devicebox button + button { margin-left: -2px; }
.acctform { display: grid; gap: 6px; max-width: 360px; margin-top: 12px; }
.acctform input { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); font-size: 16px; }
.acctform button { margin-top: 8px; padding: 10px; }
.err { color: var(--danger); margin: 4px 0 0; font-size: 14px; }
@media (max-width: 720px) {
  .top { position: sticky; }
  .acct { align-self: flex-start; }
}
.modal.gate { background: var(--bg); }
.modal.gate .modal-card { max-width: 440px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.gatehead { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.gatehead small { display: block; color: var(--muted); font-size: 12px; }
.chk.remember { font-size: 14px; color: var(--ink); margin-top: 6px; }
.switch { margin-top: 14px; font-size: 14px; }
.switch .linkbtn { font-size: 14px; font-weight: 600; }
@media (max-width: 720px) {
  .modal.gate { padding: 0; }
  .modal.gate .modal-card { border: none; }
}
