/* ---------- Design tokens (mirror Tailwind config) ---------- */
:root {
  --bg: #EFEFEF;
  --card: #FFFFFF;
  --ink: #0A0A0A;
  --muted: #8E8E93;
  --line: #E5E5EA;
  --accent: #F87171;

  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);

  --nav-height: 76px;
}

html, body { background: var(--bg); overflow-x: hidden; }
body {
  -webkit-tap-highlight-color: transparent;
  background-image:
    url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.045 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-repeat: repeat;
}
* { -webkit-touch-callout: none; }

/* Tabular figures for any price/number display */
.tnum, .vinyl-card-price, .cover-disc + * .text-2xl,
[class*="text-3xl"] .font-serif, .font-serif.text-3xl {
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
}

/* Fade-up stagger for grid cards (collection / shelf / wishlist) */
@keyframes fade-up {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: no-preference) {
  #vinyl-grid > *,
  #vinyl-shelf > *,
  .h-scroll > *,
  .wishlist-grid > * {
    animation: fade-up 0.35s ease-out both;
  }
  #vinyl-grid > *:nth-child(1), #vinyl-shelf > *:nth-child(1) { animation-delay: 0ms; }
  #vinyl-grid > *:nth-child(2), #vinyl-shelf > *:nth-child(2) { animation-delay: 35ms; }
  #vinyl-grid > *:nth-child(3), #vinyl-shelf > *:nth-child(3) { animation-delay: 70ms; }
  #vinyl-grid > *:nth-child(4), #vinyl-shelf > *:nth-child(4) { animation-delay: 105ms; }
  #vinyl-grid > *:nth-child(5), #vinyl-shelf > *:nth-child(5) { animation-delay: 140ms; }
  #vinyl-grid > *:nth-child(6), #vinyl-shelf > *:nth-child(6) { animation-delay: 175ms; }
  #vinyl-grid > *:nth-child(7), #vinyl-shelf > *:nth-child(7) { animation-delay: 210ms; }
  #vinyl-grid > *:nth-child(8), #vinyl-shelf > *:nth-child(8) { animation-delay: 245ms; }
  #vinyl-grid > *:nth-child(n+9), #vinyl-shelf > *:nth-child(n+9) { animation-delay: 280ms; }
}

/* Headings get the serif treatment by default */
h1, h2, h3, .font-display { font-family: 'Fraunces', Georgia, serif; letter-spacing: -0.01em; }

/* ---------- Hide scrollbars on horizontal scrollers ---------- */
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }
.no-scrollbar::-webkit-scrollbar { display: none; }

