/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #ffffff;
  --bg2:       #f7f6f3;
  --bg3:       #f0efe9;
  --text:      #1a1a18;
  --text2:     #6b6a65;
  --text3:     #a09f9a;
  --border:    rgba(0,0,0,0.1);
  --border2:   rgba(0,0,0,0.18);
  --border3:   rgba(0,0,0,0.28);
  --accent:    #1a1a18;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --sidebar-w: 210px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:      #141413;
    --bg2:     #1e1d1b;
    --bg3:     #252421;
    --text:    #e8e6df;
    --text2:   #9a9890;
    --text3:   #5e5d58;
    --border:  rgba(255,255,255,0.08);
    --border2: rgba(255,255,255,0.14);
    --border3: rgba(255,255,255,0.22);
    --accent:  #e8e6df;
  }
}

/* Manual theme overrides — set via JS, override system preference */
[data-theme="light"] {
  --bg:      #ffffff;
  --bg2:     #f7f6f3;
  --bg3:     #f0efe9;
  --text:    #1a1a18;
  --text2:   #6b6a65;
  --text3:   #a09f9a;
  --border:  rgba(0,0,0,0.1);
  --border2: rgba(0,0,0,0.18);
  --border3: rgba(0,0,0,0.28);
  --accent:  #1a1a18;
}
[data-theme="dark"] {
  --bg:      #141413;
  --bg2:     #1e1d1b;
  --bg3:     #252421;
  --text:    #e8e6df;
  --text2:   #9a9890;
  --text3:   #5e5d58;
  --border:  rgba(255,255,255,0.08);
  --border2: rgba(255,255,255,0.14);
  --border3: rgba(255,255,255,0.22);
  --accent:  #e8e6df;
}

/* ── Theme toggle ── */
.theme-toggle { margin-left: auto; padding: 4px 6px; border: none; background: transparent; color: var(--text3); cursor: pointer; border-radius: var(--radius-sm); display: flex; align-items: center; transition: color 0.13s, background 0.13s; flex-shrink: 0; }
.theme-toggle:hover { color: var(--text); background: var(--bg3); }

html, body { height: 100%; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 14px; color: var(--text); background: var(--bg3); -webkit-font-smoothing: antialiased; }

/* ── Layout ── */
.app { display: flex; height: 100vh; max-width: 1100px; margin: 0 auto; background: var(--bg); border-left: 0.5px solid var(--border); border-right: 0.5px solid var(--border); }

/* ── Sidebar ── */
.sidebar { width: var(--sidebar-w); border-right: 0.5px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; padding: 24px 0; }
.logo { padding: 0 22px 22px; font-size: 16px; font-weight: 600; letter-spacing: -0.4px; border-bottom: 0.5px solid var(--border); margin-bottom: 14px; display: flex; align-items: center; }
.logo-muted { opacity: 0.35; font-weight: 400; }
nav { display: flex; flex-direction: column; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 22px; font-size: 13px; color: var(--text2); cursor: pointer; transition: background 0.12s, color 0.12s; user-select: none; }
.nav-item:hover { background: var(--bg2); color: var(--text); }
.nav-item.active { color: var(--text); font-weight: 500; background: var(--bg2); }
.nav-icon { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.55; }
.nav-item.active .nav-icon { opacity: 1; }
.sidebar-footer { margin-top: auto; padding: 18px 22px; border-top: 0.5px solid var(--border); display: flex; align-items: center; gap: 10px; }
.profile-name { font-size: 13px; font-weight: 500; }
.profile-handle { font-size: 11px; color: var(--text3); margin-top: 1px; }

