/* Hand-Me-Downs Art Frame — "Modern Museum" Theme
   Hybrid: warm editorial from art-frame-from-pi + dark modern from N527 */

@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;600;700&family=Inter:wght@300;400;500;600&display=swap');

:root {
  /* Warm dark palette */
  --bg: #0d0b09;
  --bg-warm: #131110;
  --surface: #1a1714;
  --surface-hover: #221f1a;
  --surface-elevated: #2a2620;
  --border: #332e27;
  --border-subtle: #272320;

  /* Warm accent browns */
  --accent: #8B7355;
  --accent-hover: #A08668;
  --accent-light: #C4B6A0;
  --accent-dim: rgba(139, 115, 85, 0.15);
  --accent-glow: rgba(139, 115, 85, 0.3);

  /* Text */
  --text: #F0EDE8;
  --text-sec: #9B9388;
  --text-dim: #6B635A;
  --text-warm: #C4B6A0;

  /* Status */
  --danger: #C4524A;
  --success: #6B8F71;

  /* Typography */
  --font-display: 'Playfair Display', Georgia, 'Times New Roman', serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;

  /* Radii */
  --r: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-pill: 20px;
  --r-round: 50%;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 20px rgba(139, 115, 85, 0.15);

  /* Layout */
  --np-height: 76px;
  --header-height: 56px;
  --tab-height: 46px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: calc(var(--np-height) + var(--safe-bottom) + 8px);
  overscroll-behavior: contain;
  -webkit-font-smoothing: antialiased;
}

/* ━━━ Header ━━━ */

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 16px;
  height: var(--header-height);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  background: rgba(13, 11, 9, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 100;
}
header h1 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-warm);
  letter-spacing: -0.01em;
}
.header-right { display: flex; gap: 8px; }
.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-sec);
  font-size: 1.15rem;
  width: 38px; height: 38px;
  border-radius: var(--r-md);
  cursor: pointer;
  display: grid; place-items: center;
  transition: all 0.15s ease;
}
.icon-btn:hover, .icon-btn:active {
  background: var(--surface-hover);
  border-color: var(--accent);
  color: var(--text);
}

/* ━━━ Tabs ━━━ */

.tabs {
  display: flex;
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: var(--header-height);
  background: rgba(13, 11, 9, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 99;
}
.tab {
  flex: 1;
  padding: 12px 4px 10px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.2s;
}
.tab:hover { color: var(--text-sec); }
.tab.active { color: var(--accent-light); border-bottom-color: var(--accent); }
.badge {
  display: inline-block;
  background: var(--accent);
  color: var(--bg);
  font-size: 0.6rem;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 8px;
  margin-left: 4px;
  vertical-align: super;
}

/* ━━━ Tab Content ━━━ */

.tab-content { padding: 16px; }
.tab-content.hidden { display: none; }

/* ━━━ Search ━━━ */

.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}
.search-bar input {
  flex: 1;
  padding: 11px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.92rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.search-bar input::placeholder { color: var(--text-dim); }
.search-bar input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

/* ━━━ Buttons ━━━ */

.btn-primary {
  padding: 11px 22px;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: var(--r-md);
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}
.btn-primary:hover { background: var(--accent-hover); box-shadow: var(--shadow-glow); }
.btn-primary:active { transform: scale(0.98); }

.btn-secondary {
  padding: 9px 16px;
  background: var(--surface);
  color: var(--text-sec);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-family: var(--font-body);
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  display: inline-block;
  text-align: center;
}
.btn-secondary:hover { background: var(--surface-hover); color: var(--text); border-color: var(--accent); }

.btn-small {
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  color: var(--text-sec);
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-small:hover { background: var(--surface-hover); border-color: var(--accent); color: var(--text); }
.btn-danger { color: var(--danger); border-color: rgba(196, 82, 74, 0.3); }
.btn-danger:hover { background: rgba(196, 82, 74, 0.08); border-color: var(--danger); }

/* ━━━ Pills / Chips ━━━ */

.source-pills, .dept-pills, .filter-pills {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.source-pills::-webkit-scrollbar,
.dept-pills::-webkit-scrollbar,
.filter-pills::-webkit-scrollbar { display: none; }

.pill {
  padding: 7px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  color: var(--text-dim);
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}
.pill:hover { color: var(--text-sec); border-color: var(--text-dim); }
.pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
  font-weight: 600;
}

/* ━━━ Grid ━━━ */

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

/* ━━━ Artwork Cards ━━━ */

.card {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s, box-shadow 0.2s;
}
.card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: var(--shadow-md), var(--shadow-glow);
}
.card:active { transform: translateY(0) scale(0.98); }

.card-img-wrap {
  position: relative;
  width: 100%;
  padding-top: 125%;
  background: var(--bg-warm);
  overflow: hidden;
}
.card-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.4s ease, opacity 0.3s;
}
.card:hover .card-img { transform: scale(1.04); }
.card-img.loading, .card-img.error { opacity: 0; }

