:root {
  --bg: #0e0b14;
  --bg-card: #181323;
  --bg-card-2: #1f1830;
  --fg: #f4eef9;
  --fg-dim: #b9aecc;
  --muted: #80758f;
  --accent: #ff5fa2;
  --accent-2: #7aa6ff;
  --green: #4ade80;
  --green-soft: rgba(74, 222, 128, 0.5);
  --red: #f87171;
  --border: #2a2238;
  --border-soft: #3a3148;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(1200px 600px at 80% -10%, #2c1a3a 0%, transparent 60%),
              radial-gradient(900px 500px at -10% 30%, #1a1a3a 0%, transparent 55%),
              var(--bg);
  color: var(--fg);
  font-family: "Pretendard JP Variable", "Pretendard JP", -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", "Hiragino Sans", "Meiryo", sans-serif;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ============ Topbar ============ */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
  background: rgba(14, 11, 20, 0.78);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: baseline; gap: 12px; }
.logo {
  font-weight: 800; font-size: 22px;
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  letter-spacing: -0.02em;
}
.tag { color: var(--fg-dim); font-size: 13px; font-variant-numeric: tabular-nums; }

.status { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--fg-dim); }
.np-actions { display: flex; justify-content: flex-end; margin-top: -8px; }
/* np-card 가 숨겨진 상태(방송 종료/검출 미보유)면 히스토리 버튼도 함께 숨김 */
.np-card[hidden] + .np-actions { display: none; }
.hist-btn {
  background: transparent; color: var(--fg-dim);
  border: 1px solid var(--border-soft); border-radius: 999px;
  padding: 5px 14px; font: inherit; font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.hist-btn:hover { color: var(--fg); border-color: var(--accent); background: rgba(255,95,162,0.08); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); transition: background 0.3s; }
.dot.live { background: var(--red); animation: pulse 1.6s ease-in-out infinite; }
.dot.off { background: var(--muted); }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.55); }
  50%      { box-shadow: 0 0 0 8px rgba(248, 113, 113, 0); }
}

/* ============ Layout ============ */
main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 48px;
  display: grid;
  gap: 18px;
}

