:root {
  --bg: #0f1115;
  --bg-elevated: #1a1d24;
  --bg-card: #20242d;
  --border: #2a2f3a;
  --text: #e8eaed;
  --text-muted: #9aa0a6;
  --primary: #1a73e8;
  --primary-hover: #1764cc;
  --danger: #ea4335;
  --danger-hover: #c5372b;
  --success: #34a853;
  --radius: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

h1 { font-size: 1.75rem; font-weight: 600; margin-bottom: 0.5rem; }
h2 { font-size: 1.25rem; font-weight: 600; margin-bottom: 1rem; }
p { color: var(--text-muted); margin-bottom: 0.75rem; line-height: 1.5; }
.muted { color: var(--text-muted); font-size: 0.9rem; }
.error { color: var(--danger); font-size: 0.9rem; margin-top: 0.5rem; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-block;
  padding: 0.65rem 1.25rem;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease;
  text-align: center;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--bg-card); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg-elevated); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); }
.btn-danger-outline { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-danger-outline:hover { background: rgba(234, 67, 53, 0.1); }

/* ---------- Forms ---------- */
label {
  display: block;
  margin-top: 1rem;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}
input[type="text"], input[type="password"], select {
  width: 100%;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}
input:focus, select:focus { outline: none; border-color: var(--primary); }

.row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.row label { margin: 0; }
label.row { cursor: pointer; margin-top: 0.75rem; }

/* ---------- Landing ---------- */
.page-landing { background: var(--bg); }
.landing {
  max-width: 540px;
  margin: auto;
  padding: 3rem 1.5rem;
  text-align: center;
}
.landing h1 { font-size: 2.25rem; margin-bottom: 1rem; }

/* ---------- Admin ---------- */
.admin {
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
  padding: 2rem 1.5rem;
  flex: 1;
}
.admin header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1.5rem;
}
.card {
  background: var(--bg-card);
  padding: 1.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 1.25rem;
}
#createRoomForm { gap: 0.75rem; margin-bottom: 1.25rem; }
#createRoomForm select { width: auto; min-width: 140px; }

.room-list { list-style: none; }
.room-item {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}
.room-item .link {
  flex: 1; min-width: 0;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.85rem;
  color: var(--primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.room-item .meta { color: var(--text-muted); font-size: 0.8rem; }
.room-item button { padding: 0.4rem 0.75rem; font-size: 0.85rem; }

/* ---------- Lobby ---------- */
.lobby {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.lobby .card { max-width: 460px; width: 100%; }

/* ---------- Stage (video / sala) ---------- */
.stage {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: #000;
}
.videos {
  flex: 1;
  position: relative;
  overflow: hidden;
}
.video-tile {
  position: absolute;
  background: var(--bg-elevated);
  overflow: hidden;
}
.video-remote {
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.video-self {
  width: 28vw;
  max-width: 200px;
  aspect-ratio: 3 / 4;
  top: env(safe-area-inset-top, 12px);
  right: 12px;
  border-radius: var(--radius);
  border: 2px solid rgba(255,255,255,0.15);
  z-index: 2;
}
.video-tile video {
  width: 100%; height: 100%; object-fit: cover; background: #000;
}
.video-self video { transform: scaleX(-1); }

.placeholder {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 1rem;
  background: linear-gradient(135deg, #2a2f3a, #1a1d24);
  color: var(--text-muted);
}
.placeholder-self { gap: 0; font-size: 0.75rem; }
.avatar {
  width: 96px; height: 96px;
  border-radius: 50%;
  background: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 2.5rem; font-weight: 600; color: white;
}
.placeholder-self .avatar { width: 56px; height: 56px; font-size: 1.4rem; }

.subtitles {
  position: absolute;
  left: 0; right: 0; bottom: 12%;
  text-align: center;
  padding: 0 1rem;
  pointer-events: none;
  font-size: clamp(1.1rem, 3vw, 1.6rem);
  line-height: 1.35;
  text-shadow: 0 2px 6px rgba(0,0,0,0.8);
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
}
.subtitles .live,
.subtitles .final {
  background: rgba(0,0,0,0.55);
  border-radius: 6px;
  padding: 0.35rem 0.7rem;
  max-width: min(92%, 760px);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-word;
}
.subtitles .final {
  background: rgba(0,0,0,0.45);
  opacity: 0.85;
}

.lang-badge {
  position: absolute;
  left: 12px; top: env(safe-area-inset-top, 12px);
  background: rgba(0,0,0,0.55);
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  font-size: 0.8rem;
  color: var(--text);
  z-index: 3;
}
.self-label {
  position: absolute; left: 8px; bottom: 8px;
  background: rgba(0,0,0,0.6);
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  font-size: 0.75rem;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 1rem;
  padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to top, rgba(0,0,0,0.6), transparent);
  z-index: 4;
  flex-wrap: wrap;
}

.volume-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(255,255,255,0.06);
  border-radius: 28px;
  padding-right: 0.85rem;
}
.volume-group .btn-icon {
  background: transparent;
}
.volume-group .btn-icon:hover {
  background: rgba(255,255,255,0.12);
}
#volumeSlider {
  -webkit-appearance: none;
  appearance: none;
  width: 110px;
  height: 4px;
  background: rgba(255,255,255,0.25);
  border-radius: 999px;
  outline: none;
  cursor: pointer;
}
#volumeSlider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--text);
  border: none;
  cursor: pointer;
}
#volumeSlider::-moz-range-thumb {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--text);
  border: none;
  cursor: pointer;
}
@media (max-width: 480px) {
  #volumeSlider { width: 80px; }
}
.btn-icon {
  width: 56px; height: 56px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.12);
  color: white;
  font-size: 1.4rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s ease;
}
.btn-icon:hover { background: rgba(255,255,255,0.2); }
.btn-icon.off { background: var(--danger); }
.btn-icon.btn-danger { background: var(--danger); }
.btn-icon.btn-danger:hover { background: var(--danger-hover); }

.status {
  position: absolute;
  top: env(safe-area-inset-top, 12px);
  left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.6);
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 5;
  max-width: 70vw;
  text-align: center;
}
.status:empty { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 600px) {
  h1 { font-size: 1.4rem; }
  .video-self { width: 32vw; right: 8px; }
  .btn-icon { width: 52px; height: 52px; }
}

@media (orientation: landscape) and (max-height: 500px) {
  .video-self { width: 18vh; }
}
