:root{
  --bg:#0f0f0f; --card:#121212; --accent:#ff0000; --muted:#bdbdbd; --white:#ffffff;
  --tab-bg: rgba(255,255,255,0.03);
  --text-color: var(--white);
  --header-bg: #0f0f0f;
  --bg-overlay: rgba(0,0,0,0.9); /* 新增：深色模式的播放器底色 */
}
html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--white);
  font-family: "Segoe UI", Roboto, "Noto Sans TC", Arial;
  /* 關鍵：防止瀏覽器下拉整理 */
  overscroll-behavior-y: contain; 
}
body.light-mode {
  --bg:#f9f9f9; --card:#ffffff; --accent:#ff0000; --muted:#606060; --white:#030303;
  --tab-bg: rgba(0,0,0,0.06);
  --text-color: var(--white);
  --header-bg: #f9f9f9;
  --bg-overlay: rgba(255,255,255,0.9); /* 修正：亮色模式的播放器底色 */
}
body.light-mode header{
    background:var(--header-bg);
    background:linear-gradient(0deg, rgba(0,0,0,0.02), transparent);
}
body.light-mode input[type="text"].search-input{
    background:#ffffff;
    border:1px solid rgba(0,0,0,0.1);
    color:var(--white);
}
body.light-mode button.search-btn{
    background:#065fd4;
    color:#fff;
}
body.light-mode .hot-keywords-panel, body.light-mode .hot-keywords-panel{
    background:var(--bg);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
body.light-mode .queue-area .queue-item{
    /* 修正：亮色模式下佇列項目背景改為白色並加邊框 */
    background: var(--card); 
    border: 1px solid rgba(0,0,0,0.1);
}
body.light-mode .queue-area .queue-item .drag-handle {
    color: var(--muted);
}
body.light-mode .queue-area .queue-item .small-btn {
    background: rgba(0, 0, 0, 0.08); 
    color: var(--white);
}
body.light-mode .queue-area .queue-item[style*="rgba(126,232,250,0.06)"] {
    background: rgba(0, 92, 187, 0.2) !important;
    border-color: rgba(0, 92, 187, 0.4) !important;
}
body.light-mode .small-btn.active-lib-btn {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}


header{height:64px;display:flex;align-items:center;padding:8px 12px 8px 56px;gap:8px;background:linear-gradient(0deg, rgba(255,255,255,0.02), transparent);position:sticky;top:0;z-index:80;backdrop-filter: blur(6px);}
.logo{
  display:flex;
  align-items:center;
  gap:8px;
  cursor:default;
  min-width:200px;
}
.yt-mark{width:44px;height:28px;border-radius:6px;background:var(--accent);display:flex;align-items:center;justify-content:center;font-weight:700;color:#fff;box-shadow:0 2px 8px rgba(0,0,0,0.4);}
.logo-title{font-weight:600;font-size:18px;letter-spacing:0.2px}

@media (max-width: 1023px) {
  .logo {
    min-width: auto;
    gap: 4px;
  }
  .logo-title {
    display: none;
  }
}

.search-wrap{flex:1;display:flex;justify-content:center;}
.search-box{display:flex;gap:8px;width:100%;max-width:900px;align-items:center;}

/* 修正：提升漢堡按鈕層級，使其在播放器開啟時可見 */
.hamburger-btn {
  position: fixed;
  left: 8px; /* 微調位置 */
  top: 12px;
  z-index: 200; /* 高於 header 但低於搜尋圖層 */
  background: transparent;
  border: none;
  color: var(--white);
  font-size: 24px;
  cursor: pointer;
  padding: 8px;
}

/* 修正：Logo 區域排版優化，防止重疊 */
.logo-text-group {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.logo-subtitle {
  font-size: 10px;
  color: var(--muted);
  line-height: 1;
  margin-top: 2px;
  white-space: nowrap;
}

/* 修正：螢幕變窄時的自定義響應式 */
@media (max-width: 1023px) {
  .logo {
    min-width: auto;
    gap: 8px;
  }
  
  /* 確保標題不消失，而是根據寬度彈性縮放或調整 */
  .logo-title {
    display: block; /* 強制顯示 */
    font-size: 16px;
  }

  /* 如果螢幕真的很窄（如手機），再隱藏副標題以騰出空間 */
  @media (max-width: 400px) {
    .logo-subtitle {
      display: none;
    }
  }
}

/* 修正：在分割模式下，確保內容不會被側邊欄完全遮擋時的流暢度 */
body.player-open .side-nav {
  z-index: 410; /* 側邊欄展開時應在播放器之上 */
}

.search-icon-btn {
  padding: 10px 14px;
  background: transparent;
  color: var(--white);
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-size: 20px;
  line-height: 1;
  display: none;
}
.exit-search-btn {
  padding: 10px 12px;
  background: transparent;
  color: var(--white);
  border: none;
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
}
.hot-keywords-panel {
  position: absolute;
  top: 64px;
  left: 0;
  right: 0;
  background: var(--bg);
  padding: 12px;
  z-index: 90;
  max-height: calc(100vh - 64px);
  overflow-y: auto;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

select#qTypeSelect{flex:0; width:100px; padding:10px 8px; margin-right: -4px; cursor:pointer;}
input[type="text"].search-input{flex:1;padding:10px 14px;border-radius:10px;border:1px solid rgba(255,255,255,0.06);background:#0b0b0b;color:var(--white);font-size:16px;}
button.search-btn{padding:10px 14px;background:var(--white);color:#000;border-radius:8px;border:none;cursor:pointer;font-weight:600;}
.app-wrap{display:flex;flex-direction:column;height:calc(100vh - 64px);overflow:hidden;}
.app-wrap .container {
  display: flex;
  gap: 16px;
  padding: 12px;
  flex: 1;
  box-sizing: border-box;
  overflow: hidden;
}

/* 當播放器開啟時，隱藏主容器（改為使用 body.player-open 控制） */
body.player-open .container {
  display: none;
}

body:not(.player-open) .container {
  display: flex;
}

/* 响应式：隐藏游戏按钮等 */
@media (max-width: 1023px) {
  .app-wrap .container {
    padding: 12px 0;
  }
}

/* 側邊欄導航 */
.side-nav {
  position: fixed;
  left: -280px;
  top: 0;
  width: 280px;
  height: 100vh;
  background: var(--card);
  z-index: 150;
  overflow-y: auto;
  transition: left 0.3s ease;
  padding-top: 64px;
}
.side-nav.active {
  left: 0;
}
.side-nav-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.side-nav-header h2 {
  margin: 0;
  font-size: 18px;
}

/* 側菜單導航選項卡 */
.side-nav-tabs {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  margin-bottom: 12px;
}

.side-tab-item {
  padding: 12px;
  border-radius: 8px;
  background: rgba(255,255,255,0.05);
  color: var(--muted);
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 500;
  user-select: none;
}

.side-tab-item:hover {
  background: rgba(255,255,255,0.1);
}

.side-tab-item.active {
  background: var(--accent);
  color: #fff;
}

.close-nav-btn {
  background: transparent;
  border: none;
  color: var(--white);
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hamburger-btn {
  position: fixed;
  left: 12px;
  top: 16px;
  z-index: 400; /* 高於 player-overlay 的 300 */
  background: transparent;
  border: none;
  color: var(--white);
  font-size: 24px;
  cursor: pointer;
  padding: 8px;
  display: block;
}

/* 在行動設備上顯示漢堡菜單 */
@media (max-width: 1023px) {
  .hamburger-btn {
    display: block;
  }
}

/* 桌機版：確保隱藏漢堡菜單 */
/* 改為透過 body.no-hamburger 控制桌機時隱藏漢堡按鈕 */
/* (漢堡顯示由 JS 控制；保留樣式為 block) */

/* 遮罩层 */
.nav-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: none;
  z-index: 140;
}
.nav-overlay.active {
  display: block;
}

.content {
  flex: 1;
  overflow: auto;
  padding: 12px;
  padding-bottom: 20px;
  min-width: 0;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
  padding-bottom: 20px;
}
.card{background:var(--card);border-radius:8px;overflow:hidden;cursor:pointer;transition:transform .12s;display:flex;flex-direction:column;position:relative;}
.card:hover{transform:translateY(-6px);}
.thumb{width:100%;aspect-ratio:16/9;object-fit:cover;background:#111;}
.meta{padding:10px;display:flex;gap:10px;align-items:flex-start;}
.meta .title{font-size:14px;font-weight:600;color:var(--white);line-height:1.2;}
.meta .channel{font-size:12px;color:var(--muted);margin-top:6px;}
.load-more{text-align:center;color:var(--muted);padding:12px;}

.player-overlay{
  position:fixed; 
  top: 0; left: 0; right: 0; bottom: 0;
  background:var(--bg-overlay);
  display:none;
  flex-direction: column; 
  align-items:center; 
  justify-content:flex-start; 
  z-index:300;
  height: 100vh; 
  overflow: hidden; 
  padding: 0; 
}

.player-overlay.show {
  display: flex;
}

/* 分割容器 */
.split-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: row;
  gap: 0;
}

/* 桌機版（寬屏）：左右分割 */
@media (min-width: 1024px) {
  .split-container {
    flex-direction: row;
  }
  
  .split-panel {
    flex: 1;
    overflow: auto;
    min-width: 0;
  }
  
  .split-player {
    flex: 0 0 45%;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 12px;
    border-right: 1px solid rgba(255,255,255,0.05);
  }
  
  .split-content {
    flex: 1;
    padding: 12px;
    overflow: auto;
    min-height: 0;
  }
  
  .split-divider {
    width: 15px;
    height: 100%;
    background: var(--accent) !important; /* 強制紅色 */
    cursor: col-resize;
    user-select: none;
    transition: background 0.2s;
    display: block;
  }
  
  .split-divider:hover {
    background: rgba(255,255,255,0.1);
  }
  
  .split-divider.dragging {
    background: var(--accent);
  }
}

/* 手機版（窄屏）：上下分割 */
@media (max-width: 1023px) {
  .split-container {
    flex-direction: column;
  }
  
  .split-panel {
    overflow: auto;
    min-height: 0;
  }
  
  .split-player {
    flex: 0 0 50%;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
  }
  
  .split-content {
    flex: 1;
    padding: 12px;
    overflow: auto;
    min-height: 0;
  }
  
  .split-divider {
    height: 15px;
    width: 100%;
    background: var(--accent) !important; /* 強制紅色 */
    cursor: row-resize;
    user-select: none;
    transition: background 0.2s;
    display: block;
  }
  
  .split-divider:hover {
    background: rgba(255,255,255,0.1);
  }
  
  .split-divider.dragging {
    background: var(--accent);
  }
}

.player-box{
  width:100%;
  height:auto;
  aspect-ratio: 16/9;
  display: block;
  flex-shrink: 0;
  background:var(--card); /* 修正：使用變數 */
  border-radius:8px;
  overflow:hidden;
  position:relative;
}
.player-box #playerFrame{width:100%;height:100%;}
.player-close{position:absolute;right:12px;top:12px;z-index:10;background:#fff;color:#000;border-radius:6px;padding:8px 10px;cursor:pointer;font-weight:600;}

.queue-panel-wrap {
  width: 100%; 
  height: auto;
  display: block;
  flex-shrink: 0;
  box-sizing: border-box;
  padding: 0;
}

.queue-area {
  width: 100%;
  height: 200px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  gap: 8px;
  padding-bottom: 10px;
}

.tabbar{position:fixed;left:12px;right:12px;bottom:12px;height:64px;border-radius:14px;background:var(--tab-bg);display:flex;align-items:center;justify-content:space-around;z-index:120;backdrop-filter: blur(8px);box-shadow:0 8px 24px rgba(0,0,0,0.6);}

/* 當 playerOverlay 顯示時，隱藏 tabbar */
#playerOverlay:not([style*="display: none"]) ~ .tabbar {
  display: none;
}

.tab-item{flex:1;text-align:center;padding:8px 6px;cursor:pointer;color:var(--muted);user-select:none;}
.tab-item.active{color:var(--white);}
.tab-item .icon{display:block;font-size:18px;}
.tab-item .label{font-size:12px;margin-top:4px;}
.top-actions{display:flex;gap:8px;align-items:center;}
.pill-btn{padding:8px 10px;border-radius:10px;background:transparent;border:1px solid rgba(255,255,255,0.04);color:var(--muted);cursor:pointer;}
.playlist-manager{background:var(--card);padding:10px;border-radius:8px;max-height:calc(100vh - 120px);overflow:auto;}
.pl-list{display:flex;flex-direction:column;gap:8px;margin-bottom:8px;}
.pl-item{padding:8px;border-radius:8px;background:rgba(255,255,255,0.02);display:flex;align-items:center;justify-content:space-between;cursor:pointer;}
.pl-item.active{outline:2px solid rgba(255,255,255,0.04);}
.pl-controls{display:flex;gap:6px;}
.small-btn{padding:6px 8px;border-radius:6px;background:transparent;border:1px solid rgba(255,255,255,0.03);color:var(--muted);cursor:pointer;}
.small-btn[disabled] { opacity: 0.3; cursor: default; }
.no-result{padding:36px;text-align:center;color:var(--muted);}

.mode-btn {
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--white);
  cursor: pointer;
  font-weight: 500;
  transition: background 0.2s;
}

.mode-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

.mode-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.small-btn.active-lib-btn {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.queue-area .queue-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border-radius: 8px;
  background: rgba(255,255,255,0.02);
  transition: background 0.1s;
  cursor: grab; 
  border: 1px solid transparent;
}

.queue-area .queue-item .drag-handle {
  font-size: 20px;
  line-height: 1;
  cursor: grab;
  color: var(--muted);
  padding: 0 8px;
  display: block; 
}
.queue-area .queue-item .mobile-move-btns {
  display: none; 
}

.queue-area .queue-item.dragging {
  opacity: 0.5;
  border-color: var(--accent);
}
.queue-area .queue-item .title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 14px;
  color: var(--white);
}
.queue-area .queue-item .small-btn {
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08); 
  border: none;
  color: var(--white);
  cursor: pointer;
}

/* 修正：迷你播放器控制器背景 */
#miniPlayerControl {
  background: var(--card);
  color: var(--white);
  box-shadow: 0 4px 16px rgba(0,0,0,0.7);
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 72px;
  align-items: stretch;
}
#miniPlayerControl #mpText {
  color: var(--white);
  font-size: 14px;
}
#miniPlayerControl .small-btn {
  color: var(--white);
}

