/* ═══════════════════════════════════════════════════════════════
   RESET + ROOT VARIABLES
═══════════════════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:      #f7f2e8;
  --bg-soft: #fbf7f0;
  --panel:   rgba(255, 251, 245, 0.9);
  --panel-strong: #fffaf2;
  --border:  #d7c8b5;
  --border-strong: #bea98b;
  --accent:  #8ea483;
  --accent-strong: #72886a;
  --accent-soft: rgba(142, 164, 131, 0.18);
  --text:    #4f463d;
  --text2:   #7f7467;
  --text3:   #a39786;
  --danger:  #c26f64;
  --success: #7f9b73;
  --wood:    #e8cfaa;
  --wood-dark: #cfa777;
  --shadow:  0 18px 40px rgba(131, 109, 84, 0.12);
  --nav-h:   64px;
  --header-h: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.72), transparent 34%),
    linear-gradient(180deg, #f8f4ed 0%, #f5efe3 42%, #f2eadb 100%);
  color: var(--text);
  font-family: 'Avenir Next', 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.5;
  overflow: hidden;
}

/* ═══════════════════════════════════════════════════════════════
   LAYOUT
═══════════════════════════════════════════════════════════════ */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

.header {
  height: var(--header-h);
  background:
    linear-gradient(180deg, rgba(255, 250, 242, 0.98), rgba(249, 242, 232, 0.94));
  border-bottom: 1px solid rgba(190, 169, 139, 0.55);
  box-shadow: 0 8px 24px rgba(131, 109, 84, 0.08);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  flex-shrink: 0;
  z-index: 10;
}

.header-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  flex: 1;
  letter-spacing: 0.02em;
}

.header-logo {
  width: 28px;
  height: 28px;
  color: var(--accent-strong);
}

#header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.screen {
  display: none;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom));
}

.screen.active { display: flex; flex-direction: column; }

body[data-screen="profile"] .header,
body[data-screen="profile"] .nav,
body[data-screen="create-family"] .header,
body[data-screen="create-family"] .nav,
body[data-screen="invite"] .header,
body[data-screen="invite"] .nav {
  display: none;
}

/* ═══════════════════════════════════════════════════════════════
   BOTTOM NAVIGATION
═══════════════════════════════════════════════════════════════ */
.nav {
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(255, 250, 244, 0.96);
  border-top: 1px solid rgba(190, 169, 139, 0.45);
  box-shadow: 0 -8px 24px rgba(131, 109, 84, 0.08);
  display: flex;
  align-items: stretch;
  flex-shrink: 0;
  z-index: 20;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  transition: color 0.15s;
  min-height: 48px;
  -webkit-tap-highlight-color: transparent;
}

.nav-btn svg { width: 22px; height: 22px; }

.nav-btn.active { color: var(--accent-strong); }

.nav-btn:active { opacity: 0.7; }

/* Scanner tab — accent circle */
.nav-btn.scanner-btn {
  position: relative;
}
.nav-btn.scanner-btn .nav-icon-wrap {
  width: 46px;
  height: 46px;
  background: linear-gradient(180deg, #9eb193 0%, #7f9475 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: -14px;
  box-shadow: 0 12px 18px rgba(114, 136, 106, 0.28);
}
.nav-btn.scanner-btn svg { color: #fffdf7; width: 22px; height: 22px; }
.nav-btn.scanner-btn.active .nav-icon-wrap { box-shadow: 0 14px 24px rgba(114, 136, 106, 0.36); }

/* ═══════════════════════════════════════════════════════════════
   COMMON COMPONENTS
═══════════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: 14px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  min-height: 48px;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { opacity: 0.8; transform: scale(0.97); }
.btn-primary {
  background: linear-gradient(180deg, #9db08f, #7f9474);
  color: #fffdf8;
  box-shadow: 0 10px 20px rgba(114, 136, 106, 0.2);
}
.btn-secondary { background: #efe5d6; color: var(--text); border-color: #dccab4; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: rgba(255, 251, 245, 0.72); border: 1px solid var(--border); color: var(--text2); }
.btn-sm { padding: 8px 14px; font-size: 13px; min-height: 36px; }
.btn-full { width: 100%; }

.input {
  width: 100%;
  background: rgba(255, 251, 245, 0.92);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 15px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
  -webkit-appearance: none;
}
.input:focus {
  border-color: var(--accent-strong);
  box-shadow: 0 0 0 4px rgba(142, 164, 131, 0.14);
  background: #fffdf9;
}
.input::placeholder { color: var(--text3); }

select.input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238892a4' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 18px;
  padding-right: 36px;
  cursor: pointer;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}
.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.card {
  background: var(--panel);
  border: 1px solid rgba(190, 169, 139, 0.5);
  border-radius: 18px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

/* Toast */
#toast {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 20px;
  font-size: 14px;
  color: var(--text);
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  white-space: nowrap;
  max-width: calc(100vw - 32px);
  pointer-events: none;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.success { border-color: var(--success); color: var(--success); }
#toast.error { border-color: var(--danger); color: var(--danger); }

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(2, 12, 26, 0.85);
  z-index: 200;
  align-items: flex-end;
  justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px;
  padding-bottom: calc(20px + var(--safe-bottom));
}
.modal-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 20px;
}

/* Skeleton loader */
.skeleton {
  background: linear-gradient(90deg, var(--panel) 25%, var(--border) 50%, var(--panel) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 6px;
}
@keyframes shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }

/* Divider */
.divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

