/* ============================================================
   악보 노래방 — Design System
   Premium dark karaoke aesthetic: deep charcoal, gold accent,
   glass panels, smooth transitions.
   ============================================================ */

/* --- Design Tokens --- */
:root {
  /* Surfaces */
  --bg: #0d0f14;
  --surface: #161922;
  --surface-2: #1d2130;
  --surface-3: #262b3d;
  --glass: rgba(29, 33, 48, 0.72);
  --glass-border: rgba(255, 255, 255, 0.06);

  /* Accent */
  --accent: #f0b90b;
  --accent-2: #ffd246;
  --accent-dim: rgba(240, 185, 11, 0.15);
  --accent-glow: rgba(240, 185, 11, 0.3);

  /* Text */
  --text: #f5f5f7;
  --text-2: #a0a4b0;
  --text-3: #6b6f7d;
  --text-dim: rgba(245, 245, 247, 0.35);

  /* Semantic */
  --error: #ff5252;
  --success: #00c853;
  --warning: #ffb300;

  /* Borders */
  --border: rgba(255, 255, 255, 0.08);
  --border-2: rgba(255, 255, 255, 0.14);

  /* Typography */
  --font-sans: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, system-ui, 'Segoe UI', sans-serif;
  --font-mono: 'Noto Sans Mono', ui-monospace, 'SF Mono', 'Cascadia Code', monospace;

  /* Radius */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
  --r-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-gold: 0 0 20px rgba(240, 185, 11, 0.3);

  /* Motion */
  --t-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --t-normal: 200ms cubic-bezier(0.4, 0, 0.2, 1);
  --t-slow: 250ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Layout */
  --header-h: 60px;
  --player-h: 112px;
  --max-w: 1400px;
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  padding-bottom: var(--player-h);
}

/* --- Focus --- */
*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

button:focus-visible,
input:focus-visible {
  outline-offset: 2px;
}

/* --- Scrollbars --- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-2);
  border-radius: var(--r-full);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-3);
}
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-2) transparent;
}

/* --- Utilities --- */
.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

/* --- Banner --- */
.banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: rgba(255, 179, 0, 0.12);
  border-bottom: 1px solid rgba(255, 179, 0, 0.25);
  font-size: 13px;
  color: var(--warning);
}
.banner code {
  font-family: var(--font-mono);
  background: rgba(255, 179, 0, 0.15);
  padding: 1px 6px;
  border-radius: 4px;
}
.banner-close {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--warning);
  font-size: 20px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-sm);
  transition: background var(--t-fast);
}
.banner-close:hover {
  background: rgba(255, 179, 0, 0.15);
}

/* --- Header --- */
.header {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--glass-border);
}

.header-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.search-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  padding: 0 14px;
  height: 40px;
  max-width: 480px;
  margin-left: auto;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.search-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.search-icon {
  width: 18px;
  height: 18px;
  color: var(--text-3);
  flex-shrink: 0;
}
.search-input {
  flex: 1;
  border: none;
  background: none;
  color: var(--text);
  font-size: 14px;
  font-family: var(--font-sans);
  outline: none;
}
.search-input::placeholder {
  color: var(--text-3);
}
.search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

/* --- Main Layout --- */
.main {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 16px;
  /* 모바일 고정 하단 플레이어(collapsed 약 120px)가 마지막 카드를 가리지 않도록
     여백 확보. PC(@media 1024px)에서는 padding: 24px로 재정의되어 무해. */
  padding-bottom: 160px;
}

/* --- Section --- */
.section {
  margin-bottom: 28px;
}
.section-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 12px;
  letter-spacing: -0.01em;
}

/* --- Popular List (horizontal scroll) --- */
.popular-list {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 8px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}
.popular-list .popular-card {
  flex: 0 0 200px;
  scroll-snap-align: start;
}

