:root {
  --brand-primary: #0F1F2E;
  --brand-accent: #2C78B9;
  --brand-surface: #F2F7FB;
  --ink: #192530;
  --muted: #47606D;
  --border: #C6D8E7;
  --ok: #1F6E4A;
  --warn: #8A5A12;
  --danger: #B4232C;
  --stage-bg: #101C26;
  --tile-bg: #1A2B3A;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--brand-surface); min-height: 100vh; }

.topbar {
  background: var(--brand-primary);
  color: #fff;
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  border-bottom: 3px solid var(--brand-accent);
  flex-wrap: wrap;
}
.topbar__brand { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.topbar__badge {
  background: rgba(255,255,255,0.14);
  border: 1px solid rgba(255,255,255,0.28);
  border-radius: 4px;
  padding: 0.2rem 0.55rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.topbar__title { font-weight: 700; font-size: 1.02rem; }
.topbar__sub { font-size: 0.8rem; opacity: 0.82; }
.topbar__meta { display: flex; align-items: center; gap: 0.5rem; font-size: 0.84rem; flex-wrap: wrap; }

.container { max-width: 1120px; margin: 0 auto; padding: 1.5rem 1.15rem; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem; }

.card {
  background: #fff;
  border: 1px solid var(--border);
  border-top: 3px solid var(--brand-accent);
  border-radius: 6px;
  padding: 1.35rem 1.5rem;
}
.card h1, .card h2, .card h3 { margin-top: 0; color: var(--brand-primary); }
.muted { color: var(--muted); font-size: 0.9rem; line-height: 1.55; }

.field { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 0.9rem; }
.field label { font-size: 0.84rem; font-weight: 600; color: var(--brand-primary); }
.field input, .field select {
  width: 100%; padding: 0.55rem 0.75rem; border: 1px solid var(--border); border-radius: 4px;
  font-size: 0.95rem; font-family: inherit; background: #fff; color: var(--ink);
}
.field input:focus, .field select:focus { outline: 2px solid var(--brand-accent); outline-offset: 1px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
  padding: 0.58rem 1rem; border-radius: 4px; border: 1px solid transparent;
  font-weight: 600; font-size: 0.9rem; cursor: pointer; font-family: inherit; text-decoration: none;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--brand-accent); color: #fff; }
.btn-primary:hover:not(:disabled) { filter: brightness(0.92); }
.btn-dark { background: var(--brand-primary); color: #fff; }
.btn-ghost { background: #fff; color: var(--brand-primary); border-color: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ok { background: var(--ok); color: #fff; }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }

.notice {
  background: var(--brand-surface); border: 1px solid var(--border); border-left: 4px solid var(--brand-accent);
  border-radius: 4px; padding: 0.8rem 1rem; font-size: 0.88rem; line-height: 1.5; margin-bottom: 1rem;
}
.notice.err { border-left-color: var(--danger); background: #FDF2F2; color: #7B1E24; }
.notice.ok { border-left-color: var(--ok); background: #EDF8F2; color: #164F35; }

/* Pre-Join Video Preview */
.preview-box {
  position: relative; background: var(--stage-bg); border-radius: 6px; overflow: hidden;
  aspect-ratio: 16 / 10; display: flex; align-items: center; justify-content: center; color: #fff;
}
.preview-box video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.preview-placeholder { text-align: center; padding: 1rem; font-size: 0.9rem; opacity: 0.85; }

/* Live Room Shell */
.room-shell {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
  background: var(--stage-bg);
  color: #fff;
}
.room-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}
.room-body.has-sidebar {
  grid-template-columns: minmax(0, 1fr) 340px;
}
.stage-area {
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 0;
  overflow-y: auto;
}
.screen-spotlight {
  flex: 1 1 58%;
  min-height: 240px;
  background: #0A131A;
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 6px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.screen-spotlight video { max-width: 100%; max-height: 100%; object-fit: contain; }
.tiles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
  align-content: center;
  flex: 1;
}
.tile {
  position: relative;
  background: var(--tile-bg);
  border: 2px solid rgba(255,255,255,0.12);
  border-radius: 6px;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tile.speaking { border-color: #4CC38A; }
.tile video { width: 100%; height: 100%; object-fit: cover; }
.tile__avatar {
  width: 60px; height: 60px; border-radius: 50%; background: var(--brand-accent);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 1.25rem; color: #fff;
}
.tile__label {
  position: absolute; left: 0.5rem; bottom: 0.45rem; right: 0.5rem;
  display: flex; justify-content: space-between; align-items: center; gap: 0.35rem;
  pointer-events: none;
}
.tile__name {
  background: rgba(10, 19, 26, 0.78); color: #fff; padding: 0.18rem 0.5rem;
  border-radius: 4px; font-size: 0.78rem; font-weight: 600; max-width: 78%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tile__badge {
  background: rgba(44, 120, 185, 0.9); color: #fff; padding: 0.15rem 0.45rem;
  border-radius: 4px; font-size: 0.7rem; font-weight: 700;
}

.sidebar {
  background: #fff; color: var(--ink); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.sidebar__tabs { display: flex; border-bottom: 1px solid var(--border); }
.sidebar__tab {
  flex: 1; padding: 0.65rem; border: 0; background: var(--brand-surface); font-weight: 600;
  font-size: 0.85rem; cursor: pointer; color: var(--muted);
}
.sidebar__tab.active { background: #fff; color: var(--brand-primary); border-bottom: 2px solid var(--brand-accent); }
.sidebar__pane { flex: 1; overflow-y: auto; padding: 0.85rem; display: none; flex-direction: column; gap: 0.65rem; }
.sidebar__pane.active { display: flex; }

.part-row {
  border: 1px solid var(--border); border-radius: 4px; padding: 0.55rem 0.7rem;
  background: var(--brand-surface); display: flex; flex-direction: column; gap: 0.4rem; font-size: 0.84rem;
}
.chat-msg { background: var(--brand-surface); border-radius: 4px; padding: 0.5rem 0.65rem; font-size: 0.85rem; }
.chat-msg strong { color: var(--brand-primary); display: block; font-size: 0.78rem; }

.controls-bar {
  background: var(--brand-primary);
  border-top: 1px solid rgba(255,255,255,0.16);
  padding: 0.7rem 1rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
}
.ctl-btn {
  background: rgba(255,255,255,0.12); color: #fff; border: 1px solid rgba(255,255,255,0.2);
  border-radius: 4px; padding: 0.5rem 0.85rem; font-size: 0.85rem; font-weight: 600; cursor: pointer;
}
.ctl-btn:hover { background: rgba(255,255,255,0.2); }
.ctl-btn.active { background: var(--brand-accent); border-color: var(--brand-accent); }
.ctl-btn.off { background: #7A2329; border-color: #9C2F37; }
.ctl-btn.danger { background: var(--danger); border-color: var(--danger); }

.hidden { display: none !important; }

@media (max-width: 900px) {
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .room-body.has-sidebar { grid-template-columns: minmax(0, 1fr); grid-template-rows: 1fr 290px; }
  .sidebar { border-left: 0; border-top: 2px solid var(--brand-accent); }
  .tiles-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
}
