:root {
  --bg: #16130f;
  --panel: #211c17;
  --panel2: #2b241d;
  --line: #3a3128;
  --text: #f1e8da;
  --muted: #a8998a;
  --accent: #e0a84a;
  --accent2: #f3c97a;
  --ok: #8fc48a;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--sans); }
a { color: var(--accent2); text-decoration: none; }
button { font: inherit; cursor: pointer; }
.muted { color: var(--muted); }
.err { color: #ff8a7a; }

/* login */
#login { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(circle at 50% 30%, #2c2219, var(--bg) 70%); }
.login-card { width: min(380px, 100%); display: grid; gap: 12px; padding: 28px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 20px 60px #0008; }
.login-card input, .search input { width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: #120f0c; color: var(--text); font-size: 16px; outline: none; }
.login-card input:focus, .search input:focus { border-color: var(--accent); }
.login-card button, .search button { padding: 12px 18px; border: 0; border-radius: 10px; background: var(--accent);
  color: #1b140c; font-weight: 600; }

/* header */
.top { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 10; display: flex; gap: 16px; align-items: center;
  padding: 12px 16px; background: #16130fee; backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font: 600 24px/1 var(--serif); color: var(--text); letter-spacing: .3px; }
.brand.big { font-size: 34px; }
.search { flex: 1; display: flex; gap: 8px; min-width: 260px; }
.crumbs { padding: 10px 16px 0; color: var(--muted); font-size: 14px; }
.crumbs a { color: var(--muted); } .crumbs a:hover { color: var(--text); }
main { padding: 16px; max-width: 1400px; margin: 0 auto; }
h1 { font: 600 28px/1.2 var(--serif); margin: 6px 0 16px; }

/* rooms + shelves */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: hidden;
  transition: transform .12s, border-color .12s; color: var(--text); display: block; }
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card .img { aspect-ratio: 3/4; background: #000 center/cover no-repeat; }
.card .img.stack { aspect-ratio: auto; height: 340px; background-position: center top; }
.card .meta { padding: 10px 12px; }
.card .meta b { font: 600 17px var(--serif); display: block; }
.room-card .collage { display: flex; height: 260px; gap: 2px; background: #000; }
.room-card .collage div { flex: 1; background: center top/cover no-repeat; }
.room-card .meta b { font-size: 24px; }

/* results */
.summary { color: var(--muted); margin: 4px 0 14px; font-size: 14px; }
.results { display: grid; gap: 10px; }
.sep { margin: 18px 0 4px; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .08em; }
.res { display: grid; grid-template-columns: 76px 1fr auto; gap: 14px; align-items: center; padding: 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; color: var(--text); }
.res:hover { border-color: var(--accent); background: var(--panel2); }
.res img { width: 76px; height: 110px; object-fit: contain; background: #0b0907; border-radius: 6px; }
.res .t { font: 600 18px/1.25 var(--serif); }
.res .t.unk { color: var(--muted); font-style: italic; }
.res .a { color: var(--accent2); }
.res .m { color: var(--muted); font-size: 13px; margin-top: 4px; }
.res .spine { color: #cbbca9; font-size: 12px; margin-top: 4px; font-style: italic; overflow-wrap: anywhere; }
.res .where { text-align: right; font-size: 13px; color: var(--muted); white-space: nowrap; }
.res .where b { color: var(--text); display: block; font-size: 14px; }
.chip { display: inline-block; width: 12px; height: 12px; border-radius: 3px; border: 1px solid #fff4; vertical-align: -1px; margin-right: 3px; }
.badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 99px; border: 1px solid var(--line); margin-left: 6px; color: var(--muted); }
.badge.ft { color: var(--ok); border-color: #4d6b4a; }
.weak { opacity: .55; }
@media (max-width: 640px) {
  .res { grid-template-columns: 60px 1fr; }
  .res img { width: 60px; height: 90px; }
  .res .where { grid-column: 2; text-align: left; white-space: normal; }
  .card .img.stack { height: 260px; }
}

/* viewer */
#viewerWrap { position: fixed; inset: 0; z-index: 100; background: #000; }
#osd { position: absolute; inset: 0; }
.vbar { position: absolute; top: 0; left: 0; right: 0; display: flex; gap: 10px; align-items: center;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 10px 8px; background: linear-gradient(#000c, #0000); pointer-events: none; }
.vbar > * { pointer-events: auto; }
.vbar button { min-width: 42px; height: 42px; padding: 0 12px; border-radius: 10px; border: 1px solid #fff3;
  background: #000a; color: #fff; font-size: 18px; backdrop-filter: blur(6px); }
.vbar button.on { background: var(--accent); color: #1b140c; border-color: var(--accent); }
#vBooks { font-size: 14px; }
.vtitle { flex: 1; font: 600 17px var(--serif); text-shadow: 0 1px 4px #000; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.vbtns { display: flex; gap: 6px; }
.vinfo { position: absolute; left: 10px; bottom: calc(env(safe-area-inset-bottom, 0px) + 10px); max-width: min(460px, calc(100% - 20px));
  background: #16130fe8; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; backdrop-filter: blur(8px); }
.vinfo .t { font: 600 18px var(--serif); }
.vinfo .x { float: right; background: none; border: 0; color: var(--muted); font-size: 18px; }
.hl { border: 3px solid var(--accent); border-radius: 6px; box-shadow: 0 0 0 9999px #0006, 0 0 24px var(--accent);
  animation: pulse 1.4s ease-in-out infinite; pointer-events: none; }
@keyframes pulse { 50% { border-color: #fff; box-shadow: 0 0 0 9999px #0006, 0 0 6px var(--accent); } }
.bk { border: 2px solid #f3c97acc; border-radius: 3px; cursor: pointer; box-shadow: inset 0 0 0 1px #0006; }
.bk:hover { background: #e0a84a33; border-color: #fff; }
.bk.unk { border-style: dashed; border-color: #ffffff55; }
.navigator { border-radius: 8px; }
