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

:root {
  --bg-primary: #0f0f0f;
  --bg-secondary: #1a1a1a;
  --bg-card: #222;
  --bg-input: #2a2a2a;
  --text-primary: #eee;
  --text-secondary: #999;
  --accent: #7c3aed;
  --accent-hover: #6d28d9;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --warning: #f59e0b;
  --border: #333;
  --radius: 10px;
  --shadow: 0 4px 20px rgba(0,0,0,.4);
  font-size: 15px;
}

[data-theme="light"] {
  --bg-primary: #f5f5f5;
  --bg-secondary: #ffffff;
  --bg-card: #f0f0f0;
  --bg-input: #e8e8e8;
  --text-primary: #1a1a1a;
  --text-secondary: #666;
  --accent: #7c3aed;
  --accent-hover: #6d28d9;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success: #16a34a;
  --warning: #d97706;
  --border: #d0d0d0;
  --shadow: 0 4px 20px rgba(0,0,0,.1);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #444; border-radius: 3px; }

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

/* Header */
#top-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.logo {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--accent);
  white-space: nowrap;
}

#room-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  flex: 1;
}

#room-controls input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  padding: 6px 10px;
  font-size: .85rem;
  width: 140px;
  outline: none;
  transition: border .2s;
}

#room-controls input:focus {
  border-color: var(--accent);
}

#user-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: .85rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 14px;
  border: none;
  border-radius: var(--radius);
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .2s, opacity .2s;
  white-space: nowrap;
}

.btn:disabled {
  opacity: .4;
  cursor: not-allowed;
}

.btn .material-icons {
  font-size: 1.1rem;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-card);
}

.theme-toggle {
  width: 36px;
  height: 36px;
  padding: 0;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  flex-shrink: 0;
}

.theme-toggle:hover {
  background: var(--bg-card);
  color: var(--accent);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
}

.btn-icon {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 8px;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  justify-content: center;
}

.btn-icon:hover:not(:disabled) {
  background: var(--bg-card);
}

.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  text-decoration: underline;
  padding: 0;
  font-size: inherit;
  cursor: pointer;
}

.hidden { display: none !important; }

/* Main layout */
#main-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

#left-panel {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

#right-panel {
  width: 360px;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  background: var(--bg-secondary);
}

@media (max-width: 768px) {
  #main-layout {
    flex-direction: column;
  }
  #right-panel {
    width: 100%;
    height: 45vh;
    border-left: none;
    border-top: 1px solid var(--border);
  }
  #room-controls input {
    width: 100px;
  }
}

/* Sections */
section {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: 16px;
}

section h2 {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-primary);
}

section h2 .material-icons {
  font-size: 1.2rem;
  color: var(--accent);
}

/* Sync controls */
.sync-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sync-info {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: .85rem;
  color: var(--text-secondary);
}

.room-id {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .8rem;
  color: var(--accent);
  padding: 6px 10px;
  background: rgba(124, 58, 237, .08);
  border-radius: var(--radius);
  border: 1px solid rgba(124, 58, 237, .2);
  word-break: break-all;
}

.placeholder-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 24px;
  color: var(--text-secondary);
  text-align: center;
}

.placeholder-text .material-icons {
  font-size: 2.5rem;
  opacity: .4;
}

/* Player */
#player-section {
  flex-shrink: 0;
  padding: 12px;
  background: transparent;
}

#player-section h2 {
  margin-bottom: 8px;
}

.player-container {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

#video-player {
  width: 100%;
  height: 100%;
  min-height: 200px;
}

.video-url-row {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.video-url-row input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  padding: 8px 12px;
  font-size: .82rem;
  outline: none;
}

.video-url-row input:focus {
  border-color: var(--accent);
}

.video-url-row .btn {
  flex-shrink: 0;
}

/* Source tabs */
.source-tabs {
  display: flex;
  gap: 2px;
  margin-top: 8px;
  background: var(--bg-input);
  border-radius: var(--radius);
  padding: 3px;
}

