/* Sofia's Library — a cosy autumn reading room */

:root {
  --cream: #fbf6ee;
  --paper: #f5ede0;
  --linen: #ede2d0;
  --card: #fffcf7;
  --line: #e3d5bf;
  --ink: #3a2a1f;
  --ink-soft: #6b5444;
  --ink-faint: #9a8371;
  --walnut: #4a3223;
  --walnut-deep: #2f1f15;
  --oak: #8b5e3c;
  --rust: #b0552a;
  --rust-soft: #f3dccd;
  --mustard: #c6963a;
  --mustard-soft: #f6e8c8;
  --olive: #6d7a48;
  --olive-soft: #e3e8d2;
  --berry: #8a3a3a;
  --berry-soft: #f2d9d6;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(58, 42, 31, .06), 0 6px 18px rgba(58, 42, 31, .07);
  --shadow-lift: 0 2px 4px rgba(58, 42, 31, .08), 0 14px 30px rgba(58, 42, 31, .14);
  --font-head: 'Fraunces', Georgia, 'Times New Roman', serif;
  --font-body: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html { font-size: 17px; }
body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--cream);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; display: block; }
a { color: var(--rust); }
h1, h2, h3, h4 { font-family: var(--font-head); font-weight: 600; color: var(--walnut-deep); line-height: 1.2; margin: 0; }
h1 { font-size: 2rem; letter-spacing: -.01em; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
.muted { color: var(--ink-soft); }
.faint { color: var(--ink-faint); font-size: .88rem; }
.hidden { display: none !important; }

/* ---------- layout ---------- */

.app { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }

.sidebar {
  background: linear-gradient(180deg, var(--walnut) 0%, var(--walnut-deep) 100%);
  color: #f3e6d3;
  padding: calc(26px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 6px;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 10px 22px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  background: var(--rust); color: #fff6ea; font-size: 1.35rem;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .18);
}
.brand h1 { color: #fbefdc; font-size: 1.3rem; }
.brand small { display: block; color: #c9b196; font-size: .76rem; font-style: italic; margin-top: 2px; }

.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; border-radius: 10px;
  color: #ead9c2; text-decoration: none; font-weight: 600; font-size: .97rem;
  transition: background .15s, color .15s;
}
.nav a:hover { background: rgba(255, 240, 220, .08); color: #fff4e4; }
.nav a.active { background: var(--cream); color: var(--walnut-deep); }
.nav .ico { width: 22px; text-align: center; font-size: 1.05rem; }
.sidebar-foot { margin-top: auto; padding: 14px 12px 0; font-size: .82rem; color: #b89f84; border-top: 1px solid rgba(255, 255, 255, .08); }
.sidebar-foot kbd { background: rgba(255, 255, 255, .1); border-radius: 4px; padding: 1px 5px; font-family: inherit; }

.main { padding: 34px 44px calc(70px + env(safe-area-inset-bottom)); max-width: 1400px; width: 100%; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 26px; }
.page-head p { margin: 6px 0 0; color: var(--ink-soft); }

/* ---------- cards & tiles ---------- */

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
.card-head a { font-size: .9rem; font-weight: 700; text-decoration: none; }

.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: 2fr 1fr; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 22px; }
.tile {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px;
  box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.tile::before { content: ''; position: absolute; inset: 0 auto 0 0; width: 5px; background: var(--accent, var(--rust)); }
.tile .label { font-size: .82rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); }
.tile .value { font-family: var(--font-head); font-size: 2.05rem; font-weight: 600; color: var(--walnut-deep); line-height: 1.15; margin: 4px 0 2px; }
.tile .sub { font-size: .88rem; color: var(--ink-soft); }

/* ---------- buttons & forms ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 700; font-size: .95rem;
  padding: 10px 18px; border-radius: 999px; border: 1px solid transparent;
  background: var(--rust); color: #fff8ef; cursor: pointer; text-decoration: none;
  transition: transform .1s, background .15s, box-shadow .15s;
}
.btn:hover { background: #9a4722; box-shadow: 0 4px 12px rgba(176, 85, 42, .25); }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: var(--card); color: var(--walnut); border-color: var(--line); }
.btn.secondary:hover { background: var(--paper); box-shadow: none; }
.btn.ghost { background: transparent; color: var(--ink-soft); }
.btn.ghost:hover { background: var(--paper); box-shadow: none; }
.btn.danger { background: transparent; color: var(--berry); border-color: var(--berry-soft); }
.btn.danger:hover { background: var(--berry-soft); box-shadow: none; }
.btn.small { padding: 6px 13px; font-size: .85rem; }
.btn:disabled { opacity: .55; cursor: default; }

label.field { display: flex; flex-direction: column; gap: 5px; font-size: .86rem; font-weight: 700; color: var(--ink-soft); }
input, select, textarea {
  font: inherit; font-size: .97rem; color: var(--ink);
  background: #fffefb; border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 9px 12px; width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--oak); box-shadow: 0 0 0 3px rgba(139, 94, 60, .16); }
.form-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px 16px; }
.span-2 { grid-column: span 2; } .span-3 { grid-column: span 3; } .span-4 { grid-column: span 4; } .span-6 { grid-column: span 6; }
.form-section { grid-column: span 6; font-family: var(--font-head); font-size: 1rem; color: var(--oak); margin-top: 8px; padding-bottom: 4px; border-bottom: 1px dashed var(--line); }

.toggle { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 700; color: var(--ink-soft); font-size: .92rem; user-select: none; }
.toggle input { display: none; }
.toggle .track { width: 42px; height: 24px; border-radius: 99px; background: var(--linen); position: relative; transition: background .2s; flex-shrink: 0; }
.toggle .track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .2); transition: transform .2s; }
.toggle input:checked + .track { background: var(--olive); }
.toggle input:checked + .track::after { transform: translateX(18px); }

.stars { display: inline-flex; gap: 2px; }
.stars button { background: none; border: 0; padding: 0 1px; font-size: 1.45rem; line-height: 1; color: var(--linen); cursor: pointer; }
.stars button.on { color: var(--mustard); }
.stars button:hover { transform: scale(1.12); }
.stars-static { color: var(--mustard); letter-spacing: 1px; font-size: .95rem; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 20px; }
.toolbar input[type=search] { max-width: 320px; }
.toolbar select { width: auto; }
.seg { display: inline-flex; background: var(--paper); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.seg button { font: inherit; font-weight: 700; font-size: .86rem; border: 0; background: none; color: var(--ink-soft); padding: 6px 14px; border-radius: 999px; cursor: pointer; }
.seg button.on { background: var(--card); color: var(--walnut-deep); box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }

/* ---------- pills ---------- */

.pill { display: inline-flex; align-items: center; gap: 5px; font-size: .76rem; font-weight: 800; padding: 3px 10px; border-radius: 99px; letter-spacing: .02em; white-space: nowrap; }
.pill.read { background: var(--olive-soft); color: #4e5a2e; }
.pill.reading { background: var(--mustard-soft); color: #86621c; }
.pill.unread { background: var(--linen); color: var(--ink-soft); }
.pill.dnf { background: var(--berry-soft); color: var(--berry); }
.pill.special { background: var(--rust-soft); color: #8d3f1b; }
.pill.kindle { background: #e2e6ea; color: #3d4a57; }
.pill.preordered { background: var(--olive-soft); color: #4e5a2e; }
.pill.not-preordered { background: var(--linen); color: var(--ink-soft); }

/* ---------- covers & book grid ---------- */

.cover {
  aspect-ratio: 2 / 3; border-radius: 5px 9px 9px 5px; overflow: hidden; position: relative;
  background: linear-gradient(135deg, var(--oak), var(--walnut));
  box-shadow: inset 4px 0 0 rgba(0, 0, 0, .12), 0 3px 10px rgba(47, 31, 21, .22);
}
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cover .placeholder {
  position: absolute; inset: 0; padding: 14px 12px; display: flex; flex-direction: column; justify-content: center; text-align: center;
  color: #f8ead6; font-family: var(--font-head); font-size: .95rem; line-height: 1.25;
}
.cover .placeholder small { font-family: var(--font-body); font-size: .72rem; opacity: .8; margin-top: 8px; }
.ribbon { position: absolute; top: 8px; right: -1px; background: var(--rust); color: #fff; font-size: .66rem; font-weight: 800; padding: 3px 8px 3px 10px; border-radius: 4px 0 0 4px; letter-spacing: .04em; box-shadow: 0 2px 5px rgba(0, 0, 0, .25); }

.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 26px 20px; }
.book-card { cursor: pointer; background: none; border: 0; padding: 0; text-align: left; font: inherit; color: inherit; }
.book-card .cover { transition: transform .18s, box-shadow .18s; }
.book-card:hover .cover, .book-card:focus-visible .cover { transform: translateY(-4px) rotate(-.6deg); box-shadow: var(--shadow-lift); }
.book-card h4 { font-size: .95rem; margin: 10px 0 1px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book-card .author { font-size: .84rem; color: var(--ink-soft); }
.book-card .meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; font-size: .82rem; }

.cover-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 14px; }
.cover-row .book-card h4 { font-size: .8rem; }

/* ---------- table ---------- */

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; font-size: .93rem; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); background: var(--paper); position: sticky; top: 0; cursor: pointer; white-space: nowrap; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #fdf6ea; }
td .thumb { width: 34px; aspect-ratio: 2/3; border-radius: 3px; overflow: hidden; background: var(--linen); }
td .thumb img { width: 100%; height: 100%; object-fit: cover; }
tfoot td { font-weight: 800; background: var(--paper); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.summary-bar { display: flex; gap: 22px; flex-wrap: wrap; margin: -6px 0 18px; color: var(--ink-soft); font-size: .93rem; }
.summary-bar strong { color: var(--walnut-deep); }

/* ---------- dashboard bits ---------- */

.list { display: flex; flex-direction: column; }
.list-item { display: flex; gap: 14px; align-items: center; padding: 11px 0; border-bottom: 1px dashed var(--line); cursor: pointer; }
.list-item:last-child { border-bottom: 0; }
.list-item .cover { width: 44px; flex-shrink: 0; }
.list-item .cover .placeholder { font-size: .5rem; padding: 4px; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 800; color: var(--walnut-deep); }
.date-chip { text-align: center; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 5px 10px; min-width: 62px; flex-shrink: 0; }
.date-chip .d { font-family: var(--font-head); font-size: 1.3rem; font-weight: 600; color: var(--rust); line-height: 1.1; }
.date-chip .m { font-size: .7rem; font-weight: 800; text-transform: uppercase; color: var(--ink-faint); letter-spacing: .06em; }

.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 130px 1fr 34px; gap: 10px; align-items: center; font-size: .9rem; }
.bar-row .track { height: 12px; background: var(--paper); border-radius: 99px; overflow: hidden; }
.bar-row .fill { height: 100%; background: var(--oak); border-radius: 99px; }
.bar-row .n { text-align: right; font-weight: 800; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

.progress { height: 14px; background: var(--paper); border-radius: 99px; overflow: hidden; display: flex; }
.progress span { height: 100%; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: .86rem; color: var(--ink-soft); margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }

.empty { text-align: center; padding: 34px 20px; color: var(--ink-soft); }
.empty .big { font-size: 2.4rem; margin-bottom: 6px; }

/* ---------- scan ---------- */

.scan-hero {
  background: linear-gradient(135deg, var(--walnut) 0%, #5b3b27 100%); color: #f6e7d2;
  border-radius: 18px; padding: 30px 32px; margin-bottom: 24px; position: relative; overflow: hidden;
}
.scan-hero::after { content: '🍂'; position: absolute; right: 26px; top: 14px; font-size: 4.2rem; opacity: .18; transform: rotate(18deg); }
.scan-hero h2 { color: #fff3e1; font-size: 1.5rem; }
.scan-hero p { margin: 6px 0 18px; color: #dbc4a8; }
.scan-form { display: flex; gap: 10px; max-width: 620px; }
.scan-form input { font-size: 1.35rem; padding: 14px 18px; border-radius: 12px; border: 0; letter-spacing: .06em; background: #fffaf2; }
.scan-form input:focus { box-shadow: 0 0 0 4px rgba(198, 150, 58, .5); }
.scan-hero .toggle { color: #e8d4ba; margin-top: 16px; }
.scan-status { margin-top: 14px; font-weight: 700; min-height: 1.5em; color: #f7d9a6; }

.preview { display: grid; grid-template-columns: 220px 1fr; gap: 28px; align-items: start; }
.preview .cover-col { display: flex; flex-direction: column; gap: 10px; }
.warn { background: var(--mustard-soft); border: 1px solid #e8cf96; color: #7a5716; border-radius: var(--radius-sm); padding: 10px 14px; font-weight: 700; font-size: .92rem; margin-bottom: 14px; }

/* ---------- shelves ---------- */

.bookcase { margin-bottom: 34px; }
.bookcase h2 { margin-bottom: 12px; display: flex; align-items: baseline; gap: 10px; }
.bookcase-frame { background: #6b452c; border-radius: 10px; padding: 12px 12px 4px; box-shadow: inset 0 0 0 4px #573622, var(--shadow); }
.shelf { margin-bottom: 8px; }
.shelf-label { font-size: .76rem; font-weight: 800; color: #f1dcc0; text-transform: uppercase; letter-spacing: .08em; padding: 0 4px 6px; }
.shelf-books {
  display: flex; align-items: flex-end; gap: 3px; min-height: 150px; padding: 10px 10px 0; overflow-x: auto;
  background: linear-gradient(180deg, #3e2617 0%, #4b2f1d 100%); border-radius: 4px 4px 0 0;
}
.shelf-plank { height: 14px; background: linear-gradient(180deg, #a87850, #7f5636); border-radius: 0 0 4px 4px; box-shadow: 0 4px 6px rgba(0, 0, 0, .3); }
.spine {
  flex-shrink: 0; border: 0; cursor: pointer; font: inherit;
  writing-mode: vertical-rl; transform: rotate(180deg);
  color: #fff6e8; font-family: var(--font-head); font-size: .78rem; font-weight: 600;
  padding: 10px 4px; border-radius: 3px 3px 2px 2px; text-align: left;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  box-shadow: inset -3px 0 0 rgba(0, 0, 0, .18), inset 2px 0 0 rgba(255, 255, 255, .12);
  transition: transform .15s, filter .15s;
}
.spine:hover { transform: rotate(180deg) translateY(6px); filter: brightness(1.12); }
.spine.found { outline: 3px solid #ffd37a; outline-offset: 2px; animation: glow 1.2s ease-in-out infinite alternate; }
@keyframes glow { from { filter: brightness(1); } to { filter: brightness(1.35); } }

/* ---------- upcoming & subscriptions ---------- */

.release { display: grid; grid-template-columns: 76px 1fr auto; gap: 18px; align-items: center; padding: 16px 0; border-bottom: 1px dashed var(--line); }
.release:last-child { border-bottom: 0; }
.release .countdown { font-weight: 800; color: var(--rust); font-size: .88rem; }
.release .actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.sub-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px; }
.sub-card { cursor: pointer; transition: transform .15s, box-shadow .15s; }
.sub-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); }
.sub-card .price { font-family: var(--font-head); font-size: 1.7rem; color: var(--walnut-deep); }
.sub-card .row { display: flex; justify-content: space-between; gap: 8px; font-size: .9rem; padding: 5px 0; border-top: 1px dashed var(--line); }
.sub-card.cancelled { opacity: .62; }

/* ---------- modal & toast ---------- */

.modal-backdrop { position: fixed; inset: 0; background: rgba(40, 26, 17, .5); backdrop-filter: blur(3px); display: grid; place-items: center; padding: 24px; z-index: 50; animation: fade .15s; }
.modal { background: var(--cream); border-radius: 18px; width: min(980px, 100%); max-height: calc(100vh - 48px); overflow: auto; box-shadow: 0 30px 80px rgba(0, 0, 0, .35); }
.modal.narrow { width: min(640px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 20px 26px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--cream); z-index: 2; }
.modal-body { padding: 24px 26px; }
.modal-foot { display: flex; justify-content: space-between; gap: 10px; padding: 16px 26px; border-top: 1px solid var(--line); background: var(--paper); position: sticky; bottom: 0; flex-wrap: wrap; }
.modal-foot .right { display: flex; gap: 10px; margin-left: auto; }
.icon-btn { border: 0; background: none; font-size: 1.4rem; cursor: pointer; color: var(--ink-soft); width: 38px; height: 38px; border-radius: 50%; }
.icon-btn:hover { background: var(--paper); }
@keyframes fade { from { opacity: 0; } }

.toasts { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 10px; z-index: 60; }
.toast { background: var(--walnut-deep); color: #fbeedc; padding: 12px 18px; border-radius: 12px; box-shadow: var(--shadow-lift); font-weight: 700; font-size: .93rem; animation: slide .25s ease-out; max-width: 380px; }
.toast.error { background: var(--berry); }
@keyframes slide { from { transform: translateY(14px); opacity: 0; } }

.search-results { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; margin-top: 12px; max-height: 340px; overflow: auto; }
.search-hit { display: flex; gap: 12px; align-items: center; padding: 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); cursor: pointer; text-align: left; font: inherit; color: inherit; }
.search-hit:hover { border-color: var(--oak); }
.search-hit img, .search-hit .noimg { width: 40px; aspect-ratio: 2/3; object-fit: cover; border-radius: 3px; background: var(--linen); flex-shrink: 0; }

.callout { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 20px; font-size: .93rem; color: var(--ink-soft); }
.callout ol { margin: 8px 0 0; padding-left: 20px; }
.callout code { background: var(--card); padding: 1px 6px; border-radius: 5px; border: 1px solid var(--line); font-size: .86rem; }

/* ---------- reading progress ---------- */

.reading-row { display: grid; grid-template-columns: 52px 1fr; gap: 14px; padding: 12px 0; border-bottom: 1px dashed var(--line); align-items: center; }
.reading-row:last-child { border-bottom: 0; }
.reading-row .cover { width: 52px; cursor: pointer; }
.reading-row .cover .placeholder { font-size: .5rem; padding: 4px; }
.reading-row .title { font-weight: 800; color: var(--walnut-deep); cursor: pointer; }
.page-bar { height: 8px; background: var(--paper); border-radius: 99px; overflow: hidden; margin: 6px 0 8px; }
.page-bar span { display: block; height: 100%; background: var(--olive); border-radius: 99px; }
.log-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.log-form input { width: 110px; padding: 7px 10px; }
.log-list { list-style: none; padding: 0; margin: 8px 0 0; font-size: .88rem; }
.log-list li { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; border-bottom: 1px dashed var(--line); }
.log-list button { border: 0; background: none; color: var(--ink-faint); cursor: pointer; font-size: 1rem; padding: 2px 6px; }

/* ---------- camera scanner ---------- */

.camera-overlay { position: fixed; inset: 0; z-index: 70; background: #120b07; color: #fbeedc; display: flex; flex-direction: column; }
.camera-overlay video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.camera-top, .camera-bottom { position: relative; z-index: 2; padding: calc(14px + env(safe-area-inset-top)) 18px 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; background: linear-gradient(180deg, rgba(18, 11, 7, .8), transparent); }
.camera-bottom { margin-top: auto; flex-direction: column; padding: 20px 18px calc(22px + env(safe-area-inset-bottom)); background: linear-gradient(0deg, rgba(18, 11, 7, .85), transparent); text-align: center; }
.camera-frame { position: absolute; z-index: 1; left: 50%; top: 45%; width: min(78vw, 420px); height: min(30vw, 170px); transform: translate(-50%, -50%); border-radius: 16px; box-shadow: 0 0 0 9999px rgba(18, 11, 7, .45); border: 3px solid rgba(251, 238, 220, .9); transition: border-color .2s; }
.camera-frame::after { content: ''; position: absolute; left: 8%; right: 8%; top: 50%; height: 2px; background: #e8763f; box-shadow: 0 0 12px #e8763f; animation: scanline 1.6s ease-in-out infinite alternate; }
@keyframes scanline { from { transform: translateY(-50px); } to { transform: translateY(50px); } }
.camera-frame.hit { border-color: #9fd36b; }
.camera-msg { font-weight: 800; font-size: 1.05rem; min-height: 1.5em; }
.camera-close { background: rgba(251, 238, 220, .16); color: #fff; border: 0; border-radius: 999px; padding: 10px 18px; font: inherit; font-weight: 800; cursor: pointer; }
.camera-chip { background: rgba(251, 238, 220, .14); padding: 6px 14px; border-radius: 99px; font-size: .88rem; font-weight: 700; }

/* ---------- trends ---------- */

.wrapped-hero {
  background: radial-gradient(circle at 85% 15%, rgba(232, 118, 63, .35), transparent 45%), linear-gradient(135deg, var(--walnut) 0%, var(--walnut-deep) 100%);
  color: #f6e7d2; border-radius: 20px; padding: 30px 32px; margin-bottom: 22px;
  display: grid; grid-template-columns: 1fr auto; gap: 24px; align-items: center;
}
.wrapped-hero h2 { color: #fff3e1; font-size: 1.7rem; }
.wrapped-hero .big-stats { display: flex; gap: 34px; flex-wrap: wrap; margin-top: 18px; }
.wrapped-hero .big-stats div { display: flex; flex-direction: column; }
.wrapped-hero .big-stats b { font-family: var(--font-head); font-size: 2.3rem; font-weight: 600; color: #fff6ea; line-height: 1.1; }
.wrapped-hero .big-stats span { font-size: .85rem; color: #d8bf9f; font-weight: 700; }
.goal-ring { width: 150px; text-align: center; }
.goal-ring svg { width: 150px; height: 150px; }
.goal-ring .btn { margin-top: 8px; }

.highlights { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; margin-bottom: 22px; }
.highlight { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px; min-height: 140px; }
.highlight .label { font-size: .78rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); }
.highlight .value { font-family: var(--font-head); font-size: 1.35rem; font-weight: 600; color: var(--walnut-deep); line-height: 1.2; }
.highlight .sub { font-size: .88rem; color: var(--ink-soft); }
.highlight .covers { display: flex; gap: 6px; margin-top: auto; padding-top: 8px; }
.highlight .covers .cover { width: 40px; }
.highlight .covers .cover .placeholder { font-size: .45rem; padding: 3px; }
.highlight.feature { flex-direction: row; gap: 14px; align-items: center; }
.highlight.feature .cover { width: 70px; flex-shrink: 0; }

.chart { display: flex; flex-direction: column; gap: 6px; }
.chart-bars { display: flex; align-items: flex-end; gap: 3px; height: 180px; border-bottom: 1px solid var(--line); position: relative; margin-right: 34px; }
.chart-bars .col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; position: relative; cursor: default; min-width: 0; }
.chart-bars .col:hover .bar { filter: brightness(1.1); }
.chart-bars .bar { width: 100%; max-width: 44px; background: var(--oak); border-radius: 4px 4px 0 0; min-height: 0; transition: height .4s; }
.chart-bars .bar.today { background: var(--rust); }
.chart-bars .val { font-size: .74rem; font-weight: 800; color: var(--ink-soft); margin-bottom: 3px; font-variant-numeric: tabular-nums; }
.chart-bars .grid-line { position: absolute; left: 0; right: 0; border-top: 1px dashed var(--line); font-size: .7rem; color: var(--ink-faint); pointer-events: none; }
.chart-bars .grid-line span { position: absolute; left: calc(100% + 6px); top: -9px; }
.chart-labels { display: flex; gap: 3px; font-size: .74rem; color: var(--ink-faint); margin-right: 34px; }
.chart-labels span { flex: 1; text-align: center; min-width: 0; overflow: hidden; white-space: nowrap; }

.heatmap-wrap { overflow-x: auto; padding-bottom: 6px; }
.heatmap { display: grid; grid-template-rows: repeat(7, 13px); grid-auto-flow: column; grid-auto-columns: 13px; gap: 3px; width: max-content; }
.heatmap i { border-radius: 3px; background: var(--paper); outline: 1px solid rgba(58, 42, 31, .04); }
.heatmap i[data-l="1"] { background: #efd3bd; } .heatmap i[data-l="2"] { background: #dea27b; }
.heatmap i[data-l="3"] { background: #c06a3c; } .heatmap i[data-l="4"] { background: #87391a; }
.heatmap i.blank { background: transparent; outline: 0; }
.heat-months { display: grid; grid-auto-flow: column; grid-auto-columns: 16px; font-size: .72rem; color: var(--ink-faint); margin-bottom: 4px; width: max-content; }
.heat-legend { display: flex; gap: 4px; align-items: center; font-size: .78rem; color: var(--ink-faint); margin-top: 8px; }
.heat-legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

.rank { display: flex; flex-direction: column; }
.rank-row { display: grid; grid-template-columns: 26px 40px 1fr auto; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.rank-row:last-child { border-bottom: 0; }
.rank-row .n { font-family: var(--font-head); font-size: 1.2rem; color: var(--rust); text-align: center; }
.rank-row .cover { width: 40px; }
.rank-row .cover .placeholder { font-size: .42rem; padding: 3px; }

.tooltip { position: fixed; z-index: 80; pointer-events: none; background: var(--walnut-deep); color: #fbeedc; padding: 7px 11px; border-radius: 9px; font-size: .84rem; font-weight: 700; box-shadow: var(--shadow-lift); transform: translate(-50%, calc(-100% - 10px)); white-space: nowrap; }
.tooltip small { display: block; font-weight: 600; color: #d8bf9f; }

/* Wrapped story (full screen, tap to advance) */
.story { position: fixed; inset: 0; z-index: 75; color: #fff6ea; display: flex; flex-direction: column; user-select: none; background: var(--story-bg, #4a3223); transition: background .5s; }
.story-bars { display: flex; gap: 5px; padding: calc(14px + env(safe-area-inset-top)) 16px 0; }
.story-bars i { flex: 1; height: 4px; border-radius: 4px; background: rgba(255, 246, 234, .3); overflow: hidden; }
.story-bars i.done { background: #fff6ea; }
.story-close { position: absolute; top: calc(26px + env(safe-area-inset-top)); right: 14px; z-index: 2; background: none; border: 0; color: #fff6ea; font-size: 1.6rem; cursor: pointer; padding: 6px 10px; }
.story-slide { flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: 30px 28px calc(30px + env(safe-area-inset-bottom)); gap: 14px; animation: rise .5s ease-out; }
.story-slide .kicker { font-weight: 800; text-transform: uppercase; letter-spacing: .14em; font-size: .85rem; opacity: .8; }
.story-slide .huge { font-family: var(--font-head); font-size: clamp(3.4rem, 16vw, 7rem); font-weight: 600; line-height: 1; }
.story-slide h2 { color: #fff6ea; font-size: clamp(1.6rem, 6vw, 2.6rem); max-width: 16em; }
.story-slide p { font-size: 1.1rem; max-width: 26em; opacity: .9; margin: 0; }
.story-slide .cover { width: min(42vw, 190px); box-shadow: 0 20px 50px rgba(0, 0, 0, .4); }
.story-slide .cover-fan { display: flex; justify-content: center; }
.story-slide .cover-fan .cover { width: min(26vw, 120px); margin: 0 -10px; }
.story-slide .cover-fan .cover:nth-child(odd) { transform: rotate(-6deg); }
.story-slide .cover-fan .cover:nth-child(even) { transform: rotate(5deg) translateY(10px); }
.story-hint { text-align: center; font-size: .8rem; opacity: .6; padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
@keyframes rise { from { opacity: 0; transform: translateY(18px); } }

/* ---------- sign-in pages ---------- */

body.auth-page { min-height: 100vh; display: grid; place-items: center; padding: calc(24px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom)); background: radial-gradient(circle at 80% 10%, rgba(232, 118, 63, .25), transparent 40%), linear-gradient(160deg, var(--walnut) 0%, var(--walnut-deep) 100%); }
.auth-card { width: min(420px, 100%); background: var(--cream); border-radius: 22px; padding: 34px 30px 28px; box-shadow: 0 30px 80px rgba(0, 0, 0, .35); text-align: center; }
.auth-card .brand-mark { margin: 0 auto 14px; width: 62px; height: 62px; font-size: 1.9rem; border-radius: 16px; }
.auth-card .credit-line { margin: 4px 0 0; color: var(--ink-faint); font-style: italic; font-size: .9rem; }
.auth-form { display: flex; flex-direction: column; gap: 14px; margin-top: 24px; text-align: left; }
.auth-form input { font-size: 16px; padding: 12px 14px; }
.auth-form .btn { width: 100%; }
.auth-msg { color: var(--berry); font-weight: 700; font-size: .92rem; min-height: 0; }
.auth-msg:empty { display: none; }
.auth-msg.ok { color: #4e5a2e; }
.signed-in { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; padding-top: 12px; border-top: 1px solid rgba(255, 255, 255, .08); }
.signed-in span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.signed-in button { align-self: flex-start; background: rgba(255, 240, 220, .1); color: #f3e6d3; border: 0; border-radius: 99px; padding: 5px 12px; font: inherit; font-weight: 700; font-size: .8rem; cursor: pointer; }
.signed-in button:hover { background: rgba(255, 240, 220, .2); }
.nav-signout { display: none !important; }

/* ---------- responsive ---------- */

@media (max-width: 1080px) {
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .wrapped-hero { grid-template-columns: 1fr; }
  .main { padding: 28px 26px 70px; }
}
@media (max-width: 820px) {
  html { font-size: 16px; }
  .app { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; height: auto; z-index: 20; flex-direction: row; align-items: center; padding: calc(10px + env(safe-area-inset-top)) 12px 10px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .sidebar::-webkit-scrollbar { display: none; }
  input, select, textarea { font-size: 16px; } /* stops iPhone zooming in on form fields */
  .wrapped-hero { padding: 24px 20px; }
  .wrapped-hero .big-stats { gap: 22px; }
  .wrapped-hero .big-stats b { font-size: 1.9rem; }
  .highlights { grid-template-columns: 1fr 1fr; gap: 12px; }
  .highlight { padding: 14px; min-height: 0; }
  .highlight.feature { grid-column: span 2; }
  .chart-bars { height: 150px; }
  .toolbar input[type=search] { max-width: none; flex: 1 1 100%; }
  .tiles { grid-template-columns: 1fr 1fr; gap: 12px; }
  .tile { padding: 14px 14px 14px 18px; }
  .tile .value { font-size: 1.6rem; }
  h1 { font-size: 1.7rem; }
  .brand { padding: 0 8px 0 0; }
  .brand h1, .brand small, .sidebar-foot { display: none; }
  .nav-signout { display: flex !important; }
  .nav { display: flex; gap: 4px; }
  .nav a { padding: 8px 12px; white-space: nowrap; font-size: .88rem; }
  .main { padding: 22px 16px calc(60px + env(safe-area-inset-bottom)); }
  .preview { grid-template-columns: 1fr; }
  .preview .cover-col { max-width: 200px; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span-3, .span-4, .span-6, .form-section { grid-column: span 2; }
  .span-2 { grid-column: span 1; }
  .release { grid-template-columns: 56px 1fr; }
  .release .actions { grid-column: span 2; justify-content: flex-start; }
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 20px 14px; }
  .scan-form { flex-direction: column; }
  .modal-backdrop { padding: 0; }
  .modal { max-height: 100vh; border-radius: 0; }
}