/* ============ Player card ============ */
.player-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}
.player-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.source-tabs { display: inline-flex; gap: 6px; background: #0c0915; border-radius: var(--radius-sm); padding: 4px; }
.tab {
  display: inline-flex; align-items: center; gap: 8px;
  border: 0; background: transparent; color: var(--fg-dim);
  font: inherit; font-size: 13px;
  padding: 7px 14px; border-radius: 8px; cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.tab:hover:not([disabled]) { color: var(--fg); }
.tab.active { background: linear-gradient(120deg, var(--accent), #c14de0); color: white; font-weight: 600; }
.tab[disabled] { opacity: 0.35; cursor: not-allowed; }

.tab-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex: none; }
.tab-dot.live { background: var(--red); box-shadow: 0 0 6px rgba(248,113,113,0.8); }
.tab-dot.off  { background: var(--muted); }
.tab-dot.na   { background: transparent; border: 1px dashed var(--border); }

.player-meta { color: var(--muted); font-size: 12px; display: inline-flex; align-items: center; gap: 10px; }
.ext-link {
  color: var(--fg-dim); text-decoration: none;
  font-size: 12px; padding: 4px 10px;
  border: 1px solid var(--border-soft); border-radius: 999px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.ext-link:hover { color: var(--fg); border-color: var(--accent); background: rgba(255,95,162,0.08); }
.ext-link[hidden] { display: none; }

.player-stage {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
}
.player-stage video,
.player-stage iframe,
#yt-host {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  border: 0;
  background: #000;
}
#yt-host iframe { width: 100%; height: 100%; border: 0; }
.empty {
  position: absolute; inset: 0;
  display: grid; place-items: center; text-align: center;
  color: var(--fg-dim); padding: 32px;
  background: linear-gradient(180deg, #14101e 0%, #0a0810 100%);
}
.empty[hidden] { display: none; }
.offline .offline-title {
  font-size: 24px; font-weight: 800; color: var(--fg);
  letter-spacing: 0.18em;
}
.offline .offline-sub { color: var(--muted); margin-top: 6px; font-size: 13px; }

/* ============ Now Playing ============ */
.np-card {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  background: var(--bg-card);
  border: 2px solid var(--border-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  transition: border-color 600ms ease, box-shadow 600ms ease, opacity 400ms ease;
  opacity: 1;
  overflow: hidden;
}
.np-card[hidden] { display: none; }
.np-card.active {
  border-color: var(--green);
  box-shadow: 0 0 0 1px rgba(74, 222, 128, 0.15), 0 4px 24px rgba(74, 222, 128, 0.18);
}
.np-card.inactive {
  border-color: var(--border-soft);
  opacity: 0.78;
}
.np-jacket {
  width: 64px; height: 64px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: #0c0915;
  flex: none;
}
.np-info { min-width: 0; }
.np-title {
  font-weight: 700; font-size: 17px;
  color: var(--fg);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  letter-spacing: -0.01em;
}
.np-artist {
  font-size: 13px; color: var(--fg-dim);
  margin-top: 3px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.np-pulse {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted);
  flex: none; margin-right: 4px;
  transition: background 600ms ease, box-shadow 600ms ease;
}
.np-card.active .np-pulse {
  background: var(--green);
  animation: np-pulse 2s ease-in-out infinite;
}
@keyframes np-pulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--green-soft); }
  50%      { box-shadow: 0 0 0 6px rgba(74, 222, 128, 0); }
}

/* ============ History modal ============ */
.modal {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  padding: 16px;
}
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.modal-panel {
  position: relative;
  width: 100%; max-width: 480px; max-height: 80vh;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 15px; font-weight: 700; color: var(--fg); }
.modal-close {
  background: transparent; border: 0; color: var(--fg-dim);
  font: inherit; font-size: 22px; line-height: 1; padding: 4px 8px;
  border-radius: 6px; cursor: pointer;
}
.modal-close:hover { color: var(--fg); background: rgba(255,255,255,0.06); }
.modal-body { overflow-y: auto; padding: 6px 0; }
.hist-loading, .hist-empty {
  padding: 32px 16px; text-align: center; color: var(--muted); font-size: 13px;
}
.hist-day {
  padding: 8px 16px 4px;
  font-size: 11px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.06em;
  font-weight: 600;
  position: sticky; top: 0; background: var(--bg-card); z-index: 1;
}
.hist-row {
  display: grid; grid-template-columns: 56px 1fr auto;
  gap: 12px; align-items: center;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
}
.hist-row:first-child { border-top: 0; }
.hist-row.now-playing {
  background: rgba(74, 222, 128, 0.06);
}
.hist-row.now-playing .hist-title { color: var(--fg); }
.hist-now-badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 10px; font-weight: 700;
  color: var(--green); letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 2px 6px;
  border: 1px solid var(--green);
  border-radius: 4px;
  margin-left: 6px;
  vertical-align: 2px;
}
.hist-now-badge::before {
  content: ''; width: 5px; height: 5px; border-radius: 50%;
  background: var(--green);
  animation: np-pulse 2s ease-in-out infinite;
}
.hist-jacket {
  width: 44px; height: 44px;
  object-fit: cover;
  border-radius: 6px;
  background: #0c0915;
}
.hist-meta { min-width: 0; }
.hist-title {
  font-size: 14px; color: var(--fg); font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.hist-artist {
  font-size: 12px; color: var(--fg-dim); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.hist-time {
  font-size: 11px; color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ============ Mobile ============ */
@media (max-width: 760px) {
  .topbar { padding: 12px 16px; }
  main { padding: 14px 14px 32px; gap: 14px; }
  .player-toolbar { flex-direction: column; align-items: stretch; gap: 8px; }
  .player-meta { text-align: right; }
  .np-card { padding: 10px 12px; gap: 12px; }
  .np-jacket { width: 54px; height: 54px; }
  .np-title { font-size: 15px; }
  .np-artist { font-size: 12px; }
}

/* ============ Mobile portrait + 세로 동영상 — 한 화면에 푸터까지 ============ */
/* svh = small viewport height (URL bar 보일 때 기준 → 절대 안 잘림).
   safe-area-inset = iOS 홈 인디케이터/Android 하단 바 회피. (viewport-fit=cover 필요)
   body.video-portrait 클래스가 있을 때만 활성 — 가로 동영상이면 16:9 그대로 두는 게 자연스러움. */
@media (max-width: 760px) and (orientation: portrait) {
  body.video-portrait {
    height: 100vh;
    height: 100svh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
  body.video-portrait .topbar {
    position: static;
    flex: 0 0 auto;
    padding: 8px 14px;
  }
  body.video-portrait .logo { font-size: 18px; }
  body.video-portrait main {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 8px 6px 4px;
    gap: 8px;
    max-width: none;
    margin: 0;        /* default `margin: 0 auto` 가 flex 컨텍스트에서 stretch 를 막음 */
    width: 100%;
  }
  /* player-card 는 stage+toolbar 만큼만. 남는 세로공간은 NP/footer 쪽으로. */
  body.video-portrait .player-card {
    flex: 0 1 auto;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  body.video-portrait .player-toolbar { flex: 0 0 auto; padding: 8px 12px; }
  /* stage 는 16:9 베이스 대비 +50% 까지만 (`(100vw - 12) * 9/16 * 1.5`). */
  body.video-portrait .player-stage {
    height: calc((100vw - 12px) * 9 / 16 * 1.5);
    aspect-ratio: auto;
  }
  body.video-portrait .np-card,
  body.video-portrait .np-actions { flex: 0 0 auto; }
  body.video-portrait .np-card { padding: 8px 10px; gap: 10px; }
  body.video-portrait .np-jacket { width: 44px; height: 44px; }
  body.video-portrait .np-title { font-size: 14px; }
  body.video-portrait .np-artist { font-size: 11px; margin-top: 1px; }
  body.video-portrait .np-actions { margin-top: -4px; }
  body.video-portrait .hist-btn { padding: 4px 10px; font-size: 11px; }
}
