@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@300;400;500&family=IBM+Plex+Sans:wght@300;400;500;600&display=swap");

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

:root {
  --unit: 8px;
  --bg: #0a0a0a;
  --bg-raised: #111111;
  --bg-hover: #1a1a1a;
  --bg-active: #1e1e1e;
  --border: #222;
  --border-light: #2a2a2a;
  --text: #c8c8c8;
  --text-dim: #666;
  --text-bright: #e8e8e8;
  --accent: #e96401;
  --accent-dim: #a55518;
  --mono: "IBM Plex Mono", monospace;
  --sans: "IBM Plex Sans", sans-serif;
  --row-h: 32px; /* 4 × unit */
  --player-h: 0px;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  display: flex;
  flex-wrap: wrap;
}

/* ── Sidebar ── */
#sidebar {
  width: 280px;
  min-width: 280px;
  height: calc(100vh - var(--row-h) - var(--player-h));
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.sidebar-brand {
  padding: 0 calc(2 * var(--unit));
  height: calc(2 * var(--row-h));
  display: flex;
  align-items: center;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#sidebar-header {
  height: calc(2 * var(--row-h));
  padding: 0 calc(2 * var(--unit));
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--unit);
  flex-shrink: 0;
}

#sidebar-header h1 {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 0;
  cursor: pointer;
}

#sidebar-header h1:hover {
  color: var(--text);
}

#sidebar-search {
  width: 100%;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 2px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  padding: calc(0.75 * var(--unit)) calc(1.5 * var(--unit));
  outline: none;
  transition: border-color 0.15s;
}

#sidebar-search::placeholder {
  color: var(--text-dim);
}
#sidebar-search:focus {
  border-color: var(--accent-dim);
}

#playlist-list {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-light) transparent;
}

.sidebar-item {
  display: flex;
  align-items: center;
  padding: 0 calc(2 * var(--unit));
  height: var(--row-h);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
  gap: var(--unit);
}

.sidebar-item:hover {
  background: var(--bg-hover);
}
.sidebar-item.active {
  background: rgba(233, 100, 1, 0.06);
  border-left: 2px solid var(--accent);
  padding-left: calc(2 * var(--unit) - 2px);
}

.sidebar-item-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13px;
}

.sidebar-item-count {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  flex-shrink: 0;
}

.sidebar-item-date {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-dim);
  flex-shrink: 0;
}

/* ── SVG icons ── */
.icon {
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
  pointer-events: none;
}

/* ── Sidebar collapsible group ── */
.sidebar-group-toggle {
  user-select: none;
}

.sidebar-group-arrow {
  display: inline-flex;
  align-items: center;
  color: var(--text-dim);
  flex-shrink: 0;
  transition: transform 0.15s;
}

.sidebar-group.open .sidebar-group-arrow {
  transform: rotate(90deg);
}

.sidebar-group-items {
  display: none;
}

.sidebar-group.open .sidebar-group-items {
  display: block;
}

.sidebar-sub-item {
  padding-left: calc(4 * var(--unit)) !important;
  font-size: 12px;
}

.sidebar-sub-item.active {
  padding-left: calc(4 * var(--unit) - 2px) !important;
}

.sidebar-section {
  padding: 0 calc(2 * var(--unit)) var(--unit);
  height: calc(2 * var(--row-h));
  display: flex;
  align-items: flex-end;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 1;
}

