/* ===========================
   BanG Dream! Song Sorter — style.css

   1. Variables / Base
   2. Header (진행률)
   3. App Layout (grid)
   4. A. Band Selector
   5. B. Song List (+ 필터칩, 프레스 피드백)
   6. C. YouTube
   7. D/E. Right Panel (히스토그램 / 히트맵)
   8. Bottom Bar
   9. Rank Popup (modal)
   10. Disclaimer / Capture
   11. 반응형 (≤1023px)
=========================== */

/* ===========================
   1. Variables / Base
=========================== */
:root {
  --bg: #0e0e14;
  --surface: #16161f;
  --surface2: #1e1e2a;
  --border: #2a2a3a;
  --text: #e8e8f0;
  --text-sub: #7a7a9a;
  --accent: #c084fc;
  --header-h: 52px;

  --tier-1: #ff6b9d;
  --tier-2: #ff9f6b;
  --tier-3: #ffd06b;
  --tier-4: #6bcfff;
  --tier-5: #9d9dbd;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, sans-serif;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ===========================
   2. Header
=========================== */
header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}
.logo-emoji { font-size: 1.2rem; }
header h1 {
  font-family: 'M PLUS Rounded 1c', sans-serif;
  font-size: 1.1rem;
  font-weight: 800;
  background: linear-gradient(135deg, #c084fc, #ff6b9d);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: 0.02em;
}
.header-progress {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.75rem;
  color: var(--text-sub);
}
.progress-bar {
  width: 120px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #c084fc, #ff6b9d);
  border-radius: 2px;
  transition: width 0.4s ease;
}

/* ===========================
   3. App Layout
=========================== */
.app {
  display: grid;
  grid-template-columns: 56px 1fr 280px;
  grid-template-rows: 1fr auto;
  flex: 1 1 auto;
  height: calc(100vh - var(--header-h));
  overflow: hidden;
}
.band-selector { grid-column: 1; grid-row: 1; }
.center        { grid-column: 2; grid-row: 1; }
.right-panel   { grid-column: 3; grid-row: 1; }
.bottom-bar    { grid-column: 1 / 4; grid-row: 2; }

/* ===========================
   4. A. Band Selector
=========================== */
.band-selector {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 0;
  gap: 6px;
  overflow-y: auto;
}
.band-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid transparent;
  background: var(--surface2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.55rem;
  font-weight: 700;
  color: var(--text-sub);
  transition: all 0.15s;
  flex-shrink: 0;
  overflow: hidden;
  font-family: 'M PLUS Rounded 1c', sans-serif;
}
.band-btn:hover { border-color: var(--accent); color: var(--text); }
.band-btn.active { border-color: var(--tier-1); background: rgba(255,107,157,0.14); }
.band-btn.all { font-size: 0.6rem; }
.band-btn.all.active { border-color: var(--accent); color: var(--accent); background: rgba(192,132,252,0.14); }
.band-btn-icon {
  width: 30px;
  height: 30px;
  object-fit: contain;
  display: block;
}
.band-divider { width: 26px; height: 1px; background: var(--border); flex-shrink: 0; }

/* ===========================
   5. B. Song List
=========================== */
.center {
  display: grid;
  grid-template-columns: 1fr 1.5fr;
  overflow: hidden;
}
.song-list-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
}
.song-list-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.band-label {
  font-family: 'M PLUS Rounded 1c', sans-serif;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--tier-1);
}
.filter-pills {
  display: flex;
  gap: 4px;
  margin-left: auto;
  flex-wrap: wrap;
}
.pill {
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 0.65rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-sub);
  cursor: pointer;
  transition: all 0.12s;
}
.pill:hover { color: var(--text); }
.pill.active { font-weight: 700; }
.copy-btn {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.65rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-sub);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  transition: all 0.12s;
}
.copy-btn:hover { border-color: var(--accent); color: var(--accent); }

.song-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
  -webkit-touch-callout: none;
  user-select: none;
}
.song-empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--text-sub);
  font-size: 0.8rem;
}
.song-item {
  position: relative;
  display: flex;
  align-items: center;
  padding: 8px 14px;
  gap: 10px;
  cursor: pointer;
  border-bottom: 1px solid rgba(42,42,58,0.5);
  border-left: 3px solid transparent;
  transition: background 0.1s;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}
.song-item:hover { background: var(--surface2); }
.song-item.ranked { border-left-color: var(--row-tier, transparent); }