/* 中央對齊上下首按鈕列 */
#miniPlayerControl > div:last-child {
  display: flex;
  justify-content: center;
  gap: 8px;
}


@media(max-width:900px){ 
  .sidebar{display:none;}
  .grid{grid-template-columns:repeat(auto-fill,minmax(180px,1fr));} 
  .tabbar{left:6px;right:6px;bottom:6px;}
  .content{padding-bottom:80px;}
  
  .search-wrap {
    display: none !important; 
    flex: 1; 
  }
  .search-icon-btn {
    display: block;
    margin-left: auto;
  }
  .search-wrap.active {
    display: flex !important;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: var(--bg);
    padding: 8px 12px;
    /* 關鍵：確保高於漢堡按鈕 (200) */
    z-index: 1000; 
    transition: none;
  }
  .search-wrap.active .search-box {
    width: 100%;
  }
  .hot-keywords-panel {
    position: fixed;
    top: 64px;
  }
  header {
    height: 64px;
    display: flex;
    align-items: center;
    /* 增加左側內距，為漢堡按鈕騰出固定空間 */
    padding: 8px 12px 8px 60px; 
    gap: 8px;
    background: linear-gradient(0deg, rgba(255,255,255,0.02), transparent);
    position: sticky;
    top: 0;
    z-index: 80;
    backdrop-filter: blur(6px);
  }
  .logo {
    min-width: unset;
  }
}