/* ---------- Bottom navigation with central FAB notch ---------- */
.bnav {
  position: fixed;
  left: 0; right: 0;
  bottom: 0;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--card);
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: center;
  /* Notch carved out top-center for the floating FAB */
  -webkit-mask:
    radial-gradient(28px at 50% 0, transparent 98%, #000 100%) 50% 0/100% 32px no-repeat,
    linear-gradient(#000, #000) 0 32px/100% calc(100% - 32px) no-repeat;
          mask:
    radial-gradient(28px at 50% 0, transparent 98%, #000 100%) 50% 0/100% 32px no-repeat,
    linear-gradient(#000, #000) 0 32px/100% calc(100% - 32px) no-repeat;
  box-shadow: 0 -2px 12px rgba(0,0,0,0.04);
}
.bnav-item {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 4px;
  color: var(--muted);
  font-size: 1.25rem;
  padding-top: 8px;
  transition: color 0.15s ease;
}
.bnav-item::after {
  content: '';
  width: 5px; height: 5px;
  border-radius: 50%;
  background: transparent;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}
.bnav-item.active { color: var(--accent); }
.bnav-item.active::after {
  background: var(--accent);
  box-shadow: 0 0 6px rgba(255, 90, 75, 0.55);
}
.bnav-fab {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(var(--safe-bottom) + var(--nav-height) - 30px);
  width: 56px; height: 56px;
  background: var(--ink); color: #fff;
  border-radius: 9999px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  z-index: 41;
  box-shadow: 0 10px 24px rgba(0,0,0,0.25);
}
.bnav-fab:active { transform: translateX(-50%) scale(0.96); }

/* ---------- Horizontal album carousels (Popular Today / Recents) ---------- */
.h-scroll {
  display: flex; gap: 12px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  padding: 4px 20px 4px 20px;
  margin: 0 -20px;
}
.h-scroll > * { scroll-snap-align: start; flex: 0 0 auto; }

/* ---------- Vinyl shelf: 3D cover wall (drag to rearrange) ---------- */
.shelf {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.875rem;
  padding: 0.5rem 0 1.25rem;
}
@media (min-width: 640px) {
  .shelf { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1.125rem; }
}

.shelf-item {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: inherit;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
  touch-action: none;
  min-width: 0;
}
.shelf-item:active { cursor: grabbing; }

.shelf-item__cover {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 0.625rem;
  overflow: hidden;
  background: var(--line);
  transform: perspective(800px) rotateY(-5deg);
  transform-origin: right center;
  box-shadow:
    0 8px 18px rgba(0, 0, 0, 0.18),
    0 2px 4px rgba(0, 0, 0, 0.10);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  -webkit-touch-callout: none;
}
.shelf-item__cover img,
.shelf-item__placeholder {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  user-select: none;
}
.shelf-item__placeholder {
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 1.5rem;
}

.shelf-item:hover .shelf-item__cover,
.shelf-item:focus-visible .shelf-item__cover {
  transform: perspective(800px) rotateY(0deg) translateY(-3px);
  box-shadow:
    0 14px 26px rgba(0, 0, 0, 0.22),
    0 4px 8px rgba(0, 0, 0, 0.12);
}

.shelf-item__meta {
  margin-top: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  min-width: 0;
}
.shelf-item__artist {
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.shelf-item__title {
  font-family: 'Fraunces', serif;
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.2;
  color: var(--ink);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Drag states (SortableJS) */
.sortable-ghost { opacity: 0.25; }
.sortable-ghost .shelf-item__cover { box-shadow: none; }
.sortable-chosen .shelf-item__cover {
  transform: perspective(800px) rotateY(0deg) scale(1.06);
  box-shadow:
    0 20px 36px rgba(0, 0, 0, 0.28),
    0 6px 12px rgba(0, 0, 0, 0.16);
}
.shelf.dragging .shelf-item { transition: none; }

/* ---------- Scanner (camera overlay) ---------- */
#qr-video {
  width: 100%;
  max-width: 360px;
  aspect-ratio: 1;
  margin: 0 auto;
  border-radius: 1.5rem;
  overflow: hidden;
  background: #000;
  position: relative;
}
#qr-video video {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover;
  border-radius: 1.5rem;
}
.scanner-frame {
  position: relative;
  border-radius: 1.5rem;
  overflow: hidden;
}

/* ---------- Form inputs (overrides Django widget defaults) ---------- */
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="url"], input[type="search"], select, textarea {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 0.875rem;
  padding: 0.75rem 1rem;
  font: inherit; color: var(--ink);
  -webkit-appearance: none; appearance: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(10,10,10,0.06);
}
textarea { min-height: 96px; resize: vertical; }
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%238E8E93'%3E%3Cpath d='M5 8l5 5 5-5H5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 1.25rem;
  padding-right: 2.5rem;
}

/* Compact pill selects in the filter bar */
#filter-options select,
select.wishlist-priority {
  border-radius: 9999px;
  padding: 0.5rem 2rem 0.5rem 1rem;
  font-size: 0.8125rem;
  background-position: right 0.6rem center;
  background-size: 1rem;
  text-overflow: ellipsis;
}

/* Pill-shaped selects inside vinyl forms (match filter bar style) */
form.space-y-4 select {
  border-radius: 9999px;
  padding: 0.75rem 2.5rem 0.75rem 1.25rem;
  background-position: right 1rem center;
}

/* Scanner condition select — id selector wins over Tailwind CDN preflight,
   which is injected after app.css and strips the bare `select` styling. */
#scan-condition {
  width: 100%;
  background-color: var(--card);
  border: 1px solid var(--line);
  border-radius: 9999px;
  padding: 0.75rem 2.5rem 0.75rem 1.25rem;
  font: inherit;
  color: var(--ink);
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%238E8E93'%3E%3Cpath d='M5 8l5 5 5-5H5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  background-size: 1.25rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
#scan-condition:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(10,10,10,0.06);
}

