:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  background: #111827;
  color: #f9fafb;
}

body {
  margin: 0;
  min-height: 100vh;
}

[hidden] {
  display: none !important;
}

body:not(.room-joined) #load-form-shell,
body:not(.room-joined) #player-wrap,
body:not(.room-joined) #settings-panel,
body:not(.room-joined) #playlist-panel {
  display: none !important;
}

.app {
  box-sizing: border-box;
  width: 100vw;
  height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  padding: 16px;
}

h1 {
  margin: 0 0 8px;
}

.app-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.app-title-version {
  font-size: 0.58em;
  line-height: 1;
  color: #93c5fd;
  font-weight: 600;
  letter-spacing: 0.02em;
}

h2 {
  margin-top: 0;
}

.subhead {
  margin: 0;
  color: #9ca3af;
}

.left-pane {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 16px;
}

.app-header {
  padding: 4px 6px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.load-form-shell {
  flex: 0 0 auto;
  width: min(580px, 100%);
  max-width: 0;
  overflow: hidden;
  opacity: 0;
  transform: translateY(-6px);
  pointer-events: none;
  transition: max-width 220ms ease, opacity 180ms ease, transform 220ms ease;
}

.load-form-shell.is-visible {
  max-width: min(580px, 100%);
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.load-form {
  flex: 1;
  justify-content: flex-end;
  max-width: 580px;
}

.load-form input {
  flex: 1 1 300px;
  min-width: 220px;
}

.load-actions {
  display: flex;
  gap: 8px;
}

.right-sidebar {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  padding-right: 4px;
}

.card {
  border: 1px solid #374151;
  border-radius: 12px;
  padding: 16px;
  background: #1f2937;
}

.player-card {
  padding: 12px;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  gap: 10px;
}

.idle-room-state {
  min-height: 0;
  display: grid;
  place-items: center;
  gap: 10px;
  text-align: center;
  background: radial-gradient(circle at top, #263548 0%, #1f2937 60%, #1b2433 100%);
}

.idle-meme-caption {
  margin: 0;
  color: #d1d5db;
  font-size: 1rem;
  max-width: 42ch;
}

.room-joined-fade-in {
  animation: room-joined-fade-in 220ms ease-out;
}

@keyframes room-joined-fade-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

input,
button {
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #4b5563;
  background: #111827;
  color: #f9fafb;
}

input[type="range"] {
  padding: 0;
  border: 0;
  background: transparent;
}

button {
  cursor: pointer;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.status {
  color: #d1d5db;
  margin: 0;
}

.badge {
  font-weight: 700;
  margin: 0;
}

.player-toolbar {
  border: 1px solid #374151;
  border-radius: 12px;
  background: linear-gradient(180deg, #1b2535 0%, #111827 100%);
  padding: 10px;
  display: grid;
  gap: 8px;
}

.toolbar-row {
  display: grid;
  align-items: center;
  gap: 8px;
}

.toolbar-main-row {
  grid-template-columns: auto minmax(0, 1fr) auto auto;
}

.toolbar-meta-row {
  grid-template-columns: auto 130px auto auto 1fr;
}

.toolbar-slider {
  width: 100%;
}

.volume-slider {
  min-width: 90px;
}

.timecode {
  min-width: 3.2rem;
  color: #d1d5db;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.icon-btn {
  min-width: 72px;
  padding: 8px 10px;
}

#player {
  width: 100%;
  min-height: 0;
  height: 100%;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
}

#player iframe {
  width: 100%;
  height: 100%;
  display: block;
}

.member-strip {
  border: 1px solid #374151;
  border-radius: 12px;
  background: #111827;
  padding: 8px 10px;
}

.member-chips {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.member-chip {
  width: 72px;
  display: grid;
  justify-items: center;
  gap: 6px;
  transition: opacity 160ms ease, filter 160ms ease;
}

.member-chip.is-inactive {
  opacity: 0.42;
  filter: saturate(0.7);
}

.member-chip-avatar {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 700;
  color: #f9fafb;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.member-chip-name {
  width: 100%;
  text-align: center;
  font-size: 0.78rem;
  color: #d1d5db;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.member-chip.is-host .member-chip-avatar {
  box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.55);
}

.current-room-label {
  margin: 0 0 12px;
  font-size: 0.9rem;
  color: #9ca3af;
  font-weight: 500;
  letter-spacing: 0.01em;
}

.leave-room-btn {
  width: 100%;
  padding: 10px;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.45);
  color: #fca5a5;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: background 150ms ease, border-color 150ms ease;
}

.leave-room-btn:hover {
  background: rgba(239, 68, 68, 0.22);
  border-color: rgba(239, 68, 68, 0.7);
}

.playlist-items {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.playlist-item {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto auto auto;
  gap: 10px;
  border: 1px solid #374151;
  border-radius: 10px;
  padding: 10px;
  background: #111827;
}

.playlist-item-thumb-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  overflow: hidden;
  background: #0b1220;
}

.playlist-item-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.playlist-item-channel-badge {
  position: absolute;
  bottom: 8px;
  right: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(17, 24, 39, 0.85);
  backdrop-filter: blur(4px);
  padding: 4px 8px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.playlist-item-channel-thumb {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  background: #374151;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.playlist-item-channel-name {
  font-size: 0.8rem;
  color: #f3f4f6;
  white-space: nowrap;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.playlist-item-meta {
  min-width: 0;
}

.playlist-item-title {
  margin: 0;
  font-weight: 600;
  line-height: 1.2;
}

.playlist-item-description {
  margin: 6px 0 0;
  color: #d1d5db;
  font-size: 0.92rem;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.playlist-item-info {
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.playlist-item-duration {
  color: #60a5fa;
  font-size: 0.85rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.playlist-item-subtitle {
  color: #9ca3af;
  font-size: 0.85rem;
  text-align: right;
  white-space: nowrap;
}

.playlist-actions {
  display: flex;
  gap: 6px;
}

@media (max-width: 1040px) {
  .app {
    width: 100%;
    height: auto;
    min-height: 100vh;
    grid-template-columns: 1fr;
  }

  .left-pane {
    grid-template-rows: auto auto auto;
  }

  .player-card {
    min-height: 0;
  }

  .toolbar-main-row {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .toolbar-main-row .timecode:first-of-type {
    display: none;
  }

  .toolbar-meta-row {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .toolbar-meta-row .badge,
  .toolbar-meta-row .status {
    grid-column: 1 / -1;
    margin: 0;
  }

  .app-header {
    flex-direction: column;
    align-items: stretch;
  }

  .load-form-shell {
    width: 100%;
  }

  .load-form-shell.is-visible {
    max-width: 100%;
  }

  .load-form {
    max-width: none;
    justify-content: flex-start;
  }

  .load-actions {
    width: 100%;
  }

  .load-actions button {
    flex: 1;
  }
}