/* ── Avatar ── */
.avatar { width: 30px; height: 30px; border-radius: 50%; background: #dbeafe; color: #1e40af; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; flex-shrink: 0; }
.avatar-lg { width: 52px; height: 52px; font-size: 16px; }

/* ── Main ── */
.main { flex: 1; overflow-y: auto; }
.view { display: none; padding: 32px 36px; }
.view.active { display: block; }
h1 { font-size: 20px; font-weight: 600; letter-spacing: -0.3px; margin-bottom: 4px; }
.page-sub { font-size: 13px; color: var(--text2); margin-bottom: 26px; }
.section-label { font-size: 11px; font-weight: 600; color: var(--text3); text-transform: uppercase; letter-spacing: 0.07em; margin-bottom: 12px; }

/* ── Tabs ── */
.tabs { display: flex; gap: 6px; margin-bottom: 22px; flex-wrap: wrap; }
.tab { padding: 6px 14px; border-radius: 100px; font-size: 12px; font-weight: 500; border: 0.5px solid var(--border2); cursor: pointer; background: transparent; color: var(--text2); transition: all 0.13s; }
.tab:hover { border-color: var(--border3); color: var(--text); }
.tab.active { background: var(--text); color: var(--bg); border-color: var(--text); }

/* ── My List ── */
.list-grid { display: flex; flex-direction: column; gap: 8px; }
.list-item { display: flex; align-items: center; gap: 14px; padding: 11px 14px; border: 0.5px solid var(--border); border-radius: var(--radius-md); background: var(--bg); transition: border-color 0.13s; }
.list-item:hover { border-color: var(--border2); }
.rank-num { font-size: 16px; color: var(--text3); width: 24px; text-align: right; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.item-cover { height: 100px; width: auto; min-width: 40px; border-radius: 4px; flex-shrink: 0; background: var(--bg2); display: flex; align-items: center; justify-content: center; font-size: 48px; overflow: hidden; align-self: flex-start; margin-left: 6px; }
.item-cover img { height: 100%; width: auto; display: block; }
.item-info { flex: 1; min-width: 0; align-self: flex-start; padding-top: 6px; }
.item-title { font-size: 20px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-meta { font-size: 16px; color: var(--text2); margin-top: 2px; }
.item-remove { color: var(--text3); font-size: 18px; line-height: 1; cursor: pointer; padding: 4px; opacity: 0; transition: opacity 0.13s; border: none; background: none; }
.list-item:hover .item-remove { opacity: 1; }
.item-remove:hover { color: var(--text); }

/* ── Item actions (up/down/remove) ── */
.item-actions { display: flex; align-items: center; gap: 2px; opacity: 0; transition: opacity 0.13s; flex-shrink: 0; }
.list-item:hover .item-actions { opacity: 1; }
.move-btn { display: flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 4px; border: none; background: transparent; color: var(--text3); cursor: pointer; transition: background 0.1s, color 0.1s; padding: 0; }
.move-btn:hover:not(:disabled) { background: var(--bg2); color: var(--text); }
.move-btn:disabled { opacity: 0.2; cursor: default; }
.item-remove { display: flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 4px; border: none; background: transparent; color: var(--text3); cursor: pointer; font-size: 20px; line-height: 1; transition: background 0.1s, color 0.1s; padding: 0; margin-left: 2px; }
.item-remove:hover { background: var(--bg2); color: var(--text); }

/* ── Move animation ── */
@keyframes nudge-up {
  0%   { transform: translateY(10px) scale(0.98); opacity: 0.5; }
  40%  { transform: translateY(-3px) scale(1.01); opacity: 1; }
  70%  { transform: translateY(1px)  scale(1.0);  opacity: 1; }
  100% { transform: translateY(0)    scale(1.0);  opacity: 1; }
}
@keyframes nudge-down {
  0%   { transform: translateY(-10px) scale(0.98); opacity: 0.5; }
  40%  { transform: translateY(3px)   scale(1.01); opacity: 1; }
  70%  { transform: translateY(-1px)  scale(1.0);  opacity: 1; }
  100% { transform: translateY(0)     scale(1.0);  opacity: 1; }
}
.item-moved-up   { animation: nudge-up   0.32s cubic-bezier(0.34,1.56,0.64,1) both; }
.item-moved-down { animation: nudge-down 0.32s cubic-bezier(0.34,1.56,0.64,1) both; }

/* ── Drag and drop ── */
.drag-handle { color: var(--text3); cursor: grab; padding: 4px 2px; flex-shrink: 0; display: flex; align-items: center; opacity: 0; transition: opacity 0.13s; touch-action: none; }
.drag-handle:active { cursor: grabbing; color: var(--text); opacity: 1; }
.list-item:hover .drag-handle { opacity: 1; }
.list-item.dragging { opacity: 0.3; border-style: dashed; }

.drop-line { height: 2px; background: var(--text); border-radius: 1px; margin: 2px 0; pointer-events: none; flex-shrink: 0; }

/* ── View header ── */
.view-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 0; }
.view-header .page-sub { margin-bottom: 26px; }

/* ── Export ── */
.export-wrap { position: relative; margin-top: 4px; }
.export-btn { display: flex; align-items: center; gap: 6px; padding: 7px 14px; font-size: 12px; font-weight: 500; border: 0.5px solid var(--border2); border-radius: var(--radius-md); background: transparent; color: var(--text2); cursor: pointer; transition: all 0.13s; white-space: nowrap; }
.export-btn:hover { border-color: var(--border3); color: var(--text); background: var(--bg2); }
.export-btn.open { border-color: var(--border3); color: var(--text); background: var(--bg2); }
.export-menu { display: none; position: absolute; top: calc(100% + 4px); right: 0; background: var(--bg); border: 0.5px solid var(--border2); border-radius: var(--radius-md); overflow: hidden; z-index: 50; min-width: 120px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
.export-menu.open { display: block; }
.export-option { display: block; width: 100%; padding: 9px 16px; font-size: 13px; text-align: left; background: transparent; border: none; color: var(--text2); cursor: pointer; transition: background 0.1s, color 0.1s; border-bottom: 0.5px solid var(--border); }
.export-option:last-child { border-bottom: none; }
.export-option:hover { background: var(--bg2); color: var(--text); }
.add-area { margin-top: 14px; position: relative; }
.search-wrap { position: relative; }
.search-wrap input { width: 100%; padding: 10px 38px 10px 36px; border: 0.5px solid var(--border2); border-radius: var(--radius-md); font-size: 13px; background: var(--bg2); color: var(--text); outline: none; transition: border-color 0.13s, background 0.13s; }
.search-wrap input:focus { border-color: var(--border3); background: var(--bg); }
.search-wrap input:disabled { opacity: 0.5; cursor: not-allowed; }
.search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text3); pointer-events: none; }
.spinner { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); width: 14px; height: 14px; border: 1.5px solid var(--border2); border-top-color: var(--text2); border-radius: 50%; animation: spin 0.7s linear infinite; display: none; }
.spinner.visible { display: block; }
@keyframes spin { to { transform: translateY(-50%) rotate(360deg); } }
.limit-note { font-size: 11px; color: var(--text3); margin-top: 10px; text-align: center; display: none; }

