:root {
  --bg: #0f0f12;
  --bg-2: #17171c;
  --bg-3: #212129;
  --line: #2c2c36;
  --fg: #f1f1f4;
  --muted: #9a9aa8;
  --accent: #7c5cff;
  --accent-2: #a18bff;
  --live: #ff3b4e;
  --ok: #2fbf71;
  --warn: #f2a93b;
  --radius: 12px;
  --topbar: 60px;
  --sidebar: 280px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.5 "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-2); }
img { display: block; }
button, input, select { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }
code { background: var(--bg-3); padding: 1px 6px; border-radius: 4px; }

/* ------------------------------------------------------------ buttons */
.btn {
  background: var(--bg-3); border: 1px solid var(--line); border-radius: 999px;
  padding: 8px 16px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
  color: var(--fg); white-space: nowrap; transition: background .15s;
}
.btn:hover { background: #2b2b35; }
.btn:disabled { opacity: .6; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #6a48ff; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0; background: transparent; cursor: pointer;
  display: grid; place-items: center; flex: none;
}
.icon-btn:hover { background: var(--bg-3); }
.link-btn { background: none; border: 0; color: var(--accent-2); cursor: pointer; padding: 0; font-size: 13px; text-decoration: none; }
.link-btn:hover { text-decoration: underline; }

/* ------------------------------------------------------------ topbar */
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar);
  display: flex; align-items: center; gap: 12px; padding: 0 16px;
  background: rgba(15, 15, 18, .92); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
}
.menu-btn { display: none; }
.logo { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--fg); font-size: 19px; letter-spacing: -.3px; flex: none; }
.logo svg { width: 30px; height: 30px; fill: var(--accent); stroke: none; }
.logo .logo-play { fill: #fff; }
.logo b { color: var(--accent-2); }

.search {
  flex: 1; max-width: 760px; margin: 0 auto; display: flex; align-items: stretch;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 999px; overflow: hidden;
}
.search:focus-within { border-color: var(--accent); }
.search input { flex: 1; min-width: 0; background: transparent; border: 0; outline: 0; padding: 9px 18px; }
.search select {
  background: transparent; border: 0; border-left: 1px solid var(--line); padding: 0 10px; outline: 0; cursor: pointer; color: var(--muted);
}
.search select option { background: var(--bg-2); color: var(--fg); }
.search-btn { background: var(--bg-3); border: 0; border-left: 1px solid var(--line); padding: 0 18px; cursor: pointer; display: grid; place-items: center; }
.search-btn:hover { background: #2b2b35; }
.search-btn svg { width: 20px; height: 20px; }

/* ------------------------------------------------------------ layout */
.layout { display: flex; min-height: calc(100vh - var(--topbar)); }
.sidebar {
  width: var(--sidebar); flex: none; padding: 16px; border-right: 1px solid var(--line);
  position: sticky; top: var(--topbar); height: calc(100vh - var(--topbar)); overflow-y: auto; background: var(--bg);
}
.main { flex: 1; min-width: 0; padding: 20px 24px 60px; }
.backdrop { display: none; }

.add-channel { display: flex; gap: 6px; margin-bottom: 18px; }
.add-channel input {
  flex: 1; min-width: 0; background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; outline: 0;
}
.add-channel input:focus { border-color: var(--accent); }
.add-channel .btn { border-radius: 10px; padding: 8px 12px; }

.sidebar-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 6px; }
.sidebar-head h2 { font-size: 14px; margin: 0; }
.sidebar-head h2 span { font-weight: 400; font-size: 12px; }
.sidebar-hint { font-size: 12px; margin-top: 12px; }

.channel-list { list-style: none; margin: 0; padding: 0; }
.channel { display: flex; align-items: center; border-radius: 10px; }
.channel:hover { background: var(--bg-2); }
.channel label { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 7px 8px; cursor: pointer; }
.channel input { accent-color: var(--accent); width: 16px; height: 16px; flex: none; }
.channel img { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; background: var(--bg-3); flex: none; }
.channel.off img, .channel.off .ch-name { opacity: .45; }
.ch-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-solo, .ch-remove {
  border: 0; background: none; cursor: pointer; color: var(--muted); width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; opacity: 0; flex: none;
}
.ch-solo svg, .ch-remove svg { width: 16px; height: 16px; }
.channel:hover .ch-solo, .channel:hover .ch-remove, .ch-solo:focus, .ch-remove:focus { opacity: 1; }
.ch-solo:hover, .ch-remove:hover { background: var(--bg-3); color: var(--fg); }
.empty-channels { padding: 16px 8px; font-size: 13px; }

/* ------------------------------------------------------------ results */
.results-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.results-head h1 { font-size: 20px; margin: 0; }
.notice { padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; background: var(--bg-2); border: 1px solid var(--line); }
.notice.err { border-color: rgba(255, 59, 78, .5); background: rgba(255, 59, 78, .08); }
.notice.warn { border-color: rgba(242, 169, 59, .5); background: rgba(242, 169, 59, .08); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 28px 18px; }
.card { color: inherit; text-decoration: none; display: block; min-width: 0; }
.thumb { position: relative; aspect-ratio: 16/9; border-radius: var(--radius); overflow: hidden; background: var(--bg-3); }
.thumb img { width: 100%; height: 100%; object-fit: cover; transition: transform .25s; }
.card:hover .thumb img { transform: scale(1.04); }
.badge {
  position: absolute; right: 8px; bottom: 8px; background: rgba(0, 0, 0, .8); padding: 1px 6px;
  border-radius: 5px; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.badge.live { background: var(--live); }
.badge.upcoming { background: rgba(0, 0, 0, .8); color: #ffd36b; }
.watched { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(255, 255, 255, .25); }
.watched div { height: 100%; background: var(--live); }
.card-body { display: flex; gap: 12px; padding-top: 12px; }
.card-body .avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; flex: none; }
.card-body > div { min-width: 0; }
.card h3 {
  font-size: 15px; line-height: 1.4; margin: 0 0 4px; font-weight: 600;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card p { margin: 0; font-size: 13px; }
.card.skeleton .thumb, .card.skeleton h3, .card.skeleton p {
  background: linear-gradient(90deg, var(--bg-2), var(--bg-3), var(--bg-2)); background-size: 200% 100%;
  animation: shimmer 1.2s infinite linear;
}
.card.skeleton h3 { height: 16px; width: 90%; border-radius: 4px; }
.card.skeleton p { height: 12px; width: 60%; border-radius: 4px; margin-top: 8px; }
.card.skeleton .card-body > div { flex: 1; }
@keyframes shimmer { to { background-position: -200% 0; } }

.empty { grid-column: 1 / -1; text-align: center; padding: 80px 20px; color: var(--muted); }
.empty.welcome h2 { color: var(--fg); font-size: 22px; margin: 0 0 8px; }
.empty.welcome p { margin: 0 0 20px; line-height: 1.7; }
.load-more-wrap { display: flex; justify-content: center; margin-top: 32px; min-height: 1px; }

/* ------------------------------------------------------------ watch */
.watch { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 24px; align-items: start; }
.watch-main { min-width: 0; }
.theater .watch { grid-template-columns: 1fr; }
.theater .watch-side .up-next { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); display: grid; gap: 20px 16px; }
.theater .watch-side .card { display: block; }
.theater .watch-side .card .thumb { width: 100%; }
.theater .main { padding-top: 0; }
.theater #playerHost { margin: 0 -24px; }
.theater #playerHost .utv { border-radius: 0; max-height: calc(100vh - var(--topbar) - 40px); }

.video-info h1 { font-size: 20px; line-height: 1.4; margin: 14px 0 10px; word-break: keep-all; overflow-wrap: anywhere; }
.video-meta { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 12px; }
.channel-chip {
  display: inline-flex; align-items: center; gap: 8px; background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 14px 4px 4px; cursor: pointer; font-weight: 600;
}
.channel-chip:hover { background: var(--bg-3); }
.channel-chip img { width: 28px; height: 28px; border-radius: 50%; }
.description {
  background: var(--bg-2); border-radius: var(--radius); padding: 12px 14px; white-space: pre-wrap;
  overflow-wrap: anywhere; font-size: 13.5px; line-height: 1.65;
}
.description:empty { display: none; }
.description.collapsed { max-height: 6.6em; overflow: hidden; -webkit-mask-image: linear-gradient(#000 60%, transparent); mask-image: linear-gradient(#000 60%, transparent); }
#descToggle { margin-top: 6px; }

.side-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.side-head h2 { font-size: 16px; margin: 0; }
.up-next { display: flex; flex-direction: column; gap: 10px; }
.watch-side .card { display: flex; gap: 10px; }
.watch-side .card .thumb { width: 168px; flex: none; border-radius: 8px; }
.watch-side .card-body { padding-top: 0; }
.watch-side .card .avatar { display: none; }
.watch-side .card h3 { font-size: 14px; }
.watch-side .card p { font-size: 12px; }
.watch-side .card.skeleton .card-body { flex: 1; }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; color: var(--muted); }
.switch input { display: none; }
.switch span { width: 34px; height: 20px; border-radius: 999px; background: var(--bg-3); position: relative; transition: background .2s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(14px); }

/* ------------------------------------------------------------ player */
.utv {
  position: relative; aspect-ratio: 16/9; width: 100%; background: #000; border-radius: var(--radius);
  overflow: hidden; outline: 0; user-select: none; -webkit-user-select: none;
}
.utv.is-fs { border-radius: 0; aspect-ratio: auto; height: 100%; max-height: none !important; }
.utv-frame, .utv-frame iframe, .utv-frame .utv-yt { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
/* 쉴드: iframe 위를 덮어 YouTube 기본 UI(제목, 추천, 로고 등) 클릭/호버를 막는다 */
.utv-shield { position: absolute; inset: 0; z-index: 2; cursor: pointer; }
.utv.idle .utv-shield { cursor: none; }
.utv.ad .utv-shield, .utv.pass .utv-shield { pointer-events: none; }
.utv-poster { position: absolute; inset: 0; z-index: 3; cursor: pointer; background: #000; }
.utv-poster img { width: 100%; height: 100%; object-fit: cover; opacity: .75; }
.utv.started .utv-poster { display: none; }
.utv-bigplay {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 76px; height: 76px; border-radius: 50%;
  border: 0; background: rgba(124, 92, 255, .92); display: grid; place-items: center; cursor: pointer; color: #fff;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .5); transition: transform .15s;
}
.utv-bigplay:hover { transform: translate(-50%, -50%) scale(1.08); }
.utv-bigplay svg { width: 36px; height: 36px; fill: #fff; stroke: none; margin-left: 4px; }
.utv-spinner {
  position: absolute; left: 50%; top: 50%; width: 48px; height: 48px; margin: -24px; z-index: 4; border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, .2); border-top-color: #fff; animation: spin .8s linear infinite; display: none; pointer-events: none;
}
.utv.loading.started .utv-spinner { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

.utv-flash {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 5; pointer-events: none; opacity: 0;
}
.utv-flash span { background: rgba(0, 0, 0, .7); padding: 8px 16px; border-radius: 8px; font-size: 16px; font-weight: 600; }
.utv-flash.icon { width: 64px; height: 64px; border-radius: 50%; background: rgba(0, 0, 0, .6); display: grid; place-items: center; }
.utv-flash.icon svg { width: 30px; height: 30px; fill: #fff; stroke: none; }
.utv-flash.show { animation: flash .7s ease-out; }
@keyframes flash { 0% { opacity: 1; transform: translate(-50%, -50%) scale(.9); } 100% { opacity: 0; transform: translate(-50%, -50%) scale(1.25); } }

.utv-badge, .utv-ad {
  position: absolute; left: 14px; top: 14px; z-index: 6; background: rgba(0, 0, 0, .75); padding: 5px 12px; border-radius: 6px;
  font-size: 13px; font-weight: 600; pointer-events: none;
}
.utv-badge { color: #ffd36b; }
.utv-ad { color: var(--warn); }
.utv-resume {
  position: absolute; left: 14px; bottom: 76px; z-index: 6; display: flex; align-items: center; gap: 8px;
  background: rgba(20, 20, 26, .92); padding: 8px 10px 8px 14px; border-radius: 10px; font-size: 13px;
}
.utv-resume button { border: 0; border-radius: 6px; padding: 4px 10px; cursor: pointer; background: var(--bg-3); }
.utv-resume button[data-act=resume] { background: var(--accent); color: #fff; }
.utv-error {
  position: absolute; inset: 0; z-index: 8; background: rgba(0, 0, 0, .88); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px; text-align: center; padding: 20px;
}
.utv-error p { margin: 0; font-size: 15px; }

.utv-controls {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 7; padding: 30px 12px 6px;
  background: linear-gradient(transparent, rgba(0, 0, 0, .78)); transition: opacity .25s;
}
.utv.idle .utv-controls, .utv:not(.started) .utv-controls { opacity: 0; pointer-events: none; }
.utv.ad .utv-controls { opacity: .35; }
.utv.ad .utv-controls:hover { opacity: 1; }

.utv-progress { position: relative; height: 16px; display: flex; align-items: center; cursor: pointer; touch-action: none; }
.utv-track { position: relative; width: 100%; height: 4px; background: rgba(255, 255, 255, .22); border-radius: 2px; transition: height .12s; }
.utv-progress:hover .utv-track { height: 6px; }
.utv-buffered, .utv-played, .utv-hover { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 2px; }
.utv-buffered { background: rgba(255, 255, 255, .35); }
.utv-hover { background: rgba(255, 255, 255, .25); opacity: 0; }
.utv-progress:hover .utv-hover { opacity: 1; }
.utv-played { background: var(--accent); z-index: 1; }
.utv-thumb {
  position: absolute; top: 50%; width: 14px; height: 14px; margin: -7px; border-radius: 50%; background: var(--accent-2);
  z-index: 2; transform: scale(0); transition: transform .12s;
}
.utv-progress:hover .utv-thumb { transform: scale(1); }
.utv-tip {
  position: absolute; bottom: 22px; transform: translateX(-50%); background: rgba(0, 0, 0, .85); padding: 2px 8px;
  border-radius: 4px; font-size: 12px; font-variant-numeric: tabular-nums; opacity: 0; pointer-events: none; white-space: nowrap;
}
.utv-progress:hover .utv-tip { opacity: 1; }

.utv-bar { display: flex; align-items: center; gap: 2px; height: 44px; }
.utv-btn {
  width: 40px; height: 40px; border: 0; background: none; cursor: pointer; display: grid; place-items: center;
  border-radius: 8px; color: #fff; opacity: .92; flex: none;
}
.utv-btn:hover { opacity: 1; background: rgba(255, 255, 255, .1); }
.utv-btn svg { width: 24px; height: 24px; }
.utv-btn [d*="M8 5v14"], .utv-btn [d^="M7 5h4"], .utv-btn [d^="M6 6l9"], .utv-btn [d^="M4 9h4"] { fill: currentColor; stroke: none; }
.utv-btn [d^="M12 5V2"] { fill: currentColor; stroke: none; }
.utv-btn text { fill: currentColor; stroke: none; font-family: system-ui, sans-serif; }
.utv-btn .stroke { fill: none; stroke: currentColor; }
.utv-btn.active { color: var(--accent-2); }
.utv-rate-btn { width: auto; padding: 0 10px; font-weight: 700; font-size: 13px; font-variant-numeric: tabular-nums; }

.utv-vol { display: flex; align-items: center; }
.utv-vol input {
  width: 0; opacity: 0; transition: width .2s, opacity .2s; -webkit-appearance: none; appearance: none; height: 4px;
  background: linear-gradient(to right, #fff var(--fill, 100%), rgba(255, 255, 255, .3) var(--fill, 100%)); border-radius: 2px; cursor: pointer;
}
.utv-vol:hover input, .utv-vol input:focus { width: 80px; opacity: 1; margin: 0 8px 0 2px; }
.utv-vol input::-webkit-slider-thumb { -webkit-appearance: none; width: 12px; height: 12px; border-radius: 50%; background: #fff; }
.utv-vol input::-moz-range-thumb { width: 12px; height: 12px; border: 0; border-radius: 50%; background: #fff; }

.utv-time { font-size: 13px; font-variant-numeric: tabular-nums; margin-left: 8px; white-space: nowrap; color: #e6e6ea; }
.utv-live {
  margin-left: 10px; border: 0; background: none; color: var(--live); font-weight: 700; font-size: 12px; cursor: pointer; letter-spacing: .5px;
}
.utv-live.behind { color: #aaa; }
.utv-spacer { flex: 1; }

.utv-menu-wrap { position: relative; }
.utv-menu {
  position: absolute; right: 0; bottom: 48px; background: rgba(24, 24, 30, .96); border-radius: 10px; padding: 6px;
  min-width: 140px; box-shadow: 0 10px 30px rgba(0, 0, 0, .5); display: flex; flex-direction: column;
}
.utv-menu-title { font-size: 12px; color: var(--muted); padding: 4px 10px 6px; }
.utv-menu button { border: 0; background: none; text-align: left; padding: 7px 10px; border-radius: 6px; cursor: pointer; }
.utv-menu button:hover { background: rgba(255, 255, 255, .08); }
.utv-menu button.on { color: var(--accent-2); font-weight: 700; }
.utv-menu button.on::before { content: "✓ "; }

/* ------------------------------------------------------------ dialog / toast */
.dialog {
  background: var(--bg-2); color: var(--fg); border: 1px solid var(--line); border-radius: 16px; padding: 24px;
  width: min(520px, calc(100vw - 32px));
}
.dialog::backdrop { background: rgba(0, 0, 0, .6); }
.dialog h2 { margin: 0 0 16px; font-size: 18px; }
.dialog h3 { margin: 20px 0 8px; font-size: 14px; }
.setting { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.setting span { display: flex; flex-direction: column; gap: 2px; }
.setting small { font-size: 12px; line-height: 1.5; }
.setting input { accent-color: var(--accent); width: 18px; height: 18px; margin-top: 2px; flex: none; }
.setting-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.shortcuts { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; font-size: 13px; color: var(--muted); }
kbd { background: var(--bg-3); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font-size: 11px; color: var(--fg); font-family: inherit; }
.dialog-foot { display: flex; justify-content: flex-end; margin-top: 20px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: #2a2a33; padding: 10px 18px;
  border-radius: 10px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 100;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .4); max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { border-left: 3px solid var(--ok); }
.toast.err { border-left: 3px solid var(--live); }

/* ------------------------------------------------------------ responsive */
@media (max-width: 1100px) {
  .watch { grid-template-columns: 1fr; }
  .watch-side .up-next { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 20px 16px; }
  .watch-side .card { display: block; }
  .watch-side .card .thumb { width: 100%; }
  .watch-side .card-body { padding-top: 10px; }
}
@media (max-width: 860px) {
  .menu-btn { display: grid; }
  .sidebar {
    position: fixed; left: 0; top: var(--topbar); z-index: 40; transform: translateX(-100%); transition: transform .25s;
    box-shadow: 10px 0 30px rgba(0, 0, 0, .4);
  }
  .sidebar-open .sidebar { transform: none; }
  .sidebar-open .backdrop { display: block; position: fixed; inset: var(--topbar) 0 0 0; background: rgba(0, 0, 0, .5); z-index: 35; }
  .main { padding: 16px 14px 60px; }
  .theater #playerHost { margin: 0 -14px; }
  .ch-solo, .ch-remove { opacity: 1; }
}
@media (max-width: 640px) {
  :root { --topbar: 108px; }
  .topbar { flex-wrap: wrap; gap: 6px 8px; padding: 8px 10px; align-content: center; }
  .logo { margin-right: auto; }
  .search { order: 3; flex-basis: 100%; }
  .search input { padding: 8px 12px; }
  .search select { padding: 0 6px; font-size: 13px; max-width: 96px; }
  .search-btn { padding: 0 12px; }
  .grid { grid-template-columns: 1fr; }
  #playerHost { margin: 0 -14px; }
  #playerHost .utv { border-radius: 0; }
  .utv-btn[data-act=back], .utv-btn[data-act=fwd], .utv-btn[data-act=pass] { display: none; }
  .utv-vol input { display: none; }
}
