:root {
  --bg: #0f1419;
  --panel: #1a222d;
  --border: #2d3a4d;
  --text: #e7edf5;
  --muted: #8b9bb0;
  --accent: #3d8bfd;
  --danger: #e85d5d;
  --ok: #3ecf8e;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.top h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
}

.room-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.65rem;
}

.room-bar label {
  display: flex;
  flex-direction: column;
  font-size: 0.75rem;
  color: var(--muted);
  gap: 0.2rem;
}

.room-bar input {
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  min-width: 8rem;
}

button {
  padding: 0.45rem 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button.on {
  border-color: var(--ok);
  color: var(--ok);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.layout {
  display: grid;
  grid-template-columns: 1fr minmax(260px, 320px);
  gap: 1rem;
  padding: 1rem;
  align-items: start;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

.stage {
  min-width: 0;
}

.videos {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.75rem;
}

.videos.meet-video-rail {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.tile {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  aspect-ratio: 16 / 10;
}

.videos.meet-video-rail .tile {
  aspect-ratio: unset;
}

.tile video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  display: block;
}

.tile .label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
}

.tile .ann-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  touch-action: none;
}

.tile .ann-layer.active {
  pointer-events: auto;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.8rem;
}

.hint {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
}

.side {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 1rem;
}

.side h2 {
  margin: 0.75rem 0 0.35rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.side h2:first-child {
  margin-top: 0;
}

.list {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.9rem;
}

.list.files {
  padding-left: 0;
  list-style: none;
}

.list.files li {
  margin-bottom: 0.35rem;
}

.list.files a {
  color: var(--accent);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.file-btn {
  display: inline-flex;
  align-items: center;
  padding: 0.45rem 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
}

.wb-panel {
  margin-top: 0.75rem;
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
}

.wb-panel.hidden {
  display: none;
}

.wb-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
}

/* Pinned to #pane-whiteboard (position: absolute .meet-pane), not the viewport — avoids
   flex-row layout stealing width from the canvas and fixes coordinate letterboxing. */
.wb-tool-float {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  z-index: 70;
  width: 200px;
  max-width: min(200px, calc(100% - 1.5rem));
  max-height: min(calc(100vh - 120px), calc(100% - 2rem));
  overflow-y: auto;
  padding: 0.65rem 0.7rem;
  background: rgba(18, 22, 30, 0.96);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
  pointer-events: auto;
}

.wb-tool-float__title {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.35rem;
}

.wb-tool-float .wb-toolbar__field {
  margin-top: 0.45rem;
}

.wb-tool-float .wb-toolbar__stamps {
  margin-top: 0.55rem;
}

.wb-toolbar__field {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  color: var(--muted);
}

.wb-toolbar__field--grow {
  flex: 1 1 140px;
  min-width: 120px;
}

.wb-toolbar__field select,
.wb-toolbar__field input[type="color"] {
  padding: 0.25rem 0.35rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.8rem;
}

.wb-toolbar__field input[type="range"] {
  width: 100%;
}

.wb-toolbar__val {
  color: var(--text);
  font-weight: 600;
}

.wb-toolbar__stamps {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
}

.wb-toolbar__stamp-hint {
  color: var(--muted);
  margin-right: 0.15rem;
}

.wb-stamp {
  min-width: 2rem;
  height: 2rem;
  padding: 0 0.35rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

.wb-stamp:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.wb-stamp-cancel {
  font-size: 0.7rem;
  padding: 0.25rem 0.45rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
}

.wb-stamp-cancel:hover {
  color: var(--danger);
  border-color: var(--danger);
}

.wb-canvas-stack {
  position: relative;
  flex: 1;
  min-height: 0;
  touch-action: none;
  cursor: crosshair;
}

/* Fill the stack so pointer mapping matches the full visible board (linear 1280×720 stretch). */
.wb-canvas-stack #whiteboard {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
}

.wb-canvas-stack .wb-preview-layer {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
  border: none;
  background: transparent;
}

.wb-text-overlay {
  min-width: 140px;
  max-width: min(360px, 42vw);
  padding: 0.35rem 0.45rem;
  font-size: 0.9rem;
  line-height: 1.35;
  border-radius: 8px;
  border: 2px solid var(--accent);
  background: rgba(10, 12, 18, 0.98);
  color: var(--text);
  resize: both;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
}

.hidden {
  display: none !important;
}

/* --- Meeting (Teams-like) --- */
.setup-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  gap: 1rem;
  background: radial-gradient(ellipse at top, #1a2a44 0%, var(--bg) 55%);
}

.setup-banner {
  width: 100%;
  max-width: 520px;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--accent);
  background: rgba(61, 139, 253, 0.12);
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.4;
  text-align: center;
}

.setup-banner.hidden {
  display: none !important;
}

.setup-card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.75rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.setup-card--wide {
  max-width: 560px;
}

.setup-link-row {
  margin-top: 1rem;
}

.setup-link-row label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.setup-link-field {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}

.setup-link-field input {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.55rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.75rem;
}

.setup-copy {
  flex-shrink: 0;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

.setup-copy:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.setup-actions--row {
  margin-top: 1.25rem;
}

.setup-card h1 {
  margin: 0 0 0.35rem;
  font-size: 1.5rem;
}

.setup-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 1rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.setup-field input {
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.setup-actions {
  margin-top: 1rem;
}

.setup-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.5rem 0;
}

.setup-foot {
  margin-top: 1.25rem;
  font-size: 0.8rem;
}

.meet-app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding-bottom: 5.5rem;
}

.meet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.meet-header__title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.meet-logo {
  color: var(--accent);
  text-decoration: none;
  font-weight: 700;
  margin-right: 0.75rem;
}

.meet-header__right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.btn-end-meeting {
  background: #5c2d2d;
  border: 1px solid #8a3a3a;
  color: #ffd6d6;
  padding: 0.45rem 0.75rem;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
}

.btn-end-meeting:hover {
  background: #7a3838;
  border-color: #b04848;
  color: #fff;
}

.btn-leave {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.meet-shell {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr minmax(280px, 360px);
  gap: 0.75rem;
  padding: 0.75rem;
  min-height: 0;
}

@media (max-width: 960px) {
  .meet-shell {
    grid-template-columns: 1fr;
  }
  .meet-right {
    max-height: none !important;
  }
}

.meet-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 0;
}

.meet-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.meet-tab {
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  font-size: 0.8rem;
  cursor: pointer;
}

.meet-tab:hover {
  border-color: var(--accent);
  color: var(--text);
}

.meet-tab.meet-tab--active {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.meet-panes {
  flex: 1;
  min-height: min(58vh, 520px);
  position: relative;
  background: #0a0d12;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.meet-pane {
  display: none;
  position: absolute;
  inset: 0;
  flex-direction: column;
  min-height: 0;
}

.meet-pane.meet-pane--active {
  display: flex;
}

.main-stage-inner {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.spotlight-video {
  width: 100%;
  height: 100%;
  max-height: calc(100vh - 220px);
  object-fit: contain;
  background: #000;
}

.gallery-main {
  width: 100%;
  height: 100%;
  display: grid;
  /* Default 2×2 when no inline template is set; JS sets repeat(N,1fr) for all participants. */
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 4px;
  padding: 4px;
}

.gallery-main video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
  border-radius: 6px;
}

.wb-stage-mount {
  width: 100%;
  height: 100%;
  flex: 1;
  min-height: 0;
  padding: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #1a1f28;
}

.wb-stage-mount .wb-panel {
  width: 100%;
  height: 100%;
  margin: 0;
  border: none;
  display: flex;
  flex-direction: column;
}


.meet-right {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-width: 0;
  max-height: calc(100vh - 120px);
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  overflow: hidden;
}

.meet-right__top {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 0.65rem 0.75rem;
}

.meet-video-rail-head {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0.75rem 0 0.35rem;
}

.meet-video-rail {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.meet-video-rail .tile {
  width: 100%;
  flex-shrink: 0;
  border-radius: 10px;
  border: 2px solid transparent;
  overflow: hidden;
  background: #0a0d12;
  cursor: pointer;
  display: flex;
  flex-direction: column;
}

.meet-video-rail .tile:hover {
  border-color: rgba(100, 160, 255, 0.45);
}

.meet-video-rail .tile--local-pick {
  border-color: var(--accent);
}

.meet-video-rail .tile__media {
  position: relative;
  width: 100%;
  min-height: 72px;
  flex: 0 0 auto;
}

.meet-video-rail .tile__self-controls {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  z-index: 6;
  display: flex;
  gap: 0.3rem;
}

.meet-video-rail .tile-ctrl {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  padding: 0;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(0, 0, 0, 0.55);
  color: #e8eef5;
  cursor: pointer;
}

.meet-video-rail .tile-ctrl:hover {
  border-color: var(--accent);
  color: #fff;
}

.meet-video-rail .tile-ctrl.on {
  border-color: rgba(80, 200, 120, 0.85);
  box-shadow: 0 0 0 1px rgba(80, 200, 120, 0.35);
}

.meet-video-rail .tile-ctrl:not(.on) {
  opacity: 0.75;
  border-color: rgba(255, 100, 100, 0.55);
}

.meet-video-rail .tile--host .tile__media {
  min-height: 160px;
  max-height: 220px;
}

.meet-video-rail .tile--local-pick:not(.tile--host) .tile__media {
  min-height: 120px;
  max-height: 160px;
}

.meet-video-rail .tile__media video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  background: #000;
  min-height: inherit;
  max-height: inherit;
}

.meet-video-rail .tile__media .ann-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.meet-video-rail .tile__media .ann-layer.active {
  pointer-events: auto;
}

.meet-video-rail .tile__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.5rem;
  font-size: 0.78rem;
  background: rgba(0, 0, 0, 0.45);
}

.meet-video-rail .tile__name {
  color: var(--text);
  font-weight: 500;
}

.meet-video-rail .tile__badge--host {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.12rem 0.35rem;
  border-radius: 4px;
  background: var(--accent);
  color: #0a0d12;
  font-weight: 700;
}

.meet-chat-dock {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 140px;
  max-height: 38vh;
  border-top: 1px solid var(--border);
  padding: 0.55rem 0.75rem 0.65rem;
  background: rgba(0, 0, 0, 0.2);
}

.meet-chat-dock__title {
  margin: 0 0 0.35rem;
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.chat-log--dock {
  flex: 1 1 auto;
  min-height: 72px;
  max-height: none;
  margin-bottom: 0.45rem;
}

.meet-right__footer {
  flex: 0 0 auto;
  max-height: 28vh;
  overflow-y: auto;
  border-radius: 0;
  border: none;
  border-top: 1px solid var(--border);
}

.panel-block {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
}

.panel-block h2 {
  margin: 0 0 0.4rem;
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.chat-log {
  height: 180px;
  overflow-y: auto;
  font-size: 0.82rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem;
  margin-bottom: 0.5rem;
}

.meet-chat-dock .chat-log {
  height: auto;
}

.chat-msg {
  margin-bottom: 0.45rem;
  line-height: 1.35;
}

.chat-msg .who {
  color: var(--accent);
  font-weight: 600;
}

.chat-compose {
  display: flex;
  gap: 0.35rem;
}

.chat-compose input {
  flex: 1;
  padding: 0.45rem 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.toolbar--stack {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  align-items: stretch;
}

.meet-float {
  position: fixed;
  left: 50%;
  bottom: 1rem;
  transform: translateX(-50%);
  z-index: 50;
  max-width: calc(100vw - 2rem);
}

.meet-float__inner {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(22, 28, 38, 0.92);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
}

.meet-float__inner button {
  border-radius: 999px;
  padding: 0.4rem 0.85rem;
  font-size: 0.82rem;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}

.meet-float__inner button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.meet-float__inner button.on {
  border-color: var(--accent);
  color: var(--accent);
}

.meet-float__inner button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.meet-float__file {
  margin: 0;
  font-size: 0.82rem;
  border-radius: 999px;
  padding: 0.4rem 0.85rem;
}

.host-rec-badge {
  margin-left: 0.5rem;
}

.rec-canvas-offscreen {
  position: fixed;
  left: -9999px;
  top: 0;
  width: 1280px;
  height: 720px;
  opacity: 0;
  pointer-events: none;
}
