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

/* Author display rules on #join-screen/#app would otherwise override the
   hidden attribute's UA style — app.js relies on el.hidden for screen swaps. */
[hidden] { display: none !important; }

:root {
  --bg: #101014;
  --panel: #1a1a21;
  --panel-2: #22222b;
  --text: #e8e8ee;
  --muted: #9a9aa8;
  --accent: #e5484d;
  --accent-soft: rgba(229, 72, 77, 0.16);
  --ok: #46a758;
  --radius: 14px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

button { font: inherit; cursor: pointer; }
input { font: inherit; }

/* ---------------------------------------------------------- join screen */

#join-screen {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.join-card {
  width: 100%;
  max-width: 840px;
  background: var(--panel);
  border: 1px solid #2c2c37;
  border-radius: var(--radius);
  padding: 32px 28px;
}

.join-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  margin-top: 4px;
}
@media (min-width: 760px) {
  .join-grid { grid-template-columns: 1.2fr 1fr; align-items: start; }
}

.preview-col { display: flex; flex-direction: column; gap: 10px; }

.preview {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid #2c2c37;
}
.preview video { width: 100%; height: 100%; object-fit: cover; }

#preview-msg {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.5;
  padding: 16px 20px;
  background: #17171d;
}

#pv-retry {
  background: var(--panel-2);
  border: 1px solid #33333f;
  border-radius: 8px;
  color: var(--text);
  padding: 7px 16px;
  font-size: 13px;
}
#pv-retry:hover { border-color: var(--accent); color: var(--accent); }

.preview-ctls {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  display: flex;
  gap: 8px;
}

.mirror { transform: scaleX(-1); }

.dev {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12.5px;
  color: var(--muted);
}
.dev select {
  background: var(--panel-2);
  border: 1px solid #33333f;
  border-radius: 8px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 13.5px;
  max-width: 100%;
}
.dev select:focus { outline: 2px solid var(--accent); border-color: transparent; }

.join-card .logo { display: block; height: 44px; width: auto; margin-bottom: 14px; }
.join-card h1 { font-size: 26px; margin-bottom: 6px; }
.join-card .tagline { color: var(--muted); font-size: 14px; margin-bottom: 22px; }

#join-form { display: flex; flex-direction: column; gap: 12px; }

#join-form input[type="text"],
#join-form input[type="password"],
#join-form input:not([type]) {
  background: var(--panel-2);
  border: 1px solid #33333f;
  border-radius: 10px;
  color: var(--text);
  padding: 11px 13px;
}
#join-form input:focus { outline: 2px solid var(--accent); border-color: transparent; }

/* Keep browser autofill from flashing its light background on the dark card. */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0 1000px var(--panel-2) inset;
  -webkit-text-fill-color: var(--text);
  caret-color: var(--text);
}

.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); }
.check .sub { color: var(--muted); }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }

#join-form button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 12px;
  font-weight: 600;
  margin-top: 4px;
}
#join-form button:hover { filter: brightness(1.1); }

.hint { color: var(--muted); font-size: 12.5px; line-height: 1.5; margin-top: 18px; }

/* ---------------------------------------------------------- app frame */

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

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid #2c2c37;
  flex-wrap: wrap;
}

.brand { font-weight: 700; }
.brand span { color: var(--muted); font-weight: 400; }

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

.ctl {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid #33333f;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 14px;
}
.ctl.on { border-color: var(--ok); }
.ctl:not(.on):not(.music):not(.leave) { color: var(--muted); text-decoration: line-through; }
.ctl:disabled { opacity: 0.45; cursor: not-allowed; }
.ctl.music.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.ctl.leave { border-color: #5c2e31; color: #f2a3a6; }
.ctl.leave:hover { background: var(--accent); color: #fff; }

/* ---------------------------------------------------------- main layout */

main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  overflow-y: auto;
}

#tiles {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  align-content: start;
}

.tile {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 4 / 3;
  border: 1px solid #2c2c37;
}
.tile.connecting { outline: 2px dashed #3a3a46; }

.tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #17171d;
}

.tile .label {
  position: absolute;
  left: 8px;
  bottom: 8px;
  background: rgba(0, 0, 0, 0.55);
  padding: 3px 9px;
  border-radius: 8px;
  font-size: 13px;
  backdrop-filter: blur(4px);
}

.tile .badge {
  position: absolute;
  top: 8px;
  left: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 8px;
}

.tile .vol {
  position: absolute;
  right: 8px;
  bottom: 10px;
  width: 90px;
  accent-color: var(--accent);
  opacity: 0;
  transition: opacity 0.15s;
}
.tile:hover .vol { opacity: 1; }

/* ---------------------------------------------------------- chat panel */

#chat-panel {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid #2c2c37;
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 55vh;
  flex-shrink: 0;
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid #2c2c37;
  font-weight: 600;
  font-size: 14px;
}

#yt-form { display: flex; gap: 6px; flex: 1; max-width: 320px; }
#yt-form input {
  flex: 1;
  min-width: 0;
  background: var(--panel-2);
  border: 1px solid #33333f;
  border-radius: 8px;
  color: var(--text);
  padding: 6px 10px;
  font-size: 13px;
}
#yt-form button {
  background: var(--panel-2);
  border: 1px solid #33333f;
  border-radius: 8px;
  color: var(--text);
  padding: 6px 12px;
  font-size: 13px;
}
#yt-form button:hover { border-color: var(--accent); color: var(--accent); }

#yt-frame { flex: 1; width: 100%; border: none; background: #17171d; }

#yt-placeholder {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  padding: 24px;
  line-height: 1.6;
}

/* ---------------------------------------------------------- toast */

#toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid #3a3a46;
  color: var(--text);
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 14px;
  max-width: 90vw;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  z-index: 50;
}

/* ---------------------------------------------------------- wide screens */

@media (min-width: 1000px) {
  main { flex-direction: row; overflow: hidden; }
  /* Rows share the available height equally (grid-auto-rows: 1fr) instead of
     forcing a 4:3 box that overflows and — with align-content:center — makes
     rows overlap. Tiles fill their cell; the video's object-fit handles it. */
  #tiles {
    flex: 1;
    height: 100%;
    align-content: stretch;
    grid-auto-rows: 1fr;
    overflow: hidden;
  }
  #tiles .tile { aspect-ratio: auto; min-height: 0; height: 100%; }
  #chat-panel { width: 360px; min-height: 0; height: 100%; }
}
