@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600&family=DM+Mono:wght@400;500&display=swap');

:root,
[data-theme="dark"] {
  --bg:           #0f0f11;
  --surface:      #1a1a1f;
  --surface-2:    #222228;
  --border:       rgba(255,255,255,0.07);
  --border-hover: rgba(255,255,255,0.18);
  --accent:       #e8a838;
  --accent-dim:   rgba(232,168,56,0.15);
  --accent-hover: #f0b94a;
  --accent-text:  #0f0f11;
  --text:         #e8e8ea;
  --text-muted:   #7a7a85;
  --input-bg:     #13131a;
  --danger:       #e05050;
  --header-bg:    rgba(15,15,17,0.85);
  --shadow:       0 8px 40px rgba(0,0,0,0.6);
  --notif-bg:     rgba(26,26,31,0.97);
  --radius:       8px;
  --radius-lg:    12px;
}

[data-theme="light"] {
  --bg:           #f4f3f0;
  --surface:      #ffffff;
  --surface-2:    #f0efec;
  --border:       rgba(0,0,0,0.09);
  --border-hover: rgba(0,0,0,0.22);
  --accent:       #e8a838;
  --accent-dim:   rgba(232,168,56,0.12);
  --accent-hover: #d4952a;
  --accent-text:  #ffffff;
  --text:         #1a1a1f;
  --text-muted:   #8a8a95;
  --input-bg:     #f9f8f6;
  --danger:       #d94040;
  --header-bg:    rgba(244,243,240,0.88);
  --shadow:       0 4px 24px rgba(0,0,0,0.10);
  --notif-bg:     rgba(255,255,255,0.97);
}

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

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  background-color: var(--bg);
  font-family: 'DM Sans', sans-serif;
  color: var(--text);
  padding: 0 16px 40px;
  transition: background-color 0.25s, color 0.25s;
}

#app-header {
  width: 100%;
  position: sticky;
  top: 0;
  z-index: 200;
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
  height: 54px;
  display: flex;
  align-items: center;
}

#header-inner {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#header-logo {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
}

#header-logo svg { color: var(--accent); }

#userCount {
  position: absolute; /* Moves it out of the layout flow */
  left: 20px; /* Sticks it to the far left of the screen */
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-family: 'DM Mono', monospace;
  font-size: 13px;
  font-weight: 500;
}

#userCount svg { color: var(--accent); }

#themeToggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
}

#session-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 1100px;
  margin-bottom: 20px;
}

#session-controls input[type="text"]#sessionIdInput {
  flex: 1;
  min-width: 0;
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: 'DM Mono', monospace;
  font-size: 14px;
  padding: 0 14px;
  height: 42px;
  border-radius: var(--radius);
  outline: none;
}

#joinButton {
  height: 42px;
  padding: 0 22px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  font-size: 14px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
  flex-shrink: 0;
}
#joinButton:hover { background: var(--accent-hover); }
#joinButton.leaving {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}
#joinButton.leaving:hover { background: var(--danger); color: #fff; }

/* PIN right after Join — no far-right gap */
.pin-cluster {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.pin-cluster.is-hidden {
  display: none !important;
}
.pin-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 42px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}
.pin-toggle-btn:hover { border-color: var(--accent); color: var(--text); }
.pin-toggle-btn[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 12%, var(--input-bg));
}
.pin-toggle-label { font-weight: 600; letter-spacing: 0.02em; }
.pin-switch {
  width: 32px;
  height: 18px;
  border-radius: 9px;
  background: var(--surface-2, #e8e6e0);
  border: 1px solid var(--border);
  position: relative;
  flex-shrink: 0;
  transition: background 0.2s, border-color 0.2s;
}
.pin-switch::after {
  content: '';
  position: absolute;
  top: 1px;
  left: 1px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: left 0.2s ease, background 0.2s;
}
.pin-toggle-btn[aria-pressed="true"] .pin-switch {
  background: color-mix(in srgb, var(--accent) 30%, transparent);
  border-color: var(--accent);
}
.pin-toggle-btn[aria-pressed="true"] .pin-switch::after {
  left: 15px;
  background: var(--accent);
}

.pin-field-wrap {
  display: flex;
  align-items: center;
  max-width: 0;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
  transition: max-width 0.28s ease, opacity 0.18s ease, margin 0.28s ease;
  margin-left: 0;
}
.pin-field-wrap.open {
  max-width: 110px;
  opacity: 1;
  pointer-events: auto;
  margin-left: 2px;
}
.pin-input {
  width: 92px;
  height: 42px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--text);
  font-family: 'DM Mono', monospace;
  font-size: 15px;
  letter-spacing: 0.28em;
  text-align: center;
  outline: none;
  flex-shrink: 0;
}
.pin-input::placeholder {
  letter-spacing: 0.12em;
  color: var(--text-muted);
}
.pin-input:focus { border-color: var(--accent); }