.source-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 10px;
  border: none;
  border-radius: 7px;
  font-size: .82rem;
  font-weight: 500;
  cursor: pointer;
  background: transparent;
  color: var(--text-secondary);
  transition: background .2s, color .2s;
}

.source-tab.active {
  background: var(--bg-card);
  color: var(--text-primary);
}

.source-tab:hover:not(.active) {
  color: var(--text-primary);
}

.source-tab .material-icons {
  font-size: 1rem;
}

.source-panel {
  margin-top: 6px;
}

/* Torrent input */
.torrent-input-row {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.torrent-input-row input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  padding: 8px 12px;
  font-size: .82rem;
  outline: none;
}

.torrent-input-row input:focus {
  border-color: var(--accent);
}

.torrent-input-row .btn {
  flex-shrink: 0;
}

.torrent-file-row {
  display: flex;
  align-items: center;
  margin-top: 6px;
}

.torrent-file-row input[type="file"] {
  display: none;
}

.torrent-file-row .btn {
  font-size: .8rem;
}

/* Bitplay container */
#bitplay-container {
  width: 100%;
  height: 100%;
  min-height: 200px;
}

.torrent-progress {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 8px 12px;
  font-size: .82rem;
  color: var(--accent);
  background: rgba(124, 58, 237, .08);
  border-radius: var(--radius);
  border: 1px solid rgba(124, 58, 237, .2);
}

