/* 시청자 화면: 어두운 방송 화면 톤 */
:root {
  --bg: #0a0c10;
  --surface: #141821;
  --surface-2: #1c2130;
  --line: #2a3142;
  --text: #e8ecf3;
  --muted: #8a93a6;
  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, 0.18);
  --live: #ef4444;
  --gap: 10px;
  --page-pad: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Noto Sans KR', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

button { font: inherit; color: inherit; cursor: pointer; }
svg { display: block; }

/* ── 상단 ───────────────────────────── */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { width: 44px; height: 44px; border-radius: 10px; object-fit: contain; flex: none; background: var(--surface-2); }
.brand-text { min-width: 0; }
.brand-text h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.meta { margin: 2px 0 0; font-size: 13px; color: var(--muted); display: flex; gap: 10px; white-space: nowrap; }
.meta span:empty { display: none; }
.meta span:not(:empty) + span:not(:empty)::before { content: '·'; margin-right: 10px; }

.brand { flex: 1; }
.top-actions { display: flex; align-items: center; gap: 10px; flex: none; }
.saver, .subscribe, .seg button { white-space: nowrap; flex: none; }

.sound-status {
  font-size: 13px;
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  white-space: nowrap;
}
.sound-status.on { color: #fff; background: var(--accent); }
.sound-status b { font-weight: 700; }

.seg { display: flex; background: var(--surface-2); border-radius: 8px; padding: 3px; }
.seg button {
  border: 0;
  background: transparent;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--muted);
}
.seg button.active { background: var(--bg); color: var(--text); font-weight: 500; }

.saver { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; }
.saver input { position: absolute; opacity: 0; pointer-events: none; }
.saver-track {
  width: 34px; height: 20px; border-radius: 999px; background: var(--line); position: relative; transition: background .15s;
}
.saver-track::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s;
}
.saver input:checked + .saver-track { background: var(--accent); }
.saver input:checked + .saver-track::after { transform: translateX(14px); }

.subscribe {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 7px 14px 7px 10px;
  border-radius: 999px;
  background: #e5e7eb;
  color: #0a0c10;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}
.subscribe svg { width: 18px; height: 18px; color: var(--live); }

.notice {
  margin: 0;
  padding: 7px 16px;
  font-size: 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.notice::before { content: '공지'; font-size: 12px; font-weight: 700; color: var(--accent); margin-right: 8px; }

/* ── 경기장 화면 ───────────────────────── */
.stage { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }

.track {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
}
.track::-webkit-scrollbar { display: none; }

.page {
  flex: 0 0 100%;
  height: 100%;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  padding: var(--page-pad);
  container-type: size;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 칸 크기: 페이지 안에 16:9로 꽉 차게 (가로·세로 중 좁은 쪽 기준) */
.page-grid {
  --tw: min(
    calc((100cqw - (var(--cols) - 1) * var(--gap)) / var(--cols)),
    calc((100cqh - (var(--rows) - 1) * var(--gap)) / var(--rows) * 16 / 9)
  );
  width: calc(var(--cols) * var(--tw) + (var(--cols) - 1) * var(--gap));
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--gap);
}

.tile {
  position: relative;
  width: var(--tw);
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  outline: 3px solid transparent;
  outline-offset: -3px;
  transition: outline-color .15s;
}
.tile-media, .tile-media > div, .tile-media iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* 투명 덮개: 클릭이 유튜브로 넘어가지 않게 */
.tile-shield { position: absolute; inset: 0; z-index: 2; cursor: pointer; }
.tile.no-video .tile-shield { cursor: default; }

.tile-label {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 3px 9px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.65);
  font-size: 14px;
  font-weight: 700;
}
.tile-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  display: none;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 6px;
  background: var(--accent);
  font-size: 13px;
  font-weight: 700;
}
.tile-badge svg { width: 15px; height: 15px; }
.tile-expand {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.65);
  display: grid;
  place-items: center;
  opacity: 0.85;
}
.tile-expand:hover { background: var(--accent); opacity: 1; }
.tile-expand svg { width: 18px; height: 18px; fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.tile.sound-on { outline-color: var(--accent); }
.tile.sound-on .tile-badge { display: inline-flex; }

/* 방송 없는 칸 / 오류 칸 */
.offline {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--surface);
  color: var(--muted);
  text-align: center;
  padding: 12px;
}
.offline img.offline-logo { width: 22%; max-width: 80px; aspect-ratio: 1; object-fit: contain; opacity: 0.8; }
.offline p { margin: 0; font-size: clamp(12px, 2.4cqw, 16px); }
.offline.has-image { padding: 0; }
.offline.empty-notice { position: static; background: transparent; }
.offline.empty-notice p { font-size: 16px; }
.offline.has-image img { width: 100%; height: 100%; object-fit: cover; }

/* 썸네일 (데이터 절약) */
.thumb-wrap { position: absolute; inset: 0; }
.thumb-wrap img { width: 100%; height: 100%; object-fit: cover; }
.thumb-wrap .play {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.7);
  font-size: 12px;
  white-space: nowrap;
}