@media(min-width: 901px) {
  .search-wrap {
    display: flex !important;
  }
  .search-icon-btn {
    display: none !important;
  }
  .hot-keywords-panel {
      position: absolute;
      top: 64px;
      max-width: 900px;
      left: 50%;
      transform: translateX(-50%);
  }
  #searchHistoryPanel {
      position: absolute;
      top: 64px;
      max-width: 900px;
      left: 50%;
      transform: translateX(-50%);
  }
}

@media (max-width: 600px) {
  .player-box {
    width: 100%;
    height: auto;
    max-width: none;
    aspect-ratio: 16/9;
  }
  
  .queue-area {
      height: calc(100vh - 64px - 10vh - 160px);
  }
  
  .queue-panel-wrap {
    width: 100% !important;
    padding: 0 12px;
    box-sizing: border-box;
  }
      .player-close {
        top: 24px;
        right: 24px;
        padding: 6px 8px;
        font-size: 12px;
      }
  .search-input {
    font-size: 14px;
    padding: 8px 12px;
  }
  .search-btn {
    padding: 8px 12px;
  }
  select#qTypeSelect { width: 70px; font-size: 14px; }
  
  .queue-area .queue-item {
    gap: 8px;
  }
  .queue-area .queue-item .drag-handle {
    display: none;
  }
  .queue-area .queue-item .mobile-move-btns {
    display: flex;
    gap: 4px;
  }
  .queue-area .queue-item .mobile-move-btns .small-btn {
    padding: 6px 6px;
    line-height: 1;
    font-size: 12px;
  }
}

