/* =========================================================================
   Minha Estante — its own identity: warm paper, deep ink,
   serif type for headings and the cover as the main visual element.
   ========================================================================= */

:root {
  --paper:        #faf7f1;
  --paper-raised: #ffffff;
  --paper-sunken: #f2ede4;
  --ink:          #211d18;
  --ink-soft:     #5c554b;
  --ink-faint:    #8d8679;
  --line:         #e3dcd0;
  --line-strong:  #d2c9b9;
  --brass:        #8a5f2b;
  --brass-soft:   #f0e4d2;
  --sage:         #4a6b5a;
  --plum:         #7a3f52;
  --star:         #c08a2e;
  --shadow-sm:    0 1px 2px rgba(33, 29, 24, .06);
  --shadow-md:    0 4px 16px rgba(33, 29, 24, .10);
  --shadow-cover: 0 6px 18px rgba(33, 29, 24, .18);

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", sans-serif;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --nav-w: 232px;
  --page-max: 1180px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #16150f; --paper-raised: #1f1d16; --paper-sunken: #121109;
    --ink: #f0eadd; --ink-soft: #b7ae9e; --ink-faint: #857d6e;
    --line: #302d23; --line-strong: #423e31;
    --brass: #d6a35c; --brass-soft: #2c2519;
    --sage: #86ab94; --plum: #d094a5; --star: #e0b05a;
    --shadow-cover: 0 6px 20px rgba(0,0,0,.55); --shadow-md: 0 4px 16px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  --paper: #16150f; --paper-raised: #1f1d16; --paper-sunken: #121109;
  --ink: #f0eadd; --ink-soft: #b7ae9e; --ink-faint: #857d6e;
  --line: #302d23; --line-strong: #423e31;
  --brass: #d6a35c; --brass-soft: #2c2519;
  --sage: #86ab94; --plum: #d094a5; --star: #e0b05a;
  --shadow-cover: 0 6px 20px rgba(0,0,0,.55); --shadow-md: 0 4px 16px rgba(0,0,0,.4);
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0; letter-spacing: -.01em; }
h1 { font-size: 1.95rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; }

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }
::selection { background: var(--brass-soft); }
:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; border-radius: var(--r-sm); }

/* ------------------------------------------------------------------ layout */

.app { display: flex; min-height: 100vh; }

.nav {
  position: sticky; top: 0; align-self: flex-start;
  width: var(--nav-w); height: 100vh; flex: none;
  padding: 28px 18px 20px;
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 22px;
  background: var(--paper);
}

.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.brand-mark { width: 26px; height: 26px; flex: none; color: var(--brass); }
.brand-name { font-family: var(--serif); font-size: 1.1rem; font-weight: 600; letter-spacing: -.01em; }

.nav-add {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 11px 14px;
  background: var(--ink); color: var(--paper);
  border: none; border-radius: var(--r-md);
  font-weight: 600; font-size: .92rem; cursor: pointer;
  transition: transform .12s ease, opacity .12s ease;
}
.nav-add svg { width: 16px; height: 16px; flex: none; }
.nav-add:hover { opacity: .88; }
.nav-add:active { transform: scale(.985); }

.nav-links { display: flex; flex-direction: column; gap: 1px; }
.nav-link {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; border-radius: var(--r-md);
  color: var(--ink-soft); font-size: .93rem; font-weight: 500;
  transition: background .12s ease, color .12s ease;
}
.nav-link svg { width: 17px; height: 17px; flex: none; opacity: .75; }
.nav-link:hover { background: var(--paper-sunken); color: var(--ink); }
.nav-link.is-active { background: var(--brass-soft); color: var(--brass); font-weight: 600; }
.nav-link.is-active svg { opacity: 1; }
.nav-link .count { margin-left: auto; font-size: .78rem; color: var(--ink-faint); font-variant-numeric: tabular-nums; }
.nav-link.nav-sub { padding: 6px 12px 6px 40px; font-size: .87rem; }
.nav-link.nav-sub svg { width: 15px; height: 15px; }
.nav-sep { height: 1px; background: var(--line); margin: 4px 10px; }
.nav-foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; padding: 0 6px; }
.nav-user { font-size: .82rem; color: var(--ink-faint); }