.card-source-badge {
  position: absolute;
  top: 8px; left: 8px;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  color: var(--text-warm);
  font-size: 0.6rem;
  font-weight: 600;
  padding: 3px 7px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.card-actions {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 8px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
  opacity: 0;
  transition: opacity 0.2s;
}
.card:hover .card-actions { opacity: 1; }
@media (hover: none) { .card-actions { opacity: 1; } }

.card-btn {
  width: 34px; height: 34px;
  border-radius: var(--r-round);
  border: none;
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #fff;
  font-size: 0.85rem;
  cursor: pointer;
  display: grid; place-items: center;
  transition: all 0.15s;
}
.card-btn:hover { background: var(--accent); color: var(--bg); }
.card-btn:active { transform: scale(0.92); }
.card-btn.fav-active { color: var(--danger); }

.card-body { padding: 10px 10px 12px; }
.card-title {
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}
.card-artist {
  font-size: 0.7rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

/* ━━━ Filters ━━━ */

.filters-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
  align-items: center;
}
.filter-group {
  display: flex;
  align-items: center;
  gap: 4px;
}
.filter-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
.filter-select {
  padding: 5px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  color: var(--text-sec);
  font-family: var(--font-body);
  font-size: 0.78rem;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
}
.filter-select:focus { border-color: var(--accent); }

/* ━━━ Status / Loading ━━━ */

.status-text {
  text-align: center;
  padding: 20px;
  color: var(--text-dim);
  font-size: 0.88rem;
}

.skeleton {
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-hover) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--r-lg);
}
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
.skeleton-card { min-height: 220px; }

.scroll-sentinel { height: 1px; }
.scroll-spinner {
  display: flex;
  justify-content: center;
  padding: 24px 0;
}
.scroll-spinner::after {
  content: '';
  width: 24px; height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ━━━ Sections ━━━ */

.section-divider {
  border-top: 1px solid var(--border-subtle);
  margin: 28px 0 20px;
}
.section-heading {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--text-warm);
  margin-bottom: 14px;
}
.dept-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}
.dept-item {
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  font-size: 0.72rem;
  cursor: pointer;
  color: var(--text-dim);
  transition: all 0.15s;
}
.dept-item:hover { border-color: var(--accent); color: var(--text-sec); }
.dept-item.active { background: var(--accent); color: var(--bg); border-color: var(--accent); }

/* ━━━ Tab Headers ━━━ */

.tab-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  font-size: 0.85rem;
  color: var(--text-dim);
}
.tab-header-actions { display: flex; gap: 6px; }

/* ━━━ Queue ━━━ */

.queue-items { display: flex; flex-direction: column; gap: 4px; }
.queue-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: all 0.15s;
}
.queue-item:hover { background: var(--surface-hover); }
.queue-item.active { border-color: var(--accent); background: var(--accent-dim); }
.queue-item-thumb {
  width: 48px; height: 48px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--bg-warm);
  flex-shrink: 0;
}
.queue-item-info { flex: 1; min-width: 0; }
.queue-item-title {
  font-family: var(--font-display);
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.queue-item-artist { font-size: 0.72rem; color: var(--text-dim); }
.queue-item-remove {
  background: none; border: none; color: var(--text-dim);
  font-size: 1.1rem; cursor: pointer; padding: 4px;
  transition: color 0.15s;
}
.queue-item-remove:hover { color: var(--danger); }

/* ━━━ Empty States ━━━ */

.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-dim);
}
.empty-state p:first-child {
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--text-sec);
}
.empty-hint { font-size: 0.82rem; color: var(--text-dim); margin-top: 8px; }

/* ━━━ Settings ━━━ */

.settings-group {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  padding: 16px;
  margin-bottom: 12px;
}
.settings-group h3 {
  font-family: var(--font-display);
  font-size: 0.82rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 12px;
}
.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.88rem;
}
.setting:last-child { border-bottom: none; }
.setting select {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r);
  color: var(--text);
  padding: 6px 10px;
  font-family: var(--font-body);
  font-size: 0.82rem;
}
.setting input[type="color"] {
  width: 40px; height: 30px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: none;
  cursor: pointer;
}
.setting input[type="range"] {
  width: 100px;
  accent-color: var(--accent);
}
.setting-val {
  font-size: 0.78rem;
  color: var(--text-dim);
  min-width: 36px;
  text-align: right;
}
.setting.toggle { cursor: pointer; }
.setting.toggle input { display: none; }
.toggle-slider {
  width: 44px; height: 24px;
  background: var(--border);
  border-radius: 12px;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}
