: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; 
}

/* When the player overlay is open we hide the main content visually but keep layout
   to avoid grid reflow / column jumps caused by display:none */
.hidden-by-player {
  visibility: hidden !important;
  pointer-events: none !important;
}
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);
}
/* Inputs used in settings and modals should adapt to theme */
input[type="text"], input[type="password"], textarea {
  background: var(--card);
  color: var(--white);
  border: 1px solid rgba(255,255,255,0.04);
  padding: 8px;
  border-radius: 6px;
}
body.light-mode input[type="text"], body.light-mode input[type="password"], body.light-mode textarea {
  background: #ffffff;
  color: #000000;
  border: 1px solid rgba(0,0,0,0.08);
}

/* specific inputs that were reported */
#username, #password, #newPlName {
  box-sizing: border-box;
}

/* themed input helper class */
.themed-input {
  box-sizing: border-box;
  width: 100%;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.06);
  background: var(--card);
  color: var(--white);
}
body.light-mode .themed-input {
  background: #ffffff;
  color: #000000;
  border: 1px solid rgba(0,0,0,0.08);
}
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: 12px;
  top: 16px;
  z-index: 1500;
  width: 44px;
  height: 44px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--white);
  font-size: 20px;
  cursor: pointer;
  border-radius: 8px;
  isolation: isolate;
}
.hamburger-btn::before {
  content: "";
  position: absolute;
  width: 36px;
  height: 36px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.55);
  border-radius: 6px;
  pointer-events: none;
}

.hamburger-btn .hamburger-icon { position: relative; z-index: 1; line-height: 1; font-size: 20px; }

body.light-mode .hamburger-btn::before { background: rgba(255,255,255,0.92); }
body.light-mode .hamburger-btn { color: #0b0b0b; }
.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 {
  /* keep side-nav above overlay even when player is open */
  z-index: 1400;
}

.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;}
select#sortSelect{flex:0; width:100px; padding:10px 8px; margin-left:6px; 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 .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: 1400; /* raise above overlay */
  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;
  max-height: calc(36vh);
  overflow: auto;
  padding-right: 6px;
}

.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: 1500;
  width: 44px;
  height: 44px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--white);
  font-size: 20px;
  cursor: pointer;
  border-radius: 8px;
  isolation: isolate;
}

@media (max-width: 1023px) {
  .hamburger-btn {
    display: block;
  }
}
.nav-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: none;
  z-index: 1200; /* ensure overlay is above player, menus, etc. */
}
.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-fit, minmax(220px, 1fr));
  gap: 14px;
  padding-bottom: 20px;
}

/* Make grid tracks stretch to fill available width and avoid leftover whitespace
   when the container width changes (for example when scrollbars appear). */
.grid {
  grid-auto-columns: minmax(0, 1fr);
  justify-content: stretch;
  align-content: start;
}

.grid > .card { width: 100%; }
.card{background:var(--card);border-radius:8px;overflow:hidden;cursor:pointer;transition:transform .12s;display:flex;flex-direction:column;position:relative;box-sizing:border-box;width:auto;min-width:0;}
.card:hover{transform:translateY(-6px);} 
.thumb{width:100%;aspect-ratio:16/9;object-fit:cover;background:#111;}
.thumb-wrap{width:100%;aspect-ratio:16/9;background-size:contain;background-position:center;background-repeat:no-repeat;background-color:#000;display:block;}
.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: 64px; /* leave space for header/search row */
  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: calc(100vh - 64px);
  overflow: hidden; 
  padding: 0; 
}

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

html, body {
  overflow-x: hidden;
}

.app-wrap, .container, .content, .split-container, .split-panel {
  box-sizing: border-box;
  max-width: 100%;
}

.content { min-width: 0; overflow-x: hidden; }

.grid { justify-items: start; }

.side-nav { will-change: transform; }

@media (min-width: 901px) {
  .app-wrap, .container { width: auto; max-width: 100%; }

  .split-container { max-width: 100%; box-sizing: border-box; }

  .grid { width: 100%; box-sizing: border-box; justify-items: start; grid-auto-flow: row dense; }

  .grid {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    justify-content: start;
    grid-auto-columns: minmax(0, 1fr);
  }

  header, .player-overlay, .startup-overlay, .nav-overlay { left: 0; right: 0; }
}

.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;left: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: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;
    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;
        left: 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;
}
.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;
}

@media (min-width: 901px) {
  /* On wide screens hide hamburger when searching; keep visible on mobile */
  body.searching #hamburgerBtn {
      display: none !important;
  }

  /* Force a persistent vertical scrollbar on desktop to avoid layout shifts
     when content length changes (appearing/disappearing scrollbar). */
  html, body {
    overflow-y: scroll;
  }
}

@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);
}

/* Ensure hamburger hides while searching to avoid covering back button */
body.searching #hamburgerBtn {
  display: none !important;
}

/* Startup overlay (shown when returning user is logged in) */
.startup-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  background: rgba(0,0,0,0.92);
  z-index: 99999;
}
.startup-overlay .startup-logo {
  width: 84px;
  height: 84px;
  object-fit: cover;
  border-radius: 12px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.6);
}
.startup-overlay.hidden { display: none !important; }

/* Alternate main title shown when player overlay is NOT active */
#sectionTitleAlt { padding: 10px 0 8px 4px; }
#mainTitleAlt { margin:0; color:var(--white); }
#subTitleAlt { color:var(--muted); font-size:13px; margin-top:6px; }

/* Hide alternate title when player overlay is visible */
.player-overlay.show ~ .container #sectionTitleAlt { display: none; }