:root {
  --bg: #faf6f0;
  --card: #ffffff;
  --text: #2b2118;
  --muted: #7d6e60;
  --line: #ece3d7;
  --brand: #7a3e1d;
  --brand-ink: #ffffff;
  --ok: #2f7d4f;
  --warn: #b26a00;
  --wa: #1f9d55;
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1612;
    --card: #26201a;
    --text: #f2e9de;
    --muted: #b3a493;
    --line: #3a3128;
    --brand: #d98a55;
    --brand-ink: #1b1612;
    --ok: #6fcf97;
    --warn: #f2b45b;
    --wa: #4cd17f;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; margin-top: 1.4rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
input {
  font: inherit; color: inherit; width: 100%;
  padding: .7rem .85rem; border: 1px solid var(--line); border-radius: 10px; background: var(--card);
}
input:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
input[type=checkbox] { width: 1.2rem; height: 1.2rem; padding: 0; flex: none; accent-color: var(--brand); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .3rem;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  padding: .65rem 1rem; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); white-space: nowrap;
}
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.small { padding: .35rem .7rem; font-size: .85rem; }
.btn.warn { color: var(--warn); }
.btn.wide { width: 100%; margin-top: .8rem; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { background: none; border: 0; font-size: 1.05rem; cursor: pointer; padding: .4rem; color: var(--muted); }

/* join */
#signin { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem 16px; }
.join-card { width: 100%; max-width: 420px; text-align: center; }
.join-logo { width: 72px; height: 72px; }
.error { color: #c0392b; min-height: 1.2em; margin: 0; }

/* app shell */
#app { max-width: 640px; margin: 0 auto; padding-bottom: 5.5rem; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: .8rem 16px; position: sticky; top: 0; z-index: 5; background: var(--bg);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.1rem; }
.brand img { width: 28px; height: 28px; }
.chip {
  font-size: .8rem; font-weight: 600; color: var(--wa); text-decoration: none;
  border: 1px solid currentColor; border-radius: 999px; padding: .25rem .7rem;
}
.view { padding: 0 16px; }
.search-bar { position: sticky; top: 3.4rem; z-index: 4; background: var(--bg); padding-bottom: .5rem; }
.search-bar input { font-size: 1.05rem; padding: .85rem 1rem; border-radius: 999px; }

.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; justify-content: center; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  flex: 1; max-width: 213px; background: none; border: 0; font: inherit; font-size: .78rem; color: var(--muted);
  padding: .55rem 0 .6rem; display: grid; justify-items: center; gap: .1rem; cursor: pointer;
}
.tabs button span { font-size: 1.3rem; }
.tabs button.active { color: var(--brand); font-weight: 700; }

/* lists */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.book {
  display: flex; gap: .8rem; align-items: flex-start;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem;
}
.book.small { align-items: center; padding: .5rem .6rem; }
.book.unchecked { opacity: .5; }
.book .info { flex: 1; min-width: 0; }
.title { font-weight: 700; overflow-wrap: anywhere; }
.author { color: var(--muted); font-size: .9rem; }
.cover {
  position: relative; flex: none; width: 52px; height: 76px; border-radius: 6px; overflow: hidden;
  display: grid; place-items: center; font-weight: 800; text-transform: uppercase; font-size: .9rem;
  color: #fff; background: hsl(var(--hue) 45% 42%);
}
.book.small .cover { width: 38px; height: 56px; font-size: .75rem; }
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.owners { margin-top: .4rem; display: grid; gap: .3rem; }
.owner { display: flex; align-items: center; gap: .45rem; font-size: .9rem; flex-wrap: wrap; }
.owner > span:first-child { font-weight: 600; }
.tag { font-size: .72rem; padding: .05rem .45rem; border-radius: 999px; border: 1px solid currentColor; }
.tag.ok { color: var(--ok); }
.tag.lent { color: var(--warn); }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; display: grid; gap: .8rem; justify-items: center; }
.actions { display: flex; align-items: center; gap: .3rem; margin-top: .5rem; flex-wrap: wrap; }