/* ── Main ── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--row-h) - var(--player-h));
  min-width: 0;
}

#main-header {
  height: calc(2 * var(--row-h));
  padding: 0 calc(2 * var(--unit));
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-end;
  gap: calc(1.5 * var(--unit));
  flex-shrink: 0;
  padding-bottom: var(--unit);
}

#back-btn,
#export-csv-btn,
#export-txt-btn,
.header-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 12px;
  padding: calc(0.5 * var(--unit)) calc(1.5 * var(--unit));
  cursor: pointer;
  display: none;
  margin-bottom: 1px;
  flex-shrink: 0;
}

#back-btn:hover,
#export-csv-btn:hover,
#export-txt-btn:hover,
.header-btn:hover {
  color: var(--text);
  border-color: var(--border-light);
}

#export-global-btns .header-btn {
  display: block;
}

#export-txt-btn.visible {
  display: block;
  margin-left: auto;
}

#export-csv-btn.visible {
  display: block;
}

.export-row {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  padding: 6px 0;
}

.export-row-label {
  flex-shrink: 0;
}

.lastfm-row {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  padding: 6px 0;
}

.lastfm-label {
  flex-shrink: 0;
}

.export-options {
  display: flex;
  gap: 0;
}

.export-options button {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  padding: 4px 12px;
  border: 1px solid var(--border);
  background: none;
  cursor: pointer;
  white-space: nowrap;
  transition:
    color 0.1s,
    background 0.1s,
    border-color 0.1s;
  margin-left: -1px;
}

.export-options button:first-child {
  margin-left: 0;
}

.export-options button:hover {
  color: var(--text);
  background: var(--bg-hover);
}

#main-title {
  font-family: var(--sans);
  font-size: 22px;
  font-weight: 600;
  color: var(--text-bright);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#main-meta {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  padding-bottom: 2px;
}

#track-filter-wrap {
  padding: 0 calc(2 * var(--unit));
  height: var(--row-h);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: calc(2 * var(--unit));
}

#dedup-label {
  display: none;
  align-items: center;
  gap: 5px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}

#dedup-label:hover {
  color: var(--text);
}

#view-toggles {
  margin-left: auto;
  display: flex;
  gap: 2px;
}
#view-toggles button {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 4px;
  line-height: 1;
}
#view-toggles button:hover {
  color: var(--text);
}
#view-toggles button.active {
  color: var(--accent);
}

#dedup-toggle {
  accent-color: var(--accent);
  cursor: pointer;
}

#track-filter {
  width: 100%;
  max-width: 360px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 2px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  padding: calc(0.5 * var(--unit)) calc(1.5 * var(--unit));
  outline: none;
  transition: border-color 0.15s;
}

#track-filter::placeholder {
  color: var(--text-dim);
}
#track-filter:focus {
  border-color: var(--accent-dim);
}

/* ── Column Header ── */
#col-header {
  display: flex;
  padding: 0 calc(2 * var(--unit));
  height: var(--row-h);
  align-items: center;
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  flex-shrink: 0;
  cursor: default;
  user-select: none;
}

#col-header span {
  cursor: pointer;
}
#col-header span:hover {
  color: var(--text);
}
#col-header span.sorted {
  color: var(--accent);
}
#col-header span.sorted::after {
  content: " ▲";
  font-size: 8px;
}
#col-header span.sorted.desc::after {
  content: " ▼";
  font-size: 8px;
}
#col-header .col-play {
  cursor: default;
}
#col-header .col-play:hover {
  color: var(--text-dim);
}
#col-header .col-num {
  cursor: default;
}
#col-header .col-num:hover {
  color: var(--text-dim);
}
.col-art {
  width: 48px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 8px;
  position: relative;
}
.track-row .col-art {
  height: 48px;
  background: var(--border);
}
.col-art img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  background: var(--bg-hover);
  border: none;
  opacity: 0;
  transition: opacity 0.15s;
}
.col-art img.loaded {
  opacity: 1;
}
.col-art .play-btn {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 0;
  color: #fff;
  background: rgba(0, 0, 0, 0.3);
}
.col-art .play-btn .icon {
  width: 16px;
  height: 16px;
}
.col-art:hover img.loaded {
  opacity: 0.6;
}
.col-art:hover .play-btn {
  opacity: 1;
}
.col-art .play-btn:hover {
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
}
.col-play {
  width: 28px;
  flex-shrink: 0;
  text-align: center;
}
.col-num {
  width: 44px;
  text-align: right;
  padding-right: 14px !important;
  flex-shrink: 0;
}
.col-track {
  flex: 4;
  min-width: 0;
}
.col-artist {
  flex: 3;
  min-width: 0;
}
.col-album {
  flex: 3;
  min-width: 0;
}
.col-date {
  width: 90px;
  text-align: right;
  flex-shrink: 0;
}

/* ── Album Grid ── */
.album-grid-row {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  gap: 16px;
  padding: 0 16px;
}

.album-card {
  flex: 1 1 0;
  min-width: 0;
  max-width: 240px;
  cursor: pointer;
  padding: 8px;
  border-radius: 2px;
  transition: background 0.1s;
}

.album-card:hover {
  background: var(--bg-hover);
}

.album-card-art {
  width: 100%;
  aspect-ratio: 1;
  background: var(--border);
  overflow: hidden;
}

.album-card-art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.15s;
  display: block;
}

.album-card-art img.loaded {
  opacity: 1;
}