/* Stars */
.stars {
  display: flex;
  gap: 4px;
  cursor: pointer;
}
.stars svg {
  width: 22px;
  height: 22px;
  color: var(--text3);
  transition: color 0.1s;
}
.stars svg.filled { color: #ffd700; }

/* ═══════════════════════════════════════════════════════════════
   SCREEN: BIBLIOTHEQUE (Library)
═══════════════════════════════════════════════════════════════ */
#screen-profile {
  justify-content: center;
  align-items: center;
  padding: 32px 20px;
  background:
    radial-gradient(circle at top, rgba(255,255,255,0.72), transparent 30%),
    linear-gradient(180deg, #f8f4ed 0%, #f2eadc 55%, #ebe0cf 100%);
}

.profile-shell {
  width: min(960px, 100%);
  display: flex;
  flex-direction: column;
  gap: 28px;
  align-items: center;
}

.profile-header {
  width: min(520px, 100%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.profile-title {
  font-size: clamp(28px, 4vw, 44px);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text);
  text-align: center;
}

.profile-subtitle {
  font-size: 14px;
  color: var(--text2);
  text-align: center;
  max-width: 520px;
  line-height: 1.45;
}

.profile-header .certificate-meta {
  margin-top: 0;
}

.profile-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 18px;
}

.invite-shell {
  width: min(760px, 100%);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 28px 16px calc(24px + env(safe-area-inset-bottom, 0px));
}

.invite-title {
  font-size: clamp(28px, 4vw, 40px);
  font-weight: 700;
  line-height: 1.08;
  color: var(--text);
}

.invite-subtitle {
  font-size: 15px;
  color: var(--text2);
  line-height: 1.6;
}

.invite-meta {
  font-size: 13px;
  color: var(--text3);
  line-height: 1.5;
}

.invite-member-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.invite-member-row {
  display: grid;
  grid-template-columns: minmax(0, 2fr) 140px 140px auto;
  gap: 10px;
  align-items: end;
}

.admin-invite-result {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(255, 250, 244, 0.8);
}

.admin-invite-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.admin-invite-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(255, 250, 244, 0.8);
}

.plan-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.plan-pill.free {
  color: #9b5d18;
  background: rgba(244, 202, 147, 0.28);
  border: 1px solid rgba(184, 125, 53, 0.2);
}

.plan-pill.premium {
  color: #45613f;
  background: rgba(190, 220, 182, 0.42);
  border: 1px solid rgba(94, 130, 85, 0.24);
}

.monetization-card {
  margin-top: 14px;
  padding: 16px;
  border-radius: 20px;
  border: 1px solid rgba(210, 184, 143, 0.34);
  background:
    radial-gradient(circle at top right, rgba(241, 216, 179, 0.38), transparent 36%),
    linear-gradient(145deg, rgba(255, 249, 241, 0.98), rgba(242, 231, 214, 0.96));
  box-shadow: 0 16px 34px rgba(84, 53, 20, 0.12);
}

.monetization-kicker {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #8f6a35;
}

.monetization-title {
  margin-top: 8px;
  font-size: 20px;
  font-weight: 800;
  color: #2f2318;
}

.monetization-text {
  margin-top: 8px;
  color: #6d5944;
  line-height: 1.55;
}

.monetization-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.inline-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.profile-card {
  border: 1px solid rgba(190, 169, 139, 0.5);
  background: linear-gradient(180deg, rgba(255, 251, 245, 0.95), rgba(243, 234, 221, 0.92));
  border-radius: 24px;
  padding: 18px 16px 20px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.18s, box-shadow 0.18s, border-color 0.18s;
  color: inherit;
}

.profile-card:hover,
.profile-card:active {
  transform: translateY(-3px);
  border-color: var(--accent-strong);
  box-shadow: 0 24px 34px rgba(131, 109, 84, 0.18);
}

.profile-avatar {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 18px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  color: #fffdf8;
  font-size: 40px;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.profile-avatar::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.2), transparent 45%),
    radial-gradient(circle at 70% 30%, rgba(255,255,255,0.18), transparent 20%);
}

.profile-name {
  font-size: 17px;
  font-weight: 700;
  text-align: center;
}

.certificate-shell {
  display: grid;
  gap: 18px;
  padding: 8px 0 24px;
}

.certificate-card {
  background: rgba(255, 252, 246, 0.92);
  border: 1px solid rgba(111, 132, 102, 0.18);
  border-radius: 26px;
  padding: 22px;
  box-shadow: 0 18px 50px rgba(91, 108, 82, 0.12);
}

.certificate-title {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 8px;
}

.certificate-text {
  color: var(--muted);
  line-height: 1.6;
}

.certificate-steps {
  display: grid;
  gap: 10px;
  margin: 18px 0 0;
  padding-left: 20px;
  color: var(--text);
}

.certificate-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.certificate-secret {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(135, 158, 118, 0.11);
  border: 1px dashed rgba(111, 132, 102, 0.32);
}

.certificate-secret-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-bottom: 8px;
}

.certificate-secret code {
  display: block;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  overflow-wrap: anywhere;
}

.certificate-meta {
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
}

.loan-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.loan-suggestion {
  border: 1px solid rgba(111, 132, 102, 0.22);
  background: rgba(255, 252, 246, 0.92);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
}

.loan-suggestion:active {
  transform: scale(0.98);
}

.loan-suggestion-empty {
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
}

#screen-library {
  gap: 0;
  overflow: hidden;
  padding-bottom: 0;
}

.lib-toolbar {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background:
    linear-gradient(180deg, rgba(255, 250, 244, 0.95), rgba(245, 237, 226, 0.9));
  border-bottom: 1px solid rgba(190, 169, 139, 0.45);
  flex-shrink: 0;
}

.media-switch {
  display: inline-flex;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 250, 244, 0.84);
  width: fit-content;
}

.media-switch-btn {
  border: none;
  background: transparent;
  color: var(--text2);
  font-size: 12px;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.media-switch-btn.active {
  background: linear-gradient(180deg, #9db08f, #7f9474);
  color: #fffdf7;
}

.lib-search-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.lib-search-wrap {
  flex: 1;
  position: relative;
}
.lib-search-wrap svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text3);
  pointer-events: none;
}
.lib-search-wrap .input { padding-left: 36px; }

.lib-sort-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.lib-sort-row::-webkit-scrollbar { display: none; }

.sort-pill {
  white-space: nowrap;
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text2);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.sort-pill.active {
  background: var(--accent-soft);
  border-color: var(--accent-strong);
  color: var(--accent-strong);
}

#lib-view-toggle {
  background: rgba(255, 250, 244, 0.84);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  color: var(--text2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
#lib-view-toggle svg { width: 18px; height: 18px; }

.lib-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 16px calc(24px + var(--nav-h) + var(--safe-bottom));
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.5), transparent 36%),
    linear-gradient(180deg, rgba(249, 243, 234, 0.9), rgba(242, 234, 221, 0.95));
}

#lib-grid {
  min-height: 100%;
}

/* Grid view */
.cd-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
@media (min-width: 480px) { .cd-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 720px) { .cd-grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 1024px) { .cd-grid { grid-template-columns: repeat(5, 1fr); } }

