/* ============================================================
   Screening Room — visual identity
   A private cinema, not a dashboard: a dim room, one warm light
   source (the projector beam), and marquee-scaled numerals for
   the one truly memorable artifact — the room code.
   ============================================================ */

:root {
  --ink: #14151c;          /* main background: near-black indigo */
  --curtain: #221a2b;      /* panel background: deep aubergine */
  --curtain-raised: #2b2135;
  --line: rgba(226, 220, 240, 0.1);
  --projector: #e8a33d;    /* primary accent: warm projector light */
  --projector-dim: #a8752c;
  --screen: #f3ede1;       /* warm off-white for high-emphasis text */
  --ember: #d1495b;        /* destructive / "ending" actions */
  --mist: #948fa3;         /* secondary text */
  --mist-faint: #625d72;

  --serif: ui-serif, Georgia, "Iowan Old Style", "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --radius-sm: 3px;
  --radius-md: 6px;
}

* { box-sizing: border-box; }
*, *::before, *::after { box-sizing: inherit; }

html {
  box-sizing: border-box;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 0;
  background: var(--ink);
  color: var(--screen);
  font-family: var(--sans);
  min-height: 100vh;
  overflow-x: hidden;
  max-width: 100vw;
  background-image:
    radial-gradient(ellipse 900px 500px at 50% -10%, rgba(232, 163, 61, 0.09), transparent 60%);
  background-attachment: fixed;
}

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

a { color: inherit; }

h1, h2, h3 {
  font-family: var(--serif);
  font-weight: 500;
  letter-spacing: -0.01em;
  margin: 0;
}

p { color: var(--mist); line-height: 1.5; }

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
}

.brand-block {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.brand {
  font-family: var(--serif);
  font-size: 1.3rem;
  letter-spacing: -0.02em;
  color: var(--screen);
  display: flex;
  align-items: baseline;
  gap: 8px;
  cursor: pointer;
  border-radius: 3px;
  padding: 4px 6px;
  margin: -4px -6px;
  transition: background 0.15s ease;
  text-decoration: none;
}
.brand:hover { background: rgba(243, 237, 225, 0.06); }
.brand .dot { color: var(--projector); }

.brand-credit {
  color: var(--mist);
  font-size: 0.74rem;
  letter-spacing: 0.04em;
  text-transform: none;
  text-decoration: none;
  opacity: 0.9;
  transition: color 0.15s ease, opacity 0.15s ease;
}
.brand-credit:hover { color: var(--screen); opacity: 1; }

.whoami {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.9rem;
  color: var(--mist);
}
.whoami .avatar-sm {
  width: 28px; height: 28px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--serif); font-size: 0.9rem; color: var(--ink); font-weight: 600;
}

button {
  font-family: var(--sans);
  cursor: pointer;
  border: none;
  border-radius: var(--radius-md);
  padding: 11px 20px;
  font-size: 0.95rem;
  font-weight: 600;
  transition: transform 0.08s ease, opacity 0.15s ease;
}
button:active { transform: scale(0.98); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary { background: var(--projector); color: #241704; }
.btn-primary:hover:not(:disabled) { background: #f0ad4f; }

.btn-ghost { background: transparent; color: var(--screen); border: 1px solid var(--line); }
.btn-ghost:hover:not(:disabled) { border-color: var(--mist); }

.btn-danger { background: transparent; color: var(--ember); border: 1px solid rgba(209, 73, 91, 0.4); }
.btn-danger:hover:not(:disabled) { background: rgba(209, 73, 91, 0.12); }

.btn-small { padding: 7px 14px; font-size: 0.85rem; }

input[type="text"], input[type="password"], input[type="tel"] {
  font-family: var(--sans);
  background: var(--ink);
  border: 1px solid var(--line);
  color: var(--screen);
  border-radius: var(--radius-md);
  padding: 11px 14px;
  font-size: 0.95rem;
  width: 100%;
}
input:focus {
  outline: 2px solid var(--projector);
  outline-offset: 1px;
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--mist);
  margin-bottom: 6px;
}

.field { margin-bottom: 18px; }

.panel {
  background: var(--curtain);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 28px;
}

.error-text {
  color: var(--ember);
  font-size: 0.88rem;
  margin-top: 8px;
  min-height: 1.2em;
}
.hint-text {
  color: var(--mist-faint);
  font-size: 0.82rem;
  margin-top: 8px;
}

/* ---------- Profile picker ("Who's watching?") ---------- */

.picker-stage {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}

.picker-stage h1 {
  font-size: 2.1rem;
  color: var(--screen);
  margin-bottom: 40px;
  text-align: center;
}

.profile-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 28px;
  justify-content: center;
  max-width: 720px;
}

.profile-tile {
  background: none;
  border: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 128px;
}

.profile-tile .avatar {
  width: 108px;
  height: 108px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--serif);
  font-size: 2.4rem;
  color: rgba(20, 21, 28, 0.85);
  border: 2px solid transparent;
  transition: border-color 0.12s ease, transform 0.12s ease;
}

