:root {
  --bg: #101216;
  --panel: #181b21;
  --text: #e7e9ee;
  --muted: #9aa1ad;
  --line: #2a2e36;
  --accent: #5b8cff;
  --accent-text: #0b0d10;
  --chip: #232730;
  --embed: #1f232b;
  --warn: #f0b35a;
  --danger: #f87171;
  --new: #2b2714;
  --shadow: none;
  color-scheme: dark;
}

/* dark is the default; light only when picked with the header toggle */
:root[data-theme="light"] {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #16181d;
  --muted: #5f6672;
  --line: #dfe2e7;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --chip: #eceef2;
  --embed: #f7f8fa;
  --warn: #b45309;
  --danger: #b91c1c;
  --new: #fff7d6;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

[hidden] { display: none !important; }

button, input, select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 0;
  border-radius: 8px;
  padding: 8px 14px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

input, select {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  min-width: 0;
}

.linkbtn {
  background: none;
  color: var(--muted);
  font-weight: 500;
  padding: 6px 8px;
}

.iconbtn {
  background: none;
  color: var(--muted);
  padding: 6px;
  line-height: 0;
}
.iconbtn svg { width: 22px; height: 22px; fill: currentColor; }
.iconbtn.on { color: var(--accent); }

.muted { color: var(--muted); }
.err { color: var(--danger); margin: 0; }

/* login */

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.loginbox {
  width: 100%;
  max-width: 340px;
  display: grid;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
}
.loginbox h1 { margin: 0 0 4px; font-size: 20px; }
.loginbox label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.loginbox input { font-size: 16px; color: var(--text); }

/* header */

.top {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding: 10px 16px 0;
  padding-top: max(10px, env(safe-area-inset-top));
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  max-width: 1400px;
  margin: 0 auto 10px;
}

.brand { font-size: 17px; margin: 0; white-space: nowrap; }
#search { flex: 1 1 200px; }
.actions { display: flex; align-items: center; gap: 2px; margin-left: auto; }

.filters { font-size: 14px; }
.custom { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.toggle { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); white-space: nowrap; }

.seg {
  display: inline-flex;
  background: var(--chip);
  border-radius: 8px;
  padding: 2px;
  margin-left: auto;
}
.seg button {
  background: none;
  color: var(--muted);
  padding: 5px 12px;
  border-radius: 6px;
  font-weight: 500;
}
.seg button[aria-selected="true"] { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }

.chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  max-width: 1400px;
  margin: 0 auto;
  padding-bottom: 10px;
  scrollbar-width: none;
}
.chip {
  flex: none;
  background: var(--chip);
  color: var(--text);
  font-weight: 500;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 13px;
  display: inline-flex;
  gap: 6px;
  align-items: center;
}
.chip .n { color: var(--muted); font-variant-numeric: tabular-nums; }
.chip.sel { background: var(--accent); color: var(--accent-text); }
.chip.sel .n { color: inherit; opacity: .8; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; }

/* feed */

main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 14px 16px 40px;
}

.feed {
  display: grid;
  gap: 10px;
  max-width: 760px;
  margin: 0 auto;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  min-width: 0;
  transition: background-color 1.5s;
}
.card.fresh { background: var(--new); }
.card.focus { outline: 2px solid var(--accent); }
.card.deleted { opacity: .55; }
.card.deleted .text { text-decoration: line-through; text-decoration-thickness: 1px; }

.meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}
.meta .who { color: var(--text); font-weight: 600; }
.meta time { margin-left: auto; white-space: nowrap; }

.badge {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .02em;
  text-transform: uppercase;
  border-radius: 5px;
  padding: 2px 6px;
  color: #fff;
  white-space: nowrap;
}
.tag {
  font-size: 12px;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0 6px;
  background: none;
  color: var(--muted);
  font-weight: 500;
}
button.tag:hover { color: var(--text); }
.tag.del { color: var(--danger); border-color: currentColor; }

.text { white-space: pre-wrap; overflow-wrap: anywhere; }
.text code { background: var(--chip); border-radius: 4px; padding: 0 4px; font-size: .92em; }
.text a, .embed a { color: var(--accent); }
.reply { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.reply a { color: inherit; }

.embed {
  margin-top: 8px;
  background: var(--embed);
  border-left: 4px solid var(--line);
  border-radius: 6px;
  padding: 8px 12px;
  overflow-wrap: anywhere;
}
.embed .eauthor { font-size: 13px; font-weight: 600; }
.embed .etitle { font-weight: 700; }
.embed .edesc { white-space: pre-wrap; font-size: 14px; margin-top: 2px; }
.embed .fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px 12px; margin-top: 6px; }
.embed .fname { font-size: 13px; font-weight: 700; }
.embed .fval { font-size: 13px; white-space: pre-wrap; }
.embed .efoot { font-size: 12px; color: var(--muted); margin-top: 6px; }