@keyframes pin-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
.pin-input.pin-shake {
  animation: pin-shake 0.4s ease;
  border-color: var(--danger, #e05c5c);
}


/* Legacy gate unused — single PIN field on join row */
#pinGate { display: none !important; }
.pin-gate {
  display: none;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  margin-left: auto;
  height: 42px;
}
.pin-gate[hidden] { display: none !important; }
#session-controls.pin-gate-active #joinButton,
#session-controls.pin-gate-active .pin-cluster,
#session-controls.pin-gate-active #playlistToggleBtn {
  display: none !important;
}
#session-controls.pin-gate-active .pin-gate {
  display: inline-flex;
}
/* Keep name field the same size as normal join row */
#session-controls.pin-gate-active input[type="text"]#sessionIdInput {
  flex: 1;
  min-width: 0;
  max-width: none;
}
.pin-gate-label {
  display: inline-flex;
  align-items: center;
  height: 42px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
  line-height: 1;
}
.pin-gate-label strong {
  color: var(--accent);
  font-weight: 600;
  margin-right: 4px;
}
.pin-gate .pin-input {
  width: 96px;
  height: 42px;
  flex-shrink: 0;
  letter-spacing: 0.2em;
}
.pin-gate .pin-input::placeholder {
  letter-spacing: 0.2em;
}
.pin-gate .btn-primary,
.pin-gate .btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 42px;
  padding: 0 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1;
  box-sizing: border-box;
}
.pin-gate .btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  border: none;
}
.pin-gate .btn-ghost {
  background: var(--input-bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
}


/* Room PIN (header, left of Share) */
.room-pin-menu {
  position: relative;
  display: none;
  align-items: center;
}
.room-pin-menu.visible {
  display: flex;
}
.room-pin-btn {
  color: var(--text-muted);
}
.room-pin-btn:hover,
.room-pin-btn[aria-expanded="true"] {
  color: var(--accent);
  border-color: var(--accent);
}
.room-pin-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 180px;
  padding: 12px 14px;
  background: var(--surface, var(--input-bg));
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 10px 28px rgba(0,0,0,0.12);
  z-index: 300;
}
.room-pin-popover[hidden] { display: none !important; }
.room-pin-popover-title {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}
.room-pin-popover-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.room-pin-value {
  font-family: 'DM Mono', monospace;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.2em;
  color: var(--text);
  flex: 1;
}
.room-pin-copy {
  height: 34px;
  padding: 0 12px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-text);
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
/* Discord header control */
.discord-menu {
  position: relative;
  display: none;
  align-items: center;
}
.discord-menu.visible {
  display: flex;
}
.header-icon-btn,
.discord-header-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
  position: relative;
}
.discord-header-btn:hover {
  border-color: #5865F2;
  color: #c9cdfb;
}
.discord-header-btn.has-invite {
  border-color: rgba(88, 101, 242, 0.55);
  color: #c9cdfb;
}
.discord-dot {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #5865F2;
  box-shadow: 0 0 0 2px var(--surface, #1a1a1e);
}
.discord-dot[hidden] { display: none !important; }
.discord-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: min(300px, 86vw);
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 32px rgba(0,0,0,0.4);
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.discord-popover[hidden] { display: none !important; }
.discord-popover-title {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}
#discordInviteInput {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  font-size: 13px;
  outline: none;
  box-sizing: border-box;
}
#discordInviteInput:focus {
  border-color: #5865F2;
}
.discord-popover-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.discord-popover-actions .btn-primary,
.discord-popover-actions .btn-ghost {
  height: 34px;
  padding: 0 14px;
  font-size: 13px;
  border-radius: var(--radius);
  cursor: pointer;
}
.discord-popover-actions .btn-primary {
  background: #5865F2;
  color: #fff;
  border: none;
  font-weight: 600;
}
.discord-popover-actions .btn-primary:hover {
  background: #4752c4;
}
.discord-popover-actions .btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.discord-popover-actions .btn-ghost:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#shareButton {
  display: none;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}
