/* ── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #0d0d14;
  --surface:  #16161f;
  --surface2: #1e1e2a;
  --surface3: #252535;
  --border:   #2a2a3a;
  --accent:   #7c3aed;
  --accent2:  #a855f7;
  --blue:     #3b82f6;
  --green:    #10b981;
  --red:      #ef4444;
  --yellow:   #f59e0b;
  --text:     #e2e8f0;
  --muted:    #64748b;
  --radius:   10px;
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
.hidden { display: none !important; }

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.88);
  backdrop-filter: blur(14px);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  animation: fadeIn .3s ease;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 44px 52px;
  width: min(440px, 94vw);
  text-align: center;
  box-shadow: 0 30px 90px rgba(124,58,237,.3);
  animation: slideUp .35s ease;
}
.modal-logo {
  font-size: 3rem; margin-bottom: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
.modal h2 {
  font-size: 1.6rem; font-weight: 700; margin-bottom: 8px;
  background: linear-gradient(135deg, #fff 30%, var(--accent2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
.modal p { color: var(--muted); margin-bottom: 28px; font-size: .9rem; }
.modal input {
  width: 100%; padding: 13px 16px; margin-bottom: 14px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 1rem; outline: none;
  transition: border-color .2s;
}
.modal input:focus { border-color: var(--accent); }
.modal button {
  width: 100%; padding: 13px; gap: 8px;
  background: linear-gradient(135deg, var(--accent), var(--blue));
  border: none; border-radius: var(--radius);
  color: #fff; font-size: 1rem; font-weight: 600; cursor: pointer;
  transition: opacity .2s, transform .1s;
}
.modal button:hover { opacity: .88; }
.modal button:active { transform: scale(.98); }

/* ── Layout ───────────────────────────────────────────────────────────────── */
.app { display: flex; flex-direction: column; height: 100vh; }

/* ── Header ───────────────────────────────────────────────────────────────── */
.header {
  display: flex; align-items: center; gap: 14px;
  padding: 0 18px; height: 62px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.header-left { display: flex; align-items: center; gap: 9px; min-width: 130px; }
.logo {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, var(--accent), var(--blue));
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: .95rem; color: #fff;
}
.logo-text { font-weight: 700; font-size: .95rem; letter-spacing: .4px; }
.header-center { flex: 1; min-width: 0; }

.url-form { display: flex; gap: 7px; max-width: 680px; margin: 0 auto; align-items: center; }
.url-input-wrap {
  flex: 1; min-width: 0;
  position: relative; display: flex; align-items: center;
}
.url-icon {
  position: absolute; left: 11px;
  color: var(--red); font-size: 1.05rem;
  pointer-events: none;
}
.url-input-wrap input {
  width: 100%; padding: 9px 13px 9px 34px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: .88rem; outline: none;
  transition: border-color .2s;
}
.url-input-wrap input:focus { border-color: var(--accent); }
.url-input-wrap input::placeholder { color: var(--muted); }

.btn-primary {
  flex-shrink: 0; padding: 9px 16px; white-space: nowrap;
  background: linear-gradient(135deg, var(--accent), var(--blue));
  border: none; border-radius: 8px;
  color: #fff; font-size: .83rem; font-weight: 600; cursor: pointer;
  transition: opacity .2s; display: flex; align-items: center; gap: 6px;
}
.btn-primary:hover { opacity: .85; }

.btn-secondary {
  flex-shrink: 0; padding: 9px 14px; white-space: nowrap;
  background: var(--surface3); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: .83rem; font-weight: 600; cursor: pointer;
  transition: background .2s, border-color .2s;
  display: flex; align-items: center; gap: 6px;
}
.btn-secondary:hover { background: var(--surface2); border-color: var(--accent); }

.url-error {
  font-size: .75rem; color: var(--red); text-align: center; margin-top: 3px;
  animation: shake .3s ease;
}

.header-right { min-width: 100px; display: flex; justify-content: flex-end; }
.online-badge {
  display: flex; align-items: center; gap: 7px;
  font-size: .83rem; color: var(--muted);
  background: var(--surface2); padding: 6px 12px;
  border-radius: 99px; border: 1px solid var(--border);
}
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--green); box-shadow: 0 0 6px var(--green);
  animation: pulse 1.8s infinite; flex-shrink: 0;
}