.torrent-progress .material-icons {
  animation: spin 1.5s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.torrent-files {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.file-list-title {
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.file-list-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  font-size: .82rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background .2s, border-color .2s;
}

.file-list-item:hover {
  background: var(--bg-input);
  border-color: var(--accent);
}

.file-list-item.active {
  border-color: var(--accent);
  background: rgba(124, 58, 237, .1);
}

.file-list-item .material-icons {
  font-size: 1.1rem;
  color: var(--accent);
  flex-shrink: 0;
}

.file-list-item .file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-stop-torrent {
  flex-shrink: 0;
}

.torrent-info-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 8px 12px;
  font-size: .82rem;
  color: var(--text-secondary);
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.torrent-info-row .material-icons {
  font-size: 1.1rem;
  color: var(--accent);
  flex-shrink: 0;
}

/* Video.js custom styling */
.video-js .vjs-big-play-button {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border-color: var(--accent) !important;
  background: rgba(124, 58, 237, .15) !important;
}

.video-js .vjs-big-play-button .vjs-icon-placeholder:before {
  font-size: 47px;
  position: static;
}

.video-js .vjs-control-bar {
  background: transparent;
  padding: 0 10px 15px;
  height: auto;
}

.video-js .vjs-control-bar:before {
  content: "";
  position: absolute;
  width: 100%;
  height: 200%;
  bottom: 0;
  left: 0;
  background: linear-gradient(0deg, rgba(0,0,0,.84) 0%, rgba(0,0,0,.59) 50%, rgba(0,0,0,0) 100%);
  pointer-events: none;
}

.video-js .vjs-progress-control {
  position: absolute !important;
  bottom: 45px !important;
  width: calc(100% - 20px) !important;
  padding: 1px !important;
  height: 40px !important;
}

.video-js .vjs-progress-holder {
  height: 6px;
  border-radius: 50px;
  transition: .3s all;
}

.video-js .vjs-play-progress {
  border-radius: 50px;
}

.video-js .vjs-play-progress:before {
  font-size: 17px;
  transition: .3s all;
}

.video-js .vjs-progress-control:hover .vjs-progress-holder {
  height: 8px;
}

.video-js .vjs-load-progress div {
  border-radius: 50px;
  background: rgba(255,255,255,.33);
}

.video-js .vjs-slider {
  background: rgba(255,255,255,.27);
}

.video-js .vjs-current-time,
.video-js .vjs-duration {
  display: block;
}

.video-js .vjs-time-control.vjs-duration {
  margin-right: auto;
}

.video-js .vjs-time-control {
  padding: 0 5px;
  font-size: 15px;
  line-height: 1.2;
  height: 33px;
  display: flex;
  align-items: center;
}

.video-js .vjs-time-control.vjs-time-divider {
  padding: 0;
  min-width: 0;
  font-size: 18px;
  line-height: 1;
  z-index: 1;
}

.video-js .vjs-play-control {
  height: 33px;
  width: 33px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-js .vjs-play-control .vjs-icon-placeholder:before {
  position: relative;
  line-height: 1;
  font-size: 30px;
}

.video-js .vjs-volume-panel {
  width: 110px !important;
  height: 33px;
  margin-left: 6px;
}

.video-js .vjs-volume-panel .vjs-volume-control {
  opacity: 1;
  width: 60px !important;
  height: 33px;
}

.video-js .vjs-mute-control {
  width: 33px;
  height: 33px;
}

.video-js .vjs-mute-control .vjs-icon-placeholder:before {
  position: relative;
  line-height: 1;
  font-size: 25px;
}

.video-js .vjs-fullscreen-control {
  height: 33px;
  width: 33px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 6px;
}

.video-js .vjs-fullscreen-control .vjs-icon-placeholder:before {
  position: relative;
  line-height: 1;
  font-size: 28px;
}

.vjs-remaining-time { display: none; }
.vjs-live .vjs-time-control,
.vjs-live .vjs-time-divider { display: block; }

@media (max-width: 768px) {
  .video-js .vjs-control-bar {
    padding: 0 4px 5px;
  }
  .video-js .vjs-progress-control {
    bottom: 31px !important;
    width: calc(100% - 6px) !important;
    padding: 0 !important;
    height: 30px !important;
  }
  .video-js .vjs-play-control {
    width: 26px;
    height: 26px;
  }
  .video-js .vjs-play-control .vjs-icon-placeholder:before {
    font-size: 25px;
  }
  .video-js .vjs-time-control {
    padding: 0 4px;
    font-size: 12px;
    height: 26px;
  }
  .video-js .vjs-time-control.vjs-time-divider {
    font-size: 15px;
  }
  .video-js .vjs-volume-panel {
    width: 80px !important;
    height: 26px;
    margin-left: 4px;
  }
  .video-js .vjs-volume-panel .vjs-volume-control {
    width: 45px !important;
    height: 26px;
  }
  .video-js .vjs-mute-control {
    width: 26px;
    height: 26px;
  }
  .video-js .vjs-fullscreen-control {
    height: 26px;
    width: 26px;
  }
  .video-js .vjs-fullscreen-control .vjs-icon-placeholder:before {
    font-size: 20px;
  }
}

/* Chat */
#chat-section {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 12px;
  background: transparent;
}

#chat-section h2 {
  margin-bottom: 8px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  background: var(--bg-primary);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  min-height: 0;
}

.chat-msg {
  padding: 6px 10px;
  border-radius: 8px;
  font-size: .85rem;
  line-height: 1.4;
  word-break: break-word;
  background: var(--bg-card);
  max-width: 90%;
}

.chat-msg .msg-author {
  font-weight: 600;
  color: var(--accent);
  font-size: .78rem;
}

.chat-msg .msg-text {
  margin-top: 2px;
}

.chat-msg .msg-time {
  font-size: .7rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.chat-msg.own {
  align-self: flex-end;
  background: rgba(124, 58, 237, .15);
  border: 1px solid rgba(124, 58, 237, .25);
}

.chat-msg.system {
  align-self: center;
  background: transparent;
  font-size: .78rem;
  color: var(--text-secondary);
  text-align: center;
}

.chat-input-row {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.chat-input-row input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  padding: 8px 12px;
  font-size: .9rem;
  outline: none;
}

.chat-input-row input:focus {
  border-color: var(--accent);
}

.muted-notice {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  margin-top: 6px;
  background: rgba(239, 68, 68, .12);
  border: 1px solid rgba(239, 68, 68, .3);
  border-radius: var(--radius);
  font-size: .82rem;
  color: var(--danger);
}

/* Toast */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: .85rem;
  box-shadow: var(--shadow);
  pointer-events: auto;
  animation: slideIn .3s ease;
  max-width: 340px;
}

.toast .material-icons {
  font-size: 1.2rem;
  flex-shrink: 0;
}

.toast.info {
  background: #1e3a5f;
  border: 1px solid #2563eb;
  color: #93c5fd;
}

.toast.warning {
  background: #3a2a0a;
  border: 1px solid var(--warning);
  color: #fde68a;
}

.toast.error {
  background: #3a1010;
  border: 1px solid var(--danger);
  color: #fca5a5;
}

.toast.success {
  background: #0a3a1a;
  border: 1px solid var(--success);
  color: #86efac;
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ========== Home Page ========== */
#home-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  gap: 32px;
  overflow-y: auto;
}

.home-hero {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.hero-icon {
  font-size: 4rem !important;
  color: var(--accent);
  opacity: .8;
}

.home-hero h1 {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-primary);
}

.home-hero p {
  font-size: .95rem;
  color: var(--text-secondary);
  max-width: 360px;
}

.home-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 400px;
}