#shareButton.visible {
  display: flex;
}
#shareButton:hover { border-color: var(--accent); color: var(--accent); }

/* ── Presence toast ── */
#presence-toast {
  position: fixed;
  top: 72px;
  left: 20px;
  max-width: min(320px, calc(100vw - 40px));
  font-family: 'DM Sans', sans-serif;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--notif-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 12px;
  z-index: 150;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 6px 16px rgba(0,0,0,0.08);
}
#presence-toast.visible {
  opacity: 1;
  transform: translateY(0);
}

#player-container {
  position: relative;
  width: 100%;
  max-width: 1100px;
  background: #000;
  border-radius: var(--radius-lg);
  overflow: hidden;
  aspect-ratio: 16 / 9;
  max-height: 70vh;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

#subtitle-display {
  display: none;
  position: absolute;
  bottom: 54px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 90%;
  text-align: center;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  font-size: 18px;
  line-height: 1.5;
  padding: 4px 14px;
  border-radius: 4px;
  pointer-events: none;
  white-space: pre-line;
  z-index: 5;
}

#videoPlayer { width: 100%; height: 100%; display: block; }
#youtubeContainer { position: relative; width: 100%; height: 100%; }


#sync-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.58);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 40;
  cursor: pointer;
  border-radius: inherit;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  padding: 20px;
}

#sync-overlay.visible,
#sync-overlay[style*="flex"] {
  display: flex;
}

#sync-overlay-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  pointer-events: none;
  text-align: center;
  max-width: 280px;
  padding: 28px 24px;
  border-radius: 20px;
  background: rgba(20, 20, 24, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}

.sync-play-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, var(--accent, #e8a838), #c4841f);
  color: #111;
  box-shadow: 0 8px 24px rgba(232, 168, 56, 0.35);
  margin-bottom: 4px;
}

.sync-play-btn svg {
  margin-left: 3px;
}

.sync-title {
  font-size: 18px;
  font-weight: 650;
  color: #fff;
  letter-spacing: 0.01em;
  line-height: 1.25;
}

.sync-sub {
  font-size: 13px;
  font-weight: 450;
  color: rgba(255, 255, 255, 0.72);
  line-height: 1.4;
}

@media (max-width: 640px) {
  #sync-overlay-inner {
    max-width: min(300px, 86vw);
    padding: 26px 22px;
    gap: 10px;
  }
  .sync-play-btn {
    width: 80px;
    height: 80px;
  }
  .sync-play-btn svg {
    width: 32px;
    height: 32px;
  }
  .sync-title {
    font-size: 19px;
  }
  .sync-sub {
    font-size: 13.5px;
  }
}

#controls {
  width: 100%;
  max-width: 1100px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.controls-row { display: flex; align-items: center; gap: 10px; }
.controls-row + .controls-row { padding-top: 12px; border-top: 1px solid var(--border); }

label.file-btn, label.subtitle-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 13px;
  border-radius: var(--radius);
  cursor: pointer;
  height: 42px;
  transition: border-color 0.2s, color 0.2s;
}

label.subtitle-btn.active {
  border-color: var(--accent);
  color: var(--accent);
}

#urlInput {
  flex: 1; height: 42px; background: var(--input-bg); border: 1px solid var(--border);
  color: var(--text); padding: 0 14px; border-radius: var(--radius); outline: none;
  transition: border-color 0.2s;
}

#urlInput.awaiting-file {
  border-color: var(--accent);
  color: var(--accent);
  font-size: 13px;
}

.btn-primary {
  height: 42px; padding: 0 20px; background: var(--accent);
  color: var(--accent-text); font-weight: 600; border: none; border-radius: var(--radius);
  cursor: pointer;
}

.btn-ghost {
  height: 42px; padding: 0 16px; background: transparent; color: var(--text-muted);
  border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer;
}