/* --- Song List (vertical) --- */
.song-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* --- Song Card --- */
.song-card, .popular-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  cursor: pointer;
  transition: transform var(--t-fast), border-color var(--t-fast), box-shadow var(--t-fast);
  min-height: 56px;
}
.song-card:hover, .popular-card:hover {
  border-color: var(--border-2);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.song-card:active, .popular-card:active {
  transform: scale(0.99);
}
.song-card.disabled, .popular-card.disabled {
  opacity: 0.4;
  pointer-events: none;
}

.song-card-thumb {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: var(--r-md);
  background: linear-gradient(135deg, var(--surface-3), var(--surface-2));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
}
.popular-list .song-card-thumb {
  width: 100%;
  height: 100px;
  border-radius: var(--r-md) var(--r-md) 0 0;
  font-size: 36px;
}
.popular-list .popular-card {
  flex-direction: column;
  align-items: stretch;
  padding: 0;
  overflow: hidden;
}
.popular-list .song-card-numbers {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.popular-list .song-card-body {
  padding: 10px 12px;
}

.song-card-body {
  flex: 1;
  min-width: 0;
}
.song-card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.song-card-artist {
  font-size: 13px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.song-card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}
.chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 500;
  border-radius: var(--r-full);
  background: var(--surface-3);
  color: var(--text-2);
}
.chip-difficulty {
  background: var(--accent-dim);
  color: var(--accent);
}
.song-card-numbers {
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
  text-align: right;
  line-height: 1.4;
}

/* --- Empty / Error States --- */
.empty-state,
.error-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-3);
}
.error-state p {
  margin-bottom: 16px;
}
.btn-retry {
  padding: 8px 20px;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: var(--r-full);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--t-fast), transform var(--t-fast);
}
.btn-retry:hover {
  background: var(--accent-2);
  transform: translateY(-1px);
}

/* --- Player Section --- */
.player-section {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--glass);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-top: 1px solid var(--glass-border);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--shadow-lg);
  max-height: 100vh;
  transition: transform var(--t-slow), max-height var(--t-slow);
  transform: translateY(calc(100% - var(--player-h)));
}
.player-section.expanded {
  transform: translateY(0);
  max-height: 100vh;
  overflow-y: auto;
}

/* Grab handle */
.player-grab {
  display: flex;
  justify-content: center;
  padding: 8px 0 4px;
  cursor: pointer;
}
.grab-handle {
  width: 36px;
  height: 4px;
  border-radius: var(--r-full);
  background: var(--border-2);
  transition: background var(--t-fast);
}
.player-grab:hover .grab-handle {
  background: var(--text-3);
}

/* Player header */
.player-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  height: 44px;
}
.player-info {
  flex: 1;
  min-width: 0;
}
.player-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.player-artist {
  font-size: 12px;
  color: var(--text-3);
}
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: none;
  background: none;
  color: var(--text-2);
  cursor: pointer;
  border-radius: var(--r-sm);
  transition: color var(--t-fast), background var(--t-fast);
  flex-shrink: 0;
}
.icon-btn:hover {
  color: var(--text);
  background: var(--surface-3);
}
.icon-btn svg {
  width: 22px;
  height: 22px;
}
.icon-btn-lg {
  width: 52px;
  height: 52px;
  background: var(--accent);
  color: var(--bg);
  border-radius: var(--r-full);
}
.icon-btn-lg:hover {
  background: var(--accent-2);
  color: var(--bg);
  box-shadow: var(--shadow-gold);
}
.icon-btn-lg svg {
  width: 26px;
  height: 26px;
}

/* Player body (hidden when collapsed on mobile) */
.player-body {
  padding: 0 16px 16px;
}

/* Demo badge */
.demo-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--warning);
  background: rgba(255, 179, 0, 0.12);
  border: 1px solid rgba(255, 179, 0, 0.25);
  border-radius: var(--r-full);
  margin-bottom: 8px;
}

/* Progress bar */
.progress-wrap {
  margin-bottom: 12px;
}
.progress-bar {
  position: relative;
  height: 6px;
  background: var(--surface-3);
  border-radius: var(--r-full);
  cursor: pointer;
  overflow: hidden;
  transition: height var(--t-fast);
}
.progress-bar:hover {
  height: 8px;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: var(--r-full);
  box-shadow: 0 0 8px var(--accent-glow);
}
.time-row {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-3);
}

/* Controls */
.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 16px;
}