.media { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.thumb {
  padding: 0;
  background: var(--chip);
  border-radius: 8px;
  overflow: hidden;
  line-height: 0;
  max-width: min(100%, 420px);
}
.thumb img { max-width: 100%; max-height: 320px; display: block; }
.thumb img:not([src]) { width: 240px; height: 140px; }
.thumb.ph { width: 160px; height: 100px; display: grid; place-items: center; line-height: 1.3; font-size: 12px; color: var(--muted); font-weight: 500; padding: 8px; text-align: center; }

.history { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 8px; display: grid; gap: 8px; }
.ver { font-size: 14px; }
.ver .vh { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.ver .vt { white-space: pre-wrap; overflow-wrap: anywhere; }
ins { background: rgba(34, 197, 94, .22); text-decoration: none; border-radius: 3px; }
del { background: rgba(239, 68, 68, .2); border-radius: 3px; }

/* by book */

.columns {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(300px, 1fr);
  gap: 12px;
  overflow-x: auto;
  align-items: start;
}
.col { display: grid; gap: 10px; min-width: 0; }
.colhead { display: flex; align-items: center; gap: 8px; font-weight: 700; padding: 2px 2px 0; }
.colhead .n { color: var(--muted); font-weight: 500; }

@media (max-width: 720px) {
  #search { order: 3; flex-basis: 100%; }
  .columns { grid-auto-flow: row; grid-auto-columns: auto; overflow: visible; }
  .seg { margin-left: 0; }
  .meta time { margin-left: 0; width: 100%; }
}

.newpill {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  top: 150px;
  z-index: 6;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .25);
}

.empty { text-align: center; color: var(--muted); margin: 40px 0; }
.more { display: block; margin: 16px auto 0; background: var(--chip); color: var(--text); }

.health {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 16px 24px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  font-size: 12px;
  color: var(--muted);
}
.health .bad { color: var(--warn); }

/* dialogs */

dialog {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  padding: 0;
  max-width: min(420px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0, 0, 0, .5); }
.dlg { padding: 20px; display: grid; gap: 12px; }
.dlg h2 { margin: 0; font-size: 17px; }
.dlg p { margin: 0; }
.checks { display: grid; gap: 8px; max-height: 40vh; overflow: auto; }
.checks label { display: flex; gap: 8px; align-items: center; }
.dlgbtns { display: flex; justify-content: flex-end; gap: 6px; }
#notifyoff { margin-right: auto; color: var(--danger); }

.lightbox { max-width: 96vw; max-height: 96vh; background: #000; border: 0; }
.lightbox img { max-width: 96vw; max-height: 92vh; display: block; }
.lightbox .close {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(0, 0, 0, .6);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  padding: 4px 10px;
}

/* books */

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex: none; }
dialog.wide { max-width: min(560px, calc(100vw - 32px)); width: 100%; }
.booklist { display: grid; gap: 2px; max-height: 50vh; overflow: auto; }
.bookrow {
  display: grid;
  grid-template-columns: minmax(120px, auto) 1fr auto;
  align-items: center;
  gap: 4px 12px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}
.bookrow:last-child { border-bottom: 0; }
.bshow { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.baliases { font-size: 13px; overflow-wrap: anywhere; }
.bookrow.editing { grid-template-columns: 1fr 1.4fr; }
.bookrow.editing .ebtns { grid-column: 1 / -1; display: flex; gap: 6px; }
.bookadd { display: grid; grid-template-columns: 1fr 1.4fr auto; gap: 8px; }
.danger { color: var(--danger); }
.field { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.field input, .field select { font-size: 15px; color: var(--text); }
#assignnew { grid-template-columns: 1fr; }
.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
button.badge { padding: 2px 6px; border-radius: 5px; font-size: 11px; font-weight: 700; color: #fff; cursor: pointer; }
.badge.manual { box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .85); }

@media (max-width: 520px) {
  .bookrow, .bookadd { grid-template-columns: 1fr; }
  .bookrow.editing { grid-template-columns: 1fr; }
}

/* threads */

.fus { margin-top: 10px; border-left: 2px solid var(--line); padding-left: 12px; display: grid; gap: 8px; }
.fu { font-size: 14px; min-width: 0; }
.fu.deleted { opacity: .55; }
.fu.deleted .text { text-decoration: line-through; }
.fu.focus { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }
.fumeta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.fumeta .who { color: var(--text); font-weight: 600; }
.fumeta time { font-variant-numeric: tabular-nums; }
.fu .embed { margin-top: 4px; padding: 6px 10px; }
.fu .thumb img { max-height: 200px; }
.card.chatter { background: transparent; box-shadow: none; padding: 8px 14px; }
.card.chatter .text { color: var(--muted); }
.fupick { flex-wrap: wrap; }
.fupick select { flex: 1 1 100%; width: 100%; min-width: 0; margin-left: 24px; max-width: calc(100% - 24px); }
.small { font-size: 12px; }

.mention {
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  color: var(--accent);
  border-radius: 4px;
  padding: 0 3px;
  font-weight: 500;
}
@media (hover: hover) {
  [data-mark] { opacity: 0; transition: opacity .15s; }
  .card:hover > .meta [data-mark], .fu:hover > .fumeta [data-mark], [data-mark]:focus { opacity: 1; }
}
