@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:ital,wght@0,300;0,400;0,500;0,600;1,400&display=swap');

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

:root, [data-theme="dark"] {
  --bg: #141416;
  --surface: #1e1e22;
  --surface2: #262629;
  --border: #2e2e33;
  --fg: #dadadf;
  --dim: #6e6e78;
  --accent: #fff;
  --green: #4ade80;
  --green-dim: #22633a;
  --red: #c06060;
  --radius: 14px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --tile-bg: rgba(20,20,22,0.7);
  --tile-bg-solid: #0a0a0a;
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #f4f4f6;
  --surface: #e8e8ec;
  --surface2: #dddde2;
  --border: #c8c8d0;
  --fg: #1a1a1e;
  --dim: #6e6e78;
  --accent: #000;
  --green: #16a34a;
  --green-dim: #bbf7d0;
  --red: #b83030;
  --tile-bg: rgba(244,244,246,0.7);
  --tile-bg-solid: #e0e0e4;
  color-scheme: light;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: 'IBM Plex Mono', 'Menlo', 'Consolas', monospace;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  touch-action: manipulation;
}

/* ==========================================
   LANDING
   ========================================== */
.landing {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100vh; height: 100dvh; gap: 1.1rem; padding: 1rem;
}
.landing h1 { font-size: 3.2rem; font-weight: 300; letter-spacing: 0.2em; text-transform: lowercase; }
.landing .sub { color: var(--dim); font-style: italic; margin-bottom: 2rem; font-size: 0.9rem; }

.landing-create-row { display: flex; align-items: stretch; gap: 0; }
.landing-create-row #create-btn { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.landing-chevron {
  display: flex; align-items: center; justify-content: center;
  background: var(--fg); color: var(--bg); border: none;
  padding: 0 0.6rem; cursor: pointer; border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  border-left: 1px solid var(--bg); transition: opacity 0.15s;
}
.landing-chevron:hover { opacity: 0.85; }
.landing-chevron:active { transform: none; }
.landing-chevron.open svg { transform: rotate(180deg); }
.landing-chevron svg { transition: transform 0.2s; }

.landing-pin-row {
  width: 180px;
}
.landing-pin-row input {
  text-align: center; letter-spacing: 0.3em; font-size: 0.9rem;
}

.landing-join-row {
  display: flex; gap: 0.5rem; margin-top: 1.5rem; width: 260px;
}
.landing-join-row input {
  flex: 1; text-align: center; font-size: 0.85rem; letter-spacing: 0.15em;
}
.landing-join-btn {
  font-family: inherit; font-size: 0.85rem; background: var(--surface); color: var(--fg);
  border: 1px solid var(--border); padding: 0.55rem 1.2rem; cursor: pointer;
  border-radius: var(--radius-sm); transition: all 0.15s; white-space: nowrap;
}
.landing-join-btn:hover { border-color: var(--dim); }
.landing-join-btn:active { transform: scale(0.97); }


/* ==========================================
   BUTTONS & INPUTS
   ========================================== */
button, .btn {
  font-family: inherit; font-size: 0.95rem; background: var(--fg); color: var(--bg);
  border: none; padding: 0.65rem 1.8rem; cursor: pointer; letter-spacing: 0.06em;
  border-radius: var(--radius-sm); transition: opacity 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
button:hover { opacity: 0.85; }
button:active { transform: scale(0.97); }

input, textarea, select {
  font-family: inherit; font-size: 0.95rem; background: var(--surface); color: var(--fg);
  border: 1px solid var(--border); padding: 0.65rem 1rem; outline: none; width: 100%;
  border-radius: var(--radius-sm); transition: border-color 0.15s; -webkit-appearance: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--dim); }
input::placeholder { color: var(--dim); }

/* ==========================================
   LOBBY (pre-join)
   ========================================== */
.lobby-overlay {
  position: fixed; inset: 0; background: var(--bg); display: flex;
  align-items: center; justify-content: center; z-index: 100;
  transition: opacity 0.3s ease; padding: 1rem;
}
.lobby-overlay.hiding { opacity: 0; pointer-events: none; }

.lobby-card {
  display: flex; flex-direction: column; align-items: center; gap: 0.8rem;
  max-width: 420px; width: 100%;
}
.lobby-title { font-size: 2rem; font-weight: 300; letter-spacing: 0.2em; }
.lobby-info { color: var(--dim); font-style: italic; font-size: 0.88rem; text-align: center; line-height: 1.5; }
.lobby-hint { font-size: 0.78rem; opacity: 0.6; }
.lobby-room { font-size: 0.85rem; color: var(--dim); letter-spacing: 0.06em; }
.lobby-room strong { color: var(--fg); }
.lobby-room-info { font-size: 0.8rem; color: var(--dim); font-style: italic; }
.lobby-names { color: var(--fg); font-style: normal; }