.cd-card {
  background: var(--panel);
  border: 1px solid rgba(190, 169, 139, 0.45);
  border-radius: 18px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.18s, border-color 0.18s, box-shadow 0.18s;
  box-shadow: var(--shadow);
  -webkit-tap-highlight-color: transparent;
}
.cd-card:active { transform: scale(0.96); }
.cd-card:hover { border-color: var(--border-strong); box-shadow: 0 20px 34px rgba(131, 109, 84, 0.16); }

.cd-cover-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  background: linear-gradient(180deg, #faf5ee, #efe5d8);
  overflow: hidden;
}
.cd-cover-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.cd-cover-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 8px;
  color: var(--text3);
}
.cd-cover-placeholder svg { width: 36px; height: 36px; }
.cd-cover-placeholder span { font-size: 10px; text-align: center; padding: 0 8px; }

.cd-rating-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(79, 70, 61, 0.78);
  border-radius: 6px;
  padding: 2px 6px;
  font-size: 11px;
  font-weight: 600;
  color: #ffd700;
  display: flex;
  align-items: center;
  gap: 2px;
}

.loan-badge {
  position: absolute;
  left: 8px;
  bottom: 8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.78);
  color: #fffdf8;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
  box-shadow: 0 10px 18px rgba(46, 52, 40, 0.18);
  z-index: 2;
}

.loan-badge.book-loan-badge {
  left: auto;
  right: -6px;
  bottom: -6px;
  width: 24px;
  height: 24px;
  font-size: 9px;
}

.cd-info {
  padding: 10px;
}
.cd-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}
.cd-artist {
  font-size: 12px;
  color: var(--text2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cd-year-genre {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}
.cd-year-genre span {
  font-size: 10px;
  color: var(--text3);
  background: rgba(233, 220, 199, 0.72);
  border-radius: 4px;
  padding: 2px 6px;
}

/* List view */
.cd-list { display: flex; flex-direction: column; gap: 8px; }

.cd-list-item {
  background: var(--panel);
  border: 1px solid rgba(190, 169, 139, 0.45);
  border-radius: 18px;
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px;
  cursor: pointer;
  transition: border-color 0.15s;
  box-shadow: var(--shadow);
  -webkit-tap-highlight-color: transparent;
}
.cd-list-item:active { opacity: 0.8; }

.cd-list-thumb {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
  background: linear-gradient(180deg, #faf5ee, #efe5d8);
  display: flex;
  align-items: center;
  justify-content: center;
}
.cd-list-thumb img { width: 100%; height: 100%; object-fit: cover; }
.cd-list-thumb svg { width: 24px; height: 24px; color: var(--text3); }

.cd-list-meta { flex: 1; overflow: hidden; }
.cd-list-title {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cd-list-artist {
  font-size: 13px;
  color: var(--text2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cd-list-sub {
  font-size: 11px;
  color: var(--text3);
  margin-top: 2px;
}

.cd-list-arrow {
  color: var(--text3);
  flex-shrink: 0;
}
.cd-list-arrow svg { width: 16px; height: 16px; }

.cd-list-trailing {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.cd-list-trailing .loan-badge {
  position: static;
  width: 26px;
  height: 26px;
  font-size: 9px;
  box-shadow: none;
}

.group-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
@media (min-width: 480px) { .group-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 720px) { .group-grid { grid-template-columns: repeat(4, 1fr); } }

.group-card {
  background: var(--panel);
  border: 1px solid rgba(190, 169, 139, 0.45);
  border-radius: 18px;
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.18s, border-color 0.18s, box-shadow 0.18s;
}
.group-card:active { transform: scale(0.98); }
.group-card:hover { border-color: var(--border-strong); box-shadow: 0 20px 34px rgba(131, 109, 84, 0.16); }

.group-cover {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  background: linear-gradient(180deg, #faf5ee, #efe5d8);
}

.group-cover > img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.group-cover-collage {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
  width: 100%;
  height: 100%;
  gap: 2px;
  background: rgba(236, 227, 214, 0.9);
}

.group-cover-collage img,
.group-cover-collage .group-cover-fallback {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.group-cover-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text3);
  background: linear-gradient(180deg, #f7f1e8, #eadfcf);
}

.console-cover-themed {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #16213e 0%, #0f3460 100%);
  padding: 18%;
  box-sizing: border-box;
}
.console-cover-themed img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 3px 10px rgba(0,0,0,0.6));
}

.group-count-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  min-width: 28px;
  height: 28px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(70, 81, 62, 0.84);
  color: #fffdf8;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 18px rgba(46, 52, 40, 0.18);
}

.group-info {
  padding: 12px;
}

.group-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.group-subtitle {
  margin-top: 4px;
  font-size: 12px;
  color: var(--text2);
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 60px 24px;
  text-align: center;
  color: var(--text3);
}
.empty-state svg { width: 56px; height: 56px; opacity: 0.5; }
.empty-state h3 { font-size: 18px; color: var(--text2); }
.empty-state p { font-size: 14px; line-height: 1.6; }

/* Bookshelf mode */
#lib-grid[data-media-type="book"][data-view-mode="grid"] {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(56px, 1fr));
  gap: 18px 10px;
  align-items: end;
  padding: 28px 20px 42px;
  border-radius: 28px;
  border: 10px solid rgba(178, 135, 91, 0.34);
  background:
    linear-gradient(180deg, rgba(255, 252, 247, 0.92), rgba(244, 235, 222, 0.98)),
    repeating-linear-gradient(to bottom,
      transparent 0 92px,
      rgba(214, 177, 129, 0.18) 92px 98px,
      rgba(173, 129, 82, 0.3) 98px 104px,
      rgba(221, 191, 152, 0.18) 104px 108px,
      transparent 108px 214px);
  box-shadow:
    inset 0 0 0 2px rgba(119, 81, 45, 0.12),
    inset 10px 0 16px rgba(122, 82, 47, 0.08),
    inset -10px 0 16px rgba(122, 82, 47, 0.08),
    inset 0 0 0 1px rgba(190, 169, 139, 0.38),
    inset 0 40px 60px rgba(255, 255, 255, 0.36),
    0 0 0 1px rgba(103, 71, 40, 0.06),
    var(--shadow);
  position: relative;
}

#lib-grid[data-media-type="book"][data-view-mode="grid"]::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 24px;
  background:
    radial-gradient(circle at 14% 10%, rgba(157, 176, 143, 0.12), transparent 12%),
    radial-gradient(circle at 88% 8%, rgba(235, 199, 154, 0.16), transparent 14%),
    radial-gradient(circle at 10% 92%, rgba(157, 176, 143, 0.12), transparent 12%),
    linear-gradient(180deg, transparent 0 92px, rgba(98, 69, 42, 0.05) 92px 94px, transparent 94px 214px, rgba(98, 69, 42, 0.05) 214px 216px, transparent 216px 336px, rgba(98, 69, 42, 0.05) 336px 338px, transparent 338px 100%);
  pointer-events: none;
}

#lib-grid[data-media-type="book"][data-view-mode="grid"]::after {
  content: '';
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 14px;
  height: 18px;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(202, 161, 113, 0.28), rgba(150, 112, 70, 0.42));
  box-shadow: 0 8px 18px rgba(120, 89, 56, 0.16);
  pointer-events: none;
}

.book-card {
  position: relative;
  display: flex;
  align-items: stretch;
  justify-content: center;
  min-height: 118px;
  border: none;
  background: transparent;
  box-shadow: none;
  overflow: visible;
  transform: rotate(var(--book-tilt, 0deg)) translateY(var(--book-offset, 0px));
}

.book-spine {
  position: relative;
  width: 100%;
  min-height: 100%;
  border-radius: 8px 8px 4px 4px;
  border: 1px solid rgba(152, 135, 111, 0.32);
  background:
    linear-gradient(90deg, rgba(255,255,255,0.55), transparent 12%, transparent 88%, rgba(0,0,0,0.05)),
    linear-gradient(180deg, var(--book-tone-light), var(--book-tone-dark));
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.35),
    0 12px 14px rgba(131, 109, 84, 0.09);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 10px 6px 8px;
  transform-origin: center bottom;
}

