:root {
  --bg: #0e1116;
  --panel: #181c24;
  --panel-2: #20252f;
  --accent: #5b8cff;
  --accent-hover: #4a7bf0;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --text: #e8ecf3;
  --muted: #93a0b4;
  --border: #2a3140;
  --ok: #22c55e;
}

* { box-sizing: border-box; }
/* The [hidden] attribute must beat our `.prejoin{display:flex}` / `.call{display:flex}`
   rules — otherwise toggling section.hidden does nothing and the join screen never leaves. */
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }

.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 800; font-size: 22px; letter-spacing: -0.02em;
}
.brand .dot { color: var(--accent); }

/* ---------- Landing ---------- */
.landing {
  min-height: 100vh;
  min-height: 100dvh; /* iOS: account for Safari's dynamic toolbar */
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 24px; text-align: center;
}
.landing .hero { max-width: 520px; width: 100%; }
.landing h1 { font-size: 44px; line-height: 1.05; margin: 18px 0 8px; letter-spacing: -0.03em; }
.landing p.sub { color: var(--muted); font-size: 17px; margin: 0 0 32px; }

.btn {
  appearance: none; border: 0; cursor: pointer;
  font-size: 16px; font-weight: 600; border-radius: 12px;
  padding: 14px 22px; color: #fff; background: var(--accent);
  transition: background .15s ease, transform .05s ease;
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: translateY(1px); }
.btn.big { font-size: 19px; padding: 18px 28px; width: 100%; }
.btn.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { background: #283040; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: var(--danger-hover); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* SVG icon sizing (icons replace emoji for cross-platform consistency) */
.ctrl svg { width: 22px; height: 22px; display: block; }
.toggle-row .btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.toggle-row .btn svg { width: 18px; height: 18px; }
.label svg { width: 13px; height: 13px; display: block; }

.join-row { display: flex; gap: 8px; margin-top: 18px; }
.join-row input {
  flex: 1; background: var(--panel); border: 1px solid var(--border);
  color: var(--text); border-radius: 10px; padding: 13px 14px; font-size: 15px;
}
.join-row input:focus { outline: none; border-color: var(--accent); }
.footnote { color: var(--muted); font-size: 13px; margin-top: 28px; }

/* ---------- Pre-join ---------- */
.prejoin {
  min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 24px; gap: 18px;
}
.prejoin .card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; padding: 22px; width: 100%; max-width: 440px;
}
.prejoin video {
  width: 100%; aspect-ratio: 16/9; background: #000;
  border-radius: 12px; object-fit: cover; transform: scaleX(-1);
}
.prejoin .roomcode { color: var(--muted); font-size: 14px; margin: 4px 0 14px; }
.prejoin .roomcode b { color: var(--text); }
.prejoin label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
.prejoin input[type=text] {
  width: 100%; background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 10px; padding: 13px 14px; font-size: 15px;
}
.prejoin input:focus { outline: none; border-color: var(--accent); }
.toggle-row { display: flex; gap: 8px; margin: 14px 0; }
.toggle-row .btn { flex: 1; }
.btn.off { background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); }
.webinar-note {
  background: rgba(91,140,255,.12); border: 1px solid var(--accent); color: var(--text);
  font-size: 13px; line-height: 1.45; padding: 10px 12px; border-radius: 10px; margin: 0 0 14px;
  text-align: left;
}
#hostkey-row { text-align: left; }

/* ---------- In call ---------- */
.pill {
  display: inline-block; background: var(--panel-2); border: 1px solid var(--border);
  color: var(--muted); font-size: 11px; font-weight: 600; padding: 2px 8px;
  border-radius: 999px; margin-right: 8px;
}
.call { display: flex; flex-direction: column; height: 100vh; height: 100dvh; height: var(--app-h, 100dvh); }
.call .topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; border-bottom: 1px solid var(--border); flex: 0 0 auto;
}
.call .topbar .meta { color: var(--muted); font-size: 13px; }
.call .topbar .count { color: var(--text); font-weight: 600; }

