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

:root {
  --bg-primary: #0a0a0f; --bg-secondary: #12121a; --bg-tertiary: #1a1a26; --bg-elevated: #22222f;
  --text-primary: #e8e6f0; --text-secondary: #9896a8; --text-muted: #5c5a6b;
  --accent: #7c6aff; --accent-glow: rgba(124, 106, 255, 0.3); --accent-bright: #9b8cff;
  --danger: #ff5c7c; --success: #4ade80;
  --border: rgba(255, 255, 255, 0.06); --border-light: rgba(255, 255, 255, 0.1);
  --font-display: 'Outfit', sans-serif; --font-mono: 'JetBrains Mono', monospace;
  --radius: 10px; --radius-lg: 16px; --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --bar-h: 50px;
}

html { font-size: 15px; height: 100%; }
body { font-family: var(--font-display); background: var(--bg-primary); color: var(--text-primary); height: 100%; overflow: hidden; line-height: 1.6; }
body::before { content: ''; position: fixed; inset: 0; background: radial-gradient(ellipse at 20% 0%, rgba(124,106,255,0.06) 0%, transparent 60%), radial-gradient(ellipse at 80% 100%, rgba(124,106,255,0.03) 0%, transparent 50%); pointer-events: none; z-index: 0; }

/* ─── Seek Bar (fixed top) ─── */
#seek-bar-container { position: fixed; top: 0; left: 0; right: 0; z-index: 100; background: var(--bg-secondary); border-bottom: 1px solid var(--border); padding: 8px 16px 4px; height: var(--bar-h); display: flex; flex-direction: column; justify-content: center; }
#seek-bar-row { display: flex; align-items: center; gap: 10px; }
#btn-mute { background: none; border: none; color: var(--text-secondary); cursor: pointer; padding: 4px; display: flex; align-items: center; border-radius: 4px; transition: all var(--transition); flex-shrink: 0; }
#btn-mute:hover { color: var(--accent-bright); }
#seek-bar-track { position: relative; height: 5px; background: var(--bg-elevated); border-radius: 3px; cursor: pointer; flex: 1; }
#seek-bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-bright)); border-radius: 3px; width: 0%; transition: width 0.3s linear; }
#seek-bar-thumb { position: absolute; top: 50%; left: 0%; transform: translate(-50%,-50%); width: 13px; height: 13px; background: var(--accent-bright); border-radius: 50%; box-shadow: 0 0 10px var(--accent-glow); opacity: 0; transition: opacity var(--transition); }
#seek-bar-track:hover #seek-bar-thumb { opacity: 1; }
#seek-bar-times { display: flex; justify-content: space-between; align-items: center; margin-top: 2px; font-family: var(--font-mono); font-size: 0.65rem; color: var(--text-muted); padding-left: 32px; }
#now-playing-label { color: var(--text-secondary); font-family: var(--font-display); font-size: 0.68rem; max-width: 60%; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ─── Menu Toggle ─── */
#menu-toggle {
  position: fixed; top: calc(var(--bar-h) + 8px); left: 12px; z-index: 90;
  background: var(--bg-tertiary); border: 1px solid var(--border-light); color: var(--text-primary);
  width: 36px; height: 36px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all var(--transition);
}
#menu-toggle:hover { background: var(--bg-elevated); border-color: var(--accent); box-shadow: 0 0 12px var(--accent-glow); }