.toggle-slider::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 20px; height: 20px;
  background: var(--text);
  border-radius: var(--r-round);
  transition: transform 0.2s;
}
.setting.toggle input:checked + .toggle-slider { background: var(--accent); }
.setting.toggle input:checked + .toggle-slider::after { transform: translateX(20px); }

/* ━━━ Now Playing ━━━ */

#now-playing {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--np-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(26, 23, 20, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  padding-left: 12px;
  padding-right: 12px;
  z-index: 200;
  gap: 12px;
}
#now-playing.hidden { display: none; }
.np-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  cursor: pointer;
}
#np-thumb {
  width: 50px; height: 50px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--bg-warm);
  flex-shrink: 0;
}
.np-info { min-width: 0; }
.np-title {
  display: block;
  font-family: var(--font-display);
  font-size: 0.88rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.np-artist {
  display: block;
  font-size: 0.72rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.np-controls { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.np-btn {
  width: 38px; height: 38px;
  background: none; border: none;
  color: var(--text-sec);
  font-size: 1rem;
  cursor: pointer;
  border-radius: var(--r-round);
  display: grid; place-items: center;
  transition: all 0.15s;
}
.np-btn:hover { background: rgba(255, 255, 255, 0.06); color: var(--text); }
.np-btn:active { transform: scale(0.92); }
.np-btn-main { font-size: 1.3rem; color: var(--accent-light); }
.np-progress {
  position: absolute;
  top: -2px; left: 0; right: 0;
  height: 2px;
  background: var(--border-subtle);
}
.np-progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 1s linear;
}

/* ━━━ Modals ━━━ */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 500;
  display: grid;
  place-items: center;
  padding: 16px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 24px;
  max-width: 420px;
  width: 100%;
  position: relative;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-detail { max-width: 560px; }
.modal-close {
  position: absolute;
  top: 12px; right: 12px;
  background: none; border: none;
  color: var(--text-dim);
  font-size: 1.5rem;
  cursor: pointer; line-height: 1;
  transition: color 0.15s;
}
.modal-close:hover { color: var(--text); }
.modal-content h2 { font-family: var(--font-display); font-weight: 600; }
.modal-desc { color: var(--text-dim); font-size: 0.88rem; margin: 8px 0 16px; }
.pair-code {
  display: block;
  font-size: 2.2rem;
  font-weight: 700;
  letter-spacing: 0.3em;
  text-align: center;
  color: var(--accent-light);
  margin: 14px 0;
  font-family: 'SF Mono', 'Fira Code', monospace;
}
.pair-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  color: var(--text-dim);
  font-size: 0.78rem;
}
.pair-divider::before, .pair-divider::after {
  content: ''; flex: 1; border-top: 1px solid var(--border);
}
.pair-join-row { display: flex; gap: 8px; margin-top: 8px; }
.pair-join-row input {
  flex: 1;
  padding: 11px 14px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text);
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  text-align: center;
  font-family: 'SF Mono', 'Fira Code', monospace;
}
.pair-join-row input:focus { border-color: var(--accent); outline: none; }
#pair-status { margin-top: 12px; text-align: center; font-size: 0.82rem; }
#detail-image {
  width: 100%;
  max-height: 300px;
  object-fit: contain;
  border-radius: var(--r-md);
  background: var(--bg-warm);
  margin-bottom: 16px;
}
.detail-info h2 { font-size: 1.1rem; margin-bottom: 4px; }
.detail-artist { color: var(--accent-light); font-weight: 500; margin-bottom: 8px; }
.detail-info p { font-size: 0.82rem; color: var(--text-dim); margin-bottom: 4px; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }

/* ━━━ Responsive ━━━ */

@media (max-width: 480px) {
  .grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  header h1 { font-size: 1rem; }
  .modal-content { padding: 16px; border-radius: var(--r-md); }
  .card-body { padding: 8px 8px 10px; }
  .card-title { font-size: 0.78rem; }
}
@media (min-width: 480px) and (max-width: 768px) {
  .grid { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 768px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
  .tab-content { padding: 20px; max-width: 960px; margin: 0 auto; }
  header { padding: 0 24px; }
}
@media (min-width: 1024px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
}

.hidden { display: none !important; }
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