.stage { flex: 1 1 auto; display: flex; min-height: 0; min-width: 0; }
.grid {
  flex: 1 1 auto; display: grid; gap: 8px; padding: 12px;
  grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
  place-content: stretch;
  min-height: 0; min-width: 0; overflow: hidden;   /* never scroll — tiles are sized to fit */
}
.tile {
  position: relative; background: #000; border-radius: 12px; overflow: hidden;
  min-height: 0; min-width: 0; border: 2px solid transparent;
}
.tile.speaking { border-color: var(--accent); }
.tile video { width: 100%; height: 100%; object-fit: contain; }
.tile.self video { transform: scaleX(-1); }
.tile .placeholder {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #232a36, #161b23);
}
.tile .avatar {
  width: 64px; height: 64px; border-radius: 50%; background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 700; color: #fff;
}
.tile .label {
  position: absolute; left: 8px; bottom: 8px; z-index: 2;
  background: rgba(0,0,0,.55); color: #fff; font-size: 12px;
  padding: 3px 8px; border-radius: 6px; display: flex; align-items: center; gap: 6px;
  max-width: calc(100% - 16px);
}
.tile .label .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .muted-icon { opacity: .9; }

.toolbar {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 14px; padding-bottom: calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border); flex-wrap: wrap;
}
.ctrl {
  position: relative;
  appearance: none; cursor: pointer; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text);
  width: 54px; height: 54px; border-radius: 14px; font-size: 20px;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s ease;
}
.ctrl:hover { background: #2b3342; }
.ctrl.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.badge {
  position: absolute; top: -5px; right: -5px;
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 700;
  min-width: 18px; height: 18px; border-radius: 9px; padding: 0 4px;
  display: flex; align-items: center; justify-content: center;
}
.ctrl.off { background: var(--danger); border-color: var(--danger); color: #fff; }
.ctrl.leave { background: var(--danger); border-color: var(--danger); color: #fff; width: auto; padding: 0 18px; font-weight: 600; font-size: 15px; }
.ctrl.leave:hover { background: var(--danger-hover); }
.ctrl .cap { font-size: 10px; }

/* ---------- Chat ---------- */
.chat {
  flex: 0 0 320px; max-width: 85vw; min-height: 0;
  display: flex; flex-direction: column;
  background: var(--panel); border-left: 1px solid var(--border);
}
.chat-head {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--border); font-weight: 600;
}
.chat-x {
  appearance: none; background: transparent; border: 0; color: var(--muted);
  cursor: pointer; padding: 4px; border-radius: 6px; display: flex;
}
.chat-x:hover { background: var(--panel-2); color: var(--text); }
.chat-x svg { width: 18px; height: 18px; }
.chat-log {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  padding: 12px; display: flex; flex-direction: column; gap: 10px;
}
.chat-who { font-size: 12px; font-weight: 600; color: var(--accent); margin-bottom: 2px; }
.chat-msg.self { align-items: flex-end; display: flex; flex-direction: column; }
.chat-msg.self .chat-who { color: var(--muted); }
.chat-text {
  background: var(--panel-2); border-radius: 10px; padding: 8px 10px; font-size: 14px;
  overflow-wrap: anywhere; white-space: pre-wrap; max-width: 100%;
}
.chat-msg.self .chat-text { background: var(--accent); color: #fff; }
.chat-form { flex: 0 0 auto; display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); }
.chat-form input {
  flex: 1; min-width: 0; background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 10px; padding: 10px 12px; font-size: 14px;
}
.chat-form input:focus { outline: none; border-color: var(--accent); }
.chat-send {
  appearance: none; border: 0; background: var(--accent); color: #fff; border-radius: 10px;
  width: 42px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.chat-send:hover { background: var(--accent-hover); }
.chat-send svg { width: 18px; height: 18px; }

.toast {
  position: fixed; left: 50%; bottom: 92px; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0;
  transition: opacity .2s ease; pointer-events: none; z-index: 50;
}
.toast.show { opacity: 1; }

.center-msg {
  min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 14px; text-align: center; padding: 24px; color: var(--muted);
}

@media (max-width: 600px) {
  .landing h1 { font-size: 34px; }
  .grid { gap: 6px; padding: 6px; }
  /* Chat takes over the stage on small screens (grid collapses to 0 while open). */
  .chat { flex-basis: 100%; max-width: 100%; }
  .chat-head { padding: 10px 12px; }
  .chat-log { padding: 10px; gap: 8px; }
  /* 16px inputs stop iOS Safari from auto-zooming on focus */
  .chat-form input, .prejoin input[type=text], .join-row input { font-size: 16px; }
  .toolbar { gap: 8px; padding: 8px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
  .ctrl { width: 48px; height: 48px; }
  .ctrl svg { width: 20px; height: 20px; }
}
