:root {
  --bg: #f6f3ee;
  --panel: #fffdf9;
  --ink: #2a2622;
  --muted: #7a7168;
  --line: #e4ddd2;
  --accent: #8a4b2a;
  --accent-ink: #fff;
  --hover: #f0ebe3;
  --selected: #eadfd2;
  --danger: #a3332b;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1917;
    --panel: #24211e;
    --ink: #ece6dd;
    --muted: #a39a8f;
    --line: #37322d;
    --accent: #d08a5c;
    --accent-ink: #1b1917;
    --hover: #2d2925;
    --selected: #3a332c;
    --danger: #e06a5f;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 Georgia, "Iowan Old Style", "Palatino Linotype", serif;
}
h1, h2, h3 { font-weight: normal; margin: 0 0 .5rem; }
.meta { color: var(--muted); font-size: .9rem; margin: 0 0 1rem; }
.error { color: var(--danger); min-height: 1.5em; margin: .75rem 0 0; }

button, input, textarea, select { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line);
  background: var(--panel);
  padding: .5rem .9rem;
  border-radius: 6px;
  cursor: pointer;
}
button:hover { background: var(--hover); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--danger); }
input, textarea, select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: .5rem .6rem;
}
textarea { min-height: 7rem; resize: vertical; }
label { display: block; font-size: .85rem; color: var(--muted); margin: 1rem 0 .3rem; }
.row { display: flex; gap: .5rem; margin-top: 1.25rem; flex-wrap: wrap; }

/* ---------- login ---------- */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.card {
  width: 100%; max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 2rem;
}

/* ---------- app layout ---------- */
.app { display: grid; grid-template-columns: 340px 1fr; height: 100vh; }
.sidebar {
  display: flex; flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--panel);
  min-height: 0;
}
.sidebar header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1rem; border-bottom: 1px solid var(--line);
}
.sidebar header h1 { font-size: 1.3rem; margin: 0; }
.sidebar header .who { font-size: .85rem; color: var(--muted); }
.sidebar header button { padding: .3rem .6rem; font-size: .85rem; }

.list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.list li {
  display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: .75rem;
  padding: .75rem 1rem; border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.list li:hover { background: var(--hover); }
.list li.selected { background: var(--selected); }
.list .title { font-weight: bold; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .body {
  color: var(--muted); font-size: .88rem;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.list .empty { color: var(--muted); padding: 2rem 1rem; text-align: center; cursor: default; display: block; }
.list .empty:hover { background: none; }

.thumb {
  width: 52px; height: 72px; border-radius: 4px; object-fit: cover;
  background: var(--hover); border: 1px solid var(--line);
  display: grid; place-items: center; color: var(--muted); font-size: 1.4rem;
}

.sidebar footer { padding: 1rem; border-top: 1px solid var(--line); }
.sidebar footer button { width: 100%; padding: .7rem; }

/* ---------- main pane ---------- */
.main { overflow-y: auto; padding: 2.5rem; }
.placeholder { color: var(--muted); text-align: center; margin-top: 20vh; }
.detail { max-width: 760px; margin: 0 auto; }
.detail-head { display: flex; gap: 2rem; align-items: flex-start; margin-bottom: 2rem; }
.cover {
  width: 180px; height: 260px; object-fit: cover; flex: none;
  border-radius: 6px; border: 1px solid var(--line); background: var(--hover);
  display: grid; place-items: center; color: var(--muted); font-size: 3rem;
}
.detail h2 { font-size: 2rem; line-height: 1.2; }
.badge {
  display: inline-block; padding: .15rem .6rem; border-radius: 99px;
  border: 1px solid var(--line); font-size: .85rem; color: var(--muted);
}
.section { margin-top: 1.75rem; }
.section h3 {
  font-size: .8rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); margin-bottom: .4rem;
}
.section p { margin: 0; white-space: pre-wrap; }
.section .none { color: var(--muted); font-style: italic; }

/* ---------- form ---------- */
.edit { max-width: 640px; margin: 0 auto; }
.image-pick { display: flex; gap: 1rem; align-items: center; }
.image-pick .cover { width: 90px; height: 130px; font-size: 1.6rem; }
.choices { display: flex; gap: .5rem; flex-wrap: wrap; }
.choices label {
  margin: 0; color: var(--ink); font-size: .95rem;
  border: 1px solid var(--line); border-radius: 99px; padding: .3rem .9rem; cursor: pointer;
}
.choices input { display: none; }
.choices input:checked + span { color: var(--accent); font-weight: bold; }

.back { display: none; margin-bottom: 1rem; }

/* ---------- share panel inside the app ---------- */
.link-box { display: flex; gap: .5rem; }
.link-box input { flex: 1; min-width: 0; }
a { color: var(--accent); }
.btnlink {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: .5rem .9rem; border-radius: 6px; text-decoration: none;
}
.btnlink:hover { background: var(--hover); }
.linkish {
  background: none; border: none; padding: 0; color: var(--accent);
  font-size: .85rem; text-decoration: underline; cursor: pointer;
}
.linkish:hover { background: none; }
.sidebar header .linkish { padding: 0; margin-top: .25rem; font-size: .85rem; }

/* ---------- public profile page ---------- */
.profile-page { overflow-y: auto; }
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: .75rem 16px; border-bottom: 1px solid var(--line); background: var(--panel);
  font-size: .9rem;
}
.topbar:empty { display: none; }
.profile { max-width: 980px; margin: 0 auto; padding: 2.5rem 16px 4rem; }
.profile-head { display: flex; gap: 1.5rem; align-items: center; margin-bottom: 2.5rem; }
.profile-head h1 { font-size: 2rem; margin: 0; }
.profile-head .meta { margin: .2rem 0 0; }
.bio { margin: .75rem 0 0; max-width: 60ch; white-space: pre-wrap; }
.avatar {
  width: 84px; height: 84px; border-radius: 50%; flex: none;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 2.2rem;
}
.shelf {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1.75rem 1.25rem;
}
.shelf li { cursor: pointer; border-radius: 6px; }
.shelf li:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.shelf .cover { width: 100%; height: auto; aspect-ratio: 2 / 3; transition: transform .15s; }
.shelf li:hover .cover { transform: translateY(-3px); }
.shelf .title { margin-top: .5rem; font-weight: bold; line-height: 1.3; }

dialog {
  width: min(760px, calc(100% - 32px)); max-height: calc(100% - 64px);
  border: 1px solid var(--line); border-radius: 10px; padding: 2rem;
  background: var(--panel); color: var(--ink);
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog .detail { position: relative; }
.close { position: absolute; top: -1rem; right: -1rem; border: none; font-size: 1.1rem; }

/* ---------- phone: list and detail take turns ---------- */
@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .app.showing-main .sidebar { display: none; }
  .app:not(.showing-main) .main { display: none; }
  .main { padding: 1rem 16px 2rem; }
  .back { display: inline-block; }
  .detail-head { flex-direction: column; gap: 1rem; }
  .cover { width: 140px; height: 200px; }
  .profile-head { flex-direction: column; align-items: flex-start; gap: 1rem; }
  .shelf { grid-template-columns: repeat(2, 1fr); gap: 1.25rem 1rem; }
  dialog { padding: 1.25rem; }
  .close { top: -.5rem; right: -.5rem; }
}