.album-card-info {
  padding-top: 6px;
}

.album-card-name {
  font-size: 12px;
  color: var(--text-bright);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.album-card-artist {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.album-card:hover .album-card-name {
  color: var(--accent);
}

/* ── Track List (virtual scroll) ── */
#track-viewport {
  flex: 1;
  overflow-y: auto;
  position: relative;
  scrollbar-width: thin;
  scrollbar-color: var(--border-light) transparent;
}

#track-runway {
  position: relative;
}

.track-row {
  display: flex;
  align-items: center;
  padding: 0 calc(2 * var(--unit));
  height: var(--row-h);
  position: absolute;
  left: 0;
  right: 0;
  border-bottom: 1px solid var(--border);
  transition: background 0.08s;
}

.track-row:hover {
  background: var(--bg-hover);
}

.track-row span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.track-row .col-num {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
}

.track-row .col-track a {
  color: var(--text-bright);
  text-decoration: none;
}

.track-row .col-track a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.track-row .col-track .local-track {
  color: var(--text-dim);
  font-style: italic;
}

.track-row .col-artist {
  color: var(--text);
  cursor: pointer;
}
.track-row .col-artist:hover {
  color: var(--accent);
}
.col-source {
  flex: 2;
  min-width: 0;
}
.track-row .col-source {
  color: var(--text-dim);
  font-size: 12px;
}
.track-row .col-album {
  color: var(--text-dim);
  cursor: pointer;
}
.track-row .col-album:hover {
  color: var(--accent);
}

.track-row .col-date {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
}

/* ── Play button ── */
.track-row .col-play {
  display: flex;
  align-items: center;
  justify-content: center;
}

.play-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition:
    color 0.1s,
    background 0.1s;
  flex-shrink: 0;
  opacity: 0;
}

.track-row:hover .play-btn {
  opacity: 1;
}

.play-btn:hover {
  color: var(--accent);
  background: var(--bg-active);
}

/* ── Responsive column hiding ── */
@media (max-width: 1200px) {
  .col-source {
    display: none !important;
  }
}
@media (max-width: 1000px) {
  .col-date {
    display: none !important;
  }
}
@media (max-width: 850px) {
  .col-album {
    display: none !important;
  }
}
@media (max-width: 700px) {
  .col-num {
    display: none !important;
  }
}

/* ── Empty state ── */
#empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 12px;
}

/* ── Loading ── */
#loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  width: 100%;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
}

#loading.hidden {
  display: none;
}

/* ── Scrollbar (webkit) ── */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: #333;
}

/* ── Upload Screen ── */
#upload-screen {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  width: 100%;
  gap: 24px;
  position: relative;
}

#upload-screen header {
  text-align: center;
}

#upload-screen h1 {
  font-family: var(--sans);
  font-size: 24px;
  font-weight: 600;
  color: var(--text-bright);
}

#upload-screen p {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  max-width: 400px;
  text-align: center;
  line-height: 1.6;
}

#upload-screen a {
  color: var(--accent);
}

#drop-zone {
  width: 440px;
  height: 200px;
  border: 1px dashed var(--border-light);
  border-radius: 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  cursor: pointer;
  transition:
    border-color 0.2s,
    background 0.2s,
    box-shadow 0.2s;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
}

#drop-zone:hover,
#drop-zone.dragover {
  border-color: var(--accent);
  background: var(--bg-raised);
  box-shadow:
    0 0 40px rgba(233, 100, 1, 0.04),
    inset 0 0 40px rgba(233, 100, 1, 0.02);
}

#upload-error {
  font-family: var(--mono);
  font-size: 11px;
  color: #c44;
  display: none;
}

#sample-btn {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
}

#sample-btn:hover {
  color: var(--accent);
}

/* ── Stats View ── */
#stats-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--row-h) - var(--player-h));
  min-width: 0;
}

#stats-header {
  height: calc(2 * var(--row-h));
  padding: 0 calc(2 * var(--unit));
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-end;
  gap: calc(1.5 * var(--unit));
  flex-shrink: 0;
  padding-bottom: var(--unit);
}

#stats-title {
  font-family: var(--sans);
  font-size: 22px;
  font-weight: 600;
  color: var(--text-bright);
}

#stats-meta {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  padding-bottom: 2px;
}

#stats-content {
  flex: 1;
  overflow-y: auto;
  padding: calc(2 * var(--unit));
  scrollbar-width: thin;
  scrollbar-color: var(--border-light) transparent;
}