.home-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.home-card-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 16px;
  font-size: .9rem;
  font-weight: 600;
  color: var(--text-primary);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.home-card-header .material-icons {
  font-size: 1.2rem;
  color: var(--accent);
}

.home-card-body {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
}

.home-card-body input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  padding: 8px 12px;
  font-size: .85rem;
  outline: none;
}

.home-card-body input:focus {
  border-color: var(--accent);
}

/* ========== Profile Page ========== */
#profile-page {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 32px 20px;
  overflow-y: auto;
}

.profile-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.profile-card h2 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
  text-align: center;
}

.profile-avatar-section {
  display: flex;
  justify-content: center;
}

.avatar-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.avatar-img {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--accent);
}

.avatar-placeholder {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: var(--bg-input);
  border: 3px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar-placeholder .material-icons {
  font-size: 3rem;
  color: var(--text-secondary);
}

.profile-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.profile-field label {
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.profile-field input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  padding: 10px 12px;
  font-size: .9rem;
  outline: none;
  transition: border .2s;
}

.profile-field input:focus {
  border-color: var(--accent);
}

.field-hint {
  font-size: .75rem;
  color: var(--text-secondary);
}

.profile-save-btn {
  width: 100%;
  justify-content: center;
  padding: 10px;
  font-size: .95rem;
}

.profile-auth-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.profile-auth-section hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

.profile-auth-hint {
  font-size: .82rem;
  color: var(--text-secondary);
  text-align: center;
}

.profile-auth-section .btn {
  width: 100%;
  justify-content: center;
}

/* ========== Room Page ========== */
.room-info-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: .82rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.room-info-badge .material-icons {
  font-size: 1.1rem;
}

.room-id-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: .78rem;
  color: var(--accent);
  background: rgba(124, 58, 237, .08);
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid rgba(124, 58, 237, .2);
  white-space: nowrap;
}

.room-id-badge .material-icons {
  font-size: .9rem;
}

.btn-sm {
  padding: 4px 10px;
  font-size: .78rem;
}

.btn-sm .material-icons {
  font-size: .95rem;
}

#room-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

#sync-section {
  flex-shrink: 0;
}

.sync-buttons {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}

.sync-buttons .btn {
  flex: 1;
  justify-content: center;
}

@media (max-width: 768px) {
  .home-hero h1 { font-size: 1.5rem; }
  .hero-icon { font-size: 3rem !important; }
  #home-page { padding: 24px 16px; }
  #profile-page { padding: 20px 12px; }
  .profile-card { padding: 20px; }
}