/* ─── Signup Tooltip ─── */
#signup-tooltip {
  position: fixed; top: calc(var(--bar-h) + 50px); left: 12px; z-index: 95;
  background: var(--accent); color: #fff; padding: 12px 16px; border-radius: var(--radius);
  font-size: 0.85rem; max-width: 220px; box-shadow: 0 4px 20px var(--accent-glow);
  animation: tooltipIn 0.4s ease both;
}
#signup-tooltip strong { display: block; margin-bottom: 2px; }
#signup-tooltip p { font-size: 0.78rem; opacity: 0.9; margin: 0; }
.tooltip-arrow { position: absolute; top: -8px; left: 18px; width: 0; height: 0; border-left: 8px solid transparent; border-right: 8px solid transparent; border-bottom: 8px solid var(--accent); }
.tooltip-close { position: absolute; top: 4px; right: 8px; background: none; border: none; color: rgba(255,255,255,0.7); font-size: 1.1rem; cursor: pointer; line-height: 1; }
@keyframes tooltipIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ─── Side Menu ─── */
#menu-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 200; transition: opacity var(--transition); }
#menu-overlay.hidden { opacity: 0; pointer-events: none; }
#side-menu { position: fixed; top: 0; left: 0; bottom: 0; width: 320px; max-width: 85vw; background: var(--bg-secondary); border-right: 1px solid var(--border); z-index: 201; transform: translateX(0); transition: transform var(--transition); display: flex; flex-direction: column; overflow-y: auto; }
#side-menu.hidden { transform: translateX(-100%); }
#menu-header { display: flex; justify-content: space-between; align-items: center; padding: 20px 24px; border-bottom: 1px solid var(--border); }
#menu-header h2 { font-weight: 700; font-size: 1.2rem; background: linear-gradient(135deg, var(--accent-bright), var(--text-primary)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
#menu-close { background: none; border: none; color: var(--text-secondary); font-size: 1.6rem; cursor: pointer; padding: 4px; line-height: 1; }
#menu-user-section { padding: 16px 24px; }
#user-info { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
#user-avatar { width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--accent); }
#user-name { font-weight: 600; font-size: 0.95rem; }
#user-credits { font-size: 0.85rem; color: var(--accent-bright); font-weight: 600; padding: 8px 12px; background: rgba(124,106,255,0.08); border-radius: var(--radius); display: inline-flex; align-items: center; gap: 6px; }
.credit-icon { font-size: 1rem; }
#menu-nav { padding: 16px 24px; display: flex; flex-direction: column; gap: 8px; }
.menu-btn { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: var(--radius); font-family: var(--font-display); font-size: 0.9rem; font-weight: 500; color: var(--text-primary); text-decoration: none; background: var(--bg-tertiary); border: 1px solid var(--border); cursor: pointer; transition: all var(--transition); }
.menu-btn:hover { background: var(--bg-elevated); border-color: var(--accent); box-shadow: 0 0 12px var(--accent-glow); }
.menu-divider { height: 1px; background: var(--border); margin: 8px 0; }
#credit-packs { padding: 16px 24px; border-top: 1px solid var(--border); }
#credit-packs h3 { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 12px; text-transform: uppercase; letter-spacing: 0.08em; }
.credit-pack-btn { display: block; width: 100%; padding: 14px 16px; margin-bottom: 8px; background: var(--bg-tertiary); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text-primary); font-family: var(--font-display); font-size: 0.9rem; cursor: pointer; text-align: left; transition: all var(--transition); }
.credit-pack-btn:hover { border-color: var(--accent); background: rgba(124,106,255,0.1); }
.hidden { display: none !important; }

/* ─── Main Content ─── */
#app {
  position: relative; z-index: 1; max-width: 1400px; margin: 0 auto;
  padding-top: calc(var(--bar-h) + 6px); padding-left: 16px; padding-right: 16px; padding-bottom: 0;
  height: 100%; display: flex; flex-direction: column; overflow: hidden;
}

/* ─── Now Playing ─── */
#now-playing { padding: 8px 0; display: flex; align-items: center; justify-content: center; gap: 14px; flex-shrink: 0; }
#np-art-container { width: 56px; height: 56px; border-radius: 8px; overflow: hidden; background: var(--bg-tertiary); border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
#np-art { width: 100%; height: 100%; object-fit: cover; }
.vinyl-record { width: 36px; height: 36px; border-radius: 50%; background: #1a1a2e; position: relative; display: flex; align-items: center; justify-content: center; animation: spin 4s linear infinite; animation-play-state: paused; }
body.is-playing .vinyl-record { animation-play-state: running; }
@keyframes spin { to { transform: rotate(360deg); } }
.vinyl-groove { position: absolute; border: 1px solid rgba(255,255,255,0.04); border-radius: 50%; }
.vinyl-groove:nth-child(1) { width: 90%; height: 90%; } .vinyl-groove:nth-child(2) { width: 65%; height: 65%; } .vinyl-groove:nth-child(3) { width: 40%; height: 40%; }
.vinyl-label { width: 10px; height: 10px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent-bright)); }
#np-info { text-align: left; }
#np-title { font-size: 0.95rem; font-weight: 700; margin-bottom: 0; }
#np-subtitle { color: var(--text-secondary); font-size: 0.72rem; }

/* ─── Columns ─── */
#columns { display: flex; gap: 14px; flex: 1; min-height: 0; padding-bottom: 6px; }
#col-left { flex: 1; display: flex; flex-direction: column; gap: 10px; min-height: 0; overflow-y: auto; }
#col-right { flex: 1; display: flex; flex-direction: column; min-height: 0; }

