/* Calibre a Kindle · librería editorial cálida (claro) y biblioteca nocturna (oscuro) */

:root {
  color-scheme: light dark;
  --bg: #f5efe2;
  --surface: #fbf8f0;
  --surface-2: #ede4d0;
  --ink: #211c16;
  --muted: #675d4f;
  --line: #ddd2bb;
  --field-line: #8f8470;
  --forest: #25563f;
  --forest-hover: #1b4331;
  --forest-ink: #fbf6ea;
  --brass: #a8823a;
  --brass-text: #7d5d1f;
  --focus: #8a6420;
  --err: #9d2a1f;
  --err-bg: #f9e6e0;
  --ok: #1f5a3c;
  --ok-bg: #e2eedd;
  --warn: #6d5014;
  --warn-bg: #f6ecd0;
  --shadow: 56, 38, 12;
  --backdrop: rgba(33, 28, 22, .55);

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", "Source Serif 4", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --gutter: 16px;
  --radius: 8px;
  --t: 180ms;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171310;
    --surface: #211c17;
    --surface-2: #2c251e;
    --ink: #f0e7d3;
    --muted: #b3a893;
    --line: #3a3228;
    --field-line: #8a7f6b;
    --forest: #2f6a4e;
    --forest-hover: #388060;
    --forest-ink: #f6efdc;
    --brass: #c9a35e;
    --brass-text: #d9b878;
    --focus: #e0bd76;
    --err: #f2a99b;
    --err-bg: #3b201c;
    --ok: #a6d8b9;
    --ok-bg: #1e3126;
    --warn: #e8cf94;
    --warn-bg: #352c17;
    --shadow: 0, 0, 0;
    --backdrop: rgba(8, 6, 4, .72);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 var(--sans);
  min-height: 100vh;
  overflow-wrap: break-word;
}
img, svg { display: block; max-width: 100%; }
p { margin: 0 0 12px; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.15; margin: 0; letter-spacing: -.01em; }
em { font-style: italic; }
strong { font-weight: 650; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: 12px; top: -80px; z-index: 100; background: var(--forest); color: var(--forest-ink); padding: 12px 16px; border-radius: var(--radius); font-weight: 600; text-decoration: none; }
.skip:focus { top: 12px; }
.wrap { width: 100%; max-width: 1240px; margin-inline: auto; padding-inline: var(--gutter); }
.wrap-any { overflow-wrap: anywhere; }

.eyebrow { font: 600 12px/1.3 var(--sans); letter-spacing: .16em; text-transform: uppercase; color: var(--brass-text); margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.hint { font-size: 14px; color: var(--muted); margin-top: 8px; }

/* Buttons ---------------------------------------------------------- */
.btn, .chip, .icon-btn, select, input { font: inherit; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; min-width: 44px; padding: 10px 18px;
  font-size: 15px; font-weight: 600; line-height: 1.2; text-align: center;
  color: var(--forest-ink); background: var(--forest);
  border: 1px solid var(--forest); border-radius: var(--radius);
  cursor: pointer; text-decoration: none;
  transition: background-color var(--t), border-color var(--t), transform var(--t), box-shadow var(--t);
}
.btn:hover:not(:disabled) { background: var(--forest-hover); border-color: var(--forest-hover); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { cursor: not-allowed; background: transparent; color: var(--muted); border-color: var(--line); border-style: dashed; }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--field-line); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); border-color: var(--field-line); }
.btn-block { width: 100%; }
.btn[aria-busy="true"]:disabled { border-style: solid; color: var(--ink); }