.stats-cards {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
}

.stats-card {
  flex: 1;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stats-card-value {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 500;
  color: var(--text-bright);
}

.stats-card-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.stats-section {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 10px 0 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0;
}

.stats-section ~ .stats-section {
  margin-top: 48px;
}

.stats-list {
  margin-bottom: 20px;
}

.stats-row {
  display: flex;
  align-items: center;
  padding: 0 8px;
  height: var(--row-h);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.08s;
  gap: 8px;
  position: relative;
}

.stats-row-bar {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  background: var(--accent);
  opacity: 0.07;
  pointer-events: none;
  transition: opacity 0.08s;
}

.stats-row:hover .stats-row-bar {
  opacity: 0.13;
}

.stats-row:hover {
  background: var(--bg-hover);
}

.stats-row-rank {
  width: 30px;
  text-align: right;
  padding-right: 8px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  flex-shrink: 0;
}

.stats-row-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-bright);
}

.stats-row:hover .stats-row-name {
  color: var(--accent);
}

.stats-row-detail {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  flex-shrink: 0;
}

/* ── Histogram ── */
.histogram {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 250px;
  padding: 30px 0 20px;
  border-bottom: 1px solid var(--border);
  position: relative;
}

.histogram-col {
  flex: 1;
  min-width: 0;
  height: 100%;
  position: relative;
  display: flex;
  align-items: flex-end;
}

.histogram-bar {
  width: 100%;
  background: var(--accent);
  opacity: 0.6;
  min-height: 1px;
  transition: opacity 0.1s;
  position: relative;
  cursor: default;
}

.histogram-bar:hover {
  opacity: 1;
}

.histogram-tooltip {
  display: none;
  position: fixed;
  background: var(--bg-raised);
  border: 1px solid var(--border-light);
  color: var(--text-bright);
  font-family: var(--mono);
  font-size: 10px;
  padding: 4px 8px;
  white-space: nowrap;
  z-index: 1000;
  pointer-events: none;
}

.histogram-label {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--mono);
  font-size: 9px;
  color: var(--text-dim);
  margin-top: 4px;
  white-space: nowrap;
}

/* ── Discoveries ── */
.discoveries {
  margin-top: 20px;
}

.discovery-month {
  display: flex;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  align-items: baseline;
}

.discovery-month-label {
  width: 70px;
  flex-shrink: 0;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
}

.discovery-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.discovery-chip {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-bright);
  background: var(--bg-raised);
  border: 1px solid var(--border-light);
  padding: 2px 8px;
  cursor: pointer;
  transition:
    color 0.1s,
    border-color 0.1s;
}

.discovery-chip:hover {
  color: var(--accent);
  border-color: var(--accent-dim);
}

/* ── Stats bar ── */
#stats-bar {
  width: 100%;
  padding: 0 calc(2 * var(--unit));
  height: var(--row-h);
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  flex-shrink: 0;
  gap: calc(1.5 * var(--unit));
}

#stats-bar .stats-text {
  flex: 1;
}

.bar-btn {
  background: none;
  border: none;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0;
}

.bar-btn:hover {
  color: var(--text);
}

/* ── Overlay (shared) ── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.overlay-panel {
  background: var(--bg-raised);
  border: 1px solid var(--border-light);
  padding: 20px;
  width: 340px;
  max-width: 90vw;
}

.overlay-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.overlay-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.overlay-close:hover {
  color: var(--text);
}

.overlay-body {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.overlay-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  padding: 6px 0;
  user-select: none;
}

.overlay-row:hover {
  color: var(--text-bright);
}

.overlay-row input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
}

.overlay-btn {
  background: none;
  border: none;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  padding: 6px 0;
  text-align: left;
}

.overlay-btn:hover {
  color: var(--text);
}

.overlay-action-btn {
  width: 100%;
  background: none;
  border: 1px solid var(--accent-dim);
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent);
  cursor: pointer;
  padding: 8px 0;
  margin-top: 8px;
  transition:
    color 0.1s,
    background 0.1s;
}

.overlay-action-btn:hover {
  background: var(--accent);
  color: var(--bg);
}

/* ── Mobile overlay ── */
#mobile-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.85);
  align-items: center;
  justify-content: center;
  text-align: center;
}

#mobile-overlay .overlay-panel {
  max-width: 300px;
}