/* ─── Sections ─── */
#generate-section, #queue-section, #chat-section { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 12px; }
#chat-section { display: flex; flex-direction: column; flex: 1; min-height: 0; }
#queue-section { flex: 1; min-height: 0; overflow-y: auto; }
#generate-section h3, #queue-section h3, #chat-section h3 { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-muted); margin-bottom: 8px; font-weight: 600; flex-shrink: 0; }
#gen-form { display: flex; flex-direction: column; gap: 5px; }
#gen-prompt, #gen-title, #chat-input { background: var(--bg-tertiary); border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px; color: var(--text-primary); font-family: var(--font-display); font-size: 0.84rem; transition: border-color var(--transition); outline: none; }
#gen-prompt:focus, #gen-title:focus, #chat-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
#gen-prompt::placeholder, #gen-title::placeholder, #chat-input::placeholder { color: var(--text-muted); }
#gen-options { display: flex; align-items: center; gap: 16px; }
.toggle-label { display: flex; align-items: center; gap: 6px; font-size: 0.8rem; color: var(--text-secondary); cursor: pointer; }
.toggle-label input[type="checkbox"] { accent-color: var(--accent); width: 14px; height: 14px; }
#btn-generate { background: linear-gradient(135deg, var(--accent), var(--accent-bright)); color: #fff; border: none; border-radius: 8px; padding: 10px 16px; font-family: var(--font-display); font-size: 0.84rem; font-weight: 600; cursor: pointer; transition: all var(--transition); }
#btn-generate:hover { box-shadow: 0 4px 20px var(--accent-glow); transform: translateY(-1px); }
#btn-generate:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }
#gen-status { font-size: 0.72rem; padding: 7px 10px; border-radius: 8px; background: var(--bg-tertiary); color: var(--text-secondary); font-family: var(--font-mono); }
#gen-status.error { color: var(--danger); border: 1px solid rgba(255,92,124,0.2); }
#gen-status.success { color: var(--success); border: 1px solid rgba(74,222,128,0.2); }

.empty-state { color: var(--text-muted); font-size: 0.8rem; text-align: center; padding: 10px 0; }
.queue-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--bg-tertiary); border: 1px solid var(--border); border-radius: 8px; margin-bottom: 5px; }
.queue-item:hover { border-color: var(--border-light); }
.queue-item-number { font-family: var(--font-mono); font-size: 0.7rem; color: var(--text-muted); min-width: 18px; }
.queue-item-title { flex: 1; font-size: 0.84rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.queue-item-author { font-size: 0.7rem; color: var(--text-muted); white-space: nowrap; flex-shrink: 0; }
.queue-item-author-own { color: var(--success); font-weight: 600; }
.queue-item-own { border-color: rgba(74, 222, 128, 0.15); background: rgba(74, 222, 128, 0.04); }
.queue-item-own .queue-item-title { color: var(--success); }

/* ─── Chat ─── */
#chat-header { display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; margin-bottom: 8px; }
#chat-header h3 { margin-bottom: 0; }
#listener-count { font-family: var(--font-mono); font-size: 0.68rem; color: var(--accent-bright); background: rgba(124,106,255,0.1); padding: 3px 8px; border-radius: 20px; white-space: nowrap; }

/* Chat: newest messages at top, scroll down for older */
#chat-messages {
  flex: 1; min-height: 0; overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px;
  margin-bottom: 8px; padding: 5px; background: var(--bg-primary);
  border-radius: 8px; border: 1px solid var(--border);
  scrollbar-width: thin; scrollbar-color: var(--bg-elevated) transparent;
}

.chat-msg { display: flex; gap: 7px; padding: 5px 7px; border-radius: 6px; align-items: flex-start; }
.chat-msg:hover { background: rgba(255,255,255,0.02); }
.chat-msg-avatar { width: 22px; height: 22px; border-radius: 50%; flex-shrink: 0; margin-top: 2px; }
.chat-msg-content { min-width: 0; }
.chat-msg-name { font-size: 0.72rem; font-weight: 600; color: var(--accent-bright); margin-right: 5px; }
.chat-msg-time { font-size: 0.62rem; color: var(--text-muted); font-family: var(--font-mono); }
.chat-msg-text { font-size: 0.82rem; color: var(--text-primary); word-break: break-word; line-height: 1.35; }
#chat-input-area { display: flex; gap: 5px; flex-shrink: 0; }
#chat-input { flex: 1; }
#btn-send { background: var(--accent); color: #fff; border: none; border-radius: 8px; padding: 9px 14px; font-family: var(--font-display); font-weight: 600; font-size: 0.82rem; cursor: pointer; transition: all var(--transition); }
#btn-send:hover { background: var(--accent-bright); }
#btn-send:disabled { opacity: 0.4; cursor: not-allowed; }
#chat-login-hint { text-align: center; color: var(--text-muted); font-size: 0.75rem; margin-top: 4px; flex-shrink: 0; }

::-webkit-scrollbar { width: 4px; } ::-webkit-scrollbar-track { background: transparent; } ::-webkit-scrollbar-thumb { background: var(--bg-elevated); border-radius: 3px; }