.book-spine::before,
.book-spine::after {
  content: '';
  position: absolute;
  left: 5px;
  right: 5px;
  height: 1px;
  background: rgba(140, 125, 102, 0.16);
}

.book-spine::before { top: 16px; }
.book-spine::after { bottom: 14px; }

.book-spine::marker { display: none; }

.book-spine-title {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.08;
  letter-spacing: 0.03em;
  color: rgba(88, 77, 66, 0.94);
  overflow: hidden;
  margin: 0 auto;
  max-height: calc(100% - 28px);
  white-space: normal;
  word-break: break-word;
}

.book-spine-author {
  font-size: 8px;
  color: rgba(116, 104, 90, 0.9);
  opacity: 0.9;
  margin-top: auto;
  writing-mode: horizontal-tb;
  text-orientation: mixed;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}

.book-shadow,
.book-crease,
.book-base-shadow {
  display: none;
}

.book-front,
.book-front-meta,
.book-front-author {
  display: none;
}

.book-rating-dot {
  position: absolute;
  top: -6px;
  right: 4px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff6d7;
  color: #b88b22;
  border: 1px solid rgba(184, 139, 34, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 800;
  box-shadow: 0 6px 10px rgba(131, 109, 84, 0.12);
}

#lib-grid[data-media-type="book"][data-view-mode="list"] .cd-list-item {
  background: linear-gradient(180deg, rgba(255, 251, 245, 0.94), rgba(247, 241, 231, 0.92));
}

/* Realistic bookshelf mode.
   Rollback path: set body.dataset.bookshelfStyle = 'classic' to keep the previous rendering. */
body[data-bookshelf-style="realistic"] #lib-grid[data-media-type="book"][data-view-mode="grid"] {
  grid-template-columns: repeat(auto-fit, minmax(58px, 1fr));
  gap: 22px 12px;
  padding: 34px 22px 54px;
  border-radius: 30px;
  border: 14px solid transparent;
  background:
    linear-gradient(135deg, rgba(205, 161, 116, 0.92), rgba(128, 84, 45, 0.94)) border-box,
    linear-gradient(180deg, rgba(255, 252, 248, 0.88), rgba(245, 235, 220, 0.98)),
    repeating-linear-gradient(to bottom,
      transparent 0 96px,
      rgba(128, 87, 44, 0.04) 96px 98px,
      rgba(193, 147, 95, 0.22) 98px 104px,
      rgba(119, 77, 38, 0.18) 104px 108px,
      transparent 108px 224px) padding-box;
  box-shadow:
    inset 0 0 0 2px rgba(105, 69, 37, 0.22),
    inset 16px 0 18px rgba(255, 228, 190, 0.16),
    inset -16px 0 18px rgba(70, 42, 17, 0.14),
    inset 0 16px 16px rgba(255, 228, 190, 0.14),
    inset 0 -16px 18px rgba(78, 49, 25, 0.1),
    inset 0 0 0 1px rgba(169, 136, 102, 0.24),
    inset 0 40px 60px rgba(255,255,255,0.35),
    inset 0 -24px 30px rgba(121, 80, 41, 0.06),
    0 0 0 1px rgba(88, 56, 27, 0.1),
    0 24px 38px rgba(120, 91, 59, 0.14);
}

body[data-bookshelf-style="realistic"] #lib-grid[data-media-type="book"][data-view-mode="grid"]::before {
  background:
    radial-gradient(circle at 12% 8%, rgba(255,255,255,0.26), transparent 11%),
    radial-gradient(circle at 86% 12%, rgba(255,233,205,0.18), transparent 13%),
    linear-gradient(180deg,
      transparent 0 96px,
      rgba(92, 62, 34, 0.08) 96px 97px,
      transparent 97px 224px,
      rgba(92, 62, 34, 0.08) 224px 225px,
      transparent 225px 352px,
      rgba(92, 62, 34, 0.08) 352px 353px,
      transparent 353px 100%);
}

body[data-bookshelf-style="realistic"] #lib-grid[data-media-type="book"][data-view-mode="grid"]::after {
  left: 20px;
  right: 20px;
  bottom: 12px;
  height: 24px;
  border-radius: 14px;
  background:
    linear-gradient(180deg, rgba(224, 186, 139, 0.58), rgba(151, 105, 60, 0.58)),
    linear-gradient(90deg, rgba(255,255,255,0.18), transparent 10%, transparent 90%, rgba(90,58,27,0.16));
  box-shadow:
    0 10px 22px rgba(102, 70, 42, 0.22),
    inset 0 2px 0 rgba(255,255,255,0.28);
}

body[data-bookshelf-style="realistic"] .book-card {
  align-self: end;
}