.goto-wrap {
  position: relative;
  width: 170px;
  flex-shrink: 0;
}
#gotoInput {
  width: 100%; height: 38px; background: var(--input-bg); border: 1px solid var(--border);
  color: var(--text); font-family: 'DM Mono', monospace; padding: 0 12px; border-radius: var(--radius);
  box-sizing: border-box;
}
#gotoInput:focus {
  outline: none;
  border-color: var(--accent);
}

#gotoButton {
  height: 38px; padding: 0 16px; background: var(--surface-2); color: var(--text-muted);
  border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer;
}

/* Time wheels under the same-sized field */
.goto-wheels {
  position: absolute;
  left: 0;
  top: calc(100% + 6px);
  width: 170px;
  z-index: 80;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 0 18px;
  overflow: hidden;
  isolation: isolate;
}
.goto-wheels[hidden] { display: none !important; }
.goto-wheels-inner {
  display: flex;
  justify-content: center;
  gap: 0;
  height: 126px;
  position: relative;
  z-index: 1;
}
.goto-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}
.goto-col-label {
  position: absolute;
  top: 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  text-align: center;
  width: 33.33%;
  pointer-events: none;
}
.goto-col[data-unit="h"] .goto-col-label { left: 0; }
.goto-col[data-unit="m"] .goto-col-label { left: 33.33%; }
.goto-col[data-unit="s"] .goto-col-label { left: 66.66%; }
.goto-drum {
  flex: 1;
  height: 126px;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
  -ms-overflow-style: none;
  text-align: center;
  font-family: 'DM Mono', monospace;
  font-size: 14px;
  color: var(--text-muted);
}
.goto-drum::-webkit-scrollbar { display: none; }
.goto-drum-item {
  height: 36px;
  line-height: 36px;
  scroll-snap-align: center;
  user-select: none;
}
.goto-wheels-select {
  position: absolute;
  left: 8px;
  right: 8px;
  top: 50%;
  height: 36px;
  margin-top: -6px;
  transform: translateY(-50%);
  border-radius: 6px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border));
  pointer-events: none;
  z-index: 0;
}
.goto-wheels-fade {
  position: absolute;
  left: 0;
  right: 0;
  height: 40px;
  pointer-events: none;
  z-index: 2;
}
.goto-wheels-fade-top {
  top: 18px;
  background: linear-gradient(to bottom, var(--surface), transparent);
}
.goto-wheels-fade-bot {
  bottom: 0;
  background: linear-gradient(to top, var(--surface), transparent);
}

input[type="file"] { display: none; }

#notification, #error-notification, #mismatch-warning {
  position: fixed;
  top: 16px;
  right: 16px;
  max-width: min(360px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.35;
  display: none;
  z-index: 400;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  word-wrap: break-word;
  overflow-wrap: anywhere;
  pointer-events: none;
}
#notification {
  background: var(--notif-bg);
  border: 1px solid var(--border);
  color: var(--text);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
#error-notification {
  background: rgba(224,80,80,0.14);
  border: 1px solid rgba(224,80,80,0.4);
  color: #e05050;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
#mismatch-warning {
  background: rgba(224,80,80,0.14);
  border: 1px solid rgba(224,80,80,0.4);
  color: #e05050;
  top: 64px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}


@media (max-width: 1200px) {
  #userCount { position: static; margin-left: 16px; }
  #header-inner { margin: 0; max-width: none; }
}

@media (max-width: 650px) {
  #app-header { height: auto; padding: 10px 0; }
  #header-inner { flex-direction: row; flex-wrap: wrap; gap: 10px; }
  .controls-row { flex-wrap: wrap; }
}
/* ── Resume modal ── */
#resume-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

#resume-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 32px;
  max-width: 520px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

#resume-message {
  font-size: 15px;
  line-height: 1.7;
  color: var(--text);
  margin-bottom: 24px;
  word-break: break-word;
}

#resume-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

#resume-actions .btn-primary,
#resume-actions .btn-ghost {
  height: 38px;
  font-size: 13px;
}
/* ── v2 additions: clock, status, fullscreen ───────────────── */

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.room-clock {
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  min-width: 0;
  white-space: nowrap;
}

.status-chip {
  font-size: 11px;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  white-space: nowrap;
  border: 1px solid var(--border);
}
.status-chip:empty,
.status-chip[data-empty="1"] {
  display: none !important;
  padding: 0;
  border: none;
}