#playerFrame iframe {
  width: 100% !important;
  height: 100% !important;
  display: block;
}
/* 將此段落加入 css/style.css 底部 */

.insert-item {
  padding: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}
.insert-item:hover {
  background: rgba(255,255,255,0.1);
  color: var(--white);
}
.insert-item.is-playing {
  color: var(--accent);
  font-weight: bold;
  background: rgba(255, 0, 0, 0.05);
}
.insert-item .idx-badge {
  font-size: 10px;
  opacity: 0.5;
  min-width: 20px;
}

.queue-panel-wrap .small-btn {
    padding: 6px 10px;
    background: var(--tab-bg);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 6px;
    color: var(--white);
    font-size: 12px;
}

#snakeModal .small-btn {
    width: 60px;
    height: 60px;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #333;
    border: 1px solid #555;
    border-radius: 12px;
}

/* 當搜尋介面啟動時，隱藏漢堡按鈕 */
body.searching #hamburgerBtn {
    display: none !important;
}

/* 確保搜尋圖層在最頂層，遮蔽所有 header 內容 */
@media (max-width: 900px) {
    .search-wrap.active {
        display: flex !important;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 64px;
        background: var(--bg);
        padding: 8px 12px;
        z-index: 1000; /* 高於漢堡選單 */
        align-items: center;
    }
}

/* 分割條顯色修正：永遠顯示紅色 */
.split-divider {
    background: var(--accent) !important;
    opacity: 1 !important;
    box-shadow: 0 0 5px rgba(255, 0, 0, 0.5);
}