/* ── Reset & base ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f0f0f;
  --surface:   #1a1a1a;
  --surface2:  #242424;
  --border:    #2e2e2e;
  --text:      #e8e8e8;
  --text-dim:  #888;
  --accent:    #2563eb;
  --accent-h:  #1d4ed8;
  --danger:    #dc2626;
  --success:   #16a34a;
  --warn:      #d97706;
  --radius:    10px;
  --topbar-h:  56px;
  --strip-h:   110px;
  --chat-w:    300px;
}

html, body { height: 100%; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

.hidden { display: none !important; }

/* ── Lobby ───────────────────────────────────────────────────────────── */
#lobby {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.lobby-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.lobby-card h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: 0.04em; }

.lobby-sub { font-size: 0.85rem; color: var(--text-dim); margin-top: -12px; }

.field { display: flex; flex-direction: column; gap: 6px; }

.field label { font-size: 0.8rem; color: var(--text-dim); font-weight: 500; }

.field input {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.15s;
}
.field input:focus { border-color: var(--accent); }

.btn-primary {
  padding: 11px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-primary:hover   { background: var(--accent-h); }
.btn-primary:disabled { background: #444; cursor: not-allowed; }

.lobby-error { font-size: 0.85rem; color: #f87171; text-align: center; }

/* ── Call screen ─────────────────────────────────────────────────────── */
#call-screen {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Top bar */
#topbar {
  height: var(--topbar-h);
  flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
}

#room-label {
  font-weight: 600;
  font-size: 0.95rem;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#peer-count { font-size: 0.8rem; color: var(--text-dim); white-space: nowrap; }

.topbar-actions { display: flex; gap: 6px; }

.ctrl-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  font-size: 0;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  min-width: 52px;
}
.ctrl-btn svg { width: 20px; height: 20px; }
.ctrl-btn .ctrl-label { font-size: 0.65rem; color: var(--text-dim); }
.ctrl-btn:hover { background: var(--border); }

.ctrl-btn .icon-active          { display: none; }
.ctrl-btn.active .icon-default  { display: none; }
.ctrl-btn.active .icon-active   { display: block; }

.ctrl-btn.active { border-color: var(--danger); color: var(--danger); }
.ctrl-btn.active .ctrl-label { color: var(--danger); }

#btn-share.active { border-color: var(--success); color: var(--success); }
#btn-share.active .ctrl-label { color: var(--success); }

#btn-chat.active { border-color: var(--accent); color: var(--accent); }
#btn-chat.active .ctrl-label { color: var(--accent); }

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

.chat-btn-wrap { position: relative; display: flex; align-items: center; justify-content: center; }
.chat-badge {
  position: absolute; top: -5px; right: -7px;
  background: var(--danger); color: #fff;
  font-size: 0.6rem; font-weight: 700;
  min-width: 16px; height: 16px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 3px; pointer-events: none;
}

/* ── Main area ───────────────────────────────────────────────────────── */
#main-area {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ── Stage (spotlight + filmstrip) ──────────────────────────────────── */
#stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  gap: 0;
}

/* ── Spotlight ───────────────────────────────────────────────────────── */
#spotlight {
  flex: 1;
  position: relative;
  background: #000;
  overflow: hidden;
}

#spotlight-video {
  width: 100%;
  height: 100%;
  object-fit: contain; /* letterbox so wide content isn't cropped */
  display: block;
  background: #000;
}

/* ── Filmstrip ───────────────────────────────────────────────────────── */
#filmstrip {
  height: var(--strip-h);
  flex-shrink: 0;
  background: var(--bg);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