/* ── Main ─────────────────────────────────────────────────────────────────── */
.main { display: flex; flex: 1; overflow: hidden; }

/* ── Player ───────────────────────────────────────────────────────────────── */
.player-section {
  flex: 0 0 50%;          /* default 50/50 split */
  min-width: 220px;
  display: flex; flex-direction: column; background: #000;
}
.player-wrapper { flex: 1; position: relative; background: #000; overflow: hidden; }
.player-wrapper #player,
.player-wrapper iframe { position: absolute; inset: 0; width: 100% !important; height: 100% !important; }

/* Danmu */
.danmu-container { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 4; }
.danmu {
  position: absolute; left: 100%; white-space: nowrap;
  font-size: .87rem; font-weight: 700;
  padding: 3px 9px; border-radius: 4px;
  background: rgba(0,0,0,.45);
  text-shadow: 0 0 6px rgba(0,0,0,1), 1px 1px 3px rgba(0,0,0,1);
  animation: danmuFly linear forwards; pointer-events: none;
}
.danmu-emoji { font-size: 1.6rem; background: transparent; text-shadow: none; }
@keyframes danmuFly { from { transform: translateX(0); } to { transform: translateX(var(--travel,-3000px)); } }

/* Overlay badges */
.player-overlay { position: absolute; top: 13px; left: 13px; z-index: 5; pointer-events: none; }
.sync-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(0,0,0,.7); backdrop-filter: blur(6px);
  border: 1px solid rgba(255,255,255,.12);
  padding: 5px 12px; border-radius: 99px;
  font-size: .73rem; letter-spacing: .4px; color: #fff;
  opacity: 0; transition: opacity .4s;
}
.sync-badge.visible { opacity: 1; }
.live-dot { color: var(--red); font-size: .55rem; animation: pulse 1.2s infinite; }

/* Now playing */
.now-playing {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 16px;
  background: var(--surface); border-top: 1px solid var(--border); flex-shrink: 0;
}
.np-label {
  display: flex; align-items: center; gap: 5px;
  font-size: .62rem; font-weight: 700; letter-spacing: 1px;
  color: var(--accent2); background: rgba(124,58,237,.15);
  padding: 3px 9px; border-radius: 4px; white-space: nowrap;
}
.np-title {
  font-size: .88rem; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ── Resize handle ────────────────────────────────────────────────────────── */
.resize-handle {
  flex: 0 0 6px;
  background: var(--border);
  cursor: col-resize;
  position: relative;
  display: flex; align-items: center; justify-content: center;
  transition: background .18s;
  z-index: 20;
  user-select: none;
}
.resize-handle:hover,
.resize-handle.active { background: rgba(124,58,237,.4); }

.resize-grip {
  display: flex; flex-direction: column; gap: 3px; pointer-events: none;
}
.resize-grip::before,
.resize-grip::after {
  content: '';
  width: 2px; height: 20px;
  background: var(--muted);
  border-radius: 2px;
  transition: background .18s;
}
.resize-handle:hover .resize-grip::before,
.resize-handle:hover .resize-grip::after,
.resize-handle.active .resize-grip::before,
.resize-handle.active .resize-grip::after { background: var(--accent2); }

/* Blocks the YouTube iframe from capturing events during drag */
.drag-shield {
  position: absolute; inset: 0; z-index: 50;
  cursor: col-resize; background: transparent;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  flex: 1;                /* fill remaining space after player */
  min-width: 220px;
  display: flex; flex-direction: column;
  background: var(--surface); border-left: none;
  overflow: hidden;
}

/* ── Top panel ────────────────────────────────────────────────────────────── */
.top-panel {
  display: flex; flex-direction: column;
  height: 220px; flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}
.tab-bar { display: flex; flex-shrink: 0; border-bottom: 1px solid var(--border); }
.tab-btn {
  flex: 1; padding: 9px 4px;
  background: none; border: none; border-bottom: 2px solid transparent;
  font-size: .72rem; font-weight: 600;
  color: var(--muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 4px;
  transition: color .2s, border-color .2s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent2); border-bottom-color: var(--accent2); }
.tab-btn i { font-size: .8rem; }
.tab-text { font-size: .7rem; }

.badge {
  background: var(--accent); color: #fff;
  font-size: .62rem; font-weight: 700;
  padding: 1px 5px; border-radius: 99px; min-width: 16px; text-align: center;
}
.tab-content { flex: 1; overflow-y: auto; padding: 7px; }

/* Users */
.user-list { list-style: none; display: flex; flex-direction: column; gap: 5px; }
.user-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 9px; border-radius: 8px;
  background: var(--surface2); font-size: .83rem;
  animation: fadeIn .2s ease;
}
.user-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .72rem; font-weight: 700; color: #fff; flex-shrink: 0;
}
.user-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-you { font-size: .68rem; color: var(--muted); }