.main { flex: 1; min-width: 0; overflow-x: clip; }
.page { max-width: var(--page-max); margin: 0 auto; padding: 34px 32px 96px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap; margin-bottom: 26px; }
.page-head .sub { color: var(--ink-faint); font-size: .9rem; margin-top: 4px; }
.section { margin-top: 44px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.section-head h2 { font-size: 1.15rem; }
.section-head .more { font-size: .85rem; color: var(--brass); font-weight: 500; }

/* ------------------------------------------------------------------ login */

.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 16px;
  padding: 28px 24px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--paper-raised); box-shadow: var(--shadow-md);
}
.login-card .login-brand { display: flex; padding: 0 0 6px; }
.login-error { min-height: 1.2em; margin: -6px 0 0; font-size: .85rem; color: var(--plum); }
.login-error:empty { display: none; }

/* -------------------------------------------------------------------- hub */

.hub {
  max-width: 480px; margin: 0 auto; min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; gap: 28px;
  padding: 64px 16px 40px;
}
.hub-head { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.hub-head .sub { color: var(--ink-faint); font-size: .9rem; }
.hub-avatar {
  width: 72px; height: 72px; border-radius: 50%; display: grid; place-items: center; margin-bottom: 6px;
  background: var(--brass-soft); color: var(--brass); font-family: var(--serif); font-size: 2rem; font-weight: 600;
}
.hub-links { width: 100%; display: flex; flex-direction: column; gap: 12px; }
.hub-link {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px;
  border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--paper-raised);
  box-shadow: var(--shadow-sm); transition: transform .12s ease, border-color .12s ease;
}
.hub-link:hover { border-color: var(--brass); transform: translateY(-1px); }
.hub-link > svg { width: 18px; height: 18px; flex: none; margin-left: auto; color: var(--ink-faint); }
.hub-link-icon {
  width: 44px; height: 44px; flex: none; display: grid; place-items: center;
  border-radius: var(--r-md); background: var(--brass-soft); color: var(--brass);
}
.hub-link-icon svg { width: 24px; height: 24px; }
.hub-link-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.hub-link-text strong { font-family: var(--serif); font-size: 1.05rem; }
.hub-link-text span { font-size: .85rem; color: var(--ink-faint); }
.hub-logout { margin-top: auto; }
.hub-logout svg { width: 16px; height: 16px; }

/* --------------------------------------------------------------- launcher */

.nav-top { display: flex; align-items: center; justify-content: space-between; gap: 2px; }
.nav-top .brand { min-width: 0; padding-right: 0; }
.nav-top .brand-name { white-space: nowrap; }
.nav-top .btn-icon { padding: 6px; }
.launcher {
  position: fixed; z-index: 90; width: 296px; max-width: calc(100vw - 16px);
  padding: 10px; border: 1px solid var(--line); border-radius: var(--r-lg);
  background: var(--paper-raised); box-shadow: var(--shadow-md);
}
.launcher-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.launcher-tile {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 14px 6px 12px; border-radius: var(--r-md); text-align: center;
  font-size: .82rem; color: var(--ink-soft);
}
.launcher-tile:hover, .launcher-tile:focus-visible { background: var(--paper-sunken); color: var(--ink); }
.launcher-tile.is-current { background: var(--brass-soft); color: var(--brass); font-weight: 600; }
.launcher-icon {
  width: 44px; height: 44px; display: grid; place-items: center;
  border-radius: 50%; background: var(--brass-soft); color: var(--brass);
}
.launcher-tile.is-current .launcher-icon { background: var(--paper-raised); }
.launcher-icon svg { width: 22px; height: 22px; }
.launcher-label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ------------------------------------------------------------- mobile top */

.topbar { display: none; }