#filmstrip::-webkit-scrollbar { height: 4px; }
#filmstrip::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* Filmstrip tile */
.film-tile {
  flex-shrink: 0;
  width: 128px;
  height: 90px;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s;
  background: var(--surface);
}
.film-tile:hover  { border-color: var(--accent); }
.film-tile.active { border-color: #22c55e; }  /* currently spotlighted */
.film-tile.speaking { border-color: #22c55e; box-shadow: 0 0 0 2px rgba(34,197,94,0.3); }

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

/* cam-off state in filmstrip */
.film-tile .cam-off-overlay {
  position: absolute; inset: 0;
  display: none;
  align-items: center; justify-content: center;
  flex-direction: column; gap: 4px;
  background: var(--surface2);
}
.film-tile.cam-off .cam-off-overlay { display: flex; }
.film-tile.cam-off video { visibility: hidden; }

.film-tile .cam-off-overlay .avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; font-weight: 700; color: #fff;
}

/* Bottom bar on film tile */
.film-tile .tile-bar {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 3px 6px;
  background: linear-gradient(transparent, rgba(0,0,0,0.75));
  display: flex; align-items: center; gap: 4px;
}
.film-tile .tile-name {
  font-size: 0.68rem; font-weight: 500; flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.film-tile .tile-state {
  font-size: 0.55rem; padding: 1px 4px; border-radius: 3px;
  font-weight: 700; text-transform: uppercase; flex-shrink: 0;
}
.tile-state.connecting { background: var(--warn);    color: #000; }
.tile-state.connected  { background: var(--success); color: #fff; }
.tile-state.failed     { background: var(--danger);  color: #fff; }
.tile-state.local      { background: var(--accent);  color: #fff; }
.tile-state.reconnecting { background: var(--warn); color: #000; }

.film-tile .tile-muted {
  width: 14px; height: 14px; color: var(--danger); flex-shrink: 0;
}

/* Shared common tile elements used by spotlight bar too */
.tile-bar { }
.tile-name { }
.tile-muted { width: 18px; height: 18px; color: var(--danger); flex-shrink: 0; }

/* Spotlight bar */
#spotlight-bar {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 8px 12px;
  background: linear-gradient(transparent, rgba(0,0,0,0.65));
  display: flex; align-items: center; gap: 8px;
}
#spotlight-name { font-size: 0.9rem; font-weight: 600; flex: 1; }

/* cam-off overlay shared style */
.cam-off-overlay {
  position: absolute; inset: 0;
  display: none;
  align-items: center; justify-content: center;
  flex-direction: column; gap: 10px;
  background: var(--surface2);
}
.cam-off .cam-off-overlay { display: flex; }
.cam-off video            { visibility: hidden; }

.avatar {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; font-weight: 700; color: #fff;
}
.avatar-name { font-size: 0.85rem; color: var(--text-dim); }

/* ── Chat panel ──────────────────────────────────────────────────────── */
#chat-panel {
  width: var(--chat-w);
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#chat-header {
  height: 44px; padding: 0 12px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: 0.9rem; flex-shrink: 0;
}

#chat-close {
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; font-size: 1rem; padding: 4px 6px;
  border-radius: 4px; line-height: 1;
}
#chat-close:hover { background: var(--border); color: var(--text); }

#chat-messages {
  flex: 1; overflow-y: auto;
  padding: 12px; display: flex; flex-direction: column; gap: 10px;
  scroll-behavior: smooth;
}

.msg { display: flex; flex-direction: column; gap: 2px; max-width: 100%; }
.msg.self { align-items: flex-end; }
.msg.self .msg-bubble { background: var(--accent); color: #fff; }

.msg-meta { font-size: 0.68rem; color: var(--text-dim); padding: 0 4px; }
.msg-bubble {
  background: var(--surface2); border-radius: 10px;
  padding: 7px 11px; font-size: 0.85rem; line-height: 1.4;
  word-break: break-word; max-width: 240px;
}

.msg.system .msg-bubble {
  background: transparent; border: 1px solid var(--border);
  color: var(--text-dim); font-size: 0.78rem; text-align: center; max-width: 100%;
}

.msg-file {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 12px; max-width: 240px;
  text-decoration: none; color: var(--text); transition: background 0.15s; cursor: default;
}
.msg-file:hover { background: var(--border); }
.msg-file svg { flex-shrink: 0; color: var(--accent); }
.msg-file-info { display: flex; flex-direction: column; min-width: 0; }
.msg-file-name { font-size: 0.82rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-file-size { font-size: 0.7rem; color: var(--text-dim); }

.msg-progress { height: 3px; background: var(--border); border-radius: 2px; overflow: hidden; margin-top: 4px; }
.msg-progress-bar { height: 100%; background: var(--accent); width: 0%; transition: width 0.1s; }

#chat-footer {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 10px; border-top: 1px solid var(--border); flex-shrink: 0;
}

#file-attach-label {
  cursor: pointer; color: var(--text-dim);
  display: flex; align-items: center; padding: 4px;
  border-radius: 6px; transition: background 0.15s, color 0.15s; flex-shrink: 0;
}
#file-attach-label:hover { background: var(--border); color: var(--text); }
#file-input { display: none; }

#chat-input {
  flex: 1; background: var(--surface2);
  border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font-size: 0.875rem; padding: 7px 10px;
  outline: none; transition: border-color 0.15s;
}
#chat-input:focus { border-color: var(--accent); }

#chat-send {
  background: var(--accent); border: none; color: #fff;
  border-radius: 8px; width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0; transition: background 0.15s;
}
#chat-send:hover { background: var(--accent-h); }

/* ── Toasts ──────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px;
  z-index: 100; pointer-events: none;
}

.toast {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 16px;
  font-size: 0.85rem; color: var(--text);
  opacity: 0; transform: translateY(8px);
  animation: toast-in 0.2s forwards, toast-out 0.3s 2.7s forwards;
  white-space: nowrap;
}
.toast.warn  { border-color: var(--warn);    color: var(--warn); }
.toast.error { border-color: var(--danger);  color: #f87171; }

@keyframes toast-in  { to { opacity: 1; transform: translateY(0); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

/* ── Reaction picker ─────────────────────────────────────────────────── */
#reaction-picker {
  position: fixed;
  /* positioned by JS below the React button */
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 10px;
  display: flex;
  gap: 6px;
  z-index: 200;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

.react-btn {
  font-size: 1.4rem;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 8px;
  transition: background 0.15s, transform 0.1s;
  line-height: 1;
}
.react-btn:hover { background: var(--surface2); transform: scale(1.2); }

/* Floating reaction animation — appended to film tiles / spotlight */
.reaction-float {
  position: absolute;
  font-size: 2rem;
  bottom: 36px;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 10;
  animation: float-up 2.4s ease-out forwards;
}

@keyframes float-up {
  0%   { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
  60%  { opacity: 1; transform: translateX(-50%) translateY(-60px) scale(1.3); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-100px) scale(0.8); }
}

/* ── Settings / TURN panel ───────────────────────────────────────────── */
#settings-panel {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: 16px;
}

.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 28px 24px;
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  font-size: 1rem;
}

#settings-close {
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; font-size: 1rem; padding: 4px 6px; border-radius: 4px;
}
#settings-close:hover { background: var(--border); color: var(--text); }

.settings-desc {
  font-size: 0.82rem;
  color: var(--text-dim);
  line-height: 1.5;
}

.settings-actions {
  display: flex;
  gap: 8px;
}

/* TURN active indicator on Network button */
#btn-settings.turn-active {
  border-color: var(--success);
  color: var(--success);
}
#btn-settings.turn-active .ctrl-label { color: var(--success); }
