/* ─── 리셋 & 기본 ─────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f0f0f;
  --sidebar-bg:#161616;
  --surface:   #1e1e1e;
  --border:    #2a2a2a;
  --accent:    #e50914;
  --accent2:   #ff6b6b;
  --text:      #e8e8e8;
  --text-dim:  #888;
  --hover:     #252525;
  --active:    #2c1a1a;
  --sidebar-w: 300px;
  --header-h:  52px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  overflow: hidden;
}

/* ─── 레이아웃 ──────────────────────────────────── */
/* PC: 메인(좌) + 사이드바(우) */
#app { display: flex; flex-direction: row; height: 100vh; overflow: hidden; }

/* ─── 메인 영역 ─────────────────────────────────── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  background: var(--bg);
  min-width: 0;
}

/* PC: 사이드바 열기 버튼 — 오른쪽 상단 */
#open-sidebar-btn {
  position: absolute;
  top: 14px;
  right: 14px;           /* ← 오른쪽 */
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  cursor: pointer;
  padding: 7px 9px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  transition: color 0.15s, background 0.15s, opacity 0.2s,
              transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 10;
  opacity: 0;
  pointer-events: none;
}
#open-sidebar-btn.visible { opacity: 1; pointer-events: auto; }
#open-sidebar-btn:hover   { background: var(--hover); color: var(--text); transform: scale(1.1); }
#open-sidebar-btn:active  { transform: scale(0.93); }

/* 플레이어 래퍼 */
#player-wrap {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  min-height: 0;
}

#no-video { text-align: center; color: var(--text-dim); }
.no-video-icon { color: var(--border); margin-bottom: 16px; line-height: 1; }
.no-video-icon svg { display: block; margin: 0 auto; }
#no-video p { font-size: 15px; }

#video-player {
  width: 100%; height: 100%;
  object-fit: contain;
  background: #000;
  outline: none;
  /* 다운로드 버튼 숨기기 (Chromium 계열) */
  -webkit-media-controls-enclosure { overflow: hidden; }
}
/* 다운로드·PiP 버튼 CSS로 숨기기 */
video::-webkit-media-controls-download-button    { display: none !important; }
video::-webkit-media-controls-overflow-button    { display: none !important; }
video::--webkit-media-controls-panel             { overflow: hidden; }

/* ─── 커스텀 컨트롤 바 (모바일 전용) ──────────────── */
#custom-controls {
  flex-shrink: 0;
  background: rgba(15, 15, 15, 0.95);
  backdrop-filter: blur(8px);
  padding: 8px 14px 12px;
  display: none;
  flex-direction: column;
  gap: 6px;
  border-top: 1px solid var(--border);
}
#custom-controls.visible { display: flex; }

#progress-wrap {
  position: relative;
  height: 20px;
  display: flex; align-items: center;
  cursor: pointer;
  touch-action: none;
}
#progress-bg {
  position: absolute; left: 0; right: 0;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  pointer-events: none;
}
#progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  border-radius: 2px;
  transition: width 0.1s linear;
}
#progress-input {
  position: absolute; left: 0; right: 0;
  width: 100%; height: 100%;
  opacity: 0; cursor: pointer; margin: 0;
  -webkit-appearance: none; appearance: none;
}

#controls-row {
  display: flex; align-items: center; gap: 8px;
}

.ctrl-btn {
  background: none; border: none; color: var(--text);
  cursor: pointer;
  padding: 4px 6px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
  transition: color 0.15s, background 0.15s,
              transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.ctrl-btn:hover  { color: var(--accent2); background: var(--hover); transform: scale(1.15); }
.ctrl-btn:active { transform: scale(0.88); color: var(--accent); }

#time-display {
  font-size: 12px; color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0; white-space: nowrap;
}

#volume-wrap { display: flex; align-items: center; gap: 6px; margin-left: auto; }
#volume-slider {
  -webkit-appearance: none; appearance: none;
  width: 70px; height: 4px;
  background: var(--border); border-radius: 2px;
  outline: none; cursor: pointer;
}
#volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); cursor: pointer;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}
#volume-slider::-webkit-slider-thumb:hover { transform: scale(1.3); }

/* ─── 현재 재생 정보 바 ──────────────────────────── */
#now-playing {
  flex-shrink: 0;
  background: rgba(0,0,0,0.6);
  padding: 6px 14px;
  display: none; align-items: center; gap: 8px;
  font-size: 13px;
  border-top: 1px solid var(--border);
}
#now-playing.visible { display: flex; }
#now-playing-name {
  flex: 1; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; color: var(--text);
}
#replay-badge {
  background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 700;
  padding: 2px 8px; border-radius: 12px;
  animation: pulse 1s infinite;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.5} }

/* ─── 사이드바 (오른쪽) ──────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-left: 1px solid var(--border);   /* ← 왼쪽 테두리 */
  display: flex; flex-direction: column;
  transition: width 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
              min-width 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
              opacity 0.2s ease;
  overflow: hidden;
}
#sidebar.collapsed { width: 0; min-width: 0; opacity: 0; pointer-events: none; }