/* Queue / History shared list */
.list-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; gap: 8px;
  font-size: .83rem; color: var(--muted);
}
.list-empty i { font-size: 1.7rem; opacity: .5; }

.item-list { list-style: none; display: flex; flex-direction: column; gap: 5px; }
.item-card {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 7px; border-radius: 8px;
  background: var(--surface2);
  animation: fadeIn .2s ease;
}
.item-thumb {
  width: 42px; height: 30px; border-radius: 4px;
  object-fit: cover; flex-shrink: 0; background: var(--surface3);
}
.item-info { flex: 1; min-width: 0; }
.item-title {
  font-size: .77rem; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.item-meta {
  font-size: .67rem; color: var(--muted); margin-top: 2px;
  display: flex; align-items: center; gap: 4px;
}
.item-actions { display: flex; gap: 4px; flex-shrink: 0; }
.icon-btn {
  width: 28px; height: 28px; border: none; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem; cursor: pointer; transition: opacity .2s, background .2s;
}
.icon-btn-play  { background: rgba(124,58,237,.25); color: var(--accent2); }
.icon-btn-play:hover  { background: rgba(124,58,237,.45); }
.icon-btn-del   { background: rgba(239,68,68,.15); color: var(--red); }
.icon-btn-del:hover   { background: rgba(239,68,68,.3); }
.icon-btn-replay { background: rgba(59,130,246,.2); color: var(--blue); }
.icon-btn-replay:hover { background: rgba(59,130,246,.4); }

/* ── Chat ─────────────────────────────────────────────────────────────────── */
.chat-panel { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.panel-header {
  padding: 9px 14px 8px;
  font-size: .7rem; font-weight: 700; letter-spacing: 1px; text-transform: uppercase;
  color: var(--muted); flex-shrink: 0; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 6px;
}

.chat-messages {
  flex: 1; overflow-y: auto;
  padding: 10px 10px 6px;
  display: flex; flex-direction: column; gap: 5px;
}

/* Bubbles */
.chat-msg { font-size: .83rem; line-height: 1.5; animation: fadeIn .2s ease; }
.chat-msg.system {
  color: var(--muted); font-style: italic; font-size: .74rem;
  text-align: center; padding: 3px 0;
  display: flex; align-items: center; justify-content: center; gap: 5px;
}
.chat-msg.system::before,
.chat-msg.system::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.chat-bubble { display: flex; gap: 7px; align-items: flex-start; }
.chat-bubble.own { flex-direction: row-reverse; }
.bubble-dot {
  width: 7px; height: 7px; border-radius: 50%;
  flex-shrink: 0; margin-top: 6px;
}
.bubble-body {
  max-width: 82%;
  background: var(--surface2);
  padding: 5px 9px; border-radius: 10px 10px 10px 3px;
}
.chat-bubble.own .bubble-body {
  background: rgba(124,58,237,.22);
  border-radius: 10px 10px 3px 10px;
}
.bubble-name { font-size: .7rem; font-weight: 700; margin-bottom: 1px; }
.bubble-text { word-break: break-word; font-size: .82rem; }

/* Emoji picker */
.emoji-picker {
  background: var(--surface2); border-top: 1px solid var(--border);
  padding: 8px; max-height: 156px; overflow-y: auto;
}
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; }
.emoji-btn {
  background: none; border: none; font-size: 1.25rem; cursor: pointer;
  padding: 5px; border-radius: 6px; line-height: 1; transition: background .15s;
}
.emoji-btn:hover { background: var(--surface3); }

/* Chat input row */
.chat-input-row {
  display: flex; gap: 5px; align-items: center;
  padding: 8px 10px; border-top: 1px solid var(--border); flex-shrink: 0;
}
.emoji-toggle {
  flex-shrink: 0; width: 34px; height: 34px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; font-size: 1rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center; color: var(--muted);
  transition: border-color .2s, color .2s;
}
.emoji-toggle:hover { border-color: var(--accent); color: var(--accent2); }
.chat-input-row input {
  flex: 1; min-width: 0; padding: 8px 10px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: .84rem; outline: none;
  transition: border-color .2s;
}
.chat-input-row input:focus { border-color: var(--accent); }
.chat-input-row input::placeholder { color: var(--muted); }
.chat-input-row #sendBtn {
  flex-shrink: 0; width: 34px; height: 34px;
  background: var(--accent); border: none; border-radius: 8px;
  color: #fff; font-size: .85rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: opacity .2s;
}
.chat-input-row #sendBtn:hover { opacity: .85; }

