* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0A0A0C;
  --bg2: #141418;
  --bg3: #1E1E24;
  --gold: #C9A86A;
  --gold-dim: #8F7A50;
  --gold-glow: rgba(201, 168, 106, 0.15);
  --text: #E8E4DC;
  --text-dim: #9A958C;
  --red: #D4707A;
  --green: #7AB08A;
  --radius: 12px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- PIN overlay ---------- */
#pin-overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 100;
}
#pin-overlay.hidden { display: none; }
#pin-overlay h2 { color: var(--gold); margin-bottom: 8px; font-weight: 400; letter-spacing: 3px; }
.pin-sub { font-size: 12px; color: var(--text-dim); font-style: italic; margin-bottom: 24px; }
#pin-input {
  background: var(--bg2); border: 1px solid var(--bg3);
  color: var(--text); font-size: 24px; text-align: center;
  padding: 12px 20px; border-radius: var(--radius); width: 160px;
  letter-spacing: 8px; outline: none;
}
#pin-input:focus { border-color: var(--gold); }
#pin-error { color: var(--red); margin-top: 12px; font-size: 13px; min-height: 20px; }

/* ---------- App shell ---------- */
#app { display: none; max-width: 480px; margin: 0 auto; padding: 20px 16px 100px; }
#app.active { display: block; }

header { text-align: center; padding: 8px 0 16px; }
header h1 { font-size: 20px; font-weight: 300; color: var(--gold); letter-spacing: 3px; }
header .sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

/* ---------- Scanner ---------- */
.scanner-box {
  position: relative; border-radius: var(--radius); overflow: hidden;
  background: var(--bg2); border: 1px solid var(--bg3);
  aspect-ratio: 4 / 3;
}
#scan-video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame {
  position: absolute; inset: 18% 12%;
  border: 1.5px solid var(--gold);
  border-radius: 8px; opacity: 0.6; pointer-events: none;
}
.scanner-msg {
  position: absolute; bottom: 0; left: 0; right: 0;
  text-align: center; font-size: 12px; color: var(--text-dim);
  background: rgba(10, 10, 12, 0.7); padding: 6px;
}

/* ---------- Buttons / actions ---------- */
.actions { display: flex; gap: 12px; justify-content: center; margin: 16px 0 8px; }
.btn {
  background: var(--bg2); border: 1px solid var(--bg3);
  color: var(--text); padding: 10px 20px; border-radius: var(--radius);
  font-size: 14px; cursor: pointer; transition: all 0.2s;
  font-family: var(--font);
}
.btn:hover, .btn:active { border-color: var(--gold); background: var(--bg3); }
.btn.primary { background: var(--gold); color: var(--bg); border-color: var(--gold); }
.btn.primary:hover { opacity: 0.9; }
.btn.danger { color: var(--red); }
.btn.danger:hover { border-color: var(--red); }
.btn:disabled { opacity: 0.3; cursor: default; }

/* ---------- Cards ---------- */
.card {
  background: var(--bg2); border: 1px solid var(--bg3);
  border-radius: var(--radius); padding: 20px; margin: 16px 0;
}
.card h3 {
  font-size: 13px; font-weight: 400; color: var(--gold);
  letter-spacing: 1px; text-transform: uppercase; margin-bottom: 14px;
}
.hidden { display: none !important; }

/* ---------- Manual input ---------- */
.manual-row { display: flex; gap: 10px; }
.manual-row input {
  flex: 1; background: var(--bg3); border: 1px solid transparent;
  color: var(--text); padding: 10px 12px; border-radius: 8px;
  font-size: 15px; font-family: var(--font); outline: none;
}
.manual-row input:focus { border-color: var(--gold-dim); }

/* ---------- Result card ---------- */
.result-book { display: flex; gap: 14px; margin-bottom: 8px; }
#result-cover {
  width: 72px; height: 104px; object-fit: cover; border-radius: 6px;
  background: var(--bg3); flex: 0 0 auto;
}
#result-cover[src=""] { visibility: hidden; }
.result-fields { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.result-fields input, .modal input {
  background: var(--bg3); border: 1px solid transparent;
  color: var(--text); padding: 8px 10px; border-radius: 8px;
  font-size: 14px; font-family: var(--font); outline: none; width: 100%;
}
.result-fields input:focus, .modal input:focus { border-color: var(--gold-dim); }
.result-isbn { font-size: 12px; color: var(--text-dim); font-family: monospace; }

.field-label {
  font-size: 12px; color: var(--text-dim); letter-spacing: 1px;
  margin: 14px 0 8px; text-transform: uppercase;
}
#f-location, #e-location { margin-top: 8px; }

/* ---------- Chips ---------- */
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 6px 14px; border-radius: 20px; font-size: 13px;
  background: var(--bg3); color: var(--text-dim); cursor: pointer;
  border: 1px solid transparent; transition: all 0.2s; user-select: none;
}
.chip.active { background: var(--gold-glow); color: var(--text); border-color: var(--gold-dim); }