#sidebar-header {
  display: flex; align-items: center; gap: 8px;
  padding: 0 14px;
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

/* 닫기 버튼 왼쪽, 로고 오른쪽 */
#sidebar-toggle {
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; padding: 5px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  transition: color 0.15s, background 0.15s,
              transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  flex-shrink: 0;
}
#sidebar-toggle:hover  { color: var(--text); background: var(--hover); transform: scale(1.12); }
#sidebar-toggle:active { transform: scale(0.9); }

.logo-text { font-weight: 700; font-size: 15px; letter-spacing: 0.5px; flex: 1; }
.logo-icon { color: var(--accent); display: flex; align-items: center; flex-shrink: 0; }

/* 검색 */
#search-wrap { padding: 10px 12px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.search-inner {
  position: relative; display: flex; align-items: center;
}
.search-icon {
  position: absolute; left: 9px; color: var(--text-dim); pointer-events: none; flex-shrink: 0;
}
#search-input {
  width: 100%;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px 7px 30px;
  color: var(--text); font-size: 13px;
  outline: none; transition: border-color 0.15s, background 0.15s;
}
#search-input:focus { border-color: var(--accent); background: #222; }
#search-input::placeholder { color: var(--text-dim); }

/* 트리 */
#tree-container { flex: 1; overflow-y: auto; padding: 8px 0; }
#tree-container::-webkit-scrollbar { width: 4px; }
#tree-container::-webkit-scrollbar-track { background: transparent; }
#tree-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
#tree-loading { padding: 20px 16px; color: var(--text-dim); font-size: 13px; }

/* 트리 노드 */
.tree-node { user-select: none; }

.tree-folder-label {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 12px; cursor: pointer; border-radius: 6px;
  transition: background 0.12s;
  white-space: nowrap; overflow: hidden;
}
.tree-folder-label:hover { background: var(--hover); }

.folder-arrow {
  color: var(--text-dim); flex-shrink: 0;
  display: flex; align-items: center;
  transition: transform 0.2s ease;
}
.folder-arrow.open { transform: rotate(90deg); }

.folder-icon {
  flex-shrink: 0; color: #c8a84b;
  display: inline-flex; align-items: center;
}
.folder-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.folder-count {
  margin-left: auto;
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1px 7px;
  line-height: 1.6;
}

/* 하트 버튼 (재생 정보 바) */
#heart-btn {
  display: none;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}
#heart-btn:hover { background: rgba(255,255,255,0.08); color: #e05; }
#heart-btn:active { transform: scale(0.9); }
#heart-btn svg { transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1); }

/* 목록 하트 배지 */
.video-hearts {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: auto;
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  opacity: 0.85;
}

.tree-children { display: none; padding-left: 14px; }
.tree-children.open { display: block; }

.tree-video-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; cursor: pointer; border-radius: 6px;
  transition: background 0.12s, transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  white-space: nowrap; overflow: hidden;
}
.tree-video-item:hover  { background: var(--hover); transform: translateX(2px); }
.tree-video-item:active { transform: scale(0.98); }
.tree-video-item.active { background: var(--active); color: var(--accent2); }
.tree-video-item.active .video-icon { color: var(--accent2); }

.video-icon { color: var(--accent); flex-shrink: 0; display: flex; align-items: center; }
.video-name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.video-size { display: none; }

/* ─── PC 전용 ────────────────────────────────────── */
@media (min-width: 769px) {
  #video-player { max-height: calc(100vh - 48px); }
  #custom-controls { display: none !important; }
  /* PC에서 now-playing은 absolute 오버레이 */
  #now-playing {
    position: absolute; bottom: 0; left: 0; right: 0;
    border-top: none;
    background: linear-gradient(transparent, rgba(0,0,0,0.85));
    backdrop-filter: blur(4px);
    padding: 24px 16px 10px;
  }
}

/* ─── 모바일 반응형 ──────────────────────────────── */
@media (max-width: 768px) {
  :root { --header-h: 46px; }

  html, body { overflow: hidden; }

  #app {
    flex-direction: column;
    height: 100dvh;
  }

  /* 영상 상단, 목록 하단 */
  #main    { order: 1; flex: 1; min-height: 0; }
  #sidebar { order: 2; }

  #sidebar {
    width: 100% !important;
    min-width: 100% !important;
    height: 42dvh;
    min-height: 120px;
    max-height: 55dvh;
    border-left: none;
    border-top: 2px solid var(--accent);
    opacity: 1 !important;
    pointer-events: auto !important;
    transition: height 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  #sidebar-toggle   { display: none; }
  #open-sidebar-btn { display: none !important; }

  #main {
    display: flex; flex-direction: column;
    overflow: hidden; align-items: stretch; justify-content: flex-start;
  }
  #player-wrap { flex: 1; min-height: 0; }
  #video-player { max-height: none; }

  #custom-controls.visible { display: flex; }
  #volume-slider { display: none; }

  #now-playing { font-size: 12px; padding: 4px 12px; }
  .tree-video-item  { padding: 8px 12px; }
  .tree-folder-label { padding: 8px 12px; }
}