.lobby-preview {
  width: 100%; display: flex; flex-direction: column; gap: 0.5rem;
  margin: 0.5rem 0;
}
.lobby-cam-box {
  width: 100%; aspect-ratio: 16/9; background: var(--surface); border-radius: var(--radius);
  overflow: hidden; display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border);
}
.lobby-cam-box video {
  width: 100%; height: 100%; object-fit: contain; transform: scaleX(-1);
}
.lobby-cam-placeholder { color: var(--dim); font-size: 0.85rem; font-style: italic; }

.lobby-mic-bar {
  width: 100%; height: 4px; background: var(--surface); border-radius: 2px; overflow: hidden;
}
.lobby-mic-level {
  height: 100%; width: 0%; background: var(--green); border-radius: 2px;
  transition: width 0.05s linear;
}

.lobby-toggles { display: flex; gap: 0.8rem; justify-content: center; }

.lobby-btn-group { position: relative; display: flex; flex-direction: column; align-items: center; }
.lobby-chevron {
  font-family: inherit; background: var(--surface); color: var(--dim); border: 1px solid var(--border);
  padding: 0.1rem 0.6rem; cursor: pointer; border-radius: 0 0 var(--radius-xs) var(--radius-xs);
  margin-top: -1px; transition: all 0.15s; display: flex; align-items: center;
}
.lobby-chevron svg { width: 12px; height: 12px; stroke-linecap: round; stroke-linejoin: round; }
.lobby-chevron:hover { color: var(--fg); border-color: var(--dim); }
.lobby-chevron:active { transform: none; }
.lobby-chevron.open { color: var(--fg); background: var(--surface2); }

.lobby-device-popup {
  display: none; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
  background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 0.6rem; margin-top: 0.4rem; z-index: 10; min-width: 220px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3); flex-direction: column; gap: 0.3rem;
}
.lobby-device-popup.open { display: flex; }
.lobby-device-popup label { font-size: 0.65rem; color: var(--dim); letter-spacing: 0.04em; }
.lobby-select {
  font-family: inherit; font-size: 0.75rem; padding: 0.35rem 0.5rem; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius-xs); color: var(--fg);
  width: 100%;
}

.lobby-pin-row { width: 100%; }
.lobby-pin-row input { text-align: center; letter-spacing: 0.3em; font-size: 1.1rem; }

.lobby-join-row { display: flex; gap: 0.5rem; width: 100%; }
.lobby-join-row input { flex: 1; text-align: center; }
.lobby-join-btn { white-space: nowrap; }

.lobby-share {
  display: flex; gap: 0.5rem; width: 100%; margin-top: 0.3rem;
}
.lobby-share input { font-size: 0.78rem; text-align: center; color: var(--dim); }
.lobby-share button { font-size: 0.78rem; padding: 0.5rem 0.9rem; white-space: nowrap; }

/* ==========================================
   ROOM
   ========================================== */
.room { display: none; height: 100vh; height: 100dvh; flex-direction: column; }
.room.active { display: flex; animation: fadeIn 0.3s ease; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.45rem 1rem; border-bottom: 1px solid var(--border);
  flex-shrink: 0; background: var(--bg); z-index: 20;
}
.topbar .room-name { font-size: 0.82rem; color: var(--dim); letter-spacing: 0.1em; }

.topbar-actions { display: flex; gap: 0.5rem; align-items: center; }

.topbar-people {
  font-family: inherit; font-size: 0.78rem; color: var(--dim); background: none;
  border: none; padding: 0.3rem 0.5rem; cursor: pointer; letter-spacing: 0.04em;
  transition: color 0.15s;
}
.topbar-people:hover { color: var(--fg); }

.ctrl-btn {
  font-family: inherit; font-size: 0.75rem; background: var(--surface); color: var(--dim);
  border: 1px solid var(--border); padding: 0.3rem 0.65rem; cursor: pointer;
  border-radius: var(--radius-xs); transition: all 0.15s; letter-spacing: 0.04em;
  white-space: nowrap; -webkit-tap-highlight-color: transparent;
}
.ctrl-btn:hover { border-color: var(--dim); color: var(--fg); }
.ctrl-btn.active { background: var(--fg); color: var(--bg); border-color: var(--fg); }

.main-area { flex: 1; display: flex; overflow: hidden; min-height: 0; position: relative; }

/* ==========================================
   CONTROL BAR
   ========================================== */
