:root {
  --paper: #faf6ef;
  --card: #ffffff;
  --ink: #2b2118;
  --muted: #7a6a5c;
  --line: #e9e0d3;
  --accent: #c2562b;
  --accent-ink: #fff;
  --accent-soft: #f7e3d8;
  --green: #3f7d3a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(43, 33, 24, .06), 0 6px 20px rgba(43, 33, 24, .06);
  --serif: 'Fraunces', Georgia, serif;
  --sans: 'Inter', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--paper); color: var(--ink); font: 15px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: inherit; }
h1, h2, h3 { font-family: var(--serif); font-weight: 700; line-height: 1.15; margin: 0; }
h1 { font-size: clamp(28px, 4vw, 38px); }
h2 { font-size: 22px; }
h3 { font-size: 17px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
[hidden] { display: none !important; }

/* ---------- top bar */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 20px; padding: 12px 24px;
  background: rgba(250, 246, 239, .92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.brand { font-family: var(--serif); font-weight: 700; font-size: 20px; text-decoration: none; white-space: nowrap; }
.brand-mark { display: inline-block; transform: rotate(-12deg); }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { text-decoration: none; padding: 7px 12px; border-radius: 999px; color: var(--muted); font-weight: 500; white-space: nowrap; }
.nav a:hover { color: var(--ink); background: #f1e9dd; }
.nav a.active { color: var(--ink); background: var(--accent-soft); }
.badge { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; }
.me-chip { display: flex; align-items: center; gap: 8px; text-decoration: none; font-weight: 600; }
.avatar { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; color: #fff; font-family: var(--serif); font-weight: 700; flex: none; }
.avatar.lg { width: 76px; height: 76px; font-size: 32px; }

.view { max-width: 1120px; margin: 0 auto; padding: 32px 24px 80px; }

/* ---------- buttons + inputs */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 9px 16px; border-radius: 999px; font: 600 14px var(--sans); cursor: pointer; text-decoration: none; white-space: nowrap; transition: transform .05s, background .15s; }
.btn:hover { background: #f5efe6; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #a94822; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { color: #b42318; }
.btn.sm { padding: 6px 12px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: default; }
.btn.ok { background: #e6f1e3; border-color: #cfe3c9; color: var(--green); }

label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-weight: 600; font-size: 13px; margin-bottom: 5px; }
input[type=text], input[type=password], input[type=search], input[type=date], input[type=number], textarea, select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font: 15px var(--sans); color: var(--ink); }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 500; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.error { color: #b42318; font-size: 14px; min-height: 20px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.section { margin-top: 32px; }
.section > h2 { margin-bottom: 14px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.page-head p { margin: 6px 0 0; }

/* ---------- auth */
.auth { display: grid; grid-template-columns: 1.1fr 1fr; gap: 48px; align-items: center; min-height: calc(100vh - 120px); }
.auth-hero h1 { font-size: clamp(36px, 5vw, 56px); }
.auth-hero h1 em { color: var(--accent); }
.auth-hero p { font-size: 18px; color: var(--muted); max-width: 460px; }
.season-strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 28px; max-width: 480px; }
.season-strip canvas { width: 100%; border-radius: 10px; box-shadow: var(--shadow); }
.auth .card { padding: 28px; max-width: 420px; width: 100%; justify-self: center; }
.tabs { display: flex; gap: 4px; background: #f1e9dd; border-radius: 999px; padding: 4px; margin-bottom: 20px; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 8px 12px; border-radius: 999px; font: 600 14px var(--sans); color: var(--muted); cursor: pointer; }
.tabs button.active { background: #fff; color: var(--ink); box-shadow: var(--shadow); }
.tabs.inline { display: inline-flex; margin: 0; }
.tabs.inline button { flex: none; }

/* ---------- books */
.books { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 22px 18px; }
.book { all: unset; cursor: pointer; display: flex; flex-direction: column; gap: 8px; }
.book:focus-visible .cover { outline: 3px solid var(--accent); }
.cover { aspect-ratio: 2 / 3; width: 100%; border-radius: 4px 8px 8px 4px; overflow: hidden; background: #ddd; box-shadow: 0 2px 4px rgba(0,0,0,.12), 0 10px 24px rgba(43,33,24,.14);
  transition: transform .15s; position: relative; }
.book:hover .cover { transform: translateY(-3px) rotate(-.6deg); }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover.ph { display: flex; flex-direction: column; justify-content: center; padding: 12px; color: #fff; text-align: center; font-family: var(--serif); font-weight: 700; font-size: 15px; line-height: 1.2; }
.cover.ph small { font-family: var(--sans); font-weight: 500; font-size: 11px; opacity: .8; margin-top: 8px; }
.book-title { font-weight: 600; font-size: 14px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book-author { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stars { color: #e2a400; letter-spacing: 1px; font-size: 13px; }
.month-group { margin-top: 36px; }
.month-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding-bottom: 12px; margin-bottom: 18px; border-bottom: 1px dashed var(--line); }
.month-head h2 { display: flex; align-items: center; gap: 10px; }
.season-dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty h3 { color: var(--ink); margin-bottom: 6px; }

/* ---------- modal */
.modal-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(43, 33, 24, .45); display: grid; place-items: center; padding: 20px; animation: fade .15s; }
.modal { background: var(--paper); border-radius: 18px; width: min(640px, 100%); max-height: calc(100vh - 40px); overflow: auto; padding: 24px; box-shadow: 0 30px 80px rgba(0,0,0,.3); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.x { border: 0; background: none; font-size: 26px; line-height: 1; cursor: pointer; color: var(--muted); }
@keyframes fade { from { opacity: 0; } }
.results { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.result { all: unset; cursor: pointer; display: flex; gap: 12px; align-items: center; padding: 8px; border-radius: 10px; }
.result:hover, .result:focus-visible { background: #f1e9dd; }
.result .cover { width: 46px; flex: none; }
.result .cover.ph { font-size: 8px; padding: 4px; }
.book-form { display: grid; grid-template-columns: 150px 1fr; gap: 20px; }
.book-form .cover-col { display: flex; flex-direction: column; gap: 8px; }
.rating-input { display: flex; gap: 2px; }
.rating-input button { border: 0; background: none; font-size: 26px; cursor: pointer; color: #d9cfc1; padding: 0 2px; line-height: 1; }
.rating-input button.on { color: #e2a400; }

/* ---------- recap */
.recap { display: grid; grid-template-columns: 340px 1fr; gap: 28px; align-items: start; }
.recap-controls { position: sticky; top: 84px; display: flex; flex-direction: column; gap: 18px; }
.month-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.month-nav strong { font-family: var(--serif); font-size: 22px; text-align: center; flex: 1; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.seg button { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 8px 4px; font: 600 12px var(--sans); cursor: pointer; color: var(--muted); }
.seg button.active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.recap-stage { background: repeating-conic-gradient(#efe7db 0 25%, #f6f0e6 0 50%) 0 0 / 24px 24px; border-radius: 18px; padding: 28px; display: grid; place-items: center; min-height: 500px; }
.recap-stage canvas { max-width: 100%; max-height: calc(100vh - 170px); width: auto; height: auto; border-radius: 10px; box-shadow: 0 20px 60px rgba(43,33,24,.3); background: #fff; }
.pick-list { display: flex; flex-direction: column; gap: 6px; max-height: 280px; overflow: auto; }
.pick-list label { display: flex; align-items: center; gap: 10px; font-size: 13px; cursor: pointer; padding: 4px; border-radius: 8px; }
.pick-list label:hover { background: #f5efe6; }
.pick-list img, .pick-list .mini-ph { width: 26px; height: 39px; object-fit: cover; border-radius: 2px; flex: none; background: #ccc; }
.pick-list .move { margin-left: auto; display: flex; gap: 2px; }
.pick-list .move button { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 2px 4px; font-size: 12px; }
.theme-chip { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; color: #fff; font-weight: 600; }
.theme-chip small { display: block; font-weight: 500; opacity: .85; }

/* ---------- people + feed */
.people { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.person { display: flex; align-items: center; gap: 12px; padding: 14px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.person .info { flex: 1; min-width: 0; }
.person .info a { font-weight: 600; text-decoration: none; }
.person .info a:hover { text-decoration: underline; }
.person .info div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person .acts { display: flex; flex-direction: column; gap: 6px; }
.feed { display: flex; flex-direction: column; gap: 12px; }
.feed-item { display: flex; gap: 14px; padding: 14px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); align-items: flex-start; }
.feed-item .cover { width: 56px; flex: none; }
.feed-item .cover.ph { font-size: 9px; padding: 4px; }
.feed-item p { margin: 4px 0 0; }
.feed-item .review { font-style: italic; color: var(--muted); margin-top: 6px; }
.home-grid { display: grid; grid-template-columns: 1fr 320px; gap: 28px; align-items: start; }
.home-side { display: flex; flex-direction: column; gap: 16px; position: sticky; top: 84px; }
.mini-preview { width: 100%; border-radius: 10px; box-shadow: var(--shadow); display: block; }
.profile-head { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.profile-head .info { flex: 1; min-width: 220px; }
.stat-row { display: flex; gap: 22px; margin-top: 10px; flex-wrap: wrap; }
.stat-row b { font-size: 18px; display: block; font-family: var(--serif); }
.stat-row span { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.lock { text-align: center; padding: 60px 20px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 999px; font-weight: 500; z-index: 60; box-shadow: 0 10px 30px rgba(0,0,0,.25); }
.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  .auth, .recap, .home-grid { grid-template-columns: minmax(0, 1fr); }
  .recap > *, .home-grid > * { min-width: 0; }
  .recap-controls, .home-side { position: static; }
  .recap-stage { order: -1; padding: 14px; min-height: 0; }
  .recap-stage canvas { max-height: 70vh; }
  .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 16px; }
  .nav { order: 3; flex-basis: 100%; overflow-x: auto; }
  .view { padding: 20px 16px 60px; }
  .book-form { grid-template-columns: 1fr; }
  .book-form .cover-col { flex-direction: row; align-items: flex-end; }
  .book-form .cover-col .cover { width: 110px; }
  .books { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 18px 12px; }
}

/* background picker */
.bg-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.bg-opt { border: 2px solid transparent; background: #fff; border-radius: 12px; padding: 4px; cursor: pointer; display: flex; flex-direction: column; gap: 5px; font: 600 12px var(--sans); color: var(--ink); text-align: center; box-shadow: var(--shadow); }
.bg-opt canvas { width: 100%; aspect-ratio: 4 / 5; border-radius: 8px; display: block; }
.bg-opt span { padding: 0 2px 3px; }
.bg-opt:hover { border-color: var(--line); }
.bg-opt.active { border-color: var(--accent); color: var(--accent); }

/* hidden books */
.hid-tag { font-size: 11px; color: var(--muted); margin-top: 3px; }
.hide-check { align-items: flex-start; margin: 4px 0 14px; }
.hide-check input { margin-top: 2px; flex: none; }
.hide-check small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; margin-top: 2px; line-height: 1.4; }
.pick-list label.is-hidden img, .pick-list label.is-hidden .mini-ph { opacity: .4; }
.pick-list .move .hide-btn { filter: grayscale(1); opacity: .45; font-size: 14px; }
.pick-list .move .hide-btn.on { filter: none; opacity: 1; }