/* Roomier textarea so text isn't cramped in the top-right corner */
form.space-y-4 textarea {
  padding: 1rem 1.25rem;
  line-height: 1.5;
  min-height: 110px;
}

/* ---------- Loading spinner ---------- */
.spinner-ring {
  width: 32px; height: 32px;
  border: 3px solid var(--line);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Info list smallcaps labels (vinyl detail) */
.info-list > div {
  gap: 1rem;
  align-items: baseline;
}
.info-list dt {
  font-variant-caps: all-small-caps;
  letter-spacing: 0.06em;
  font-weight: 600;
  color: var(--muted);
  flex-shrink: 0;
}
.info-list dd {
  font-variant-numeric: tabular-nums;
  text-align: right;
  min-width: 0;
  word-break: break-word;
}

/* ---------- List view (collection) ---------- */
#vinyl-grid.list-mode {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
#vinyl-grid.list-mode .vinyl-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
}
#vinyl-grid.list-mode .vinyl-cover-wrap {
  flex: 0 0 56px;
  width: 56px; height: 56px;
  border-radius: 0.5rem;
  overflow: hidden;
  aspect-ratio: 1;
}
#vinyl-grid.list-mode .vinyl-card-body {
  flex: 1;
  min-width: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "artist price" "title year";
  column-gap: 0.5rem;
  row-gap: 0.125rem;
}
#vinyl-grid.list-mode .vinyl-card-artist { grid-area: artist; }
#vinyl-grid.list-mode .vinyl-card-title  { grid-area: title; font-size: 0.95rem; }
#vinyl-grid.list-mode .vinyl-card-body > .flex { display: contents; }
#vinyl-grid.list-mode .vinyl-card-year   { grid-area: year; justify-self: end; }
#vinyl-grid.list-mode .vinyl-card-price  { grid-area: price; justify-self: end; }

/* ---------- Vinyl cover with disc sticking out (detail page) ---------- */
.cover-disc {
  position: relative;
  width: min(50%, 220px);
  margin: 0 auto 0.5rem;
  aspect-ratio: 1;
  overflow: visible;
}
.cover-disc__glow {
  position: absolute;
  z-index: 0;
  inset: -45%;
  width: 190%; height: 190%;
  object-fit: cover;
  border-radius: 50%;
  filter: blur(50px) saturate(1.8);
  opacity: 0.5;
  pointer-events: none;
}
.cover-disc__disc {
  position: absolute;
  z-index: 1;
  top: 2%;
  right: -26%;
  width: 96%;
  aspect-ratio: 1;
  height: auto;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, #c81e1e 0 5.5%, #0a0a0a 5.5% 7%, transparent 7%),
    repeating-radial-gradient(circle at 50% 50%, rgba(255,255,255,0.05) 0 1px, transparent 1px 4px),
    radial-gradient(circle at 30% 30%, #2a2a2a 0%, #050505 70%);
  box-shadow: 0 10px 28px rgba(0,0,0,0.35);
  animation: vinyl-spin 16s linear infinite;
}
.cover-disc__disc::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 2.4%; height: 2.4%;
  border-radius: 50%;
  background: var(--bg);
}
.cover-disc__cover {
  position: relative;
  z-index: 2;
  width: 100%;
  aspect-ratio: 1;
  height: auto;
  object-fit: cover;
  border-radius: 0.75rem;
  box-shadow: 0 14px 32px rgba(0,0,0,0.22);
}
@keyframes vinyl-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .cover-disc__disc { animation: none; }
}