.icon-btn {
  width: 44px; height: 44px; display: inline-grid; place-items: center; padding: 0;
  background: transparent; color: var(--ink); border: 1px solid transparent; border-radius: 50%;
  cursor: pointer; transition: background-color var(--t);
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg, .search-ico { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

.link { background: none; border: 0; padding: 0; min-height: 44px; color: var(--forest); font: inherit; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
@media (prefers-color-scheme: dark) { .link { color: var(--brass-text); } }

/* Form fields ------------------------------------------------------ */
label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
input[type="email"], input[type="password"], input[type="search"], select {
  width: 100%; min-height: 48px; padding: 10px 14px;
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--field-line); border-radius: var(--radius);
  transition: border-color var(--t), box-shadow var(--t);
}
input::placeholder { color: var(--muted); opacity: .85; }
input[aria-invalid="true"] { border-color: var(--err); box-shadow: 0 0 0 1px var(--err); }
select { width: auto; max-width: 100%; padding-right: 12px; }
.inline-error { color: var(--err); background: var(--err-bg); border-left: 3px solid var(--err); padding: 10px 12px; border-radius: 4px; font-size: 14px; margin: 10px 0 0; }
.inline-error[hidden] { display: none; }
.saved { font-size: 14px; color: var(--ok); margin: 12px 0 0; min-height: 1.5em; }

/* Header ----------------------------------------------------------- */
.topbar { border-bottom: 1px solid var(--line); background: var(--bg); position: sticky; top: 0; z-index: 20; }
.topbar-in { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 64px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; min-height: 44px; min-width: 0; }
.brand-name { font-family: var(--serif); font-size: 21px; font-weight: 600; letter-spacing: -.01em; white-space: nowrap; }
.brand-name em { color: var(--brass-text); font-weight: 400; }
.mark-book { fill: var(--forest); }
.mark-spine { stroke: var(--brass); stroke-width: 2.5; fill: none; }
.mark-ribbon { fill: var(--brass); }
.top-actions { display: flex; align-items: center; gap: 8px; min-width: 0; }
.top-actions form { margin: 0; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; max-width: 240px; padding: 8px 14px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--field-line); border-radius: 999px;
  font-size: 14px; font-weight: 600; cursor: pointer; transition: background-color var(--t);
}
.chip:hover { background: var(--surface-2); }
.chip-long { display: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { flex: none; width: 10px; height: 10px; border-radius: 50%; border: 2px dashed var(--brass); }
.chip.is-set .dot { background: var(--forest); border: 2px solid var(--forest); }
@media (prefers-color-scheme: dark) { .mark-book { fill: #3f8561; } .chip.is-set .dot { background: #7fc29c; border-color: #7fc29c; } }
@media (min-width: 560px) { .chip-short { display: none; } .chip-long { display: inline; } }
@media (max-width: 400px) { .brand-name { font-size: 18px; } .brand .mark { width: 26px; height: 26px; } .top-actions .btn-ghost { padding-inline: 12px; } }
@media (max-width: 359px) { .brand .mark { display: none; } .brand-name { font-size: 17px; } .top-actions { gap: 6px; } .chip { padding-inline: 10px; } .top-actions .btn-ghost { padding-inline: 10px; } }

/* Hero ------------------------------------------------------------- */
.hero { padding: 24px 0 14px; }
@media (min-width: 640px) { .hero { padding: 40px 0 22px; } }
.hero h1 { font-size: clamp(27px, 6.4vw, 54px); max-width: 16em; text-wrap: balance; }
.hero h1 em { color: var(--forest); font-weight: 500; }
@media (prefers-color-scheme: dark) { .hero h1 em { color: var(--brass-text); } }
.hero-dest { margin: 8px 0 0; color: var(--muted); font-size: 15px; }
.hero-dest .link { display: inline-flex; align-items: center; }
.hero-dest strong { color: var(--ink); }

/* Toolbar ---------------------------------------------------------- */
.catalog { padding-bottom: 24px; }
.toolbar { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; padding: 18px 0; border-top: 1px solid var(--line); }
.search { position: relative; display: flex; gap: 8px; }
.search input { padding-left: 42px; min-width: 0; flex: 1 1 auto; }
.search .btn { flex: none; }
.toolbar > * { min-width: 0; }
.search-ico { position: absolute; left: 13px; top: 14px; color: var(--muted); pointer-events: none; }
.sort { display: flex; align-items: center; gap: 10px; }
.sort label { margin: 0; white-space: nowrap; color: var(--muted); }
.sort select { flex: 1 1 auto; min-width: 0; }
@media (min-width: 760px) {
  .toolbar { grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 24px; }
  .sort select { flex: none; }
}
.results-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 16px; margin: 6px 0 20px; }
.results-head h2 { font-size: 26px; }
.results-head h2:focus { outline: none; }
.results-head h2:focus-visible { outline: 3px solid var(--focus); outline-offset: 4px; }
.results-head p { margin: 0; font-size: 14px; }

/* Book grid -------------------------------------------------------- */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 28px 16px; transition: opacity var(--t); }
@media (min-width: 640px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 36px 24px; } }
@media (min-width: 900px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 44px 28px; } }
@media (min-width: 1160px) { .grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.grid.is-loading { opacity: .5; pointer-events: none; }

.book { display: flex; flex-direction: column; min-width: 0; }
.cover {
  display: block; width: 100%; padding: 0 6% 10px; margin: 0;
  background: none; border: 0; border-bottom: 3px solid var(--line); border-radius: 0;
  cursor: pointer; font: inherit; color: inherit;
}
.cover:focus-visible { outline-offset: 4px; }
.frame { position: relative; display: block; width: 100%; aspect-ratio: 2 / 3; container-type: inline-size; transition: transform var(--t) ease; }
.cover:hover .frame { transform: translateY(-4px); }
.frame img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; object-position: center bottom;
  opacity: 0; transition: opacity 220ms ease;
  filter: drop-shadow(0 6px 8px rgba(var(--shadow), .28)) drop-shadow(0 1px 1px rgba(var(--shadow), .35));
}
.frame img.in { opacity: 1; }
.ph, .sk { background: linear-gradient(100deg, var(--surface-2) 30%, var(--surface) 50%, var(--surface-2) 70%) 0 0 / 300% 100%; animation: shimmer 1.4s linear infinite; }
.ph { position: absolute; inset: 0; border-radius: 3px; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

.fallback {
  position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between; gap: 8px;
  padding: 12% 11% 10% 17%; border-radius: 3px 5px 5px 3px; color: #f6efdc; text-align: left; overflow: hidden;
  background-color: var(--c, #2f5d46);
  background-image: linear-gradient(90deg, rgba(0,0,0,.28) 0, rgba(0,0,0,.28) 7%, rgba(255,255,255,.1) 8%, transparent 12%);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.08), 0 6px 8px rgba(var(--shadow), .26);
}
.fallback::before { content: ""; position: absolute; inset: 5% 5% 5% 12%; border: 1px solid rgba(214, 178, 108, .55); border-radius: 2px; pointer-events: none; }
.fallback.v0 { --c: #2f5d46; } .fallback.v1 { --c: #6a2d36; } .fallback.v2 { --c: #2c4a5a; }
.fallback.v3 { --c: #6f5330; } .fallback.v4 { --c: #3d3a52; }
.fb-title { position: relative; font: 600 clamp(13px, 11cqw, 26px)/1.15 var(--serif); display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 6; line-clamp: 6; overflow: hidden; overflow-wrap: anywhere; }
.fb-author { position: relative; font: 600 clamp(9px, 6.4cqw, 13px)/1.25 var(--sans); letter-spacing: .06em; text-transform: uppercase; color: #e3c88c; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; overflow-wrap: anywhere; }

.book-title { font-size: 18px; line-height: 1.22; margin: 16px 0 4px; min-height: 2.44em; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3; overflow: hidden; overflow-wrap: anywhere; }
.book-author { font-size: 14px; color: var(--muted); margin: 0 0 14px; min-height: 1.55em; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; overflow-wrap: anywhere; }
.book-actions { display: grid; gap: 8px; margin-top: auto; }
.book-actions .btn { width: 100%; padding-inline: 10px; font-size: 14px; }
@media (min-width: 640px) { .book-title { font-size: 19px; } }

.book.skeleton { pointer-events: none; }
.sk { border-radius: 4px; }
.sk-title { height: 2.44em; margin: 16px 0 4px; }
.sk-author { height: 1.55em; width: 60%; margin: 0 0 14px; }
.sk-btn { height: 44px; margin-bottom: 8px; border-radius: var(--radius); }

/* States ----------------------------------------------------------- */
.state { max-width: 460px; margin: 28px auto 12px; text-align: center; padding: 28px 8px; }
.state svg { margin: 0 auto 14px; width: 64px; height: 64px; fill: none; stroke: var(--brass); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.state h3 { font-size: 24px; margin-bottom: 8px; }
.state p { color: var(--muted); }
.state.is-error h3 { color: var(--err); }
.state .btn { margin-top: 8px; }

.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin: 40px 0 8px; flex-wrap: wrap; }
.pager[hidden] { display: none; }
.pager-info { font-weight: 600; font-size: 14px; min-width: 7.5em; text-align: center; font-variant-numeric: tabular-nums; }
.fine-print { color: var(--muted); font-size: 13px; padding-block: 24px 120px; }
.fine-print p { border-top: 1px solid var(--line); padding-top: 18px; max-width: 70ch; }

/* Notices ---------------------------------------------------------- */
.notices { position: fixed; left: 0; right: 0; bottom: 12px; z-index: 50; display: flex; justify-content: center; padding-inline: var(--gutter); pointer-events: none; }
.notice { pointer-events: auto; width: 100%; max-width: 560px; display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; align-items: start; padding: 12px 6px 12px 16px; border-radius: var(--radius); border-left: 4px solid; box-shadow: 0 10px 30px rgba(var(--shadow), .3); animation: rise 200ms ease; max-height: 45vh; overflow: auto; }
.notice.info, .notice.success { background: var(--ok-bg); color: var(--ok); border-color: var(--forest); }
.notice.error { background: var(--err-bg); color: var(--err); border-color: var(--err); }
.notice.warn { background: var(--warn-bg); color: var(--warn); border-color: var(--brass); }
.notice-title { font-weight: 700; margin: 0; font-size: 15px; }
.notice-text { margin: 0; font-size: 14px; grid-column: 1; overflow-wrap: anywhere; }
.notice .icon-btn { grid-column: 2; grid-row: 1 / span 2; color: inherit; }
.notice a { color: inherit; font-weight: 700; }
.slot .notice { max-width: none; box-shadow: none; max-height: 30vh; }
.slot:empty { display: none; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* Dialogs ---------------------------------------------------------- */
dialog { color: var(--ink); background: var(--surface); border: 1px solid var(--line); padding: 0; max-width: none; max-height: none; overscroll-behavior: contain; }
dialog::backdrop { background: var(--backdrop); }
dialog[open] { animation: dlg-in 200ms ease; }
dialog[open]::backdrop { animation: fade 200ms ease; }
@keyframes dlg-in { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.sheet { width: min(100% - 16px, 780px); max-height: calc(100dvh - 16px); margin: auto; border-radius: 14px; box-shadow: 0 24px 70px rgba(var(--shadow), .45); }
.sheet[open] { display: flex; flex-direction: column; }
.sheet-small { width: min(100% - 16px, 520px); }
.sheet-head { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 8px 0 20px; }
.sheet-head .eyebrow { margin: 0; }
.sheet-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 8px 20px 20px; overscroll-behavior: contain; }
.sheet-body:focus-visible { outline-offset: -3px; }
.sheet-foot { flex: none; padding: 12px 20px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--surface); border-radius: 0 0 14px 14px; display: grid; gap: 10px; }
.foot-actions { display: grid; gap: 8px; }
.foot-actions .hint { margin: 0; }
.foot-actions .btn { width: 100%; }
@media (min-width: 520px) { .foot-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; } .foot-actions .btn { width: auto; min-width: 140px; } .foot-actions .hint { flex: 1 1 100%; text-align: right; } }
@media (max-width: 639px) { .sheet:not(.sheet-small) { margin: auto auto 0; width: 100%; max-height: 92dvh; border-radius: 16px 16px 0 0; } .sheet:not(.sheet-small) .sheet-foot { border-radius: 0; } }

.detail-grid { display: grid; gap: 20px; }
.detail-cover { width: min(52%, 190px); margin-inline: auto; }
.detail-cover .frame { transition: none; }
.detail-cover .frame.fit { aspect-ratio: auto; }
.detail-cover .frame.fit img { position: static; width: auto; height: auto; max-height: 320px; margin-inline: auto; }
@media (min-width: 640px) { .detail-cover .frame.fit img { margin-inline: 0; max-height: 400px; } }
.detail-text h2 { font-size: clamp(26px, 6vw, 34px); overflow-wrap: anywhere; }
.detail-authors { color: var(--brass-text); font-weight: 600; margin: 8px 0 16px; overflow-wrap: anywhere; }
.detail-desc { font-family: var(--serif); font-size: 17px; line-height: 1.7; white-space: pre-line; overflow-wrap: anywhere; max-width: 62ch; }
.detail-desc.is-empty { color: var(--muted); font-style: italic; }
.detail-desc .sk-line { height: 1em; margin: 0 0 12px; }
.detail-desc .sk-line:nth-child(2) { width: 92%; } .detail-desc .sk-line:nth-child(3) { width: 96%; } .detail-desc .sk-line:nth-child(4) { width: 60%; }
@media (min-width: 640px) { .detail-grid { grid-template-columns: 200px minmax(0, 1fr); gap: 32px; } .detail-cover { width: 100%; margin: 6px 0 0; } .sheet-body { padding: 8px 28px 24px; } .sheet-head { padding-left: 28px; } .sheet-foot { padding-inline: 28px; } }

.settings-body h2 { font-size: 26px; margin-bottom: 10px; }
.settings-body label { margin-top: 18px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
.form-actions .btn { flex: 1 1 140px; }

.modal { width: min(100% - 32px, 460px); margin: auto; border-radius: 14px; box-shadow: 0 24px 70px rgba(var(--shadow), .45); max-height: calc(100dvh - 32px); overflow: auto; }
.modal-in { padding: 24px; }
.modal-in h2 { font-size: 26px; margin-bottom: 12px; }
.confirm-text { font-size: 17px; }

/* Login ------------------------------------------------------------ */
.login-page { display: grid; min-height: 100dvh; }
.login { position: relative; display: grid; align-content: center; justify-items: center; padding: 32px var(--gutter) 160px; min-height: 100dvh; overflow: hidden; }
.login-card { position: relative; z-index: 1; width: 100%; max-width: 420px; padding: 36px 28px 28px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 20px 60px rgba(var(--shadow), .18); }
.login-card .mark { margin-bottom: 18px; }
.login-title { font-size: clamp(34px, 9vw, 44px); }
.login-title em { color: var(--brass-text); font-weight: 400; }
.login-lead { margin: 14px 0 22px; color: var(--muted); }
.login-form input { margin-bottom: 4px; }
.login-form .btn { margin: 18px 0 6px; }
.login-card .muted { margin: 14px 0 0; }
.spines { position: absolute; left: 0; right: 0; bottom: 0; height: 130px; display: flex; align-items: flex-end; justify-content: center; gap: 4px; padding-inline: 8px; border-bottom: 10px solid var(--brass); pointer-events: none; overflow: hidden; }
.spines i { flex: 0 1 34px; min-width: 14px; border-radius: 3px 3px 0 0; background: var(--forest); box-shadow: inset 3px 0 0 rgba(255,255,255,.12), inset 0 8px 0 -4px rgba(214,178,108,.5); }
.spines i:nth-child(6n+1) { height: 100px; } .spines i:nth-child(6n+2) { height: 84px; background: #6a2d36; }
.spines i:nth-child(6n+3) { height: 112px; background: #6f5330; } .spines i:nth-child(6n+4) { height: 92px; background: #2c4a5a; }
.spines i:nth-child(6n+5) { height: 104px; background: #3d3a52; } .spines i:nth-child(6n) { height: 78px; }
@media (max-width: 420px) { .login-card { padding: 28px 20px 22px; } .spines { height: 100px; } }

/* Reduced motion --------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
  .cover:hover .frame { transform: none; }
  .ph, .sk { background: var(--surface-2); }
}

.kindle-list { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 10px; }
.kindle-item { border: 1px solid var(--line, currentColor); border-radius: 12px; padding: 12px; display: grid; gap: 10px; }
.kindle-info { display: grid; gap: 2px; }
.kindle-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.kindle-actions .btn { flex: 0 1 auto; min-height: 40px; padding-block: 6px; }
.badge { font-size: 14px; font-weight: 600; color: var(--ok); }
.settings-body h3 { font-size: 18px; margin: 24px 0 0; }