/* ── Search ───────────────────────────────────────────────────────────────── */
.search-tab-content { padding: 0 !important; display: flex; flex-direction: column; }
.search-box {
  position: relative; padding: 7px 7px 5px; flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}
.search-box input {
  width: 100%; padding: 8px 30px 8px 30px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: .83rem; outline: none;
  transition: border-color .2s;
}
.search-box input:focus { border-color: var(--accent); }
.search-box input::placeholder { color: var(--muted); }
.search-icon {
  position: absolute; left: 18px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: .78rem; pointer-events: none;
}
.search-clear {
  position: absolute; right: 16px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: .8rem; padding: 2px 4px; border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
}
.search-clear:hover { color: var(--text); }

.search-state {
  padding: 10px 12px; font-size: .78rem; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center;
}
.search-state .fa-spinner { font-size: 1.1rem; color: var(--accent2); }

.search-no-key {
  width: 100%; background: rgba(245,158,11,.07);
  border: 1px solid rgba(245,158,11,.2);
  border-radius: 8px; padding: 14px 12px; text-align: center;
}
.search-no-key > .key-icon { font-size: 1.6rem; color: var(--yellow); margin-bottom: 8px; }
.search-no-key p { color: var(--muted); line-height: 1.55; font-size: .78rem; margin-bottom: 4px; }
.search-no-key a {
  color: var(--blue); text-decoration: none; font-weight: 600;
}
.search-no-key a:hover { text-decoration: underline; }
.search-no-key code {
  display: block; margin-top: 10px; padding: 7px 10px;
  background: var(--bg); border-radius: 6px;
  font-family: monospace; font-size: .7rem;
  color: var(--green); word-break: break-all; text-align: left;
  border: 1px solid var(--border);
}

.search-results-list { flex: 1; overflow-y: auto; padding: 6px 7px; }

/* Search result items – reuse item-card but with slightly larger thumb */
.search-result .item-thumb {
  width: 64px; height: 36px; border-radius: 5px; object-fit: cover;
}

/* ── Animations ───────────────────────────────────────────────────────────── */
@keyframes fadeIn  { from { opacity: 0 } to { opacity: 1 } }
@keyframes slideUp { from { opacity: 0; transform: translateY(22px) } to { opacity: 1; transform: none } }
@keyframes pulse   { 0%,100% { opacity:1 } 50% { opacity:.35 } }
@keyframes shake   { 0%,100% { transform:translateX(0) } 25%,75% { transform:translateX(-4px) } 50% { transform:translateX(4px) } }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 680px) {
  .main { flex-direction: column; }
  .resize-handle { display: none; }
  .player-section { flex: 0 0 auto !important; width: 100% !important; height: 45vw; min-width: 0; }
  .sidebar { flex: 1; width: 100% !important; height: auto; min-width: 0; border-top: 1px solid var(--border); }
  .header { flex-wrap: wrap; height: auto; padding: 10px; gap: 8px; }
  .header-left, .header-right { min-width: unset; }
  .header-center { width: 100%; order: 3; }
  .tab-text { display: none; }
  .top-panel { height: 170px; }
  .btn-primary, .btn-secondary { padding: 8px 10px; font-size: .78rem; }
}