.status-chip[data-tone="ok"] {
  color: #6bcf8e;
  border-color: rgba(107, 207, 142, 0.25);
  background: rgba(107, 207, 142, 0.08);
}

.status-chip[data-tone="warn"] {
  color: var(--accent);
  border-color: rgba(232, 168, 56, 0.3);
  background: var(--accent-dim);
}

.status-chip[data-tone="muted"] {
  color: var(--text-muted);
}

#player-container {
  position: relative;
  width: min(100%, 1100px);
  max-height: calc(100svh - 16rem);
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border);
}

#player-container:fullscreen,
#player-container:-webkit-full-screen {
  max-height: none;
  width: 100%;
  height: 100%;
  border-radius: 0;
  aspect-ratio: auto;
}

#videoPlayer,
#youtubeContainer,
#youtubePlayer {
  width: 100%;
  height: 100%;
  display: block;
  background: #000;
}

#youtubeContainer {
  position: absolute;
  inset: 0;
}

.fs-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 30;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}

#player-container:hover .fs-btn,
#player-container:focus-within .fs-btn {
  opacity: 1;
}

.fs-btn:hover {
  background: rgba(0, 0, 0, 0.75);
  border-color: rgba(255, 255, 255, 0.3);
}

#subtitle-display {
  position: absolute;
  left: 50%;
  bottom: 12%;
  transform: translateX(-50%);
  max-width: 90%;
  padding: 6px 14px;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  font-size: clamp(14px, 2.2vw, 20px);
  line-height: 1.35;
  text-align: center;
  border-radius: 6px;
  pointer-events: none;
  z-index: 20;
  white-space: pre-wrap;
}

@media (max-width: 640px) {
  .room-clock { display: none; }
  .status-chip { font-size: 10px; padding: 2px 6px; }
  #player-container {
    max-height: calc(100svh - 18rem);
  }
}


/* YouTube stage — keep iframe visible and sized */
#player-container {
  position: relative;
  width: min(100%, 1100px);
  max-height: calc(100svh - 16rem);
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border);
}

#videoPlayer {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

#youtubeContainer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #000;
  z-index: 1;
}

#youtubeContainer iframe,
#youtubePlayer {
  width: 100% !important;
  height: 100% !important;
  border: 0;
  display: block;
}

#videoPlayer[style*="display: none"],
#videoPlayer[style*="display:none"] {
  pointer-events: none;
}


/* Nudge attention to Load after a local file is chosen */
@keyframes load-pulse-anim {
  0%   { box-shadow: 0 0 0 0 rgba(232, 168, 56, 0.7); transform: scale(1); }
  40%  { box-shadow: 0 0 0 8px rgba(232, 168, 56, 0); transform: scale(1.04); }
  100% { box-shadow: 0 0 0 0 rgba(232, 168, 56, 0); transform: scale(1); }
}

#loadButton.load-pulse {
  animation: load-pulse-anim 0.7s ease-out 2;
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}


/* Room waiting / catch-up overlay */
#wait-overlay {
  position: absolute;
  inset: 0;
  z-index: 25;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  border-radius: inherit;
  pointer-events: none;
}

#wait-overlay.visible {
  display: flex;
}

#wait-overlay-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  color: #fff;
  font-size: 15px;
  font-weight: 500;
  text-align: center;
  padding: 16px 20px;
}

.wait-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top-color: var(--accent, #e8a838);
  border-radius: 50%;
  animation: wait-spin 0.8s linear infinite;
}

@keyframes wait-spin {
  to { transform: rotate(360deg); }
}

/*
 * Player column stays fixed (same as session-controls / controls).
 * Playlist docks outside to the right — does not resize or shift the player.
 */
#stage-row {
  position: relative;
  width: 100%;
  max-width: 1100px;
  margin-bottom: 12px;
}
#stage-row #player-container {
  width: 100%;
  max-width: 100%;
  margin-bottom: 0;
}
.playlist-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 42px;
  padding: 0 14px;
  flex-shrink: 0;
}
.playlist-badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}
.playlist-badge[hidden] { display: none !important; }