@media (max-width: 860px) {
  .app { flex-direction: column; }
  .nav {
    position: fixed; bottom: 0; top: auto; left: 0; right: 0;
    width: 100%; height: auto; z-index: 40;
    flex-direction: row; align-items: center; gap: 0;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    border-right: none; border-top: 1px solid var(--line);
    background: color-mix(in srgb, var(--paper) 94%, transparent);
    backdrop-filter: blur(12px);
  }
  .nav-top, .nav-sep, .nav-foot, .nav-add { display: none; }
  .nav-links { flex-direction: row; width: 100%; gap: 0; }
  .nav-link { flex: 1 1 0; min-width: 0; flex-direction: column; gap: 3px; padding: 7px 2px; font-size: .68rem; text-align: center; border-radius: var(--r-sm); }
  /* Label on a single line; if it does not fit, ellipsis instead of wrapping. */
  .nav-link span { max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .nav-link svg { width: 20px; height: 20px; }
  .nav-link .count { display: none; }
  .nav-link.is-active { background: transparent; }
  /* Submenus leave the bar; Shelf stays highlighted in any of its subsections. */
  .nav-link.nav-sub { display: none; }
  .nav-link.in-section { color: var(--brass); font-weight: 600; }
  .nav-link.in-section svg { opacity: 1; }
  .topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    position: sticky; top: 0; z-index: 30; padding: 12px 16px;
    background: color-mix(in srgb, var(--paper) 92%, transparent);
    backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
  }
  .topbar .brand { display: flex; padding: 0; }
  .topbar-actions { display: flex; gap: 6px; }
  .page { padding: 20px 16px 110px; }
  h1 { font-size: 1.6rem; }

  /* Filters become a horizontal scrolling strip instead of stacking. */
  .filter-bar {
    flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
    margin-left: -16px; margin-right: -16px; padding: 12px 16px 14px;
  }
  .filter-bar::-webkit-scrollbar { display: none; }
  .filter-bar > * { flex: none; }
  .filter-bar .toolbar-spacer { display: none; }
}

/* ----------------------------------------------------------------- buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 15px; border-radius: var(--r-md);
  border: 1px solid var(--line-strong); background: var(--paper-raised);
  color: var(--ink); font-size: .88rem; font-weight: 500; cursor: pointer;
  transition: background .12s ease, border-color .12s ease, transform .1s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--paper-sunken); }
.btn:active { transform: scale(.98); }
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn-primary:hover { background: var(--ink); opacity: .88; }
.btn-brass { background: var(--brass); border-color: var(--brass); color: #fff; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: var(--paper-sunken); color: var(--ink); }
.btn-sm { padding: 6px 11px; font-size: .82rem; }
.btn-icon { padding: 8px; border-radius: 50%; }
.btn-danger { color: var(--plum); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ------------------------------------------------------------------- forms */

.field { display: flex; flex-direction: column; gap: 5px; }
.field > label { font-size: .78rem; font-weight: 600; color: var(--ink-soft); letter-spacing: .02em; text-transform: uppercase; }
.input, .select, .textarea {
  width: 100%; padding: 10px 12px;
  background: var(--paper-raised); border: 1px solid var(--line-strong);
  border-radius: var(--r-md); font-size: .92rem;
  transition: border-color .12s ease, box-shadow .12s ease;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--brass);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brass) 18%, transparent);
}
.textarea { min-height: 96px; resize: vertical; line-height: 1.6; font-family: var(--serif); font-size: 1rem; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1 1 150px; }
.hint { font-size: .78rem; color: var(--ink-faint); }

/* --------------------------------------------------------------- chips */

.chips { display: flex; gap: 7px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 999px;
  border: 1px solid var(--line-strong); background: transparent;
  font-size: .82rem; color: var(--ink-soft); cursor: pointer; transition: all .12s ease;
}
.chip { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip:hover { border-color: var(--ink-faint); color: var(--ink); }
.chip.is-active { background: var(--ink); border-color: var(--ink); color: var(--paper); font-weight: 600; }
.chip .n { font-variant-numeric: tabular-nums; opacity: .65; font-size: .76rem; }
.chip-static { cursor: default; }
.chip-tag { background: var(--brass-soft); border-color: transparent; color: var(--brass); }

/* ------------------------------------------------------------------- shelf */

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; }
.toolbar-spacer { flex: 1; }
/* Shelf subsection tabs: on desktop the sidebar already covers them. */
@media (min-width: 861px) { .mobile-only { display: none !important; } }
.view-toggle { display: flex; border: 1px solid var(--line-strong); border-radius: var(--r-md); overflow: hidden; }
.view-toggle button { padding: 7px 10px; background: transparent; border: none; cursor: pointer; color: var(--ink-faint); display: flex; }
.view-toggle button svg { width: 16px; height: 16px; }
.view-toggle button.is-active { background: var(--paper-sunken); color: var(--ink); }
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 14px 0 18px; border-bottom: 1px solid var(--line); margin-bottom: 22px; }
.filter-bar .select { width: auto; min-width: 128px; padding: 7px 10px; font-size: .84rem; border-radius: var(--r-sm); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(146px, 1fr)); gap: 30px 22px; }
@media (max-width: 560px) { .grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 24px 14px; } }