/* Lyrics */
.lyrics-container {
  height: 200px;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  padding: 20px 8px;
  mask-image: linear-gradient(to bottom, transparent, black 15%, black 85%, transparent);
  -webkit-mask-image: linear-gradient(to bottom, transparent, black 15%, black 85%, transparent);
}
.lyrics-inner {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 100%;
  justify-content: center;
}
.lyric-line {
  text-align: center;
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.6;
  transition: all var(--t-normal);
  padding: 4px 8px;
  border-radius: var(--r-sm);
  word-break: keep-all;
}
.lyric-prev {
  font-size: 15px;
  color: var(--text-3);
}
.lyric-current {
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}
.lyric-next {
  font-size: 15px;
  color: var(--text-3);
}
/* 실제 노래방식 음절 점진 색 채움: JS(rAF)가 --p(진행률 %)를 매 프레임 갱신하고
   글리프를 골드→흰색 그라디언트 클립으로 덮어칠한다 */
.syllable {
  --p: 0%;
  color: transparent;
  background-image: linear-gradient(90deg,
    var(--accent) var(--p),
    var(--text) var(--p));
  -webkit-background-clip: text;
  background-clip: text;
}
.syllable-active {
  text-shadow: 0 0 14px var(--accent-glow);
}
@supports not ((-webkit-background-clip: text) or (background-clip: text)) {
  .syllable { color: var(--text); }
  .syllable-active { color: var(--accent); }
}

/* Score area */
.score-area {
  position: relative;
  min-height: 120px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: auto;
  margin-top: 8px;
}
.score-container {
  width: 100%;
  min-height: 120px;
  padding: 8px;
}
.score-container svg {
  width: 100% !important;
  height: auto !important;
  background: transparent !important;
}
/* Dark theme for OSMD SVG */
.score-container svg path,
.score-container svg line,
.score-container svg rect {
  stroke: var(--text-2);
}
.score-container svg text {
  fill: var(--text-2);
}
.score-container svg ellipse,
.score-container svg circle {
  fill: var(--text);
  stroke: var(--text);
}
/* Highlighted note */
.score-note-active,
.score-note-active ellipse,
.score-note-active path,
.score-note-active circle,
.score-note-active rect {
  fill: var(--accent) !important;
  stroke: var(--accent) !important;
  filter: drop-shadow(0 0 6px var(--accent-glow));
}
/* OSMD cursor styling */
.score-container .vf-cursor rect {
  fill: var(--accent-dim);
  stroke: var(--accent);
  stroke-width: 1;
}

.score-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  color: var(--text-3);
  font-size: 13px;
}
.score-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 120px;
  color: var(--error);
  font-size: 13px;
}

/* --- Responsive: PC two-column --- */
@media (min-width: 1024px) {
  body {
    padding-bottom: 0;
  }
  .header {
    padding: 0 24px;
  }
  .header-title {
    font-size: 20px;
  }
  .main {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    padding: 24px;
    align-items: start;
  }
  .list-section {
    max-height: calc(100vh - var(--header-h) - 48px);
    overflow-y: auto;
    padding-right: 8px;
  }
  .player-section {
    position: sticky;
    top: calc(var(--header-h) + 24px);
    transform: none !important;
    max-height: calc(100vh - var(--header-h) - 48px);
    overflow-y: auto;
    border-radius: var(--r-xl);
    border: 1px solid var(--glass-border);
  }
  .player-grab {
    display: none;
  }
  .player-body {
    display: block !important;
  }
  .lyrics-container {
    height: 160px;
  }
  .lyric-current {
    font-size: 24px;
  }
}

@media (min-width: 1280px) {
  .main {
    grid-template-columns: 1fr 1.2fr;
  }
}

/* --- Animations --- */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.song-card, .popular-card {
  animation: fadeIn var(--t-normal) both;
}
.song-card:nth-child(1), .popular-card:nth-child(1) { animation-delay: 0ms; }
.song-card:nth-child(2), .popular-card:nth-child(2) { animation-delay: 30ms; }
.song-card:nth-child(3), .popular-card:nth-child(3) { animation-delay: 60ms; }
.song-card:nth-child(4), .popular-card:nth-child(4) { animation-delay: 90ms; }
.song-card:nth-child(5), .popular-card:nth-child(5) { animation-delay: 120ms; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 8px var(--accent-glow); }
  50% { box-shadow: 0 0 16px var(--accent-glow); }
}
.progress-fill {
  animation: pulse 2s ease-in-out infinite;
}

/* --- Reduced motion --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  html {
    scroll-behavior: auto;
  }
}