/* ---------- Collection filter / view modes ---------- */
#filter-options { display: none; }
#filter-bar.filters-open #filter-options { display: grid; }
.card-hidden { display: none !important; }
.view-mode-toggle .scanner-mode-btn.active { background: #0A0A0A; color: #fff; }

/* List view: stack vinyl-card horizontally */
#vinyl-grid.list-mode { grid-template-columns: 1fr; }
#vinyl-grid.list-mode .vinyl-card {
    display: grid;
    grid-template-columns: 64px 1fr auto;
    gap: 12px;
    align-items: center;
    padding: 8px;
}
#vinyl-grid.list-mode .vinyl-cover-wrap { width: 64px; height: 64px; border-radius: 0.75rem; overflow: hidden; aspect-ratio: 1; }
#vinyl-grid.list-mode .vinyl-card-body { padding: 0; }
.shelf-item--selected { outline: none; }

/* ---------- Scanner: tab + mode states ---------- */
.scanner-section.tab-hidden { display: none; }
.scanner-tab-btn.active { background: #0A0A0A; color: #fff; }
.scanner-mode-btn.active { background: #0A0A0A; color: #fff; }

/* Scanner result cards (built dynamically by scanner.js) */
.result-vinyl-card {
    background: #fff;
    border-radius: 1rem;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04), 0 2px 8px rgba(0,0,0,0.04);
    display: flex; flex-direction: column;
    position: relative;
}
.result-vinyl-card .vinyl-cover-wrap { aspect-ratio: 1; background: var(--line); }
.result-vinyl-card .vinyl-cover-img { width: 100%; height: 100%; object-fit: cover; }
.result-vinyl-card .vinyl-cover-placeholder { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 1.5rem; }
.result-vinyl-card .vinyl-card-body { padding: 12px; display: flex; flex-direction: column; gap: 2px; }
.result-vinyl-card .vinyl-card-artist { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; }
.result-vinyl-card .vinyl-card-title { font-family: 'Fraunces', serif; font-size: 0.95rem; font-weight: 600; line-height: 1.2; }
.result-vinyl-card .vinyl-card-year { font-size: 0.75rem; color: var(--muted); }
.result-vinyl-card .result-card-meta-row { display: flex; gap: 8px; flex-wrap: wrap; font-size: 0.7rem; color: var(--muted); margin-top: 4px; }
.result-vinyl-card .vinyl-card-price { font-size: 0.85rem; font-weight: 600; color: var(--ink); margin-top: 6px; }
.result-vinyl-card .price-loading::after { content: '…'; color: var(--muted); }
.result-vinyl-card .result-add-btn {
    position: absolute; top: 8px; right: 8px;
    width: 36px; height: 36px;
    border-radius: 9999px;
    background: var(--ink); color: #fff;
    display: flex; align-items: center; justify-content: center;
    border: none; cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
.result-vinyl-card .result-add-btn.btn-wishlist-mode { background: var(--accent); }
.result-vinyl-card .result-add-btn.btn-added { background: #34c759; }
.result-vinyl-card .result-add-btn:disabled { opacity: 0.7; }

/* ---------- Skeleton shimmer for cover images ---------- */
@keyframes shimmer-slide {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.vinyl-cover-wrap,
.shelf-item__cover {
  background:
    linear-gradient(90deg, var(--line) 0%, rgba(255, 255, 255, 0.6) 50%, var(--line) 100%)
    0 0 / 200% 100% var(--line);
  animation: shimmer-slide 2.2s linear infinite;
}
.vinyl-cover-wrap img,
.shelf-item__cover img {
  background: var(--card);
}

/* ---------- HTMX top loading bar ---------- */
#htmx-progress {
  position: fixed;
  top: 0; left: 0;
  height: 2.5px;
  width: 0;
  background: linear-gradient(90deg, var(--accent), #ff8a7a);
  z-index: 100;
  opacity: 0;
  transition: width 0.3s ease-out, opacity 0.2s ease;
  box-shadow: 0 0 8px rgba(255, 90, 75, 0.6);
  pointer-events: none;
}
#htmx-progress.loading { opacity: 1; }

/* ---------- Reduce motion safety ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