.book-card { display: flex; flex-direction: column; gap: 9px; cursor: pointer; }
.book-card:hover .cover { transform: translateY(-4px); box-shadow: 0 12px 26px rgba(33, 29, 24, .22); }

.cover {
  position: relative; aspect-ratio: 2 / 3; width: 100%;
  border-radius: var(--r-sm); overflow: hidden;
  background: var(--paper-sunken); box-shadow: var(--shadow-cover);
  transition: transform .18s ease, box-shadow .18s ease;
}
.cover img { width: 100%; height: 100%; object-fit: cover; }
.cover-fallback {
  display: flex; flex-direction: column; justify-content: space-between; height: 100%; padding: 12px 10px;
  background: linear-gradient(160deg, var(--paper-sunken), color-mix(in srgb, var(--brass) 14%, var(--paper-sunken)));
}
.cover-fallback .t { font-family: var(--serif); font-size: .82rem; font-weight: 600; line-height: 1.25; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; }
.cover-fallback .a { font-size: .7rem; color: var(--ink-faint); }
.cover-fallback::after { content: ""; position: absolute; inset: 0 auto 0 0; width: 5px; background: color-mix(in srgb, var(--brass) 40%, transparent); }

.cover-badge {
  position: absolute; top: 7px; right: 7px; padding: 3px 7px; border-radius: 999px;
  font-size: .66rem; font-weight: 700; letter-spacing: .03em; text-transform: uppercase;
  background: color-mix(in srgb, #000 62%, transparent); color: #fff; backdrop-filter: blur(4px);
}
.cover-fav { position: absolute; top: 7px; left: 7px; color: #fff; filter: drop-shadow(0 1px 2px rgba(0,0,0,.5)); }
.cover-fav svg { width: 15px; height: 15px; }
/* Trash button that shows on card hover (or focus); the "Lendo" badge moves out of the way. */
.cover-remove {
  position: absolute; top: 6px; right: 6px; width: 30px; height: 30px; border: none; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer; color: #fff;
  background: color-mix(in srgb, #000 62%, transparent); backdrop-filter: blur(4px);
  opacity: 0; transform: scale(.85); transition: opacity .15s ease, transform .15s ease, background .15s ease;
}
.cover-remove svg { width: 15px; height: 15px; }
.cover-remove:hover, .cover-remove:focus-visible { background: #b3261e; }
.book-card:hover .cover-remove, .book-card:focus-within .cover-remove { opacity: 1; transform: none; }
.cover-badge { transition: opacity .15s ease; }
.book-card:hover .cover-badge, .book-card:focus-within .cover-badge { opacity: 0; }
.row-remove { opacity: 0; transition: opacity .15s ease; }
.row-remove svg { width: 16px; height: 16px; }
.list-row:hover .row-remove, .list-row:focus-within .row-remove { opacity: 1; }
.row-remove:hover { color: #b3261e; }
/* Touch screens have no hover: the trash button is always visible. */
@media (hover: none) {
  .cover-remove, .row-remove { opacity: 1; transform: none; }
}
.cover-progress { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: color-mix(in srgb, #000 35%, transparent); }
.cover-progress span { display: block; height: 100%; background: var(--brass); }

.book-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.book-title { font-family: var(--serif); font-size: .93rem; font-weight: 600; line-height: 1.25; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.book-author { font-size: .79rem; color: var(--ink-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-sub { font-size: .76rem; color: var(--ink-faint); display: flex; align-items: center; gap: 6px; }

.list { display: flex; flex-direction: column; }
.list-row { display: grid; grid-template-columns: 46px 1fr auto; gap: 16px; align-items: center; padding: 12px 6px; border-bottom: 1px solid var(--line); cursor: pointer; }
.list-row:hover { background: var(--paper-sunken); }
.list-row .cover { box-shadow: var(--shadow-sm); }
.list-row .book-title { -webkit-line-clamp: 1; font-size: 1rem; }
.list-right { display: flex; align-items: center; gap: 14px; font-size: .8rem; color: var(--ink-faint); }
@media (max-width: 560px) { .list-right .hide-sm { display: none; } }

/* ------------------------------------------------------------------- stars */

.stars { display: inline-flex; gap: 2px; color: var(--star); }
.stars svg { width: 14px; height: 14px; }
.stars.lg svg { width: 26px; height: 26px; }
.stars-input { display: inline-flex; align-items: center; gap: 3px; }
.stars-input button { background: none; border: none; padding: 2px; cursor: pointer; color: var(--line-strong); display: flex; transition: transform .1s ease, color .1s ease; }
.stars-input button svg { width: 27px; height: 27px; }
.stars-input button:hover { transform: scale(1.12); }
.stars-input button.on { color: var(--star); }

/* --------------------------------------------------------------- book page */

.book-page { display: grid; grid-template-columns: 268px 1fr; gap: 44px; align-items: start; }
.book-page > * { min-width: 0; }
@media (max-width: 760px) { .book-page { grid-template-columns: 1fr; gap: 26px; } }

.book-hero-cover { position: sticky; top: 28px; display: flex; flex-direction: column; gap: 14px; }
@media (max-width: 760px) {
  .book-hero-cover { position: static; flex-direction: row; gap: 18px; align-items: flex-start; }
  .book-hero-cover .cover { width: 132px; flex: none; }
  .book-hero-cover .hero-actions { flex: 1; }
}
.hero-actions { display: flex; flex-direction: column; gap: 8px; }

.book-headline h1 { font-size: 2.1rem; overflow-wrap: break-word; }
.book-headline .subtitle { font-family: var(--serif); font-size: 1.15rem; color: var(--ink-soft); font-style: italic; margin-top: 4px; }
.book-headline .author { font-size: 1rem; color: var(--ink-soft); margin-top: 10px; }
@media (max-width: 560px) { .book-headline h1 { font-size: 1.5rem; } }

.meta-grid { display: flex; flex-wrap: wrap; gap: 6px 28px; margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.meta-item dt { color: var(--ink-faint); font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; }
.meta-item dd { margin: 2px 0 0; font-size: .86rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.status-switch { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 24px; }
.status-switch button {
  flex: 1 1 110px; padding: 10px 14px; border-radius: var(--r-md);
  border: 1px solid var(--line-strong); background: var(--paper-raised);
  font-size: .86rem; font-weight: 600; cursor: pointer; color: var(--ink-soft); transition: all .12s ease;
}
.status-switch button:hover { border-color: var(--ink-faint); color: var(--ink); }
.status-switch button.on { background: var(--ink); border-color: var(--ink); color: var(--paper); }

.panel { background: var(--paper-raised); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 20px; }
.panel + .panel { margin-top: 16px; }
/* On the book page, the first panel comes right after the status buttons. */
.status-switch + .panel { margin-top: 18px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.panel-head h3 { font-size: 1rem; }

.progress-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.progress-figure { font-family: var(--serif); font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.progress-figure span { color: var(--ink-faint); font-size: .95rem; }
.bar { height: 7px; border-radius: 999px; background: var(--paper-sunken); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--brass); border-radius: 999px; transition: width .3s ease; }
.bar-lg { height: 11px; }
.progress-input { display: flex; gap: 8px; align-items: center; }
.progress-input .input { width: 92px; text-align: center; font-variant-numeric: tabular-nums; }

.review { font-family: var(--serif); font-size: 1.02rem; line-height: 1.7; white-space: pre-wrap; }
.description { font-family: var(--serif); font-size: 1rem; line-height: 1.75; color: var(--ink-soft); white-space: pre-wrap; }
.description.clamped { display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }

.notes { display: flex; flex-direction: column; }
.note { padding: 14px 0; border-top: 1px solid var(--line); display: flex; gap: 14px; }
.note:first-child { border-top: none; padding-top: 0; }
.note-page { flex: none; width: 54px; font-size: .74rem; color: var(--brass); font-weight: 700; text-transform: uppercase; letter-spacing: .03em; padding-top: 2px; }
.note-body { flex: 1; min-width: 0; }
.note-text { font-family: var(--serif); font-size: 1rem; line-height: 1.65; white-space: pre-wrap; }
.note-foot { display: flex; align-items: center; gap: 10px; margin-top: 6px; font-size: .74rem; color: var(--ink-faint); }

/* -------------------------------------------------------------- dashboard */

.greeting { font-family: var(--serif); font-size: 2.2rem; margin-bottom: 2px; }
@media (max-width: 560px) { .greeting { font-size: 1.7rem; } }

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); gap: 1px; margin-top: 26px; border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; background: var(--line); }
.stat { background: var(--paper-raised); padding: 18px; display: flex; flex-direction: column; gap: 2px; }
.stat .v { font-family: var(--serif); font-size: 2rem; line-height: 1; font-variant-numeric: tabular-nums; }
.stat .l { font-size: .78rem; color: var(--ink-faint); }

.goal-card { margin-top: 18px; padding: 22px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--paper-raised); }
.goal-card .top { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.goal-fig { font-family: var(--serif); font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.goal-fig span { color: var(--ink-faint); font-size: 1rem; }
.goal-note { margin-top: 12px; font-size: .86rem; display: flex; align-items: center; gap: 7px; color: var(--sage); }
.goal-note.off { color: var(--plum); }
.goal-note svg { width: 15px; height: 15px; flex: none; }
/* Covers of a goal's books; read ones get a check badge. */
.goal-books { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-top: 16px; }
.goal-book { position: relative; width: 58px; flex: none; }
.goal-book .cover { box-shadow: var(--shadow-cover); }
.goal-book:not(.is-read) .cover { opacity: .6; }
.goal-book:hover .cover { opacity: 1; transform: translateY(-3px); }
.goal-book .cover-badge { font-size: .5rem; padding: 2px 4px; top: 4px; right: 4px; }
.goal-book-check {
  position: absolute; right: -5px; bottom: -5px; width: 20px; height: 20px; border-radius: 50%;
  display: grid; place-items: center; background: var(--sage); color: #fff; box-shadow: 0 0 0 2px var(--paper-raised);
}
.goal-book-check svg { width: 12px; height: 12px; }
.goal-book-more { align-self: center; }
/* Picking the goal's books. */
.goal-picker { max-height: 46vh; overflow-y: auto; margin-top: 8px; border: 1px solid var(--line); border-radius: var(--r-md, 8px); }
.goal-pick { display: grid; grid-template-columns: auto 34px 1fr auto; gap: 12px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.goal-pick:last-child { border-bottom: none; }
.goal-pick:hover { background: var(--paper-sunken); }
.goal-pick input { width: 17px; height: 17px; accent-color: var(--brass); }
.goal-stats { display: flex; gap: 22px; flex-wrap: wrap; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.goal-stats div { font-size: .8rem; color: var(--ink-faint); }
.goal-stats b { display: block; font-family: var(--serif); font-size: 1.1rem; color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }

.reading-strip { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.reading-item { display: flex; gap: 16px; padding: 16px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--paper-raised); cursor: pointer; transition: box-shadow .15s ease; }
.reading-item:hover { box-shadow: var(--shadow-md); }
.reading-item .cover { width: 66px; flex: none; }
.reading-item .info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.reading-item .bar { margin-top: auto; }

.rail { display: flex; gap: 18px; overflow-x: auto; padding-bottom: 6px; scroll-snap-type: x mandatory; scrollbar-width: thin; }
.rail::-webkit-scrollbar { height: 6px; }
.rail::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 999px; }
.rail .book-card { width: 124px; flex: none; scroll-snap-align: start; }

/* ------------------------------------------------------------------- stats */

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.chart { width: 100%; height: auto; overflow: visible; display: block; }
.chart .axis { stroke: var(--line); stroke-width: 1; }
.chart .label { fill: var(--ink-faint); font-size: 10px; font-family: var(--sans); }
.chart .value { fill: var(--ink-soft); font-size: 10px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chart .bar-rect { fill: var(--brass); }
.chart .bar-rect.muted { fill: color-mix(in srgb, var(--brass) 35%, transparent); }

.ranklist { display: flex; flex-direction: column; gap: 10px; }
.rank { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; }
.rank .n { font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank .c { font-size: .78rem; color: var(--ink-faint); font-variant-numeric: tabular-nums; }
.rank .bar { grid-column: 1 / -1; height: 5px; }

.superlatives { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; }
.superlative { display: flex; gap: 12px; align-items: center; cursor: pointer; }
.superlative .cover { width: 48px; flex: none; }
.superlative .k { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-faint); }

/* -------------------------------------------------------------- modal */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: color-mix(in srgb, #1a1710 55%, transparent);
  backdrop-filter: blur(3px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 7vh 16px 16px; overflow-y: auto; animation: fade .16s ease;
}
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

.modal {
  width: 100%; max-width: 620px; background: var(--paper);
  border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: 0 24px 60px rgba(0,0,0,.3); animation: rise .18s ease; overflow: hidden;
}
.modal-wide { max-width: 760px; }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { flex: 1; font-size: 1.1rem; }
.modal-body { padding: 18px; display: flex; flex-direction: column; gap: 16px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 18px; border-top: 1px solid var(--line); background: var(--paper-sunken); }
@media (max-width: 560px) {
  .modal-backdrop { padding: 0; }
  .modal { min-height: 100%; border-radius: 0; border: none; max-width: none; }
}

.search-input-wrap { position: relative; }
.search-input-wrap .input { padding: 13px 40px; font-size: 1rem; }
.search-input-wrap .ico { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--ink-faint); display: flex; }
.search-input-wrap .ico svg { width: 17px; height: 17px; }
/* Search in progress: old results dimmed and the "Buscando..." row. */
.results.is-loading > :not(.searching) { opacity: .45; transition: opacity .15s ease; }
.results .searching { padding: 12px 18px 6px; }

.results { display: flex; flex-direction: column; max-height: 52vh; overflow-y: auto; margin: 0 -18px; }
.result {
  display: grid; grid-template-columns: 44px 1fr auto; gap: 14px; align-items: center;
  padding: 11px 18px; cursor: pointer; border: none; background: none; text-align: left; width: 100%;
  border-top: 1px solid var(--line); color: inherit;
}
.result:first-child { border-top: none; }
.result:hover, .result:focus-visible { background: var(--paper-sunken); }
.result .cover { box-shadow: var(--shadow-sm); }
.result .r-title { font-family: var(--serif); font-size: .96rem; font-weight: 600; line-height: 1.3; }
.result .r-meta { font-size: .78rem; color: var(--ink-faint); margin-top: 2px; }
.result .r-flag { font-size: .72rem; font-weight: 700; color: var(--sage); text-transform: uppercase; letter-spacing: .03em; }
.results-group { padding: 14px 18px 6px; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); background: var(--paper); }

.confirm-book { display: flex; gap: 18px; }
.confirm-book .cover { width: 108px; flex: none; }
.confirm-book .info { flex: 1; min-width: 0; }
@media (max-width: 480px) { .confirm-book .cover { width: 80px; } }

/* ------------------------------------------------------------ empty states */

.empty { text-align: center; padding: 60px 20px; color: var(--ink-faint); }
.empty svg { width: 42px; height: 42px; margin-bottom: 14px; opacity: .4; }
.empty h3 { font-size: 1.1rem; color: var(--ink); margin-bottom: 6px; }
.empty p { font-size: .9rem; max-width: 380px; margin: 0 auto 18px; }

.skeleton { background: linear-gradient(90deg, var(--paper-sunken) 25%, var(--line) 50%, var(--paper-sunken) 75%); background-size: 240% 100%; animation: shimmer 1.3s infinite; border-radius: var(--r-sm); }
@keyframes shimmer { from { background-position: 120% 0; } to { background-position: -20% 0; } }
.spinner { width: 15px; height: 15px; border: 2px solid var(--line-strong); border-top-color: var(--brass); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast-wrap { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
@media (max-width: 860px) { .toast-wrap { bottom: 76px; } }
.toast {
  display: flex; align-items: center; gap: 10px; padding: 11px 16px; border-radius: 999px;
  background: var(--ink); color: var(--paper); font-size: .87rem;
  box-shadow: var(--shadow-md); animation: rise .18s ease; pointer-events: auto;
}
.toast.err { background: var(--plum); color: #fff; }
.toast button { background: none; border: none; color: inherit; text-decoration: underline; font-weight: 600; cursor: pointer; }

.notice { padding: 10px 14px; border-radius: var(--r-md); background: var(--brass-soft); color: var(--brass); font-size: .82rem; display: flex; gap: 8px; align-items: flex-start; }
.notice svg { width: 15px; height: 15px; flex: none; margin-top: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