/* ─── Mobile ─── */
@media (max-width: 768px) {
  :root { --bar-h: 42px; }
  html { font-size: 13px; height: 100dvh; }
  body { height: 100dvh; }
  #app { padding-top: calc(var(--bar-h) + 2px); padding-left: 6px; padding-right: 6px; height: 100dvh; }
  #now-playing { gap: 6px; padding: 2px 0; }
  #np-art-container { width: 36px; height: 36px; border-radius: 6px; }
  #np-title { font-size: 0.82rem; }
  #np-subtitle { font-size: 0.65rem; }

  #columns { flex-direction: column; gap: 5px; flex: 1; min-height: 0; overflow: hidden; }
  #col-left { flex: 0 0 auto; display: flex; flex-direction: column; gap: 5px; max-height: 45%; overflow-y: auto; }
  #col-right { flex: 1; min-height: 0; display: flex; flex-direction: column; }

  #generate-section, #queue-section, #chat-section { padding: 8px; border-radius: 10px; }
  #generate-section h3, #queue-section h3, #chat-section h3 { font-size: 0.65rem; margin-bottom: 4px; }
  #gen-form { gap: 4px; }
  #gen-prompt { padding: 6px 8px; font-size: 0.78rem; }
  #gen-title { padding: 6px 8px; font-size: 0.78rem; }
  #gen-options { gap: 10px; }
  .toggle-label { font-size: 0.72rem; }
  #btn-generate { padding: 7px 10px; font-size: 0.78rem; }
  #gen-status { font-size: 0.65rem; padding: 5px 8px; }

  #queue-section { max-height: 80px; overflow-y: auto; }
  .queue-item { padding: 5px 8px; margin-bottom: 3px; }
  .queue-item-title { font-size: 0.78rem; }
  .queue-item-author { font-size: 0.62rem; }
  .empty-state { font-size: 0.72rem; padding: 5px 0; }

  #chat-section { flex: 1; min-height: 0; }
  #chat-header { margin-bottom: 4px; }
  #chat-messages { margin-bottom: 4px; gap: 1px; }
  .chat-msg { padding: 3px 5px; }
  .chat-msg-avatar { width: 18px; height: 18px; }
  .chat-msg-name { font-size: 0.65rem; }
  .chat-msg-time { font-size: 0.55rem; }
  .chat-msg-text { font-size: 0.75rem; }
  #chat-input { padding: 6px 8px; font-size: 0.78rem; }
  #btn-send { padding: 6px 10px; font-size: 0.78rem; }

  #menu-toggle { width: 30px; height: 30px; }
  #menu-toggle svg { width: 16px; height: 16px; }
  #signup-tooltip { top: calc(var(--bar-h) + 40px); left: 6px; max-width: 180px; font-size: 0.72rem; padding: 8px 12px; }
}

@keyframes fadeInUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* ─── Username Modal ─── */
#username-modal { position: fixed; inset: 0; z-index: 500; display: flex; align-items: center; justify-content: center; }
#username-modal.hidden { display: none !important; }
#username-modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.7); backdrop-filter: blur(6px); }
#username-modal-box {
  position: relative; z-index: 1; background: var(--bg-secondary); border: 1px solid var(--border-light);
  border-radius: var(--radius-lg); padding: 28px 32px; max-width: 380px; width: 90%;
  box-shadow: 0 16px 48px rgba(0,0,0,0.5); animation: fadeInUp 0.3s ease;
}
#username-modal-box h2 { font-size: 1.2rem; font-weight: 700; margin-bottom: 4px; background: linear-gradient(135deg, var(--accent-bright), var(--text-primary)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
#username-modal-box p { font-size: 0.82rem; color: var(--text-secondary); margin-bottom: 16px; }
#username-input {
  display: block; width: 100%; background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: 8px; padding: 11px 14px; color: var(--text-primary); font-family: var(--font-display);
  font-size: 0.95rem; outline: none; transition: border-color var(--transition); margin-bottom: 8px;
}
#username-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
#username-input::placeholder { color: var(--text-muted); }
#username-error { font-size: 0.78rem; color: var(--danger); margin-bottom: 8px; }
#username-submit {
  display: block; width: 100%; background: linear-gradient(135deg, var(--accent), var(--accent-bright));
  color: #fff; border: none; border-radius: 8px; padding: 11px; font-family: var(--font-display);
  font-size: 0.95rem; font-weight: 600; cursor: pointer; transition: all var(--transition); margin-top: 4px;
}
#username-submit:hover { box-shadow: 0 4px 20px var(--accent-glow); transform: translateY(-1px); }
#username-submit:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
#now-playing { animation: fadeInUp 0.3s ease; }
#generate-section { animation: fadeInUp 0.3s ease 0.05s both; }
#queue-section { animation: fadeInUp 0.3s ease 0.1s both; }
#chat-section { animation: fadeInUp 0.3s ease 0.15s both; }
.spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--text-muted); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; margin-right: 6px; vertical-align: middle; }