body[data-bookshelf-style="realistic"] .book-spine {
  border-radius: 9px 9px 3px 3px;
  border-color: rgba(108, 84, 63, 0.22);
  background:
    linear-gradient(90deg, rgba(255,255,255,0.52) 0 6%, rgba(255,255,255,0.08) 6% 12%, transparent 12% 88%, rgba(50,34,20,0.12) 88% 100%),
    linear-gradient(180deg, var(--book-tone-light), var(--book-tone-dark));
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,0.22),
    inset -8px 0 10px rgba(44, 30, 18, 0.08),
    0 14px 18px rgba(104, 74, 45, 0.11);
}

body[data-bookshelf-style="realistic"] .book-spine::before,
body[data-bookshelf-style="realistic"] .book-spine::after {
  left: 7px;
  right: 9px;
  background: rgba(88, 62, 41, 0.13);
}

body[data-bookshelf-style="realistic"] .book-shadow,
body[data-bookshelf-style="realistic"] .book-crease,
body[data-bookshelf-style="realistic"] .book-base-shadow {
  display: block;
}

body[data-bookshelf-style="realistic"] .book-shadow {
  position: absolute;
  inset: 10px 4px 6px auto;
  width: 10px;
  border-radius: 0 8px 8px 0;
  background: linear-gradient(180deg, rgba(53, 37, 24, 0.02), rgba(53, 37, 24, 0.14));
  mix-blend-mode: multiply;
  pointer-events: none;
}

body[data-bookshelf-style="realistic"] .book-crease {
  position: absolute;
  top: 7px;
  bottom: 7px;
  left: 9px;
  width: 2px;
  border-radius: 2px;
  background: rgba(255,255,255,0.24);
  pointer-events: none;
}

body[data-bookshelf-style="realistic"] .book-base-shadow {
  position: absolute;
  left: 4px;
  right: 4px;
  bottom: -7px;
  height: 12px;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(95, 66, 40, 0.22), transparent 68%);
  pointer-events: none;
}

body[data-bookshelf-style="realistic"] .book-spine-title {
  font-size: 11px;
  line-height: 1.05;
  letter-spacing: 0.04em;
  color: rgba(73, 58, 44, 0.96);
  text-shadow: 0 1px 0 rgba(255,255,255,0.22);
  max-height: calc(100% - 30px);
}

body[data-bookshelf-style="realistic"] .book-spine-author {
  font-size: 8px;
  color: rgba(98, 80, 62, 0.9);
  padding-top: 6px;
  border-top: 1px solid rgba(88, 62, 41, 0.12);
}

/* Software bookshelf mode inspired by classic library/catalog apps.
   Backup path: body.dataset.bookshelfStyle = 'realistic' */
body[data-bookshelf-style="software"] #lib-grid[data-media-type="book"][data-view-mode="grid"] {
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 28px 18px;
  align-items: end;
  padding: 30px 24px 58px;
  border-radius: 20px;
  border: 12px solid transparent;
  background:
    linear-gradient(135deg, rgba(165, 113, 66, 0.96), rgba(95, 58, 29, 0.98)) border-box,
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240' viewBox='0 0 240 240'%3E%3Crect width='240' height='240' fill='%23ead8bc'/%3E%3Cg opacity='.18'%3E%3Cpath d='M0 26h240M0 84h240M0 146h240M0 204h240' stroke='%23855532' stroke-width='2'/%3E%3Cpath d='M16 0c18 33 18 68 0 104s-18 71 0 104M68 0c22 41 22 81 0 122s-22 77 0 118M124 0c16 28 16 57 0 88s-16 62 0 96s16 56 0 56M182 0c20 38 20 79 0 118s-20 78 0 122' stroke='%23976842' stroke-width='3' fill='none' stroke-linecap='round'/%3E%3Cpath d='M36 20c36 8 62 8 98 0s62-8 106 0M24 118c44 10 70 10 112 0s68-10 104 0M10 188c30 7 64 7 98 0s76-7 122 0' stroke='%23fff7ea' stroke-width='2' fill='none' opacity='.5'/%3E%3C/g%3E%3C/svg%3E") padding-box,
    linear-gradient(180deg, rgba(246, 236, 220, 0.98), rgba(233, 217, 194, 0.98)) padding-box;
  box-shadow:
    inset 0 0 0 1px rgba(96, 61, 32, 0.24),
    inset 16px 0 18px rgba(255, 221, 177, 0.12),
    inset -16px 0 18px rgba(70, 42, 18, 0.12),
    0 26px 40px rgba(92, 59, 30, 0.18);
}

body[data-bookshelf-style="software"] #lib-grid[data-media-type="book"][data-view-mode="grid"]::before {
  background:
    radial-gradient(circle at 10% 8%, rgba(255,255,255,0.16), transparent 12%),
    radial-gradient(circle at 90% 10%, rgba(255,255,255,0.12), transparent 10%),
    linear-gradient(180deg, rgba(255,255,255,0.08), transparent 18%, transparent 82%, rgba(84, 50, 23, 0.08));
}

body[data-bookshelf-style="software"] #lib-grid[data-media-type="book"][data-view-mode="grid"]::after {
  left: 18px;
  right: 18px;
  bottom: 16px;
  height: 20px;
  border-radius: 10px;
  background:
    linear-gradient(180deg, rgba(190, 132, 78, 0.62), rgba(112, 68, 35, 0.72)),
    linear-gradient(90deg, rgba(255,255,255,0.14), transparent 12%, transparent 88%, rgba(67, 40, 19, 0.18));
  box-shadow:
    0 10px 22px rgba(96, 61, 32, 0.22),
    inset 0 2px 0 rgba(255,255,255,0.18);
}

body[data-bookshelf-style="software"] .book-card {
  width: 100% !important;
  min-height: 0;
  align-items: flex-end;
  transform: none;
  padding-bottom: 16px;
}