/* 롱프레스 진행 피드백 (좌→우 채움, CSS transition) */
.song-item::after {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  right: 100%;
  background: rgba(192,132,252,0.16);
  pointer-events: none;
  transition: right 0s;
}
.song-item.pressing::after {
  right: 0;
  transition: right 350ms linear;
}
.song-num {
  font-size: 0.65rem;
  color: var(--text-sub);
  width: 24px;
  text-align: right;
  flex-shrink: 0;
}
.song-title {
  font-size: 0.8rem;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.song-item.ranked .song-title { color: var(--text); }
.song-item:not(.ranked) .song-title { color: var(--text-sub); }
.song-band-tag {
  font-size: 0.6rem;
  color: var(--text-sub);
  background: var(--surface2);
  padding: 1px 7px;
  border-radius: 10px;
  flex-shrink: 0;
  max-width: 90px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.song-noyt { font-size: 0.7rem; color: var(--border); flex-shrink: 0; }
.rank-badge {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
}
.rb-1 { background: rgba(255,107,157,0.2); border: 1px solid var(--tier-1); }
.rb-2 { background: rgba(255,159,107,0.2); border: 1px solid var(--tier-2); }
.rb-3 { background: rgba(255,208,107,0.2); border: 1px solid var(--tier-3); }
.rb-4 { background: rgba(107,207,255,0.2); border: 1px solid var(--tier-4); }
.rb-5 { background: rgba(157,157,189,0.2); border: 1px solid var(--tier-5); }
.rb-empty { background: var(--surface2); border: 1px dashed var(--border); }

/* ===========================
   6. C. YouTube
=========================== */
.youtube-panel {
  display: flex;
  flex-direction: column;
  background: #000;
  overflow: hidden;
}
.yt-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #000;
}
#youtube-player, #youtube-player iframe {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  border: 0;
}
.yt-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-sub);
  background: #000;
  z-index: 2;
}
.yt-placeholder[hidden] { display: none; }
.yt-icon {
  width: 44px;
  height: 44px;
  background: rgba(255,255,255,0.08);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
}
.yt-label { font-size: 0.75rem; }
.yt-hint { font-size: 0.65rem; color: var(--border); }
.yt-now-playing {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 0.72rem;
  color: rgba(255,255,255,0.85);
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.yt-now-playing[hidden] { display: none; }
.yt-now-playing.muted { color: var(--text-sub); }
.yt-now-playing #yt-song-name { overflow: hidden; text-overflow: ellipsis; }
.yt-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--tier-1); animation: pulse 1.5s infinite; flex-shrink: 0; }
.yt-now-playing.muted .yt-dot { animation: none; background: var(--text-sub); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.3} }

