:root {
  --bg: #1b1d22;
  --surface: #24272e;
  --surface-2: #2e323b;
  --border: #3a3f4a;
  --text: #e8e9ec;
  --muted: #9aa0ab;
  --accent: #6ea8fe;
  --accent-press: #5790e0;
  --danger: #ff6b6b;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

.topbar {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 18px 20px 8px;
}
.topbar h1 { margin: 0; font-size: 1.5rem; letter-spacing: 0.5px; }
.tag { color: var(--muted); font-size: 0.85rem; }

main {
  flex: 1;
  padding: 12px 16px 24px;
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}

.lookup { display: flex; flex-direction: column; gap: 10px; }

.input-row {
  display: flex;
  gap: 8px;
}

input[type="text"] {
  flex: 1;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 1.05rem;
}
input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}

.icon-btn {
  flex: 0 0 auto;
  width: 52px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  display: grid;
  place-items: center;
}
.icon-btn:active { background: var(--surface-2); }

button { cursor: pointer; font: inherit; }

.primary {
  background: var(--accent);
  color: #11151c;
  border: none;
  border-radius: var(--radius);
  padding: 14px;
  font-size: 1.05rem;
  font-weight: 600;
}
.primary:active { background: var(--accent-press); }
.primary:disabled { opacity: 0.55; }

.status {
  min-height: 1.2em;
  margin: 16px 2px;
  color: var(--muted);
}
.status.error { color: var(--danger); }

/* Review card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 8px;
}
.card-head { display: flex; gap: 14px; }
.card-cover {
  flex: 0 0 96px;
  width: 96px;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  background: var(--surface-2);
  border-radius: 8px;
}
.card-cover.placeholder {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
}
.card-title { margin: 0 0 4px; font-size: 1.2rem; line-height: 1.25; }
.card-subtitle { margin: 0 0 6px; color: var(--muted); font-size: 0.95rem; }
.card-authors { margin: 0; font-size: 0.98rem; }

.card-meta {
  list-style: none;
  margin: 16px 0 0;
  padding: 14px 0 0;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 14px;
  font-size: 0.92rem;
}
.card-meta dt { color: var(--muted); }
.card-meta dd { margin: 0; }

.card-desc {
  margin: 14px 0 0;
  font-size: 0.92rem;
  color: #cdd1d9;
  white-space: pre-wrap;
}

.provenance {
  margin-top: 14px;
  font-size: 0.78rem;
  color: var(--muted);
}

/* Write actions */
.actions {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.action-row { display: flex; gap: 8px; }
.action-row select {
  flex: 0 0 auto;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 12px;
}
.action-row .primary { flex: 1; }
.secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  font-size: 0.95rem;
}
.shelf-buttons { display: flex; gap: 8px; }
.chip {
  flex: 1;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 10px;
  font-size: 0.9rem;
}
.chip:active, .secondary:active { background: var(--border); }
button:disabled, select:disabled { opacity: 0.55; }
.exists-note { margin: 0; color: var(--muted); font-size: 0.9rem; }
.exists-note a, .action-result a { color: var(--accent); }
.action-result { margin: 0; color: #9fe0ad; font-size: 0.95rem; }

/* Scanner overlay */
/* The `hidden` attribute must win over the rule below: `.scanner` and the UA's
   `[hidden]{display:none}` have equal specificity, so without this the author
   `display:flex` wins and the overlay is permanently visible, covering the app. */
.scanner[hidden] { display: none; }
.scanner {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
#scanner-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.scanner-frame {
  position: relative;
  width: 78%;
  max-width: 360px;
  aspect-ratio: 5 / 3;
  border: 3px solid rgba(255,255,255,0.85);
  border-radius: 12px;
  box-shadow: 0 0 0 100vmax rgba(0,0,0,0.45);
}
.scanner-hint {
  position: absolute;
  bottom: 96px;
  color: #fff;
  text-shadow: 0 1px 4px #000;
}
.scanner-close {
  position: absolute;
  bottom: 28px;
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 999px;
  padding: 12px 28px;
  font-size: 1rem;
}

.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
}
.footer a { color: var(--accent); text-decoration: none; }
.net-state.offline { color: var(--danger); }

/* On-screen debug log (?debug=1) */
.debuglog {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 45vh;
  overflow: auto;
  margin: 0;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.88);
  color: #9fe0ad;
  font: 11px/1.35 ui-monospace, "SF Mono", Menlo, monospace;
  white-space: pre-wrap;
  word-break: break-word;
  z-index: 100;
  border-top: 1px solid var(--border);
}