body[data-bookshelf-style="software"] .book-card::after {
  content: '';
  position: absolute;
  left: -8px;
  right: -8px;
  bottom: 0;
  height: 14px;
  border-radius: 5px;
  background:
    linear-gradient(180deg, rgba(214, 160, 101, 0.88), rgba(118, 71, 37, 0.92)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='24' viewBox='0 0 160 24'%3E%3Crect width='160' height='24' fill='%23b97c49'/%3E%3Cg opacity='.24'%3E%3Cpath d='M0 7c18 3 32 3 50 0s32-3 50 0s32 3 60 0' stroke='%23754523' stroke-width='2' fill='none'/%3E%3Cpath d='M0 17c22 4 36 4 56 0s36-4 56 0s30 4 48 0' stroke='%23f7d8b3' stroke-width='1.5' fill='none'/%3E%3C/g%3E%3C/svg%3E");
  box-shadow:
    0 8px 12px rgba(89, 53, 25, 0.18),
    inset 0 1px 0 rgba(255,255,255,0.18);
  pointer-events: none;
}

body[data-bookshelf-style="software"] .book-base-shadow,
body[data-bookshelf-style="software"] .book-spine,
body[data-bookshelf-style="software"] .book-shadow,
body[data-bookshelf-style="software"] .book-crease {
  display: none;
}

body[data-bookshelf-style="software"] .book-front {
  display: flex;
  flex-direction: column;
  width: 100%;
  aspect-ratio: 0.72;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(118, 78, 42, 0.24);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.22), rgba(255,255,255,0) 18%),
    linear-gradient(180deg, var(--book-tone-light), var(--book-tone-dark));
  box-shadow:
    0 10px 18px rgba(88, 54, 25, 0.16),
    0 3px 0 rgba(255,255,255,0.18) inset;
  position: relative;
}

body[data-bookshelf-style="software"] .book-front::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(115deg, rgba(255,255,255,0.18), transparent 28%, transparent 72%, rgba(0,0,0,0.08));
  pointer-events: none;
}

body[data-bookshelf-style="software"] .book-front img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

body[data-bookshelf-style="software"] .book-front-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 12px 10px 10px;
}

body[data-bookshelf-style="software"] .book-front-title {
  font-size: 12px;
  line-height: 1.2;
  font-weight: 700;
  color: rgba(72, 52, 35, 0.96);
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

body[data-bookshelf-style="software"] .book-front-author {
  display: block;
  margin-top: 10px;
  font-size: 10px;
  color: rgba(97, 76, 58, 0.9);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

body[data-bookshelf-style="software"] .book-front-meta {
  display: block;
  margin-top: 8px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(118, 82, 47, 0.72);
}

body[data-bookshelf-style="software"] .book-rating-dot {
  top: -8px;
  right: -4px;
  z-index: 3;
}

body[data-bookshelf-style="software"] .loan-badge.book-loan-badge {
  right: -6px;
  bottom: -6px;
  z-index: 3;
}

/* ═══════════════════════════════════════════════════════════════
   SCREEN: SCANNER
═══════════════════════════════════════════════════════════════ */
#screen-scanner {
  background: #000;
  position: relative;
  overflow: hidden;
}

#scanner-video-wrap {
  position: relative;
  width: 100%;
  flex: 1;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

#scanner-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Quagga insère sa propre <video> et <canvas> dans le conteneur */
#scanner-video-wrap video {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  object-fit: cover;
  display: block;
}

/* Canvas de détection Quagga — masqué, on n’a pas besoin des tracés */
#scanner-video-wrap canvas,
#scanner-canvas {
  display: none !important;
}

/* Overlay */
.scanner-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* Dark vignette around scan area */
.scanner-vignette-top,
.scanner-vignette-bottom,
.scanner-vignette-left,
.scanner-vignette-right {
  position: absolute;
  background: rgba(2, 12, 26, 0.72);
}
.scanner-vignette-top    { top: 0; left: 0; right: 0; height: calc(50% - 60px); }
.scanner-vignette-bottom { bottom: 0; left: 0; right: 0; height: calc(50% - 60px); }
.scanner-vignette-left   { top: calc(50% - 60px); bottom: calc(50% - 60px); left: 0; width: calc(50% - 130px); }
.scanner-vignette-right  { top: calc(50% - 60px); bottom: calc(50% - 60px); right: 0; width: calc(50% - 130px); }

/* Scan rectangle */
.scan-rect {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 260px;
  height: 120px;
  border: 2px solid var(--accent);
  border-radius: 8px;
  box-shadow: 0 0 0 4px rgba(0, 212, 255, 0.1);
}

/* Corner accents */
.scan-rect::before, .scan-rect::after,
.scan-rect .corner-br, .scan-rect .corner-tl {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  border-color: var(--accent);
  border-style: solid;
}
.scan-rect::before { top: -2px; left: -2px; border-width: 3px 0 0 3px; border-radius: 4px 0 0 0; }
.scan-rect::after  { top: -2px; right: -2px; border-width: 3px 3px 0 0; border-radius: 0 4px 0 0; }
.scan-rect .corner-bl { position: absolute; bottom: -2px; left: -2px; width: 20px; height: 20px; border: solid var(--accent); border-width: 0 0 3px 3px; border-radius: 0 0 0 4px; }
.scan-rect .corner-br { position: absolute; bottom: -2px; right: -2px; width: 20px; height: 20px; border: solid var(--accent); border-width: 0 3px 3px 0; border-radius: 0 0 4px 0; }

/* Scanning line animation */
.scan-line {
  position: absolute;
  left: 4px;
  right: 4px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  top: 0;
  animation: scanMove 2s ease-in-out infinite;
  border-radius: 1px;
}
@keyframes scanMove {
  0%   { top: 4px; opacity: 1; }
  50%  { top: calc(100% - 6px); opacity: 1; }
  100% { top: 4px; opacity: 1; }
}

/* Scanner status panel */
.scanner-status {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(transparent, rgba(2, 12, 26, 0.95));
  padding: 32px 20px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  pointer-events: none;
}

.scanner-status .status-text {
  font-size: 14px;
  color: var(--text2);
  text-align: center;
}

.scanner-status .scan-result-text {
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
  text-align: center;
}

.scanner-status .scanner-btns {
  display: flex;
  gap: 10px;
  pointer-events: all;
  flex-wrap: wrap;
  justify-content: center;
}

/* No camera fallback */
.scanner-fallback {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 40px 24px;
  flex: 1;
  text-align: center;
}

.scanner-fallback svg { width: 48px; height: 48px; color: var(--text3); }
.scanner-fallback h3 { font-size: 18px; color: var(--text2); }
.scanner-fallback p { font-size: 14px; color: var(--text3); line-height: 1.6; }

.manual-barcode-wrap {
  width: 100%;
  max-width: 320px;
  display: flex;
  gap: 8px;
}

.inline-lookup-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.inline-lookup-row .input {
  flex: 1;
}

/* Scanned feedback flash */
.scan-flash {
  position: absolute;
  inset: 0;
  background: rgba(0, 212, 255, 0.2);
  pointer-events: none;
  opacity: 0;
  animation: flashAnim 0.4s forwards;
}
@keyframes flashAnim { 0% { opacity: 1; } 100% { opacity: 0; } }

