:root {
  --bg: #faf6ef;
  --card: #fffdf9;
  --ink: #2b2118;
  --muted: #7a6c5d;
  --line: #e6dccb;
  --accent: #9c4a2f;
  --accent-ink: #fff;
  --bar: #eadfcb;
  --fill: #c9803f;
  --good: #3f7d4e;
  --danger: #a63232;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1814;
    --card: #26211b;
    --ink: #f1e9dc;
    --muted: #a99b8a;
    --line: #3a332a;
    --accent: #d98a62;
    --accent-ink: #1c1814;
    --bar: #3a332a;
    --fill: #d9a05b;
    --good: #6bb67d;
    --danger: #e07a7a;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1, h2, h3 { font-family: Georgia, "Iowan Old Style", serif; margin: 0; line-height: 1.2; }
.wrap { max-width: 1000px; margin: 0 auto; padding: 20px 16px 60px; }
.muted { color: var(--muted); font-weight: 400; }
.error { color: var(--danger); }

button, input {
  font: inherit;
  color: inherit;
}
button {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover { filter: brightness(1.08); }
button.good { color: var(--good); border-color: var(--good); }
button.danger { color: var(--danger); }
button.small { padding: 4px 10px; font-size: 14px; }
button.link { background: none; border: none; padding: 0 4px; color: var(--accent); text-decoration: underline; cursor: pointer; font-size: 14px; }
button.link.danger { color: var(--danger); }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
}
label { display: block; font-size: 14px; margin-bottom: 12px; color: var(--muted); }
label input { margin-top: 4px; color: var(--ink); }
label.check { display: flex; align-items: center; gap: 8px; color: var(--ink); }
label.check input { width: auto; margin: 0; }

/* auth */
.hero { text-align: center; margin: 28px 0 24px; }
.hero h1 { font-size: 2rem; }
.hero p { color: var(--muted); margin: 8px 0 0; }
.auth-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 680px) { .auth-grid { grid-template-columns: 1fr; } }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}
.card h2 { font-size: 1.25rem; margin-bottom: 14px; }
.card button[type="submit"] { width: 100%; margin-top: 4px; }
input.idinput { text-transform: uppercase; letter-spacing: 0.08em; }

/* group page */
.top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.top h1 { font-size: 1.8rem; }
.idline { color: var(--muted); font-size: 14px; margin-top: 4px; }
.idline code { background: var(--bar); border-radius: 6px; padding: 2px 8px; color: var(--ink); letter-spacing: 0.08em; font-size: 14px; }
.top-actions { display: flex; gap: 8px; }

.sub { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-family: inherit; margin-bottom: 8px; }
.chips { list-style: none; margin: 0 0 28px; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 3px 12px; font-size: 14px; }
.chip.me { border-color: var(--accent); color: var(--accent); }

.shelf { margin-bottom: 32px; }
.shelf h2 { font-size: 1.3rem; margin-bottom: 12px; display: flex; align-items: baseline; gap: 8px; }
.count { font-family: system-ui, sans-serif; font-size: 0.85rem; color: var(--muted); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 14px; }

.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.tile.completed { border-left: 4px solid var(--good); }
.tile.in_progress { border-left: 4px solid var(--fill); }
.tile-title { font-family: Georgia, serif; font-size: 1.1rem; line-height: 1.25; overflow-wrap: anywhere; }
.tile-meta { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.tile-meta a { color: var(--accent); }

.readers { display: flex; flex-direction: column; gap: 8px; }
.reader-head { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.rname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rlabel { color: var(--muted); white-space: nowrap; }
.reader.done .rlabel { color: var(--good); }
.bar { height: 8px; background: var(--bar); border-radius: 99px; overflow: hidden; margin-top: 3px; }
.fill { height: 100%; background: var(--fill); border-radius: 99px; transition: width 0.3s; }
.reader.done .fill { background: var(--good); }
.hint { font-size: 12px; color: var(--muted); }

.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: auto; padding-top: 8px; border-top: 1px dashed var(--line); }
.pg { display: flex; align-items: center; gap: 6px; margin: 0; font-size: 13px; }
.pg input { width: 74px; margin: 0; padding: 4px 8px; }

.empty { text-align: center; color: var(--muted); padding: 40px 16px; border: 1px dashed var(--line); border-radius: var(--radius); }

/* dialog */
dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--ink); padding: 22px; width: min(440px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog h2 { margin-bottom: 16px; font-size: 1.3rem; }
.dialog-actions { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.spacer { flex: 1; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; opacity: 0; pointer-events: none; transition: all 0.2s; max-width: calc(100vw - 32px); z-index: 10; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