.controlbar {
  display: flex; align-items: center; justify-content: center; gap: 0.3rem;
  padding: 0.5rem 1rem; border-top: 1px solid var(--border);
  background: var(--bg); flex-shrink: 0; z-index: 20;
}
.cb {
  display: flex; flex-direction: column; align-items: center; gap: 0.15rem;
  background: var(--surface); color: var(--dim); border: 1px solid var(--border);
  padding: 0.45rem 0.9rem; cursor: pointer; border-radius: var(--radius-sm);
  transition: all 0.15s; -webkit-tap-highlight-color: transparent; font-family: inherit;
  position: relative;
}
.cb svg { width: 20px; height: 20px; stroke-linecap: round; stroke-linejoin: round; }
.cb span { font-size: 0.6rem; letter-spacing: 0.04em; }
.cb:hover { border-color: var(--dim); color: var(--fg); }
.cb:active { transform: scale(0.95); }
.cb.active { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.cb.off { background: rgba(192,96,96,0.15); color: var(--red); border-color: rgba(192,96,96,0.3); }
.cb.leave { color: var(--red); border-color: rgba(192,96,96,0.25); }
.cb.leave:hover { background: rgba(192,96,96,0.15); border-color: rgba(192,96,96,0.4); color: #e08080; }

.chat-badge {
  position: absolute; top: -4px; right: -4px; background: var(--red);
  color: #fff; font-size: 0.55rem; min-width: 16px; height: 16px;
  border-radius: 8px; display: flex; align-items: center; justify-content: center;
  padding: 0 4px; font-family: sans-serif; font-weight: 600;
}

/* Present popup */
.present-group { position: relative; display: inline-flex; }
.present-popup {
  display: none; position: absolute; bottom: calc(100% + 8px); left: 50%;
  transform: translateX(-50%); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 5px; flex-direction: column; gap: 3px;
  z-index: 50; white-space: nowrap;
}
.present-popup.open { display: flex; }
.present-popup button {
  background: none; border: none; color: var(--fg); font-family: inherit;
  font-size: 0.75rem; padding: 6px 14px; cursor: pointer; border-radius: var(--radius-xs);
  text-align: left;
}
.present-popup button:hover { background: var(--surface2); }

/* Excalidraw tile */
.excalidraw-tile { position: relative; }
.excalidraw-tile .excalidraw-frame {
  width: 100%; height: 100%; border: none; border-radius: var(--radius);
  background: #fff;
}

/* ==========================================
   PREFERENCES PANEL
   ========================================== */
.prefs-panel {
  display: flex; flex-direction: column; gap: 0.5rem; padding: 0 1rem;
  border-top: 1px solid var(--border); background: var(--surface);
  flex-shrink: 0; overflow: hidden; max-height: 0; overflow-y: auto;
  transition: max-height 0.3s ease, padding 0.3s ease;
}
.prefs-panel.open { max-height: 220px; padding: 0.8rem 1rem; }

.prefs-section {
  display: flex; align-items: flex-start; gap: 0.5rem; flex-wrap: wrap;
}
.prefs-section label {
  font-size: 0.72rem; color: var(--dim); flex-shrink: 0; letter-spacing: 0.04em; width: 5rem;
  padding-top: 0.25rem;
}
.pref-select {
  font-family: inherit; font-size: 0.75rem; background: var(--bg); color: var(--fg);
  border: 1px solid var(--border); padding: 0.3rem 0.5rem; border-radius: var(--radius-xs);
  flex: 1; min-width: 0;
}
.pref-btn {
  font-family: inherit; font-size: 0.7rem; background: var(--surface2); color: var(--dim);
  border: 1px solid var(--border); padding: 0.25rem 0.6rem; border-radius: var(--radius-xs);
  cursor: pointer; white-space: nowrap; transition: all 0.15s;
}
.pref-btn:hover { color: var(--fg); border-color: var(--dim); }

.pref-meter-track {
  flex: 1; height: 4px; background: var(--bg); border-radius: 2px; overflow: hidden; min-width: 60px;
}
.pref-meter-fill { height: 100%; width: 0%; background: var(--green); border-radius: 2px; transition: width 0.05s linear; }

/* ==========================================
   CONTENT / TILES GRID
   ========================================== */
.content-area {
  flex: 1; display: flex; overflow: hidden; padding: 8px; gap: 8px; min-height: 0;
}
.content-area .presenter-main { display: none; }
.content-area .presenter-sidebar { display: none; }
.content-area .presenter-overflow { display: none; }

.tiles-container { flex: 1; display: grid; gap: 8px; overflow: hidden; min-height: 0; }
.tiles-container.grid-1 { grid-template-columns: 1fr; }
.tiles-container.grid-2 { grid-template-columns: 1fr 1fr; }
.tiles-container.grid-3 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.tiles-container.grid-4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.tiles-container.grid-many { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

/* ==========================================
   PRESENTER MODE
   ========================================== */
.content-area.presenter {
  display: grid; grid-template-columns: 1fr auto; grid-template-rows: 1fr auto;
  gap: 8px; padding: 8px;
}
.content-area.presenter .tiles-container { display: none; }
.content-area.presenter .presenter-main {
  display: grid; grid-column: 1; grid-row: 1 / 3;
  border-radius: var(--radius); overflow: hidden; background: var(--tile-bg-solid);
  border: 1px solid var(--border); gap: 4px; padding: 4px; min-height: 0;
}
.content-area.presenter .presenter-main .video-tile {
  width: 100%; height: 100%; border-radius: var(--radius-sm); background: var(--tile-bg-solid); min-height: 0;
}
.content-area.presenter .presenter-main .video-tile video {
  object-fit: contain !important; border-radius: var(--radius-sm); background: var(--tile-bg-solid);
}
.presenter-main.screens-1 { grid-template-columns: 1fr; }
.presenter-main.screens-2 { grid-template-columns: 1fr 1fr; }
.presenter-main.screens-many { grid-template-columns: 1fr 1fr; grid-auto-rows: 1fr; }

.content-area.presenter .presenter-main .video-tile.pinned { box-shadow: inset 0 0 0 2px #60a0ff; }
.content-area.presenter .presenter-main .video-tile .peer-label { background: var(--tile-bg); }

.content-area.presenter .presenter-sidebar {
  display: flex; flex-direction: column; gap: 8px; grid-column: 2; grid-row: 1; overflow-y: auto;
}
.content-area.presenter .presenter-sidebar .video-tile {
  width: 180px; height: 120px; flex-shrink: 0; border-radius: var(--radius-sm);
}
.content-area.presenter .presenter-sidebar .video-tile video { border-radius: var(--radius-sm); }
.content-area.presenter .presenter-sidebar .video-tile .avatar { font-size: 1.4rem; }
.content-area.presenter .presenter-sidebar .video-tile .peer-label { font-size: 0.68rem; padding: 0.1rem 0.4rem; bottom: 0.3rem; left: 0.3rem; }

.content-area.presenter .presenter-overflow {
  display: flex; flex-direction: row; gap: 8px; grid-column: 1 / 3; grid-row: 2;
  overflow-x: auto; justify-content: center;
}
.content-area.presenter .presenter-overflow .video-tile {
  width: 140px; height: 90px; flex-shrink: 0; border-radius: var(--radius-sm);
}
.content-area.presenter .presenter-overflow .video-tile video { border-radius: var(--radius-sm); }
.content-area.presenter .presenter-overflow .video-tile .avatar { font-size: 1.2rem; }
.content-area.presenter .presenter-overflow .video-tile .peer-label { font-size: 0.62rem; padding: 0.08rem 0.35rem; bottom: 0.25rem; left: 0.25rem; }
.content-area.presenter .presenter-overflow:empty { display: none; }

.content-area.presenter.participants-hidden .presenter-sidebar { display: none; }
.content-area.presenter.participants-hidden .presenter-overflow { display: none; }
.content-area.presenter.participants-hidden .presenter-main { grid-column: 1 / 3; grid-row: 1 / 3; }

.content-area.presenter .presenter-main .presenter-badge { display: inline-block; }

/* ==========================================
   VIDEO TILES
   ========================================== */
.video-tile {
  position: relative; background: var(--surface); overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius); transition: box-shadow 0.25s ease, opacity 0.3s ease;
  min-height: 0;
}
.video-tile.tile-enter { opacity: 0; }
.video-tile:has(.tile-dropdown.open) { overflow: visible; }

.video-tile video {
  width: 100%; height: 100%; object-fit: contain; border-radius: var(--radius); background: var(--surface);
}
.video-tile video.screen-share { object-fit: contain; background: var(--tile-bg-solid); }

.video-tile .peer-label {
  position: absolute; bottom: 0.5rem; left: 0.6rem; font-size: 0.78rem;
  color: var(--fg); background: var(--tile-bg); padding: 0.15rem 0.55rem;
  border-radius: var(--radius-xs); backdrop-filter: blur(4px);
  display: flex; align-items: center; gap: 0.35rem;
}
.video-tile .avatar { font-size: 2.2rem; color: var(--dim); letter-spacing: 0.04em; font-weight: 500; }

.video-tile.speaking { box-shadow: inset 0 0 0 2px var(--green); }
.video-tile.is-sharing { box-shadow: inset 0 0 0 2px var(--green); }
.video-tile.is-sharing .presenter-badge { display: inline-block; }
.video-tile.pinned { box-shadow: inset 0 0 0 2px #60a0ff; }
.video-tile.video-hidden video { display: none !important; }
.video-tile.video-hidden .avatar { display: flex !important; }
.video-tile.remote-muted .peer-label::after {
  content: '(muted by you)'; font-size: 0.6rem; color: #bf6d6d; margin-left: 0.3rem;
}

/* Host indicator */
.video-tile.is-host .peer-label::before {
  content: '*'; font-size: 0.7rem; color: #f0c060; margin-right: 0.15rem;
}

.conn-status {
  position: absolute; top: 0.45rem; right: 0.55rem; font-size: 0.7rem;
  letter-spacing: 0.04em; border-radius: var(--radius-xs); padding: 0.1rem 0.4rem;
}
.conn-status.connecting { color: var(--dim); background: var(--tile-bg); }
.conn-status.relay { color: #b0a060; background: var(--tile-bg); }
.conn-status.failed { color: var(--red); background: rgba(192,96,96,0.15); }

.media-indicator { width: 6px; height: 6px; border-radius: 50%; background: #5a5a5a; flex-shrink: 0; }
.media-indicator.has-audio { background: var(--green); }
.media-indicator.muted { background: #bf6d6d; }

.presenter-badge {
  display: none; font-size: 0.65rem; color: var(--green);
  background: rgba(34,99,58,0.5); padding: 0.1rem 0.45rem;
  border-radius: var(--radius-xs); letter-spacing: 0.05em;
  margin-left: 0.3rem; animation: pulse-green 2s ease-in-out infinite;
}
@keyframes pulse-green { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }

/* ==========================================
   TILE MENU
   ========================================== */
.tile-menu { position: absolute; top: 0.4rem; left: 0.5rem; z-index: 10; opacity: 1; }
@media (hover: hover) {
  .tile-menu { opacity: 0; transition: opacity 0.15s; }
  .video-tile:hover .tile-menu { opacity: 1; }
}

.tile-menu-btn {
  font-family: inherit; font-size: 0.85rem; background: var(--tile-bg); color: var(--dim);
  border: 1px solid var(--border); width: 30px; height: 30px;
  border-radius: var(--radius-xs); cursor: pointer; backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; padding: 0;
  line-height: 1; letter-spacing: 2px; transition: all 0.15s; -webkit-tap-highlight-color: transparent;
}
.tile-menu-btn:hover { color: var(--fg); background: var(--surface); border-color: var(--dim); }

.tile-dropdown {
  display: none; position: absolute; top: 34px; left: 0; background: var(--surface2);
  border: 1px solid var(--border); border-radius: var(--radius-sm); min-width: 130px;
  padding: 4px; backdrop-filter: blur(12px); box-shadow: 0 8px 32px rgba(0,0,0,0.5); z-index: 50;
}
.tile-dropdown.open { display: block; }

.tile-dropdown button {
  display: block; width: 100%; font-family: inherit; font-size: 0.78rem; color: var(--fg);
  background: transparent; border: none; padding: 0.4rem 0.6rem; cursor: pointer;
  border-radius: var(--radius-xs); text-align: left; letter-spacing: 0.02em; transition: background 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.tile-dropdown button:hover { background: var(--surface); }
.tile-dropdown button:active { transform: none; }
.tile-dropdown button.menu-danger { color: var(--red); }
.tile-dropdown button.menu-danger:hover { background: rgba(192,96,96,0.1); }

.tile-dropdown .volume-row { display: flex; align-items: center; gap: 0.5rem; padding: 0.3rem 0.6rem; }
.tile-dropdown .volume-row label { font-size: 0.7rem; color: var(--dim); flex-shrink: 0; width: 2rem; }
.tile-dropdown input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 3px;
  background: var(--border); border-radius: 2px; outline: none; border: none; padding: 0;
}
.tile-dropdown input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: var(--fg); cursor: pointer;
}
.tile-dropdown .divider { height: 1px; background: var(--border); margin: 3px 0; }

/* ==========================================
   CHAT PANEL
   ========================================== */
.chat-panel {
  width: 0; border-left: none;
  flex-direction: column; flex-shrink: 0; background: var(--bg);
  transition: width 0.25s ease; z-index: 15; display: flex;
  overflow: hidden;
}
.chat-panel.open { width: 300px; border-left: 1px solid var(--border); }

.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--border);
  font-size: 0.82rem; color: var(--dim); letter-spacing: 0.06em;
}
.chat-close {
  background: none; border: none; color: var(--dim); font-size: 1.3rem; padding: 0.2rem 0.5rem; cursor: pointer;
}
.chat-close:hover { color: var(--fg); }

.chat-messages {
  flex: 1; overflow-y: auto; padding: 0.8rem;
  display: flex; flex-direction: column; gap: 0.55rem;
}
.chat-msg .chat-author { font-size: 0.75rem; color: var(--dim); margin-right: 0.3rem; }
.chat-msg .chat-text { font-size: 0.9rem; word-break: break-word; }

.chat-msg.chat-whisper { opacity: 0.85; }
.chat-whisper-label {
  font-size: 0.65rem; color: #9080c0; font-style: italic; margin-right: 0.3rem;
  letter-spacing: 0.02em;
}

.chat-input-row { display: flex; border-top: 1px solid var(--border); position: relative; }
.chat-input-row input { border: none; border-radius: 0; flex: 1; }
.chat-input-row button { padding: 0.65rem 1rem; font-size: 0.85rem; border-radius: 0; }

.chat-autocomplete {
  display: none; position: absolute; bottom: 100%; left: 0; right: 0;
  background: var(--surface2); border: 1px solid var(--border);
  border-bottom: none; border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  max-height: 150px; overflow-y: auto; z-index: 20;
}
.chat-autocomplete.open { display: block; }
.ac-item {
  padding: 0.4rem 0.8rem; font-size: 0.78rem; color: var(--fg);
  cursor: pointer; transition: background 0.1s;
}
.ac-item:hover, .ac-item.selected { background: var(--surface); }


/* ==========================================
   TOAST
   ========================================== */
.toast {
  position: fixed; bottom: 5rem; left: 50%; background: var(--surface2); color: var(--fg);
  padding: 0.45rem 1.3rem; font-size: 0.82rem; z-index: 200; pointer-events: none;
  border-radius: var(--radius-sm); border: 1px solid var(--border); white-space: nowrap;
  transform: translate(-50%, 10px); opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ==========================================
   SCROLLBAR
   ========================================== */
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.mobile-only { display: none !important; }

/* ==========================================
   MOBILE
   ========================================== */
@media (max-width: 700px) {
  .landing h1 { font-size: 2.5rem; }
  .lobby-title { font-size: 2rem; }
  .lobby-card { gap: 0.6rem; }
  .lobby-cam-box { aspect-ratio: 4/3; }

  .topbar { padding: 0.35rem 0.6rem; }
  .topbar .room-name { font-size: 0.72rem; }

  .controlbar { gap: 0.15rem; padding: 0.4rem 0.4rem; }
  .cb { padding: 0.4rem 0.55rem; }
  .cb svg { width: 18px; height: 18px; }
  .cb span { font-size: 0.55rem; }

  .prefs-panel.open { max-height: 300px; }
  .desktop-only { display: none !important; }
  .mobile-only { display: flex !important; }

  .tiles-container.grid-2, .tiles-container.grid-3, .tiles-container.grid-4 { grid-template-columns: 1fr 1fr; }
  .tiles-container.grid-many { grid-template-columns: 1fr 1fr; }

  .video-tile .avatar { font-size: 1.6rem; }
  .video-tile .peer-label { font-size: 0.65rem; padding: 0.1rem 0.4rem; bottom: 0.3rem; left: 0.3rem; }

  .content-area.presenter { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .content-area.presenter .presenter-main { grid-column: 1; grid-row: 1; }
  .content-area.presenter .presenter-sidebar {
    grid-column: 1; grid-row: 2; flex-direction: row; overflow-x: auto; overflow-y: hidden;
  }
  .content-area.presenter .presenter-sidebar .video-tile { width: 100px; height: 70px; }
  .content-area.presenter .presenter-overflow { grid-column: 1; grid-row: 3; }
  .content-area.presenter .presenter-overflow .video-tile { width: 80px; height: 55px; }
  .content-area.presenter.participants-hidden .presenter-main { grid-column: 1; grid-row: 1 / 3; }

  .chat-panel { width: 0 !important; position: fixed; inset: 0; z-index: 50; border-left: none !important; }
  .chat-panel.open { width: 100% !important; }

  .tile-menu-btn { width: 26px; height: 26px; font-size: 0.72rem; }
  .tile-dropdown { min-width: 120px; }
  .tile-dropdown button { padding: 0.45rem 0.6rem; font-size: 0.72rem; }

  .toast { bottom: 4.5rem; font-size: 0.75rem; padding: 0.35rem 1rem; }

  .lobby-devices { gap: 0.3rem; }
}

@media (max-width: 380px) {
  .cb { padding: 0.35rem 0.4rem; }
  .cb svg { width: 16px; height: 16px; }
  .cb span { font-size: 0.5rem; }
  .topbar .room-name { font-size: 0.62rem; }
}

/* ==========================================
   TOPBAR EXTRAS
   ========================================== */
.topbar-left { display: flex; align-items: center; gap: 0.6rem; }
.call-timer { font-size: 0.72rem; color: var(--dim); letter-spacing: 0.04em; font-variant-numeric: tabular-nums; }
.conn-indicator { font-size: 0.65rem; padding: 0.1rem 0.4rem; border-radius: var(--radius-xs); cursor: default; }
.conn-indicator.direct { color: var(--green); }
.conn-indicator.relay { color: #b0a060; }

.conn-popover {
  position: fixed; z-index: 300; pointer-events: none;
  opacity: 0; transition: opacity 0.12s ease;
}
.conn-popover.visible { opacity: 1; }
.conn-popover-card {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.7rem 0.85rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35); max-width: 280px; min-width: 220px;
}
.conn-popover-status {
  display: flex; align-items: center; gap: 0.45rem;
  font-size: 0.78rem; font-weight: 600; margin-bottom: 0.4rem;
}
.conn-popover-dot {
  width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0;
}
.conn-popover-dot.green { background: var(--green); box-shadow: 0 0 6px var(--green); }
.conn-popover-dot.yellow { background: #b0a060; box-shadow: 0 0 6px #b0a060; }
.conn-popover-dot.mixed-dot { background: linear-gradient(135deg, var(--green) 50%, #b0a060 50%); }
.conn-popover-desc {
  font-size: 0.68rem; color: var(--dim); line-height: 1.55;
}
.conn-popover-tag {
  display: inline-block; font-size: 0.6rem; padding: 0.12rem 0.4rem;
  border-radius: var(--radius-xs); margin-top: 0.45rem;
  letter-spacing: 0.03em;
}
.conn-popover-tag.e2ee { background: rgba(80,200,120,0.12); color: var(--green); border: 1px solid rgba(80,200,120,0.25); }
.conn-popover-tag.not-e2ee { background: rgba(176,160,96,0.12); color: #b0a060; border: 1px solid rgba(176,160,96,0.25); }

/* ==========================================
   REACTIONS
   ========================================== */
.reactions-container {
  position: fixed; bottom: 5rem; left: 0; right: 0;
  pointer-events: none; z-index: 180; overflow: hidden; height: 50vh;
}
.reaction-float {
  position: absolute; bottom: 0; font-size: 1.6rem; font-weight: 600;
  color: var(--fg); opacity: 0; animation: floatUp 2s ease-out forwards;
  white-space: nowrap;
}
.reaction-float .reaction-name { font-size: 0.6rem; color: var(--dim); display: block; text-align: center; }
@keyframes floatUp {
  0% { opacity: 1; transform: translateY(0) scale(1); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-200px) scale(0.7); }
}

.react-picker {
  display: none; position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
  background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 0.3rem; margin-bottom: 0.4rem; gap: 0.15rem; z-index: 30;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3); white-space: nowrap;
}
.react-picker.open { display: flex; }
.react-picker button {
  font-family: inherit; font-size: 0.85rem; background: none; color: var(--fg);
  border: none; padding: 0.35rem 0.5rem; cursor: pointer; border-radius: var(--radius-xs);
  transition: background 0.1s; min-width: 2rem; text-align: center;
}
.react-picker button:hover { background: var(--surface); }
.react-picker button:active { transform: none; }

/* ==========================================
   MUTED REMINDER
   ========================================== */
.muted-reminder {
  position: fixed; bottom: 5rem; left: 50%; transform: translateX(-50%);
  background: rgba(192,96,96,0.9); color: #fff; padding: 0.4rem 1.2rem;
  font-size: 0.78rem; border-radius: var(--radius-sm); z-index: 190;
  pointer-events: none; opacity: 0; transition: opacity 0.2s;
}
.muted-reminder.show { opacity: 1; }

/* ==========================================
   SOUNDBOARD
   ========================================== */
.soundboard-list { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.soundboard-list .sb-btn {
  font-family: inherit; font-size: 0.65rem; background: var(--surface2); color: var(--dim);
  border: 1px solid var(--border); padding: 0.2rem 0.5rem; border-radius: var(--radius-xs);
  cursor: pointer; transition: all 0.15s; display: flex; align-items: center; gap: 0.3rem;
}
.soundboard-list .sb-btn:hover { color: var(--fg); border-color: var(--dim); }
.soundboard-list .sb-btn:active { transform: none; }
.soundboard-list .sb-remove {
  font-family: inherit; font-size: 0.6rem; background: none; color: var(--red);
  border: none; padding: 0; cursor: pointer; margin-left: 0.2rem; line-height: 1;
}
.soundboard-list .sb-remove:hover { opacity: 0.7; }
.soundboard-list .sb-remove:active { transform: none; }

.soundboard-playing {
  position: fixed; top: 3rem; left: 50%; transform: translateX(-50%);
  background: var(--surface2); color: var(--fg); padding: 0.35rem 1rem;
  font-size: 0.75rem; border-radius: var(--radius-sm); border: 1px solid var(--border);
  z-index: 190; opacity: 0; transition: opacity 0.2s; pointer-events: none;
}
.soundboard-playing.show { opacity: 1; }

/* ==========================================
   PIP BUTTON (on tile menu)
   ========================================== */

/* ==========================================
   LEAVE SCREEN
   ========================================== */
.leave-screen {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; align-items: center; justify-content: center; z-index: 200;
}
.leave-card { text-align: center; }
.leave-title {
  font-size: 2rem; font-weight: 300; letter-spacing: 0.2em; margin-bottom: 1.5rem;
  color: var(--fg);
}
.leave-room {
  font-size: 0.78rem; color: var(--dim); margin-bottom: 1.2rem; letter-spacing: 0.04em;
}
.leave-room strong { color: var(--fg); }
.leave-rejoin {
  font-family: inherit; font-size: 0.9rem; color: var(--dim);
  text-decoration: underline; text-underline-offset: 3px;
  cursor: pointer; letter-spacing: 0.04em; transition: color 0.15s;
}
.leave-rejoin:hover { color: var(--fg); }
.leave-home {
  display: block; margin-top: 0.8rem;
  font-family: inherit; font-size: 0.75rem; color: var(--dim);
  text-decoration: none; letter-spacing: 0.04em; transition: color 0.15s;
}
.leave-home:hover { color: var(--fg); }

/* ==========================================
   THEME TOGGLE
   ========================================== */
.theme-toggle {
  font-family: inherit; font-size: 0.72rem; color: var(--dim); background: none;
  border: none; padding: 0.3rem 0.5rem; cursor: pointer; letter-spacing: 0.04em;
  transition: color 0.15s;
}
.theme-toggle:hover { color: var(--fg); }
.theme-toggle:active { transform: none; }

/* ==========================================
   RAISE HAND
   ========================================== */
.hand-badge {
  position: absolute; top: 0.5rem; left: 0.6rem; z-index: 5;
  font-size: 0.7rem; color: var(--fg); background: var(--surface2);
  border: 1px solid var(--border); border-radius: var(--radius-xs);
  padding: 0.15rem 0.4rem; display: none;
}
.video-tile.hand-raised .hand-badge { display: block; }

/* ==========================================
   AWAY STATUS
   ========================================== */
.video-tile.away { opacity: 0.4; }
.video-tile.away::before {
  content: 'away';
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  font-size: 0.75rem; color: var(--dim); letter-spacing: 0.08em; z-index: 5;
}

/* ==========================================
   TYPING INDICATOR
   ========================================== */
.typing-indicator {
  font-size: 0.68rem; color: var(--dim); padding: 0.2rem 0.6rem;
  font-style: italic; letter-spacing: 0.02em;
}

/* ==========================================
   CHAT TIMESTAMPS & REACTIONS
   ========================================== */
.chat-meta {
  display: flex; align-items: baseline; gap: 0.4rem;
}
.chat-time {
  font-size: 0.6rem; color: var(--dim); opacity: 0.5; letter-spacing: 0.02em;
}
.chat-react-trigger {
  position: absolute; top: 0.15rem; right: 0.3rem;
  font-family: inherit; font-size: 0.65rem; background: var(--surface2);
  color: var(--dim); border: 1px solid var(--border); border-radius: var(--radius-xs);
  width: 18px; height: 18px; display: none; align-items: center; justify-content: center;
  cursor: pointer; padding: 0; line-height: 1;
}
.chat-msg { position: relative; }
.chat-msg:hover .chat-react-trigger { display: flex; }
.chat-reactions-row {
  display: flex; gap: 0.25rem; flex-wrap: wrap; margin-top: 0.15rem;
}
.chat-reaction-badge {
  font-size: 0.6rem; padding: 0.08rem 0.35rem; background: var(--surface2);
  border: 1px solid var(--border); border-radius: var(--radius-xs); color: var(--dim);
}
.msg-reaction-picker {
  position: absolute; top: -2rem; right: 0.3rem; z-index: 10;
  display: flex; gap: 0.15rem; background: var(--surface2);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.2rem; box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.msg-reaction-picker button {
  font-family: inherit; font-size: 0.7rem; background: none; border: none;
  color: var(--fg); padding: 0.2rem 0.4rem; cursor: pointer; border-radius: var(--radius-xs);
}
.msg-reaction-picker button:hover { background: var(--surface); }

/* ==========================================
   WAITING ROOM KNOCK
   ========================================== */
.waiting-knock {
  position: fixed; top: 1rem; right: 1rem; z-index: 300;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.6rem 0.8rem;
  display: flex; align-items: center; gap: 0.5rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  animation: slideInRight 0.2s ease;
}
.waiting-knock span { font-size: 0.78rem; color: var(--fg); }
.waiting-knock button {
  font-family: inherit; font-size: 0.7rem; padding: 0.25rem 0.6rem;
  border-radius: var(--radius-xs); cursor: pointer; border: 1px solid var(--border);
  background: var(--surface); color: var(--fg);
}
.waiting-knock button:first-of-type { background: var(--green); color: #000; border-color: var(--green); }
@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ==========================================
   TILE DRAG & DROP
   ========================================== */
.video-tile.dragging { opacity: 0.3; }
.video-tile[draggable="true"] { cursor: grab; }
.video-tile[draggable="true"]:active { cursor: grabbing; }