/* 페이지 이동 버튼·점 */
.nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 5;
  width: 44px;
  height: 64px;
  border: 0;
  border-radius: 10px;
  background: rgba(20, 24, 33, 0.85);
  display: grid;
  place-items: center;
}
.nav svg { width: 24px; height: 24px; fill: none; stroke: #fff; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.nav:disabled { opacity: 0.25; cursor: default; }
.nav.prev { left: 8px; }
.nav.next { right: 8px; }

.dots { display: flex; justify-content: center; gap: 8px; padding: 2px 0 8px; }
.dots button {
  width: 9px;
  height: 9px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--line);
}
.dots button.active { background: var(--text); width: 22px; border-radius: 999px; }

/* 휴대폰 사용법 안내 (PC에서는 숨김) */
.mobile-hint {
  display: none;
  margin: 6px 12px 16px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}
.mobile-hint b { color: var(--text); font-weight: 500; }

/* ── 크게 보기 ───────────────────────── */
.focus {
  position: absolute;
  inset: 0;
  z-index: 10;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  padding: 10px 12px 12px;
  gap: 10px;
}
.focus[hidden] { display: none; }
.focus-bar { display: flex; align-items: center; gap: 12px; }
.back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: 6px 12px 6px 8px;
  font-size: 14px;
}
.back svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.focus-bar strong { font-size: 17px; }

.focus-main { flex: 1; min-height: 0; container-type: size; display: flex; align-items: center; justify-content: center; }
.focus-frame.tile { width: min(100cqw, 100cqh * 16 / 9); }

.focus-strip {
  flex: none;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  justify-content: safe center;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.strip-item {
  position: relative;
  flex: none;
  width: 176px;
  aspect-ratio: 16 / 9;
  border-radius: 6px;
  overflow: hidden;
  background: #000;
  cursor: pointer;
  outline: 2px solid transparent;
  outline-offset: -2px;
}
.strip-item .tile-shield { z-index: 2; }
.strip-item .tile-label { top: 4px; left: 4px; font-size: 12px; padding: 2px 6px; }
.strip-item.current { outline-color: var(--accent); cursor: default; }
.strip-item.current::after {
  content: '크게 보는 중';
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-items: center;
  background: rgba(10, 12, 16, 0.6);
  font-size: 13px;
  font-weight: 700;
}
.strip-item.no-video { cursor: default; opacity: 0.6; }

/* ── 하단 단축키 안내 ───────────────────── */
.hint {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px 18px;
  padding: 7px 16px;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  background: var(--surface);
}
kbd {
  display: inline-block;
  min-width: 20px;
  padding: 1px 5px;
  margin: 0 1px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface-2);
  font-family: inherit;
  font-size: 11px;
  text-align: center;
  color: var(--text);
}

/* ── 모바일 ───────────────────────────── */
@media (max-width: 767px) {
  :root { --gap: 6px; --page-pad: 6px; }
  .top { flex-wrap: wrap; padding: 8px 12px; gap: 8px; }
  .brand { flex: 1; }
  .logo { width: 36px; height: 36px; border-radius: 8px; }
  .brand-text h1 { font-size: 15px; }
  .meta { font-size: 12px; }
  .top-actions { width: 100%; justify-content: space-between; order: 3; }
  .subscribe { padding: 6px 12px 6px 8px; font-size: 13px; }
  .sound-status { min-width: 0; font-size: 12px; padding: 5px 10px; overflow: hidden; text-overflow: ellipsis; }
  .notice { font-size: 13px; padding: 6px 12px; }
  .tile { border-radius: 6px; }
  .tile-label { top: 4px; left: 4px; font-size: 12px; padding: 2px 6px; }
  .tile-badge { top: 4px; right: 4px; font-size: 11px; padding: 2px 6px; }
  .tile-badge .badge-text { display: none; }
  .tile-expand { right: 4px; bottom: 4px; width: 30px; height: 30px; }
  .nav, .hint { display: none !important; }

  /* 휴대폰: 칸을 위쪽에 붙이고 가로 폭을 꽉 채운다. 남는 아래 공간에는 사용법 안내 */
  .stage { overflow-y: auto; }
  .track { flex: none; align-items: flex-start; }
  .page { height: auto; container-type: inline-size; align-items: flex-start; }
  .page-grid { --tw: calc((100cqw - (var(--cols) - 1) * var(--gap)) / var(--cols)); justify-content: flex-start; }
  .dots { padding: 10px 0 4px; }
  .mobile-hint { display: block; }
  /* 모바일 크게 보기: 큰 화면 바로 아래에 나머지를 2줄씩 */
  .focus { padding: 8px; overflow-y: auto; }
  .focus-main { flex: none; container-type: normal; }
  .focus-frame.tile { width: 100%; }
  .focus-strip { flex-wrap: wrap; overflow: visible; justify-content: flex-start; gap: 6px; }
  .strip-item { width: calc(50% - 3px); }
}

@media (hover: none) {
  .tile-expand { opacity: 1; }
}
