/* Pantalla de escanear: fondo oscuro de "librería de noche" y ficha clara que sube desde abajo */
body.t-night {
  --bg: #17120f; --ink: #f5f1e8; --ink-soft: rgba(245, 241, 232, .72); --ink-faint: rgba(245, 241, 232, .45);
  --line: rgba(245, 241, 232, .28); --accent: #f2c14e; --card: rgba(255, 255, 255, .08);
}
body.t-night { padding-bottom: 40px; }
[hidden] { display: none !important; }

.sc .topbar { padding-bottom: 10px; }
#torch.on { background: #f2c14e; color: #17120f; border-color: #f2c14e; }
#torch svg { width: 20px; height: 20px; }

/* visor */
.cam { position: relative; width: 100%; aspect-ratio: 3 / 4; max-height: 56dvh; border-radius: 28px; overflow: hidden; background: #000; display: grid; place-items: center; }
.cam video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.frame { position: absolute; left: 11%; right: 11%; top: 30%; height: 38%; pointer-events: none; }
.frame i { position: absolute; width: 34px; height: 34px; border: 0 solid #f2c14e; }
.frame i:nth-child(1) { left: 0; top: 0; border-width: 4px 0 0 4px; border-radius: 14px 0 0 0; }
.frame i:nth-child(2) { right: 0; top: 0; border-width: 4px 4px 0 0; border-radius: 0 14px 0 0; }
.frame i:nth-child(3) { left: 0; bottom: 0; border-width: 0 0 4px 4px; border-radius: 0 0 0 14px; }
.frame i:nth-child(4) { right: 0; bottom: 0; border-width: 0 4px 4px 0; border-radius: 0 0 14px 0; }
.frame .line { position: absolute; left: 6%; right: 6%; height: 2px; background: #f2c14e; box-shadow: 0 0 14px 2px rgba(242, 193, 78, .8); animation: sweep 2.2s ease-in-out infinite; }
@keyframes sweep { 0%, 100% { top: 10%; } 50% { top: 88%; } }
.cam-msg { position: relative; padding: 0 26px; text-align: center; font-size: 16px; line-height: 1.5; color: #f5f1e8; }
.cam-msg:empty { display: none; }
#retry { position: relative; margin-top: 14px; height: 46px; padding: 0 22px; font-size: 12px; }
.cam-hint { text-align: center; color: var(--ink-soft); font-size: 14px; font-weight: 300; margin: 14px 8px 4px; }

/* qué se ve en cada estado */
body:not([data-state="scanning"]) .frame { display: none; }
body[data-state="loading"] .cam, body[data-state="loading"] .cam-hint, body[data-state="loading"] .tools,
body[data-state="empty"] .cam, body[data-state="empty"] .cam-hint, body[data-state="empty"] .tools,
body[data-state="result"] .cam, body[data-state="result"] .cam-hint, body[data-state="result"] .tools { display: none; }
body[data-state="scanning"] .cam-msg { display: none; }
body:not([data-state="scanning"]):not([data-state="starting"]) #video { opacity: 0; }

.tools { margin-top: 18px; display: grid; gap: 14px; }
#manualForm { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
#manualForm .field { color: var(--ink); background: var(--card); }
#manualForm .pill { height: 50px; padding: 0 24px; background: var(--accent); color: #17120f; font-size: 12px; }
.photo-link { justify-self: center; font-size: 14px; color: var(--ink-soft); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.error { color: #ff9d8a; font-size: 14px; font-weight: 500; text-align: center; }
.error:empty { display: none; }

.loading { display: grid; justify-items: center; gap: 22px; margin-top: 120px; text-align: center; color: var(--ink-soft); }
.spin { width: 54px; height: 54px; border-radius: 50%; border: 4px solid var(--line); border-top-color: #f2c14e; animation: turn .9s linear infinite; }
@keyframes turn { to { transform: rotate(360deg); } }

.empty { margin-top: 70px; display: grid; gap: 16px; text-align: center; justify-items: center; }
.empty h2 { font-size: 46px; font-weight: 300; text-transform: uppercase; line-height: 1; }
.empty p { color: var(--ink-soft); max-width: 340px; }
.empty-actions { display: grid; gap: 10px; width: 100%; max-width: 340px; margin-top: 10px; }
.empty .pill { background: var(--accent); color: #17120f; }
.empty .pill.ghost { background: transparent; color: var(--ink); border-color: var(--line); }

/* ficha del libro */
.res-bg { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .55); animation: fadeIn .2s; }
.res {
  --bg: #f7ebd8; --ink: #2a1416; --ink-soft: rgba(42, 20, 22, .68); --ink-faint: rgba(42, 20, 22, .45);
  --line: rgba(42, 20, 22, .22); --accent: #8b2c2a; --card: rgba(255, 255, 255, .6);
  position: fixed; left: 50%; bottom: 0; z-index: 41; width: 100%; max-width: 560px; max-height: 90dvh; overflow-y: auto; scrollbar-width: none;
  transform: translateX(-50%); background: var(--bg); color: var(--ink); border-radius: 28px 28px 0 0;
  padding: 22px 20px max(28px, env(safe-area-inset-bottom)); box-shadow: 0 -20px 50px -10px rgba(0, 0, 0, .6);
  animation: resUp .32s cubic-bezier(.2, .8, .2, 1);
}
.res::-webkit-scrollbar { display: none; }
@keyframes resUp { from { transform: translate(-50%, 50px); opacity: 0; } }

.res-head { display: grid; grid-template-columns: 96px 1fr; gap: 18px; align-items: center; }
.res-cover { width: 96px; aspect-ratio: 2 / 3; border-radius: 5px; object-fit: cover; background: rgba(42, 20, 22, .12); box-shadow: 0 16px 24px -12px rgba(42, 20, 22, .6); }
.res-head h2 { font-family: var(--display); font-weight: 400; text-transform: uppercase; font-size: 26px; line-height: 1.02; }
.res-head .by { color: var(--ink-soft); margin-top: 6px; }
.res-head .meta { color: var(--ink-faint); font-size: 12px; letter-spacing: .06em; margin-top: 6px; }

.have { margin-top: 16px; padding: 12px 16px; border-radius: 16px; background: rgba(139, 44, 42, .12); font-size: 14px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
.actions .pill { height: 56px; padding: 0 12px; font-size: 12px; }
.actions .pill.buy { background: #f2c14e; color: #2a1416; }
.actions .pill:disabled { opacity: .5; }
.alt { text-align: center; margin-top: 12px; font-size: 13px; color: var(--ink-soft); }
.alt button { text-decoration: underline; text-underline-offset: 3px; color: var(--ink-soft); padding: 4px 6px; }

.sec { margin-top: 24px; }
.sec .label { display: block; margin-bottom: 10px; }
.ratings { list-style: none; display: grid; gap: 12px; }
.ratings li { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; align-items: center; padding: 14px 16px; border-radius: 16px; background: var(--card); }
.stars { font-size: 24px; letter-spacing: 2px; background: linear-gradient(90deg, #d79a1e var(--p), rgba(42, 20, 22, .2) var(--p)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.ratings b { font-family: var(--display); font-weight: 400; font-size: 30px; }
.ratings .src { grid-column: 1 / -1; font-size: 13px; color: var(--ink-soft); }
.readers { margin-top: 12px; font-size: 14px; color: var(--ink-soft); line-height: 1.6; }
.readers b { color: var(--ink); font-weight: 500; }
.norate { color: var(--ink-soft); font-size: 14px; }
.desc { font-size: 14px; font-weight: 300; line-height: 1.6; color: var(--ink-soft); }
.desc.clamp { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.more { margin-top: 6px; font-size: 13px; text-decoration: underline; text-underline-offset: 3px; color: var(--ink-soft); }
.links { display: flex; flex-wrap: wrap; gap: 8px; }
.links a { display: inline-flex; align-items: center; height: 40px; padding: 0 16px; border-radius: 999px; border: 1.5px solid var(--ink); font-weight: 500; font-size: 13px; letter-spacing: .04em; text-decoration: none; color: var(--ink); }
.note { font-size: 12px; color: var(--ink-faint); line-height: 1.5; margin-top: 10px; }

.done { text-align: center; padding: 8px 0 0; display: grid; gap: 12px; justify-items: center; }
.done h3 { font-family: var(--display); font-weight: 300; text-transform: uppercase; font-size: 30px; }
.done .tick { width: 56px; height: 56px; border-radius: 50%; background: #8b2c2a; position: relative; }
.done .tick::after { content: ""; position: absolute; left: 20px; top: 11px; width: 13px; height: 25px; border: solid #f7ebd8; border-width: 0 5px 5px 0; transform: rotate(45deg); }
.done .pill { width: 100%; }