/* add */
.add-modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: .6rem; }
.mode {
  font: inherit; font-weight: 600; font-size: .9rem; cursor: pointer; color: var(--text);
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem .5rem; display: grid; justify-items: center; gap: .3rem;
}
.mode-icon { font-size: 1.6rem; }
.mode.active { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.panel { margin-top: 1rem; display: grid; gap: .7rem; }
.row { display: flex; gap: .5rem; }
#reader { width: 100%; border-radius: var(--radius); overflow: hidden; background: #000; min-height: 200px; }
.file-btn { cursor: pointer; }
.fix-title { padding: .4rem .6rem; font-size: .9rem; }
.notice { background: var(--card); border: 1px solid var(--ok); color: var(--ok); padding: .8rem; border-radius: var(--radius); }

/* my books */
.me {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem; margin-bottom: 1.2rem;
}

#toast {
  position: fixed; left: 50%; bottom: 5.5rem; transform: translateX(-50%); z-index: 20;
  background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 999px;
  font-size: .9rem; max-width: calc(100% - 32px); text-align: center;
}

/* sign in */
.privacy-note {
  margin-top: 1.5rem; text-align: left; font-size: .85rem; color: var(--muted);
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem;
}
.privacy-note strong { display: block; color: var(--text); margin-bottom: .2rem; }
#wa-signin { margin-top: 1.2rem; background: var(--wa); border-color: var(--wa); color: #fff; }

/* tabs badge */
.tabs button { position: relative; }
#badge {
  position: absolute; top: .3rem; left: calc(50% + .5rem); min-width: 1.1rem; height: 1.1rem; padding: 0 .3rem;
  border-radius: 999px; background: #d64545; color: #fff; font-size: .7rem; line-height: 1.1rem; text-align: center;
}

/* requests */
#view-requests h3:first-child { margin-top: .4rem; }
.note { font-size: .9rem; font-style: italic; margin-top: .3rem; }
.tag { white-space: nowrap; }
.btn.danger { color: #c0392b; }
.want { margin-left: auto; }

/* chat */
#thread { display: grid; gap: .8rem; }
#thread-back { justify-self: start; }
.shared { margin-top: .6rem; font-size: .9rem; background: var(--card); border: 1px solid var(--ok); border-radius: 10px; padding: .6rem .8rem; }
.shared a { color: var(--wa); font-weight: 700; }
.messages { list-style: none; margin: 0; padding: 0; display: grid; gap: .4rem; }
.messages li {
  max-width: 80%; justify-self: start; background: var(--card); border: 1px solid var(--line);
  padding: .5rem .75rem; border-radius: 14px 14px 14px 4px; overflow-wrap: anywhere; white-space: pre-wrap;
}
.messages li.mine { justify-self: end; background: var(--brand); color: var(--brand-ink); border-color: var(--brand); border-radius: 14px 14px 4px 14px; }
.messages li time { display: block; font-size: .7rem; opacity: .7; margin-top: .15rem; }
.messages li.hint { max-width: none; justify-self: stretch; text-align: center; color: var(--muted); background: none; border: 1px dashed var(--line); }

/* me */
.me-footer { display: flex; justify-content: space-between; margin: 2rem 0 1rem; }
#wishes .info { font-size: .95rem; }

/* dialog sheet */
dialog {
  width: min(480px, calc(100% - 32px)); border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); color: var(--text); padding: 1.1rem;
}
dialog::backdrop { background: rgb(0 0 0 / .45); }
#sheet-form { display: grid; gap: .7rem; }
#sheet-form h3 { margin: 0; }
#sheet-text:empty { display: none; }
.row.end { flex-direction: row-reverse; justify-content: flex-start; }

/* profile dialog */
#profile-form { display: grid; gap: .7rem; }
#profile-form h3 { margin: 0; }
#profile-form label { display: grid; gap: .3rem; font-weight: 600; font-size: .9rem; }
.place { color: var(--muted); font-size: .8rem; font-weight: 400; }