.autocomplete { position: absolute; top: calc(100% + 4px); left: 0; right: 0; background: var(--bg); border: 0.5px solid var(--border2); border-radius: var(--radius-lg); overflow: hidden; z-index: 100; box-shadow: 0 6px 24px rgba(0,0,0,0.1); display: none; max-height: 300px; overflow-y: auto; }
.autocomplete.open { display: block; }
.ac-item { display: flex; align-items: center; gap: 10px; padding: 10px 14px; cursor: pointer; transition: background 0.1s; border-bottom: 0.5px solid var(--border); }
.ac-item:last-child { border-bottom: none; }
.ac-item:hover, .ac-item.focused { background: var(--bg2); }
.ac-thumb { width: 34px; height: 34px; border-radius: 4px; background: var(--bg2); flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 16px; overflow: hidden; }
.ac-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ac-title { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ac-meta { font-size: 11px; color: var(--text2); margin-top: 2px; }
.ac-empty { padding: 18px 14px; font-size: 13px; color: var(--text2); text-align: center; }
.ac-source { font-size: 10px; color: var(--text3); margin-top: 2px; }

/* ── Discover ── */
.discover-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.discover-card { border: 0.5px solid var(--border); border-radius: var(--radius-lg); padding: 16px; cursor: pointer; transition: border-color 0.13s, background 0.13s; }
.discover-card:hover { border-color: var(--border2); background: var(--bg2); }
.dc-header { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.dc-avatar { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; flex-shrink: 0; }
.dc-name { font-size: 13px; font-weight: 500; }
.dc-handle { font-size: 11px; color: var(--text2); }
.dc-cat-badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; padding: 3px 9px; border-radius: 100px; border: 0.5px solid var(--border); color: var(--text2); margin-bottom: 10px; }
.dc-items { display: flex; flex-direction: column; gap: 5px; }
.dc-row { font-size: 12px; color: var(--text2); display: flex; align-items: baseline; gap: 7px; }
.dc-num { font-size: 10px; color: var(--text3); width: 13px; flex-shrink: 0; }

/* ── Matches ── */
.match-list { display: flex; flex-direction: column; gap: 10px; }
.match-card { border: 0.5px solid var(--border); border-radius: var(--radius-lg); padding: 16px; display: flex; align-items: center; gap: 14px; transition: border-color 0.13s; }
.match-card:hover { border-color: var(--border2); }
.match-score { text-align: center; flex-shrink: 0; width: 52px; }
.score-n { font-size: 22px; font-weight: 600; line-height: 1; letter-spacing: -0.5px; }
.score-l { font-size: 10px; color: var(--text3); margin-top: 2px; }
.match-info { flex: 1; min-width: 0; }
.match-name { font-size: 13px; font-weight: 500; }
.match-handle { font-size: 11px; color: var(--text3); }
.shared-tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 8px; }
.shared-tag { font-size: 10px; padding: 3px 9px; border-radius: 100px; background: var(--bg2); color: var(--text2); border: 0.5px solid var(--border); }
.follow-btn { font-size: 12px; padding: 7px 16px; border-radius: 100px; border: 0.5px solid var(--border2); cursor: pointer; color: var(--text); background: transparent; transition: all 0.13s; white-space: nowrap; font-weight: 500; }
.follow-btn:hover { background: var(--text); color: var(--bg); border-color: var(--text); }
.follow-btn.following { background: var(--bg2); color: var(--text2); border-color: var(--border); }
.follow-btn.following:hover { background: #fee2e2; color: #b91c1c; border-color: #fca5a5; }

/* ── Profile ── */
.profile-hero { display: flex; align-items: center; gap: 16px; margin-bottom: 24px; }
.profile-hero-name { font-size: 18px; font-weight: 600; letter-spacing: -0.3px; }
.profile-hero-handle { font-size: 12px; color: var(--text2); margin-top: 3px; }
.stats-row { display: flex; gap: 28px; margin-bottom: 28px; }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat-n { font-size: 22px; font-weight: 600; letter-spacing: -0.5px; }
.stat-l { font-size: 11px; color: var(--text2); }
.profile-lists { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-top: 4px; }
.pl-card { border: 0.5px solid var(--border); border-radius: var(--radius-lg); padding: 16px; }
.pl-icon { font-size: 22px; margin-bottom: 10px; }
.pl-title { font-size: 14px; font-weight: 500; margin-bottom: 3px; }
.pl-count { font-size: 12px; color: var(--text2); }

/* ── Mobile ── */
@media (max-width: 640px) {
  .app { flex-direction: column; height: auto; min-height: 100vh; max-width: 100%; border: none; }

  .sidebar { width: 100%; border-right: none; border-bottom: 0.5px solid var(--border); padding: 0; flex-direction: row; align-items: center; position: sticky; top: 0; z-index: 50; background: var(--bg); }
  .logo { padding: 14px 18px; border-bottom: none; margin-bottom: 0; font-size: 15px; flex-shrink: 0; }
  nav { flex-direction: row; flex: 1; overflow-x: auto; }
  .nav-item { padding: 14px 14px; flex-direction: column; gap: 4px; font-size: 10px; min-width: 56px; justify-content: center; border-bottom: 2px solid transparent; }
  .nav-item.active { background: transparent; border-bottom-color: var(--text); }
  .nav-item:hover { background: var(--bg2); }
  .nav-icon { width: 18px; height: 18px; opacity: 0.7; }
  .nav-item.active .nav-icon { opacity: 1; }
  .sidebar-footer { display: none; }

  .main { flex: 1; }
  .view { padding: 20px 16px; }
  h1 { font-size: 18px; }

  .view-header { flex-wrap: wrap; gap: 8px; }
  .view-header .page-sub { margin-bottom: 16px; }

  .discover-grid { grid-template-columns: 1fr; }
  .profile-lists { grid-template-columns: repeat(2, 1fr); }

  .stats-row { gap: 16px; }

  .list-item { padding: 10px 12px; gap: 10px; }
  .drag-handle { opacity: 1; }

  .match-card { flex-wrap: wrap; gap: 10px; }
  .follow-btn { margin-left: auto; }

  .autocomplete { position: fixed; left: 0; right: 0; max-height: 50vh; border-radius: var(--radius-lg) var(--radius-lg) 0 0; bottom: 0; top: auto; box-shadow: 0 -4px 24px rgba(0,0,0,0.12); }
}

@media (max-width: 400px) {
  .tabs { gap: 4px; }
  .tab { padding: 5px 10px; font-size: 11px; }
  .export-btn span { display: none; }
}