#scanner-media-switch.media-switch {
  background: rgba(2, 12, 26, 0.75);
  border-color: rgba(255, 255, 255, 0.15);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  pointer-events: all;
}
#scanner-media-switch.media-switch::-webkit-scrollbar { display: none; }
#scanner-media-switch .media-switch-btn {
  color: rgba(255, 255, 255, 0.65);
  font-size: 11px;
  padding: 6px 10px;
  white-space: nowrap;
}
#scanner-media-switch .media-switch-btn.active {
  color: #fffdf7;
}

/* ═══════════════════════════════════════════════════════════════
   SCREEN: ADD/EDIT FORM
═══════════════════════════════════════════════════════════════ */
#screen-form { padding: 16px; gap: 16px; }

.cover-preview-wrap {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.cover-preview-img {
  width: 100px;
  height: 100px;
  border-radius: 10px;
  border: 1px solid var(--border);
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.cover-preview-img img { width: 100%; height: 100%; object-fit: cover; }
.cover-preview-img svg { width: 36px; height: 36px; color: var(--text3); }

.cover-preview-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.fetched-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  background: rgba(46, 213, 115, 0.12);
  color: var(--success);
  border: 1px solid rgba(46, 213, 115, 0.3);
}
.fetched-badge svg { width: 14px; height: 14px; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form-actions {
  display: flex;
  gap: 10px;
  padding-top: 8px;
}

.owners-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
}

.owner-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(255, 251, 245, 0.86);
  color: var(--text2);
  cursor: pointer;
}

.owner-chip input {
  accent-color: var(--accent-strong);
}

.hidden {
  display: none !important;
}

/* Tracklist editor */
.tracklist-editor {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.track-item {
  display: flex;
  gap: 8px;
  align-items: center;
}
.track-num {
  width: 28px;
  text-align: center;
  font-size: 12px;
  color: var(--text3);
  flex-shrink: 0;
}
.track-item .input { flex: 1; padding: 8px 12px; font-size: 14px; }
.track-duration {
  width: 60px;
  padding: 8px 8px;
  font-size: 13px;
  text-align: center;
}
.track-remove {
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  padding: 4px;
  display: flex;
  -webkit-tap-highlight-color: transparent;
}
.track-remove:hover { color: var(--danger); }
.track-remove svg { width: 16px; height: 16px; }

/* ═══════════════════════════════════════════════════════════════
   SCREEN: DETAIL
═══════════════════════════════════════════════════════════════ */
#screen-detail { gap: 0; }

.detail-hero {
  background: linear-gradient(180deg, rgba(255, 250, 244, 0.98), rgba(243, 235, 224, 0.92));
  border-bottom: 1px solid rgba(190, 169, 139, 0.42);
  padding: 20px 16px;
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.detail-cover {
  width: 110px;
  height: 110px;
  border-radius: 10px;
  overflow: hidden;
  flex-shrink: 0;
  background: linear-gradient(180deg, #faf5ee, #efe5d8);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
}
.detail-cover img { width: 100%; height: 100%; object-fit: cover; }
.detail-cover svg { width: 40px; height: 40px; color: var(--text3); }

.detail-meta { flex: 1; overflow: hidden; }
.detail-title { font-size: 18px; font-weight: 700; line-height: 1.3; margin-bottom: 4px; }
.detail-artist { font-size: 15px; color: var(--accent); margin-bottom: 8px; }
.detail-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }

.detail-body { padding: 16px; display: flex; flex-direction: column; gap: 16px; }

.detail-section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 10px;
}

.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.info-item { display: flex; flex-direction: column; gap: 2px; }
.info-label { font-size: 11px; color: var(--text3); text-transform: uppercase; letter-spacing: 0.4px; }
.info-value { font-size: 14px; color: var(--text); }

.tracklist-view { display: flex; flex-direction: column; gap: 0; }
.tracklist-track {
  display: flex;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(190, 169, 139, 0.3);
  align-items: center;
}
.tracklist-track:last-child { border-bottom: none; }
.track-n { width: 24px; text-align: right; font-size: 13px; color: var(--text3); flex-shrink: 0; }
.track-t { flex: 1; font-size: 14px; }
.track-d { font-size: 12px; color: var(--text3); flex-shrink: 0; }

.detail-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.rating-section { display: flex; flex-direction: column; gap: 8px; }
.rating-label { font-size: 12px; color: var(--text3); }

.notes-display {
  font-size: 14px;
  color: var(--text2);
  line-height: 1.7;
  white-space: pre-wrap;
}

/* ═══════════════════════════════════════════════════════════════
   SCREEN: STATS
═══════════════════════════════════════════════════════════════ */
#screen-stats { gap: 0; overflow: hidden; padding-bottom: 0; }
#screen-admin { padding: 16px; gap: 12px; }

.stats-toolbar {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background:
    linear-gradient(180deg, rgba(255, 250, 244, 0.95), rgba(245, 237, 226, 0.9));
  border-bottom: 1px solid rgba(190, 169, 139, 0.45);
  flex-shrink: 0;
}

.stats-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 16px calc(24px + var(--nav-h) + var(--safe-bottom));
}

.stats-hero {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.stat-box {
  background: var(--panel);
  border: 1px solid rgba(190, 169, 139, 0.45);
  border-radius: 18px;
  padding: 16px 10px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent-strong);
  line-height: 1.1;
}
.stat-label { font-size: 11px; color: var(--text3); margin-top: 4px; text-transform: uppercase; }

.genre-bar {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.genre-row { display: flex; flex-direction: column; gap: 4px; }
.genre-row-header { display: flex; justify-content: space-between; }
.genre-name { font-size: 13px; color: var(--text2); }
.genre-count { font-size: 13px; color: var(--text3); }
.genre-bar-track { height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; }
.genre-bar-fill { height: 100%; background: var(--accent); border-radius: 3px; transition: width 0.6s ease; }

.artist-list { display: flex; flex-direction: column; gap: 6px; }
.artist-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: 8px;
}
.artist-name { font-size: 13px; color: var(--text); }
.artist-count { font-size: 12px; color: var(--text3); }

.loan-item-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.loan-item-subtitle {
  font-size: 12px;
  color: var(--text3);
}