.profile-tile:hover .avatar,
.profile-tile:focus-visible .avatar {
  border-color: var(--screen);
  transform: translateY(-2px);
}

.profile-tile .name {
  font-size: 0.95rem;
  color: var(--mist);
}
.profile-tile:hover .name { color: var(--screen); }

.profile-tile .lock {
  font-size: 0.72rem;
  color: var(--mist-faint);
}

.add-profile-note {
  margin-top: 36px;
  color: var(--mist-faint);
  font-size: 0.85rem;
  text-align: center;
}

.pin-modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(10, 10, 14, 0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.pin-modal {
  background: var(--curtain-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 32px;
  width: 320px;
  text-align: center;
}
.pin-modal .avatar { margin: 0 auto 16px; }
.pin-modal input {
  text-align: center;
  letter-spacing: 0.4em;
  font-size: 1.3rem;
  font-family: var(--serif);
}
.pin-modal .actions { display: flex; gap: 10px; margin-top: 18px; }
.pin-modal .actions button { flex: 1; }

/* ---------- Lobby ---------- */

.lobby-grid {
  display: grid;
  grid-template-columns: 1fr 1.3fr;
  gap: 28px;
  padding: 40px 0 80px;
}
@media (max-width: 760px) {
  .lobby-grid { grid-template-columns: 1fr; }
}

.lobby-grid h2 {
  font-size: 1.3rem;
  color: var(--screen);
  margin-bottom: 6px;
}
.lobby-grid .panel > p.section-sub {
  margin: 0 0 20px;
  font-size: 0.88rem;
}

.room-code-reveal {
  text-align: center;
  padding: 30px 0 10px;
}
.room-code-reveal .label {
  font-size: 0.82rem;
  color: var(--mist);
  margin-bottom: 10px;
}
.room-code-reveal .code {
  font-family: var(--serif);
  font-size: 3.4rem;
  letter-spacing: 0.12em;
  color: var(--projector);
  line-height: 1;
}

.join-row {
  display: flex;
  gap: 10px;
  margin-bottom: 28px;
}
.join-row input { text-transform: uppercase; letter-spacing: 0.08em; }

.room-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.room-list-item {
  background: var(--curtain);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.room-list-item .stub {
  border-left: 2px dashed var(--mist-faint);
  padding-left: 14px;
  margin-left: 2px;
}
.room-list-item .r-name { color: var(--screen); font-size: 0.98rem; }
.room-list-item .r-meta { color: var(--mist-faint); font-size: 0.8rem; margin-top: 2px; }
.room-list-item .r-private-badge {
  font-size: 0.65rem;
  color: var(--mist-faint);
  background: rgba(148, 143, 163, 0.12);
  border: 1px solid var(--line);
  padding: 1px 6px;
  border-radius: 100px;
  margin-left: 6px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.room-list-empty {
  padding: 30px 18px;
  text-align: center;
  color: var(--mist-faint);
  background: var(--curtain);
  border-radius: var(--radius-md);
}

.perm-note {
  background: var(--curtain);
  border: 1px dashed var(--line);
  border-radius: var(--radius-md);
  padding: 18px;
  color: var(--mist);
  font-size: 0.88rem;
}

/* ---------- Room / player ---------- */

.stage {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.stage-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
}
.stage-header .room-title { display: flex; align-items: baseline; gap: 10px; }
.stage-header .room-title .code-chip {
  font-family: var(--serif);
  color: var(--projector);
  letter-spacing: 0.1em;
  font-size: 1rem;
}
.viewer-count {
  display: flex; align-items: center; gap: 6px;
  color: var(--mist); font-size: 0.85rem;
}
.viewer-count .bulb {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--projector);
  box-shadow: 0 0 8px 1px rgba(232, 163, 61, 0.7);
}

.screen-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  padding: 20px;
  min-height: 0;
}
.screen-wrap video {
  max-width: 100%;
  max-height: 78vh;
  background: #000;
  border-radius: 2px;
}

/* Crunchyroll Subtitle Styling for WebVTT ::cue in normal & fullscreen */
::cue,
video::cue,
*::cue {
  font-family: var(--sub-font-family, "Trebuchet MS", "Lucida Sans Unicode", -apple-system, sans-serif);
  font-weight: 700;
  color: var(--sub-color, #ffffff);
  background-color: var(--sub-bg, transparent);
  text-shadow: var(--sub-text-shadow,
    -2px -2px 0 #000,
     2px -2px 0 #000,
    -2px  2px 0 #000,
     2px  2px 0 #000,
    -2px  0px 0 #000,
     2px  0px 0 #000,
     0px -2px 0 #000,
     0px  2px 0 #000,
    -1px -1px 0 #000,
     1px -1px 0 #000,
    -1px  1px 0 #000,
     1px  1px 0 #000);
  font-size: clamp(12px, 3.2vmin, 26px);
  line-height: 1.35;
  white-space: pre-line;
}

/* Fullscreen Subtitles - Standard */
:fullscreen::cue,
video:fullscreen::cue,
.screen-wrap:fullscreen video::cue,
:fullscreen video::cue {
  font-size: clamp(14px, 5.2vmin, 60px);
  text-shadow: var(--sub-fullscreen-shadow,
    -3.5px -3.5px 0 #000,
     3.5px -3.5px 0 #000,
    -3.5px  3.5px 0 #000,
     3.5px  3.5px 0 #000,
    -3.5px  0px 0 #000,
     3.5px  0px 0 #000,
     0px -3.5px 0 #000,
     0px  3.5px 0 #000,
    -2.5px -2.5px 0 #000,
     2.5px -2.5px 0 #000,
    -2.5px  2.5px 0 #000,
     2.5px  2.5px 0 #000,
     0px  0px 6px rgba(0, 0, 0, 0.95));
}

/* Fullscreen Subtitles - Firefox Gecko */
:-moz-full-screen::cue,
video:-moz-full-screen::cue,
.screen-wrap:-moz-full-screen video::cue,
:-moz-full-screen video::cue {
  font-size: clamp(14px, 5.2vmin, 60px);
  text-shadow: var(--sub-fullscreen-shadow,
    -3.5px -3.5px 0 #000,
     3.5px -3.5px 0 #000,
    -3.5px  3.5px 0 #000,
     3.5px  3.5px 0 #000,
    -3.5px  0px 0 #000,
     3.5px  0px 0 #000,
     0px -3.5px 0 #000,
     0px  3.5px 0 #000,
    -2.5px -2.5px 0 #000,
     2.5px -2.5px 0 #000,
    -2.5px  2.5px 0 #000,
     2.5px  2.5px 0 #000,
     0px  0px 6px rgba(0, 0, 0, 0.95));
}

/* Fullscreen Subtitles - WebKit & Blink */
:-webkit-full-screen::cue,
video:-webkit-full-screen::cue,
.screen-wrap:-webkit-full-screen video::cue,
:-webkit-full-screen video::cue {
  font-size: clamp(14px, 5.2vmin, 60px);
  text-shadow: var(--sub-fullscreen-shadow,
    -3.5px -3.5px 0 #000,
     3.5px -3.5px 0 #000,
    -3.5px  3.5px 0 #000,
     3.5px  3.5px 0 #000,
    -3.5px  0px 0 #000,
     3.5px  0px 0 #000,
     0px -3.5px 0 #000,
     0px  3.5px 0 #000,
    -2.5px -2.5px 0 #000,
     2.5px -2.5px 0 #000,
    -2.5px  2.5px 0 #000,
     2.5px  2.5px 0 #000,
     0px  0px 6px rgba(0, 0, 0, 0.95));
}

/* Fullscreen Subtitles - Forgiving :is() selector */
:is(:fullscreen, :-webkit-full-screen, :-moz-full-screen)::cue,
video:is(:fullscreen, :-webkit-full-screen, :-moz-full-screen)::cue,
:is(:fullscreen, :-webkit-full-screen, :-moz-full-screen) video::cue {
  font-size: clamp(14px, 5.2vmin, 60px);
  text-shadow: var(--sub-fullscreen-shadow,
    -3.5px -3.5px 0 #000,
     3.5px -3.5px 0 #000,
    -3.5px  3.5px 0 #000,
     3.5px  3.5px 0 #000,
    -3.5px  0px 0 #000,
     3.5px  0px 0 #000,
     0px -3.5px 0 #000,
     0px  3.5px 0 #000,
    -2.5px -2.5px 0 #000,
     2.5px -2.5px 0 #000,
    -2.5px  2.5px 0 #000,
     2.5px  2.5px 0 #000,
     0px  0px 6px rgba(0, 0, 0, 0.95));
}

/* Fullscreen Subtitles - JS body class fallback */
body.is-video-fullscreen ::cue,
body.is-video-fullscreen video::cue,
video.is-video-fullscreen::cue {
  font-size: clamp(14px, 5.2vmin, 60px);
  text-shadow: var(--sub-fullscreen-shadow,
    -3.5px -3.5px 0 #000,
     3.5px -3.5px 0 #000,
    -3.5px  3.5px 0 #000,
     3.5px  3.5px 0 #000,
    -3.5px  0px 0 #000,
     3.5px  0px 0 #000,
     0px -3.5px 0 #000,
     0px  3.5px 0 #000,
    -2.5px -2.5px 0 #000,
     2.5px -2.5px 0 #000,
    -2.5px  2.5px 0 #000,
     2.5px  2.5px 0 #000,
     0px  0px 6px rgba(0, 0, 0, 0.95));
}

/* WebKit / Chromium text track container bottom clearance */
video::-webkit-media-text-track-container {
  bottom: var(--sub-bottom-offset, 8%) !important;
  overflow: visible !important;
}

.screen-wrap:fullscreen {
  width: 100vw;
  height: 100vh;
  padding: 0;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.screen-wrap:fullscreen video {
  max-width: 100vw;
  max-height: 100vh;
  width: 100vw;
  height: 100vh;
  object-fit: contain;
}

.screen-wrap video:fullscreen {
  max-width: 100%;
  max-height: 100vh;
  width: 100vw;
  height: 100vh;
  object-fit: contain;
  border-radius: 0;
}

/* Mobile inline expand — avoids the native fullscreen player that would break socket sync */
@media (max-width: 768px) {
  .screen-wrap.expanded {
    position: fixed;
    inset: 0;
    z-index: 40;
    padding: 0;
    background: #000;
  }
  .screen-wrap.expanded video {
    max-width: 100vw;
    max-height: 100vh;
    width: 100vw;
    height: 100vh;
    object-fit: contain;
    border-radius: 0;
  }
  .control-strip.expanded {
    display: none;
  }
}

.no-video-placeholder {
  text-align: center;
  color: var(--mist-faint);
  max-width: 360px;
}
.no-video-placeholder h3 { color: var(--mist); margin-bottom: 10px; font-size: 1.1rem; }

.control-strip {
  position: relative;
  padding: 18px 24px 26px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-top: 1px solid var(--line);
  min-height: 74px;
}
.control-strip .left {
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 1;
}
.control-strip .center {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  pointer-events: auto;
}
.control-strip .right {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
  z-index: 1;
}

.upload-label {
  display: inline-flex; align-items: center; gap: 8px;
  cursor: pointer;
}
.upload-label input[type="file"] { display: none; }

.role-badge {
  font-size: 0.72rem;
  color: var(--ink);
  background: var(--projector);
  padding: 3px 9px;
  border-radius: 100px;
  font-weight: 700;
}
.role-badge.viewer {
  background: transparent;
  color: var(--mist);
  border: 1px solid var(--line);
}
.role-badge.admin {
  background: var(--amber, #d97757);
  color: #fff;
}

.progress-note {
  font-size: 0.8rem;
  color: var(--mist-faint);
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--curtain-raised);
  border: 1px solid var(--line);
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  color: var(--screen);
  max-width: calc(100vw - 32px);
  text-align: center;
  word-break: break-word;
  z-index: 60;
}

/* ---------- Admin ---------- */

.admin-table {
  width: 100%;
  border-collapse: collapse;
}
.admin-table th {
  text-align: left;
  font-size: 0.78rem;
  color: var(--mist-faint);
  font-weight: 600;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.admin-table td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
  vertical-align: middle;
}
.admin-table tr:last-child td { border-bottom: none; }

.name-cell { display: flex; align-items: center; gap: 10px; }
.name-cell .avatar-sm { flex-shrink: 0; }

.toggle {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 22px;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .track {
  position: absolute; inset: 0;
  background: var(--line);
  border-radius: 100px;
  transition: background 0.15s ease;
}
.toggle .track::before {
  content: "";
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; top: 3px;
  background: var(--mist);
  border-radius: 50%;
  transition: transform 0.15s ease, background 0.15s ease;
}
.toggle input:checked + .track { background: rgba(232, 163, 61, 0.25); }
.toggle input:checked + .track::before { transform: translateX(16px); background: var(--projector); }

.status-pill {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 100px;
  border: 1px solid var(--line);
  color: var(--mist);
}
.status-pill.disabled { color: var(--ember); border-color: rgba(209,73,91,0.4); }

.new-profile-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 28px;
}
.new-profile-form .field { margin-bottom: 0; flex: 1; min-width: 160px; }

.section-gap { margin-top: 40px; }

/* ---------- Control panel (who can control) ---------- */

.control-panel {
  background: var(--curtain);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 20px;
  margin: 16px 24px 24px;
  max-width: 520px;
}
.control-panel-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.control-panel-header h3 {
  font-size: 1rem;
  color: var(--screen);
  margin: 0;
}
.control-panel-hint {
  font-size: 0.78rem;
  color: var(--mist-faint);
}
.control-panel-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.member-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
}
.member-avatar {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--serif);
  font-size: 0.9rem;
  color: rgba(20, 21, 28, 0.85);
  font-weight: 600;
  flex-shrink: 0;
}
.member-name {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}
.member-display {
  font-size: 0.88rem;
  color: var(--screen);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.member-badge {
  font-size: 0.7rem;
  padding: 1px 7px;
  border-radius: 100px;
  font-weight: 600;
  width: fit-content;
}
.member-badge.authorized {
  background: rgba(90, 166, 107, 0.2);
  color: #7fc48a;
  border: 1px solid rgba(90, 166, 107, 0.4);
}
.member-badge.host {
  background: rgba(201, 138, 62, 0.2);
  color: #e5a758;
  border: 1px solid rgba(201, 138, 62, 0.4);
}
.member-badge.admin {
  background: rgba(217, 119, 87, 0.25);
  color: #f39577;
  border: 1px solid rgba(217, 119, 87, 0.45);
}
.member-badge.viewer {
  background: transparent;
  color: var(--mist-faint);
  border: 1px solid var(--line);
}

.member-perms {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 2px;
}
.member-actions { display: flex; gap: 6px; }
.btn-tiny {
  padding: 4px 10px;
  font-size: 0.72rem;
  border-radius: var(--radius-sm);
  color: var(--mist);
  background: transparent;
  border: 1px solid var(--line);
  cursor: pointer;
  font-family: var(--sans);
}
.btn-tiny:hover { border-color: var(--mist); color: var(--screen); }

/* ---------- Empty state for control panel ---------- */
.empty-room {
  padding: 20px;
  text-align: center;
  color: var(--mist-faint);
  font-size: 0.88rem;
}

/* ============================================================
   Crunchyroll-Style Subtitles & Customization Modal
   ============================================================ */

.sub-settings-btn {
  margin: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

/* Subtitle modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 14, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  backdrop-filter: blur(4px);
}

.sub-modal-card {
  width: 500px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--curtain-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 24px;
  color: var(--screen);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.6);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  margin: 0;
  font-size: 1.05rem;
  color: var(--screen);
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--mist);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

.modal-close-btn:hover {
  color: var(--screen);
}

.sub-preview-container {
  width: 100%;
  height: 140px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin: 16px 0;
  border: 1px solid var(--line);
  position: relative;
}

.sub-preview-bg {
  width: 100%;
  height: 100%;
  position: relative;
  background:
    linear-gradient(rgba(15, 12, 25, 0.35), rgba(15, 12, 25, 0.55)),
    radial-gradient(circle at 65% 35%, #3d2a52, #130f1c);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 10px 14px;
  box-sizing: border-box;
}

.sub-preview-top-cue {
  font-family: var(--sub-font-family, 'Trebuchet MS', sans-serif);
  font-weight: 700;
  color: var(--sub-color, #ffffff);
  font-size: calc(15px * var(--sub-scale, 1));
  text-shadow: var(--sub-text-shadow);
  -webkit-text-stroke: var(--sub-stroke);
  paint-order: stroke fill;
  background: var(--sub-bg, transparent);
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  padding: 2px 6px;
  border-radius: 3px;
  max-width: 90%;
  text-align: center;
}

.sub-preview-cue {
  font-family: var(--sub-font-family, 'Trebuchet MS', sans-serif);
  font-weight: 700;
  color: var(--sub-color, #ffffff);
  font-size: calc(18px * var(--sub-scale, 1));
  text-shadow: var(--sub-text-shadow);
  -webkit-text-stroke: var(--sub-stroke);
  paint-order: stroke fill;
  background: var(--sub-bg, transparent);
  position: absolute;
  bottom: var(--sub-bottom-offset, 8%);
  left: 50%;
  transform: translateX(-50%);
  padding: 2px 6px;
  border-radius: 3px;
  max-width: 90%;
  text-align: center;
  transition: bottom 0.15s ease;
}

.sub-settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
  margin-top: 10px;
}

.sub-setting-field.full-width {
  grid-column: 1 / -1;
}

.sub-setting-field label {
  display: block;
  font-size: 0.78rem;
  color: var(--mist);
  margin-bottom: 5px;
}

.sub-input-select {
  width: 100%;
  background: var(--ink);
  color: var(--screen);
  border: 1px solid var(--line);
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  outline: none;
}

.sub-slider {
  width: 100%;
  accent-color: var(--projector);
}

.color-picker-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.color-picker-wrap input[type="color"] {
  width: 34px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 1px;
  background: var(--ink);
  cursor: pointer;
}

.color-val-hex {
  font-size: 0.8rem;
  color: var(--mist);
  font-family: monospace;
}

#unmute-btn {
  display: none !important;
}

/* ============================================================
   Mobile & Responsive Layout Optimizations
   Fixes edge overflows, padding on small screens, and mobile tap targets
   ============================================================ */

.admin-table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 14px;
}

@media (max-width: 768px) {
  /* Prevent iOS zoom on inputs while keeping styling clean */
  input[type="text"],
  input[type="password"],
  input[type="tel"],
  select,
  textarea {
    font-size: 16px !important;
  }

  .container {
    padding: 0 14px;
  }

  /* Topbar (lobby, admin, profiles) */
  .topbar {
    padding: 12px 14px;
    flex-wrap: wrap;
    gap: 10px;
  }
  .topbar .whoami {
    margin-left: auto;
    gap: 8px;
    font-size: 0.84rem;
  }

  /* Room Stage Header */
  .stage-header {
    padding: 10px 14px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .stage-header .room-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 6px;
    flex-wrap: wrap;
  }
  .stage-header .room-title .brand-block {
    align-items: center;
    gap: 6px;
  }
  .stage-header .room-title .code-chip {
    font-size: 0.88rem;
  }
  .stage-header .header-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 10px;
    padding-top: 6px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
  }

  /* Screen wrap and player */
  .screen-wrap {
    padding: 6px 0;
    min-height: 200px;
  }
  .screen-wrap video {
    max-width: 100%;
    width: 100%;
    max-height: 52vh;
    border-radius: 0;
  }

  /* Control strip on phones: neatly stacked and perfectly centered */
  .control-strip {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 12px 14px 18px;
    min-height: auto;
    position: static;
  }
  .control-strip .left,
  .control-strip #host-controls,
  .control-strip #viewer-note {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 8px;
    width: 100%;
    margin: 0;
  }
  .control-strip .left > *,
  .control-strip #host-controls > *,
  .control-strip #viewer-note > * {
    margin-left: 0 !important;
  }
  .control-strip .center {
    position: static;
    transform: none;
    display: flex;
    justify-content: center;
    width: 100%;
    margin: 2px 0;
  }
  .control-strip .right {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 8px;
    width: 100%;
    margin-left: 0;
  }
  .control-strip button,
  .control-strip .upload-label {
    max-width: 100%;
    text-align: center;
    justify-content: center;
    font-size: 0.82rem;
    padding: 7px 12px;
  }

  /* Control panel (who can control list) */
  .control-panel {
    margin: 0 10px 16px;
    padding: 12px 10px;
  }
  .control-panel-header {
    margin-bottom: 10px;
  }
  .control-panel-header h3 {
    font-size: 0.95rem;
  }
  .control-panel-hint {
    font-size: 0.74rem;
    line-height: 1.35;
  }
  .member-row {
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 10px;
  }
  .member-name {
    flex: 1 1 calc(100% - 46px);
    min-width: 0;
  }
  .member-actions {
    width: 100%;
    display: flex;
    gap: 6px;
    margin-top: 4px;
    padding-top: 6px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
  }
  .member-actions .btn-tiny {
    flex: 1;
    text-align: center;
    padding: 6px 8px;
    font-size: 0.76rem;
  }

  /* Subtitle Customization Modal */
  .modal-backdrop {
    padding: 10px;
  }
  .sub-modal-card {
    width: 100%;
    max-width: calc(100vw - 16px);
    max-height: 88vh;
    padding: 16px 14px;
  }
  .sub-settings-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .sub-preview-container {
    height: 100px;
    margin: 10px 0;
  }
  .sub-preview-cue {
    font-size: calc(15px * var(--sub-scale, 1));
  }
  .sub-preview-top-cue {
    font-size: calc(12px * var(--sub-scale, 1));
  }
  .modal-footer {
    display: flex;
    gap: 10px;
  }
  .modal-footer button {
    flex: 1;
    text-align: center;
  }

  /* Lobby & Panels */
  .lobby-grid {
    grid-template-columns: 1fr;
    gap: 18px;
    padding: 16px 0 60px;
  }
  .panel {
    padding: 18px 14px;
  }
  .room-list-item {
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 14px;
  }
  .room-list-item .stub {
    flex: 1 1 100%;
    margin-left: 0;
    padding-left: 10px;
  }
  .room-list-item > div:last-child {
    width: 100%;
    justify-content: flex-end;
    gap: 8px;
  }

  /* Profile Picker */
  .picker-stage {
    padding: 24px 14px;
  }
  .picker-stage h1 {
    font-size: 1.7rem;
    margin-bottom: 20px;
  }
  .profile-grid {
    gap: 14px 16px;
  }
  .profile-tile .avatar {
    width: 72px;
    height: 72px;
    font-size: 1.7rem;
  }
  .pin-modal {
    width: 100%;
    max-width: calc(100vw - 24px);
    padding: 22px 18px;
  }

  /* Admin forms & tables */
  .new-profile-form {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .new-profile-form .field {
    width: 100%;
    max-width: none !important;
    min-width: 0;
  }
  .new-profile-form button {
    width: 100%;
    margin-top: 4px;
  }
  .admin-table th,
  .admin-table td {
    padding: 8px 10px;
    font-size: 0.82rem;
    white-space: nowrap;
  }
}

@media (max-width: 768px) and (orientation: landscape) {
  .screen-wrap video {
    max-height: 80vh;
    width: auto;
  }
}