#mobile-overlay p {
  margin: 0 0 6px;
  color: var(--text-bright);
  font-size: 14px;
}

.mobile-overlay-sub {
  color: var(--text-dim) !important;
  font-size: 12px !important;
}

#mobile-dismiss {
  margin-top: 16px;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 11px;
  padding: 6px 16px;
  border-radius: 4px;
  cursor: pointer;
}

#mobile-dismiss:hover {
  color: var(--text);
  border-color: var(--text-dim);
}

@media (max-width: 700px) {
  #mobile-overlay:not(.dismissed) {
    display: flex;
  }
}

/* ── Footer links (upload screen) ── */
.footer-links {
  position: absolute;
  bottom: 24px;
  display: flex;
  gap: 16px;
}

.footer-links a,
.footer-links button {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-dim);
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

.footer-links a:hover,
.footer-links button:hover {
  color: var(--text);
}

/* ── Wrapped ── */
.wrapped-report {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  padding: 16px;
  margin: 10px 0;
}

.wrapped-report-date {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.wrapped-report-title {
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-bright);
  margin-bottom: 8px;
}

.wrapped-report-desc {
  font-size: 12px;
  color: var(--text);
  line-height: 1.6;
  margin-bottom: 10px;
}

.wrapped-report-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.wrapped-race-table {
  margin: 10px 0 20px;
  overflow-x: auto;
}

.wrapped-race-row {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.wrapped-race-header {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.wrapped-race-label {
  width: 100px;
  flex-shrink: 0;
  padding: 8px;
  font-size: 12px;
  color: var(--text-bright);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wrapped-race-cell {
  flex: 1;
  min-width: 48px;
  padding: 8px 4px;
  text-align: center;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
}

.wrapped-race-first {
  color: var(--accent);
  font-weight: 500;
}

/* ── Player bar ── */
#player-bar {
  position: relative;
  width: 100%;
  height: calc(9 * var(--unit));
  background: var(--bg-raised);
  border-top: 1px solid var(--border);
  z-index: 1500;
  display: flex;
  flex-direction: column;
}

#player-progress-wrap {
  position: relative;
  height: 3px;
  background: var(--border);
  flex-shrink: 0;
}

#player-progress-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background: var(--accent);
  width: 0%;
  pointer-events: none;
}

#player-seek {
  position: absolute;
  top: -4px;
  left: 0;
  width: 100%;
  height: 11px;
  margin: 0;
  padding: 0;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 1;
}

#player-bar:hover #player-seek {
  opacity: 1;
}

#player-seek::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: calc(1.5 * var(--unit));
  height: calc(1.5 * var(--unit));
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
}

#player-seek::-moz-range-thumb {
  width: calc(1.5 * var(--unit));
  height: calc(1.5 * var(--unit));
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
}

#player-seek::-webkit-slider-runnable-track {
  background: transparent;
}

#player-seek::-moz-range-track {
  background: transparent;
}

#player-bar-inner {
  flex: 1;
  display: flex;
  align-items: center;
  min-width: 0;
}

/* Left section: controls — matches sidebar width */
#player-controls {
  width: 280px;
  min-width: 280px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: calc(1.5 * var(--unit));
  padding: 0 calc(2 * var(--unit));
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  align-self: stretch;
}

#player-controls button {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  padding: calc(0.5 * var(--unit));
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.1s;
}

#player-controls button:hover {
  color: var(--text-bright);
}

#player-play-pause {
  font-size: 20px !important;
  color: var(--text-bright) !important;
}

#player-play-pause:hover {
  color: var(--accent) !important;
}

#player-shuffle.active {
  color: var(--accent) !important;
}

/* Right section: track info + actions */
#player-track-info {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: calc(1.5 * var(--unit));
  padding: 0 calc(2 * var(--unit));
}

#player-art {
  width: 48px;
  height: 48px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--border);
  display: block;
}

#player-art.loaded {
  background: none;
}

#player-track-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#player-title {
  font-size: 12px;
  color: var(--text-bright);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#player-artist-album {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#player-time {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
  flex-shrink: 0;
}

#player-video-toggle,
#player-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  padding: calc(0.5 * var(--unit));
  line-height: 1;
  flex-shrink: 0;
  transition: color 0.1s;
}

#player-video-toggle:hover,
#player-close:hover {
  color: var(--text-bright);
}

#player-video-toggle.active {
  color: var(--accent);
}