/* ---------- Notes ---------- */
.notes-input {
  width: 100%; background: var(--bg3); border: 1px solid transparent;
  color: var(--text); padding: 10px 12px; border-radius: 8px;
  font-size: 13px; font-family: var(--font); resize: none;
  outline: none; margin-top: 12px; min-height: 48px;
}
.notes-input:focus { border-color: var(--gold-dim); }
.notes-input::placeholder { color: var(--text-dim); }

/* ---------- Progress ---------- */
.progress-card { padding: 16px 20px; }
.progress-labels {
  display: flex; justify-content: space-between;
  font-size: 13px; color: var(--text-dim); margin-bottom: 8px;
}
.progress-bar {
  height: 8px; background: var(--bg3); border-radius: 4px; overflow: hidden;
}
.progress-fill {
  height: 100%; width: 0; background: var(--gold);
  border-radius: 4px; transition: width 0.4s;
}

/* ---------- Library ---------- */
.search-input {
  width: 100%; background: var(--bg2); border: 1px solid var(--bg3);
  color: var(--text); padding: 10px 14px; border-radius: var(--radius);
  font-size: 14px; font-family: var(--font); outline: none; margin-bottom: 12px;
}
.search-input:focus { border-color: var(--gold-dim); }
#filter-status-chips, #filter-location-chips { margin-bottom: 10px; }

.book-item {
  display: flex; gap: 12px; align-items: center;
  background: var(--bg2); border: 1px solid var(--bg3);
  border-radius: var(--radius); padding: 12px; margin-bottom: 10px;
  cursor: pointer; transition: border-color 0.2s;
}
.book-item:active { border-color: var(--gold-dim); }
.book-item img {
  width: 42px; height: 60px; object-fit: cover; border-radius: 4px;
  background: var(--bg3); flex: 0 0 auto;
}
.book-item .no-cover {
  width: 42px; height: 60px; border-radius: 4px; background: var(--bg3);
  flex: 0 0 auto; display: flex; align-items: center; justify-content: center;
  color: var(--text-dim); font-size: 18px;
}
.book-item .info { flex: 1; min-width: 0; }
.book-item .title {
  font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.book-item .meta {
  font-size: 12px; color: var(--text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.book-item .badges { display: flex; gap: 6px; margin-top: 4px; }
.badge {
  font-size: 10px; padding: 2px 8px; border-radius: 10px;
  background: var(--bg3); color: var(--text-dim);
}
.badge.st-weread, .badge.st-zlib { background: rgba(122, 176, 138, 0.15); color: var(--green); }
.badge.st-none { background: rgba(212, 112, 122, 0.12); color: var(--red); }
.badge.st-skip { background: var(--bg3); color: var(--text-dim); }
.badge.loc { background: var(--gold-glow); color: var(--gold); }

.empty-msg { text-align: center; color: var(--text-dim); font-size: 13px; padding: 30px 0; }

/* ---------- Stats ---------- */
.stat-row {
  display: flex; justify-content: space-between; padding: 8px 0;
  border-bottom: 1px solid var(--bg3); font-size: 14px;
}
.stat-row:last-child { border-bottom: none; }
.stat-row .v { color: var(--gold); }
.footer-note {
  text-align: center; font-size: 11px; color: var(--text-dim);
  font-style: italic; margin-top: 24px; line-height: 1.8;
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 90; padding: 16px;
}
.modal {
  background: var(--bg2); border: 1px solid var(--bg3);
  border-radius: var(--radius); padding: 20px;
  width: 100%; max-width: 420px; max-height: 85vh; overflow-y: auto;
}
.modal h3 {
  font-size: 13px; font-weight: 400; color: var(--gold);
  letter-spacing: 1px; text-transform: uppercase; margin-bottom: 14px;
}
.modal input { margin-bottom: 8px; }

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--bg2); border-top: 1px solid var(--bg3);
  display: flex; justify-content: center; gap: 40px;
  padding: 12px 0 max(12px, env(safe-area-inset-bottom));
  z-index: 50;
}
.nav-item {
  display: flex; flex-direction: column; align-items: center;
  color: var(--text-dim); font-size: 11px; cursor: pointer;
  background: none; border: none; font-family: var(--font);
}
.nav-item.active { color: var(--gold); }
.nav-item svg { width: 22px; height: 22px; margin-bottom: 3px; }

/* ---------- Tabs / misc ---------- */
.tab-content { display: none; }
.tab-content.active { display: block; }
.save-status {
  text-align: center; font-size: 12px; color: var(--green);
  min-height: 20px; margin-top: 8px;
}

@media (min-width: 500px) {
  #app { padding: 24px 24px 100px; }
}