.playlist-panel {
  display: none;
  flex-direction: column;
  width: 100%;
  max-width: 1100px;
  margin-top: 12px;
  max-height: 460px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.playlist-panel:not([hidden]) {
  display: flex;
}

/* Wide screens: playlist docks to the right of the player (same height).
   Narrower screens and phones: it sits under the Load Video section. */
#layout {
  position: relative;
  width: 100%;
  max-width: 1100px;
  display: flex;
  flex-direction: column;
}
@media (min-width: 1691px) {
  .playlist-panel {
    position: absolute;
    left: calc(100% + 14px);
    top: 0;
    width: clamp(280px, calc((100vw - 1100px) / 2 - 28px), 360px);
    margin-top: 0;
    max-height: none;
    box-shadow: var(--shadow);
    z-index: 40;
  }
}
.playlist-panel[hidden] {
  display: none !important;
}
.playlist-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.playlist-title {
  font-size: 13px;
  font-weight: 600;
}
.playlist-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.playlist-autoplay {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}
.toggle-switch {
  position: relative;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}
.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: background 0.15s, border-color 0.15s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  left: 2px;
  top: 2px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: transform 0.15s, background 0.15s;
}
.toggle-switch input:checked + .toggle-slider {
  background: var(--accent-dim);
  border-color: var(--accent);
}
.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(16px);
  background: var(--accent);
}
.playlist-item .pl-icon.file {
  color: var(--accent);
}
.playlist-icon-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
}
.playlist-toolbar {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid var(--border);
}
.playlist-toolbar .pl-tool-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 500;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.playlist-toolbar .pl-tool-btn:hover {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--text);
}
.playlist-toolbar .pl-tool-btn svg {
  flex-shrink: 0;
  opacity: 0.85;
}
.playlist-drop {
  flex: 1;
  overflow: auto;
  position: relative;
  min-height: 120px;
}
.playlist-drop.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: -4px;
  background: var(--accent-dim);
}
.playlist-drop-hint {
  display: none;
  margin: 0;
  padding: 24px 12px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
}
.playlist-drop.drag-over .playlist-drop-hint {
  display: block;
}
.playlist-empty {
  margin: 0;
  padding: 28px 14px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
}
.playlist-empty[hidden] { display: none !important; }
.playlist-list {
  list-style: none;
  margin: 0;
  padding: 6px;
}
.playlist-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid transparent;
}
.playlist-item:hover {
  background: var(--surface-2);
}
.playlist-item.active {
  border-color: var(--accent);
  background: var(--accent-dim);
}
.playlist-item .pl-handle {
  cursor: grab;
  color: var(--text-muted);
  font-size: 12px;
  user-select: none;
  padding: 2px 4px;
}
.playlist-item .pl-icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  color: var(--text-muted);
}
.playlist-item .pl-icon.yt { color: #f44; }
.playlist-item .pl-body {
  flex: 1;
  min-width: 0;
}
.playlist-item .pl-title {
  font-size: 12px;
  font-weight: 500;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
.playlist-item .pl-sub {
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.playlist-item .pl-match {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
  font-weight: 700;
}
.playlist-item .pl-match.ok {
  background: rgba(30, 166, 114, 0.2);
  color: #1ea672;
}
.playlist-item .pl-match.wait {
  background: rgba(232, 168, 56, 0.2);
  color: #c4922a;
}
.playlist-item .pl-match.miss {
  background: rgba(224, 80, 80, 0.15);
  color: #e05050;
}
.playlist-item.dragging {
  opacity: 0.45;
}
.playlist-item.drag-over {
  box-shadow: inset 0 2px 0 0 var(--accent);
}
.playlist-item .pl-remove {
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 4px;
}
.playlist-item .pl-remove:hover {
  color: var(--danger);
  background: rgba(224, 80, 80, 0.1);
}

/* Playlist footer: subtle clear icon + inline confirmation */
.playlist-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 6px 10px;
  border-top: 1px solid var(--border);
  min-height: 40px;
}
.pl-clear-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  opacity: 0.55;
  cursor: pointer;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
}
.pl-clear-btn:hover,
.pl-clear-btn:focus-visible {
  opacity: 1;
  color: var(--danger);
  background: rgba(224, 80, 80, 0.1);
}
.pl-clear-confirm {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}
.pl-clear-confirm[hidden], .pl-clear-btn[hidden] { display: none !important; }
.pl-clear-confirm button {
  height: 28px;
  padding: 0 12px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
}
.pl-clear-confirm .pl-confirm-yes {
  border-color: rgba(224, 80, 80, 0.45);
  color: var(--danger);
}
.pl-clear-confirm .pl-confirm-yes:hover { background: rgba(224, 80, 80, 0.12); }
.pl-clear-confirm .pl-confirm-no:hover { background: var(--surface-2); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ───────────── Mobile ───────────── */
@media (max-width: 640px) {
  body { padding: 0 12px calc(24px + env(safe-area-inset-bottom)); }

  /* Header: one tidy row */
  #app-header { height: 52px; padding: 0; margin-bottom: 12px; gap: 10px; }
  #header-inner { flex-wrap: nowrap; gap: 8px; padding: 0 2px; }
  #userCount {
    position: static;
    margin-left: 4px;
    margin-right: 4px;
    gap: 8px; /* space between person icon and number */
    flex-shrink: 0;
  }
  #header-logo { display: none; }
  .header-right { gap: 8px; margin-left: auto; }
  #themeToggle, #shareButton, .header-icon-btn, .discord-header-btn { width: 40px; height: 40px; }

  /* Session row: name + Join on one line, Playlist full width underneath */
  #session-controls { flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
  #session-controls input[type="text"]#sessionIdInput {
    height: 46px;
    font-size: 16px;
    min-width: 0;
  }
  #joinButton { height: 46px; }
  .pin-toggle-btn, .pin-input, .pin-gate .btn-primary, .pin-gate .btn-ghost { height: 46px; }
  .pin-gate { flex-wrap: wrap; }
  .playlist-toggle-btn { height: 44px; width: 100%; justify-content: center; }

  /* Player: edge to edge and pinned while you scroll the rest */
  #stage-row {
    position: sticky;
    top: 52px;
    z-index: 60;
    width: calc(100% + 24px);
    margin: 0 -12px 12px;
  }
  #stage-row #player-container,
  #player-container {
    border-radius: 0;
    border-left: none;
    border-right: none;
    max-height: 42svh;
  }
  #player-container:fullscreen { max-height: none; }
  .fs-btn { opacity: 1; width: 40px; height: 40px; }

  /* Load / subtitle controls: big touch targets */
  #controls { padding: 14px; gap: 10px; }
  .controls-row { flex-wrap: wrap; gap: 8px; }
  #urlInput { order: -1; flex: 1 0 100%; height: 46px; font-size: 16px; }
  label.file-btn, #loadButton, #clearButton { flex: 1 1 0; height: 46px; justify-content: center; }
  label.file-btn { padding: 0 8px; }
  #clearButton { flex: 0 0 auto; padding: 0 16px; }
  label.subtitle-btn { height: 44px; flex: 0 0 auto; }
  .goto-wrap { flex: 1 1 0; min-width: 0; width: auto; }
  #gotoInput { width: 100%; height: 44px; font-size: 16px; }
  .goto-wheels { width: 100%; }
  #gotoButton { height: 44px; padding: 0 14px; }

  /* Playlist: roomy rows, finger-sized buttons */
  .playlist-panel { max-height: none; }
  .playlist-toolbar .pl-tool-btn { height: 44px; font-size: 13px; }
  .playlist-icon-btn { width: 40px; height: 40px; font-size: 22px; }
  .playlist-item { padding: 10px 8px; min-height: 56px; }
  .playlist-item .pl-title { font-size: 14px; }
  .playlist-item .pl-sub { font-size: 11px; }
  .playlist-item .pl-remove { font-size: 18px; width: 40px; height: 40px; }
  .playlist-item .pl-handle { display: none; }
  .pl-clear-btn { width: 40px; height: 40px; }
  .pl-clear-confirm button { height: 36px; padding: 0 16px; }

  /* Toasts: bottom bar above home indicator, not over sticky player/header */
  #notification, #error-notification, #mismatch-warning {
    top: auto;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    left: 12px;
    right: 12px;
    max-width: none;
    width: auto;
    text-align: center;
    font-size: 14px;
    padding: 12px 14px;
    border-radius: 12px;
    z-index: 400;
    box-shadow: 0 10px 28px rgba(0,0,0,0.18);
  }
  #mismatch-warning {
    bottom: calc(64px + env(safe-area-inset-bottom, 0px));
  }
  #presence-toast {
    top: auto;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    left: 12px;
    right: 12px;
    max-width: none;
    text-align: center;
    white-space: normal;
  }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
