:root {
  --bg: #f5f6f7;
  --surface: #ffffff;
  --surface-2: #eef0f2;
  --line: #e1e4e8;
  --text: #16181b;
  --muted: #6b7178;
  --accent: #00b377;
  --accent-ink: #ffffff;
  --accent-soft: rgba(0, 179, 119, 0.12);
  --like: #ff4d6d;
  --gold: #c99400;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 6px 20px rgba(0, 0, 0, 0.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #111214;
    --surface: #1a1c1f;
    --surface-2: #24272b;
    --line: #2d3035;
    --text: #eceef0;
    --muted: #979ca3;
    --accent: #00e19a;
    --accent-ink: #0b0c0d;
    --accent-soft: rgba(0, 225, 154, 0.12);
    --like: #ff6b85;
    --gold: #ffd34d;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 'Noto Sans KR', system-ui, -apple-system, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 12px 24px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; color: inherit; text-decoration: none; white-space: nowrap; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); position: relative; }
.brand-mark::after { content: ''; position: absolute; left: 10px; top: 7px; border: 6px solid transparent; border-left: 9px solid var(--accent-ink); border-right: 0; }
.search {
  flex: 1; max-width: 560px; margin: 0 auto;
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 0 16px;
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search svg { color: var(--muted); flex: none; }
.search input { flex: 1; border: 0; outline: 0; background: none; padding: 10px 0; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-right { min-width: 0; }
.sync-status { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; white-space: nowrap; min-width: 0; max-width: 360px; cursor: default; }
.sync-status::before { flex: none; }
.sync-text { overflow: hidden; text-overflow: ellipsis; }
.sync-status::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }
.icon-btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 7px 10px; }
.icon-btn:hover { border-color: var(--muted); }

/* ---------- layout ---------- */
.layout { padding: 20px 24px 60px; max-width: 1600px; margin: 0 auto; }

/* ---------- filters ---------- */
.filters { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; margin-bottom: 20px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- 게임 · 채널 선택 ---------- */
/* 테마 프리셋: 기간·게임·참가자를 한 번에 */
.presets { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.presets[hidden] { display: none; }
.presets-label { font-size: 13px; font-weight: 700; color: var(--muted); }
.preset-list { display: flex; gap: 8px; flex-wrap: wrap; min-width: 0; }
.preset-list button {
  display: inline-flex; align-items: baseline; gap: 8px; max-width: 100%;
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 7px 15px;
}
.preset-list button:hover { border-color: var(--muted); }
.preset-list button small { color: var(--muted); font-size: 12px; white-space: nowrap; }
.preset-list button[aria-pressed='true'] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.preset-list button[aria-pressed='true'] small { color: var(--accent); }
.pickers { position: relative; display: flex; gap: 8px; flex-wrap: wrap; }
.picker-btn {
  display: inline-flex; align-items: center; gap: 6px; max-width: min(360px, 70vw);
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 7px 12px 7px 15px; font-weight: 500;
}
.picker-btn:hover { border-color: var(--muted); }
.reset-btn {
  display: inline-flex; align-items: center; gap: 5px;
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 7px 14px 7px 11px; color: var(--muted);
}
.reset-btn:hover:not(:disabled) { border-color: var(--muted); color: var(--text); }
.reset-btn:disabled { opacity: 0.45; cursor: default; }
.reset-btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.picker-btn.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.picker-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-btn svg { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; transition: transform 0.15s; }
.picker-btn[aria-expanded='true'] svg { transform: rotate(180deg); }
.picker-pop {
  position: absolute; z-index: 30; top: calc(100% + 6px); left: 0; width: min(340px, calc(100vw - 32px));
  display: flex; flex-direction: column; gap: 6px; padding: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
}
.picker-pop[hidden] { display: none; }
.picker-search { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--bg); color: var(--text); font: inherit; }
.picker-search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.picker-list { list-style: none; margin: 0; padding: 0; max-height: min(360px, 55vh); overflow: auto; }
.picker-list label { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 8px; cursor: pointer; }
.picker-list label:hover { background: var(--surface-2); }
.picker-list input { width: 16px; height: 16px; flex: none; accent-color: var(--accent); }
.picker-list img { width: 26px; height: 26px; flex: none; border-radius: 50%; object-fit: cover; background: var(--surface-2); }
.picker-list img.poster { width: 21px; height: 28px; border-radius: 4px; }
.picker-list .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-list .count { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.picker-list .empty { padding: 12px 8px; color: var(--muted); font-size: 13px; }
.picker-foot { display: flex; justify-content: space-between; border-top: 1px solid var(--line); padding-top: 6px; }
.picker-foot button { border: 0; background: none; padding: 6px 10px; border-radius: 7px; color: var(--muted); }
.picker-foot button:hover { background: var(--surface-2); color: var(--text); }
.picker-foot .picker-done { color: var(--text); font-weight: 600; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px 5px 5px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
}
.chip.all { padding-left: 12px; }
.chip img { width: 24px; height: 24px; border-radius: 50%; object-fit: cover; background: var(--surface-2); }
.chip[aria-pressed='true'] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.filter-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.seg { max-width: 100%; display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 3px; flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 7px; color: var(--muted); white-space: nowrap; }
.seg button:hover { color: var(--text); }
.seg button[aria-pressed='true'] { background: var(--text); color: var(--bg); font-weight: 500; }
.date-inputs { display: inline-flex; align-items: center; gap: 8px; }
.date-inputs input { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 6px 10px; }
.summary { margin: 0 0 0 auto; color: var(--muted); font-size: 14px; }
.summary strong { color: var(--text); }

/* ---------- results ---------- */
.results { display: grid; gap: 28px; }
.group-head { display: flex; align-items: baseline; gap: 10px; margin: 0 0 12px; font-size: 18px; }
.group-head span { font-size: 13px; color: var(--muted); font-weight: 400; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 20px 16px; }
.card { min-width: 0; display: flex; flex-direction: column; gap: 10px; border: 0; padding: 0; background: none; text-align: left; }
.thumb { position: relative; aspect-ratio: 16 / 9; border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 0.2s; }
.card:hover .thumb img { transform: scale(1.04); }
.card.adult .thumb img { filter: blur(16px); }
/* 19세 클립: 썸네일 대신 안내 (썸네일이 있으면 흐리게 깔고 그 위에) */
.thumb-19 {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  background: rgba(28, 18, 22, 0.86); color: #fff; text-align: center; padding: 8px 8px 30px; /* 아래 좋아요·길이 표시를 피해서 */
}
.thumb-19 .mark { width: 38px; height: 38px; border-radius: 50%; border: 3px solid #e0364f; display: grid; place-items: center; font-weight: 700; font-size: 15px; margin-bottom: 2px; }
.thumb-19 span:not(.mark) { font-size: 13px; }
.thumb-19 small { font-size: 12px; opacity: 0.7; }
.card.adult:hover .thumb-19 small { opacity: 1; text-decoration: underline; }
.badge {
  position: absolute; padding: 2px 7px; border-radius: 6px; font-size: 12px; font-weight: 500;
  background: rgba(0, 0, 0, 0.72); color: #fff; font-variant-numeric: tabular-nums;
}
.badge.dur { right: 8px; bottom: 8px; }
.badge.likes { left: 8px; bottom: 8px; display: inline-flex; gap: 4px; align-items: center; }
.badge.likes svg { width: 13px; height: 13px; fill: var(--like); stroke: none; }
.badge.rank { left: 8px; top: 8px; background: var(--surface); color: var(--text); font-weight: 700; }
.badge.rank.top { background: var(--gold); color: #1a1400; }
/* 오른쪽 위: 19금 표시와 게임 이름 (왼쪽 위 순위 표시와 겹치지 않게) */
.thumb-top { position: absolute; top: 8px; right: 8px; left: 48px; display: flex; justify-content: flex-end; gap: 4px; pointer-events: none; }
.thumb-top .badge { position: static; }
.badge.game { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 400; }
.card-body { display: flex; gap: 10px; }
.card-body img { width: 32px; height: 32px; border-radius: 50%; flex: none; object-fit: cover; background: var(--surface-2); }
.card-title { margin: 0; font-weight: 500; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; word-break: break-all; }
.card-title mark { background: var(--accent-soft); color: var(--accent); border-radius: 3px; }
.card-info { min-width: 0; }
.card-channel { margin: 4px 0 0; font-size: 13px; color: var(--text); opacity: 0.8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta { margin: 1px 0 0; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

.empty { text-align: center; padding: 80px 20px; color: var(--muted); border: 1px dashed var(--line); border-radius: 16px; }
.empty h3 { color: var(--text); margin: 0 0 6px; }
.empty button { margin-top: 16px; }
.more { text-align: center; margin-top: 28px; }
.more button, .admin-foot button, .empty button { border: 1px solid var(--line); background: var(--surface); padding: 10px 22px; border-radius: 10px; }
.skeleton .thumb { animation: pulse 1.2s infinite; }
.skeleton .line { height: 12px; border-radius: 6px; background: var(--surface-2); margin-top: 6px; }

/* ---------- dialogs ---------- */
dialog { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--text); padding: 20px; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.player { width: min(1280px, calc(100vw - 32px)); max-height: calc(100vh - 32px); }
.player-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 14px; }
.player-head h3 { margin: 0; font-size: 18px; }
.player-head p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.player-frame { aspect-ratio: 16 / 9; background: #000; border-radius: 10px; overflow: hidden; }
.player-frame iframe { width: 100%; height: 100%; border: 0; }
.player-link { display: inline-block; margin-top: 12px; color: var(--accent); text-decoration: none; font-size: 14px; }

.admin { width: min(560px, calc(100vw - 32px)); }
.add-form { display: flex; gap: 8px; }
.add-form input { flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 10px 12px; }
.primary { border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 700; padding: 10px 18px; border-radius: 10px; }
.hint { font-size: 13px; color: var(--muted); margin: 10px 0 16px; }
.suggest, .admin-channels { list-style: none; margin: 0; padding: 0; }
.suggest:not(:empty) { border: 1px solid var(--line); border-radius: 10px; margin-top: 6px; overflow: hidden; }
.suggest button { width: 100%; display: flex; align-items: center; gap: 10px; border: 0; background: none; padding: 8px 12px; text-align: left; }
.suggest button:hover { background: var(--surface-2); }
.suggest img, .admin-channels img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; background: var(--surface-2); }
.suggest small, .admin-channels small { color: var(--muted); display: block; font-size: 12px; }
.admin-channels li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.admin-channels li > div { flex: 1; min-width: 0; }
.admin-channels .remove { border: 1px solid var(--line); background: none; border-radius: 8px; padding: 5px 10px; font-size: 13px; color: var(--muted); }
.admin-channels .remove:hover { color: var(--like); border-color: var(--like); }
.admin-foot { display: flex; align-items: center; gap: 12px; margin-top: 16px; font-size: 13px; color: var(--muted); }
/* 수집 중인 채널·게임이 많으면 한 줄씩, 길면 스크롤 */
.admin-foot { flex-wrap: wrap; }
#adminStatus { order: -1; flex-basis: 100%; min-width: 0; white-space: pre-line; max-height: 9em; overflow-y: auto; line-height: 1.5; }
#adminStatus:empty { display: none; }

/* 여러 채널 한 번에 추가 */
.bulk { margin-top: 10px; font-size: 14px; }
.bulk summary { cursor: pointer; color: var(--accent); font-size: 13px; width: fit-content; }
.bulk textarea { display: block; width: 100%; box-sizing: border-box; margin-top: 8px; resize: vertical; border: 1px solid var(--line); background: var(--bg); color: inherit; border-radius: 10px; padding: 10px 12px; font: inherit; line-height: 1.5; }
.bulk-foot .primary { flex-shrink: 0; white-space: nowrap; }
.bulk-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 8px; font-size: 13px; color: var(--muted); }
.bulk-result { list-style: none; margin: 8px 0 0; padding: 0; font-size: 13px; max-height: 12em; overflow-y: auto; }
.bulk-result:empty { display: none; }
.bulk-result li { padding: 3px 0; overflow-wrap: anywhere; }
.bulk-result .failed { color: var(--like); }
/* 테마 참가자 중 못 찾은 이름 (관리 창) */
.preset-missing:empty { display: none; }
/* 수집이 멈춘 것 같을 때 관리자 경고 */
.admin-warn:empty { display: none; }
.admin-warn { margin: 0 0 12px; padding: 10px 12px; border-radius: 10px; background: color-mix(in srgb, var(--like) 12%, transparent); color: var(--like); font-size: 13px; line-height: 1.5; }
.admin-warn p { margin: 0; }
.admin-warn p + p { margin-top: 4px; }
.sync-status.warn { color: var(--like); }
.preset-missing { margin-top: 10px; font-size: 13px; color: var(--muted); display: grid; gap: 8px; }
.preset-missing > div { border: 1px dashed var(--line); border-radius: 10px; padding: 8px 12px; }
.preset-missing strong { color: var(--text); }
.preset-missing button { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 3px 8px; font-size: 12px; margin-left: 6px; }
.preset-missing p { margin: 6px 0 0; line-height: 1.6; overflow-wrap: anywhere; }
.bulk-result small { color: var(--muted); }

/* ---------- mobile ---------- */
@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; padding: 10px 16px; gap: 10px; }
  .search { order: 3; flex-basis: 100%; }
  .topbar-right { margin-left: auto; }
  .icon-btn span { display: none; }
  .layout { padding: 16px 16px 48px; }
  .summary { margin-left: 0; flex-basis: 100%; }
  .filter-row { flex-wrap: wrap; }
  .seg { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .seg button { flex: none; padding: 6px 10px; }
  /* 기간 버튼은 7개라 옆으로 밀어야 보였다: 4칸씩 두 줄로 */
  #rangeSeg { display: grid; grid-template-columns: repeat(4, 1fr); width: 100%; overflow: visible; }
  #rangeSeg button { padding: 6px 2px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 16px 12px; }
  .card-body img { display: none; }
  .thumb-19 { padding-top: 4px; gap: 2px; }
  .thumb-19 .mark { width: 28px; height: 28px; border-width: 2px; font-size: 12px; }
  .thumb-19 small { display: none; }
}

/* ---------- 게임 ---------- */
.chip.game img { border-radius: 5px; width: 20px; height: 26px; }
.chip.game { padding-top: 3px; padding-bottom: 3px; }
.tag {
  display: inline-block; margin-right: 6px; padding: 0 6px; border-radius: 4px;
  background: var(--surface-2); color: var(--muted); font-size: 12px; line-height: 18px;
  max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: -4px;
}
.admin-tabs { margin-bottom: 12px; }
.admin-channels li.none { color: var(--muted); font-size: 14px; justify-content: center; }
.admin-foot .logout { margin-left: auto; padding: 6px 12px; font-size: 13px; color: var(--muted); }

/* ---------- 댓글 ---------- */
.player-body { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; }
.player-main { min-width: 0; }
.comments { display: flex; flex-direction: column; min-width: 0; min-height: 0; border-left: 1px solid var(--line); padding-left: 20px; }
.comments-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.comments-head h4 { margin: 0; font-size: 15px; white-space: nowrap; }
.comments-head h4 span { color: var(--accent); }
.seg.small button { padding: 4px 8px; font-size: 12px; }
/* 댓글 칸은 높이 계산에서 빠지고(contain: size) 영상 쪽 높이에 맞춰 늘어난 뒤 안에서 스크롤 */
.comment-scroll { flex: 1 1 0; min-height: 0; contain: size; overflow-y: auto; overscroll-behavior: contain; padding-right: 4px; }
.comment-list, .replies { list-style: none; margin: 0; padding: 0; }
.comment { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.comment:last-child { border-bottom: 0; }
.comment.reply { padding: 8px 0 0; border: 0; }
.replies { margin-top: 4px; padding-left: 4px; border-left: 2px solid var(--line); padding-left: 10px; }
.comment-avatar { width: 28px; height: 28px; border-radius: 50%; flex: none; object-fit: cover; background: var(--surface-2); display: inline-block; }
.comment.reply .comment-avatar { width: 22px; height: 22px; }
.comment-main { flex: 1; min-width: 0; }
.comment-who { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13px; }
.comment-who strong { font-weight: 500; }
.comment-time { color: var(--muted); font-size: 12px; }
.best { background: var(--accent); color: var(--accent-ink); font-size: 10px; font-weight: 700; padding: 1px 5px; border-radius: 4px; }
.writer { border: 1px solid var(--accent); color: var(--accent); font-size: 11px; padding: 0 5px; border-radius: 4px; }
.comment-text { margin: 3px 0 0; font-size: 14px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.comment-text.muted { color: var(--muted); font-style: italic; }
.mention { color: var(--accent); }
.sticker { display: block; width: 80px; height: 80px; object-fit: contain; margin-top: 6px; }
.comment-actions { display: flex; align-items: center; gap: 12px; margin-top: 4px; font-size: 12px; color: var(--muted); }
.comment-likes { color: var(--like); }
.reply-toggle { border: 0; background: none; padding: 0; color: var(--accent); font-size: 12px; }
.comment-note { color: var(--muted); font-size: 14px; padding: 24px 0; text-align: center; }
.comment-more { width: 100%; margin: 8px 0 4px; border: 1px solid var(--line); background: var(--surface); padding: 8px; border-radius: 8px; font-size: 13px; }

@media (max-width: 960px) {
  .player { padding: 14px; }
  .player-body { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .comments { border-left: 0; padding-left: 0; border-top: 1px solid var(--line); padding-top: 12px; }
  .comment-scroll { flex: none; contain: none; max-height: 45vh; }
}