/* ── Results panel (popover above bar) ── */
#player-results-panel {
  position: absolute;
  bottom: 100%;
  right: calc(2 * var(--unit));
  width: 480px;
  max-width: calc(100vw - 4 * var(--unit));
  height: 60vh;
  background: var(--bg-raised);
  border: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.3);
}

#player-results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--unit) calc(1.5 * var(--unit));
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  flex-shrink: 0;
}

#player-results-header-actions {
  display: flex;
  align-items: center;
  gap: calc(0.5 * var(--unit));
}

#player-results-expand,
#player-results-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  padding: 0 calc(0.5 * var(--unit));
  line-height: 1;
}

#player-results-expand:hover,
#player-results-close:hover {
  color: var(--text);
}

#player-results-panel.expanded {
  position: fixed;
  top: calc(3 * var(--unit));
  left: calc(3 * var(--unit));
  right: calc(3 * var(--unit));
  bottom: calc(var(--player-h) + 3 * var(--unit));
  width: auto;
  max-width: none;
  height: auto;
  z-index: 2000;
  border-radius: calc(var(--unit));
  border: 1px solid var(--text-dim);
}

#player-results-panel.expanded::before {
  content: "";
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: -1;
}

#player-results-panel.expanded #player-yt-container {
  flex: 1;
  height: auto;
}

#player-results-panel.expanded #player-results {
  display: none;
}

#player-yt-container {
  flex-shrink: 0;
  height: 250px;
  overflow: hidden;
}

#player-embed {
  width: 100%;
  height: 100%;
}

#player-embed iframe {
  width: 100% !important;
  height: 100% !important;
  border: none;
  display: block;
}

#player-loading {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
  padding: calc(5 * var(--unit)) 0;
}

#player-error {
  font-family: var(--mono);
  font-size: 12px;
  color: #c44;
  text-align: center;
  padding: calc(2.5 * var(--unit)) 0;
}

#player-results {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-light) transparent;
}

.player-result {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.08s;
}

.player-result:hover {
  background: var(--bg-hover);
}

.player-result.active {
  border-left: 2px solid var(--accent);
  padding-left: 2px;
}

.player-result-thumb {
  width: 80px;
  height: 45px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg);
}

.player-result-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.player-result-title {
  font-size: 12px;
  color: var(--text-bright);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-result-meta {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Brand ── */
.brand-mark {
  position: absolute;
  top: 24px;
  left: 28px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  animation: fadeIn 0.6s ease both;
}

/* ── Entrance animation ── */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

#upload-screen > :not(.brand-mark):not(.footer-links):not(#upload-error) {
  animation: fadeUp 0.4s ease both;
}
#upload-screen > :nth-child(3) {
  animation-delay: 0.04s;
}
#upload-screen > :nth-child(4) {
  animation-delay: 0.08s;
}
#upload-screen > :nth-child(6) {
  animation-delay: 0.12s;
}
#upload-screen > :nth-child(7) {
  animation-delay: 0.16s;
}

#upload-screen .footer-links {
  animation: fadeIn 0.5s ease 0.2s both;
}

/* ── Light theme ── */
[data-theme="light"] {
  --bg: #f5f5f5;
  --bg-raised: #ffffff;
  --bg-hover: #ebebeb;
  --bg-active: #e0e0e0;
  --border: #ddd;
  --border-light: #ccc;
  --text: #333;
  --text-dim: #888;
  --text-bright: #111;
  --accent: #e96401;
  --accent-dim: #a55518;
}

[data-theme="light"] .overlay {
  background: rgba(0, 0, 0, 0.25);
}

[data-theme="light"] ::-webkit-scrollbar-thumb:hover {
  background: #aaa;
}

/* ── Theme selector ── */
.theme-row {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  padding: 6px 0;
}

.theme-row-label {
  flex-shrink: 0;
}

.theme-options {
  display: flex;
  gap: 0;
}

.theme-options input[type="radio"] {
  display: none;
}

.theme-options label {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  padding: 4px 12px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition:
    color 0.1s,
    background 0.1s,
    border-color 0.1s;
  margin-left: -1px;
}

.theme-options label:first-of-type {
  margin-left: 0;
}

.theme-options label:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.theme-options input[type="radio"]:checked + label {
  color: var(--text-bright);
  background: var(--bg-active);
  border-color: var(--accent-dim);
  z-index: 1;
  position: relative;
}