.recent-list { display: flex; flex-direction: column; gap: 8px; }
.recent-item {
  display: flex;
  gap: 10px;
  align-items: center;
  cursor: pointer;
}
.recent-thumb {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}
.recent-thumb img { width: 100%; height: 100%; object-fit: cover; }
.recent-thumb svg { width: 18px; height: 18px; color: var(--text3); }
.admin-user-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
  margin-top: 16px;
}
.admin-user-panel {
  background: rgba(255, 255, 255, 0.52);
  border: 1px solid rgba(190, 169, 139, 0.38);
  border-radius: 18px;
  padding: 16px;
}
.admin-user-panel-title {
  font-size: 14px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 6px;
}
.admin-user-list-header {
  margin-top: 18px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.admin-member-row {
  position: relative;
  background: var(--panel);
  border: 1px solid rgba(190, 169, 139, 0.45);
  border-radius: 18px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.admin-member-main {
  min-width: 0;
  flex: 1;
}
.admin-member-name {
  font-size: 15px;
  font-weight: 800;
  color: var(--text);
}
.admin-member-role {
  font-size: 12px;
  color: var(--text2);
  margin-top: 4px;
}
.admin-member-badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.badge.badge-accent {
  background: rgba(170, 104, 57, 0.12);
  color: #8b532d;
  border: 1px solid rgba(170, 104, 57, 0.22);
}
.admin-member-menu-wrap {
  position: relative;
  flex-shrink: 0;
}
.admin-member-menu-trigger {
  width: 38px;
  height: 38px;
  min-height: 38px;
  padding: 0;
  border-radius: 12px;
}
.admin-member-menu-trigger svg {
  width: 18px;
  height: 18px;
}
.admin-member-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  padding: 8px;
  border-radius: 16px;
  border: 1px solid rgba(190, 169, 139, 0.45);
  background: rgba(255, 251, 245, 0.98);
  box-shadow: 0 22px 36px rgba(79, 70, 61, 0.16);
  z-index: 20;
}
.admin-member-menu button {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  text-align: left;
  font-size: 14px;
  cursor: pointer;
}
.admin-member-menu button:hover {
  background: rgba(142, 164, 131, 0.12);
}
.admin-member-menu button.danger {
  color: var(--danger);
}
.admin-member-menu-note {
  padding: 8px 12px 4px;
  font-size: 12px;
  color: var(--text3);
}
.admin-member-empty {
  color: var(--text2);
  font-size: 13px;
  margin-top: 10px;
}
@media (max-width: 640px) {
  .admin-member-row {
    align-items: flex-start;
  }
}
.admin-log-shell {
  margin-top: 14px;
}
.admin-log-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.admin-log-toolbar-main {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.admin-log-count {
  font-size: 12px;
  color: var(--text2);
}
.admin-log-panel[hidden] { display: none !important; }
.admin-log-list { display: flex; flex-direction: column; gap: 10px; }
.admin-log-card {
  background: var(--panel);
  border: 1px solid rgba(190, 169, 139, 0.45);
  border-radius: 18px;
  padding: 14px;
  box-shadow: var(--shadow);
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.admin-log-thumb {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.admin-log-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.admin-log-thumb svg { width: 24px; height: 24px; color: var(--text3); }
.admin-log-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.admin-log-top { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.admin-log-title { font-size: 14px; font-weight: 700; color: var(--text); }
.admin-log-meta { font-size: 12px; color: var(--text2); }
.admin-log-badges { display: flex; gap: 6px; flex-wrap: wrap; }
.admin-log-badges .badge { font-size: 10px; }
.admin-log-actions { display: flex; align-items: center; justify-content: flex-end; flex-shrink: 0; }
.recent-meta { flex: 1; overflow: hidden; }
.recent-title { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-artist { font-size: 12px; color: var(--text2); }

/* ═══════════════════════════════════════════════════════════════
   LOOKUP LOADING OVERLAY
═══════════════════════════════════════════════════════════════ */
#lookup-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(2, 12, 26, 0.8);
  z-index: 300;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
}
#lookup-overlay.active { display: flex; }
.lookup-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.lookup-text { font-size: 15px; color: var(--text2); }

/* ═══════════════════════════════════════════════════════════════
   CONFIRM DIALOG
═══════════════════════════════════════════════════════════════ */
#confirm-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(2, 12, 26, 0.85);
  z-index: 400;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#confirm-overlay.active { display: flex; }
.confirm-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  max-width: 340px;
  width: 100%;
  text-align: center;
}
.confirm-title { font-size: 17px; font-weight: 700; margin-bottom: 8px; }
.confirm-msg { font-size: 14px; color: var(--text2); line-height: 1.5; margin-bottom: 20px; }
.confirm-actions { display: flex; gap: 10px; }
.confirm-actions .btn { flex: 1; }

#tutorial-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(9, 16, 25, 0.82);
  z-index: 450;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
#tutorial-overlay.active { display: flex; }
.tutorial-box {
  width: min(760px, 100%);
  max-height: min(90vh, 920px);
  overflow: auto;
  background: linear-gradient(180deg, #fffdf8 0%, #f8f1e6 100%);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 24px 60px rgba(19, 28, 38, 0.24);
  padding: 22px;
}
.tutorial-kicker {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text3);
}
.tutorial-title {
  font-size: 28px;
  font-weight: 800;
  line-height: 1.1;
  margin-top: 8px;
}
.tutorial-subtitle {
  margin-top: 10px;
  color: var(--text2);
  line-height: 1.6;
}
.tutorial-grid {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}
.tutorial-step {
  background: rgba(255,255,255,0.88);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
}
.tutorial-step-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.tutorial-step-index {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  flex: 0 0 auto;
}
.tutorial-step-title {
  font-size: 16px;
  font-weight: 700;
}
.tutorial-step p {
  margin: 0;
  color: var(--text2);
  line-height: 1.6;
}
.tutorial-step-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}
.tutorial-note {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: 14px;
  background: rgba(255,255,255,0.84);
  border: 1px dashed var(--border);
  color: var(--text2);
  line-height: 1.6;
}
.tutorial-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 18px;
}

/* ═══════════════════════════════════════════════════════════════
   SCROLLBAR
═══════════════════════════════════════════════════════════════ */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE DESKTOP
═══════════════════════════════════════════════════════════════ */
@media (min-width: 768px) {
  .nav { justify-content: center; }
  .nav-btn { max-width: 120px; }
  .modal { max-width: 520px; border-radius: 16px; margin: auto; }
  .modal-overlay { align-items: center; }
}

@media (max-width: 767px) {
  .invite-member-row {
    grid-template-columns: 1fr;
  }
}