/* ===========================
   7. D/E. Right Panel
=========================== */
.right-panel {
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.panel-tab {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.tab-btn {
  flex: 1;
  padding: 9px;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-sub);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all 0.12s;
  letter-spacing: 0.03em;
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

.histogram-panel, .heatmap-panel {
  padding: 14px;
  flex: 1;
  overflow-y: auto;
}
.heatmap-panel { display: none; }
.heatmap-panel.active { display: block; }
.histogram-panel { display: none; }
.histogram-panel.active { display: block; }

.hist-title, .hm-title {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-sub);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 12px;
}
.hist-row { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }
.hist-label {
  font-size: 0.65rem;
  font-weight: 700;
  width: 28px;
  text-align: right;
  flex-shrink: 0;
  font-family: 'M PLUS Rounded 1c', sans-serif;
}
.hist-bar-bg {
  flex: 1;
  height: 18px;
  background: var(--surface2);
  border-radius: 4px;
  overflow: hidden;
}
.hist-bar {
  height: 100%;
  border-radius: 4px;
  min-width: 2px;
  transition: width 0.4s cubic-bezier(0.34,1.56,0.64,1);
}
.hist-count { font-size: 0.65rem; color: var(--text-sub); width: 18px; text-align: right; flex-shrink: 0; }

.hm-grid { display: grid; grid-template-columns: 36px repeat(5, 1fr); gap: 3px; }
.hm-head {
  font-size: 0.55rem;
  font-weight: 700;
  text-align: center;
  color: var(--text-sub);
  padding: 2px 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.hm-band {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.5rem;
  color: var(--text-sub);
  overflow: hidden;
}
.hm-band-icon { width: 22px; height: 22px; object-fit: contain; }
.hm-cell {
  height: 22px;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.58rem;
  font-weight: 700;
  background: var(--surface2);
  transition: background 0.3s ease;
}

/* ===========================
   8. Bottom Bar
=========================== */
.bottom-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.stat-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.stat-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.68rem;
  color: var(--text);
}
.stat-chip-muted { color: var(--text-sub); }
.stat-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.bottom-progress {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}
.bp-label {
  font-size: 0.7rem;
  color: var(--text-sub);
  white-space: nowrap;
  flex-shrink: 0;
}
.bp-bar {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  min-width: 60px;
}
.bp-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #c084fc, #ff6b9d);
  border-radius: 3px;
  transition: width 0.4s ease;
}
.bp-pct {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 38px;
  text-align: right;
}
.bottom-actions { margin-left: auto; display: flex; gap: 8px; }
.btn-download, .btn-reset {
  padding: 7px 16px;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s;
  border: 1px solid var(--border);
}
.btn-download { background: var(--surface2); color: var(--text); }
.btn-download:hover { border-color: var(--accent); color: var(--accent); }
.btn-reset { background: transparent; color: var(--text-sub); }
.btn-reset:hover { border-color: #ff6b6b; color: #ff6b6b; }

/* ===========================
   9. Rank Popup (modal)
=========================== */
.popup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.popup-overlay[hidden] { display: none; }
.popup-overlay.open { opacity: 1; pointer-events: auto; }
.popup {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  width: min(340px, 92vw);
  transform: translateY(12px) scale(0.97);
  transition: transform 0.2s cubic-bezier(0.34,1.56,0.64,1);
}
.popup-overlay.open .popup { transform: translateY(0) scale(1); }
.popup-band { font-size: 0.72rem; color: var(--text-sub); margin-bottom: 4px; }
.popup-title {
  font-family: 'M PLUS Rounded 1c', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 16px;
  word-break: break-word;
}
.rank-buttons { display: flex; gap: 6px; }
.rank-btn {
  flex: 1;
  padding: 10px 4px;
  border-radius: 10px;
  border: 2px solid var(--border);
  background: var(--surface2);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: all 0.15s;
}
.rank-btn:hover { transform: translateY(-2px); border-color: var(--text-sub); }
.rank-btn.active { border-color: var(--accent); background: rgba(192,132,252,0.16); }
.rk-icon { font-size: 1.2rem; }
.rk-label { font-size: 0.58rem; font-weight: 700; font-family: 'M PLUS Rounded 1c', sans-serif; }
.popup-cancel {
  margin-top: 14px;
  width: 100%;
  padding: 9px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-sub);
  font-size: 0.72rem;
  cursor: pointer;
  transition: background 0.12s;
}
.popup-cancel:hover { background: var(--surface2); }

/* ===========================
   10. Disclaimer / Capture
=========================== */
.disclaimer {
  flex-shrink: 0;
  padding: 12px 18px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  color: #55556a;
  font-size: 0.6rem;
  line-height: 1.6;
}
.disclaimer p { margin: 0 0 4px 0; }
.disclaimer p:last-child { margin-bottom: 0; }

/* Download 캡처용 오프스크린 (레이아웃 유지, 화면 밖) */
#capture-area {
  position: fixed;
  left: -99999px;
  top: 0;
  pointer-events: none;
}

/* ===========================
   11. 반응형 (≤1023px)
=========================== */
@media (max-width: 1023px) {
  body { height: auto; overflow: auto; overflow-x: hidden; }

  .app {
    display: flex;
    flex-direction: column;
    height: auto;
    overflow: visible;
  }

  /* A: 밴드 레일 → 상단 가로 스크롤 */
  .band-selector {
    flex-direction: row;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    overflow-y: hidden;
    padding: 8px 10px;
    position: sticky;
    top: 0;
    z-index: 20;
  }
  .band-divider { width: 1px; height: 24px; }

  /* CENTER: 리스트 + 유튜브 세로 */
  .center {
    display: flex;
    flex-direction: column;
  }
  .youtube-panel { order: -1; } /* 모바일은 유튜브를 리스트 위에 */
  .yt-stage { height: 200px; flex: none; }
  .song-list-panel { border-bottom: none; }
  .song-list { max-height: 60vh; }

  /* 우측 패널 → 하단 전체폭 */
  .right-panel {
    border-left: none;
    border-top: 1px solid var(--border);
  }
  .histogram-panel, .heatmap-panel { max-height: none; }
  .hm-grid { grid-template-columns: 40px repeat(5, 1fr); }
  .hm-cell, .hm-head { height: 26px; font-size: 0.62rem; }

  /* 하단 바 */
  .bottom-bar { position: sticky; bottom: 0; z-index: 20; }
  .bottom-actions { width: 100%; }
  .bottom-actions button { flex: 1; }
}
