:root {
  color-scheme: dark;
  --background: #080a0e;
  --surface: #11151c;
  --surface-raised: #181e27;
  --border: rgba(255, 255, 255, 0.09);
  --text: #f4f7fb;
  --muted: #929dac;
  --accent: #b9ff66;
  --accent-text: #11170a;
  --danger: #ff5c6b;
  --shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; background: var(--background); color: var(--text); }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.home-page {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 28px;
  background:
    radial-gradient(circle at 15% 10%, rgba(185, 255, 102, 0.13), transparent 33rem),
    radial-gradient(circle at 95% 95%, rgba(88, 130, 255, 0.10), transparent 32rem),
    var(--background);
}

.home-card {
  width: min(100%, 720px);
  min-height: min(700px, calc(100svh - 56px));
  padding: clamp(28px, 6vw, 64px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border: 1px solid var(--border);
  border-radius: 32px;
  background: linear-gradient(145deg, rgba(24, 30, 39, 0.94), rgba(12, 15, 21, 0.96));
  box-shadow: var(--shadow);
}

.brand { display: inline-flex; align-items: center; gap: 12px; color: var(--text); font-size: 18px; font-weight: 700; text-decoration: none; letter-spacing: -0.02em; }
.brand.compact { font-size: 16px; }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 11px; background: var(--accent); color: var(--accent-text); font-weight: 900; }
.brand.compact .brand-mark { width: 30px; height: 30px; border-radius: 9px; }

.home-copy { max-width: 590px; padding: 64px 0; }
.eyebrow { margin: 0 0 14px; color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: 0.16em; text-transform: uppercase; }
.home-copy h1 { margin: 0; max-width: 600px; font-size: clamp(48px, 8vw, 78px); line-height: 0.98; letter-spacing: -0.065em; }
.home-copy > p:last-child { margin: 28px 0 0; max-width: 510px; color: var(--muted); font-size: clamp(17px, 2vw, 20px); line-height: 1.55; }

.primary-button {
  border: 0;
  min-height: 58px;
  padding: 0 22px;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-radius: 16px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
  transition: transform 150ms ease, filter 150ms ease;
}
.primary-button:hover { transform: translateY(-2px); filter: brightness(1.04); }
.primary-button:disabled { cursor: wait; opacity: 0.65; transform: none; }
.form-error { margin: 12px 0 0; color: #ffabb2; }

.call-page { height: var(--call-height, 100dvh); overflow: hidden; }
.call-shell { height: 100%; display: grid; grid-template-rows: 66px minmax(0, 1fr) 82px; }
.call-header { position: relative; z-index: 40; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 0 22px; border-bottom: 1px solid var(--border); background: var(--background); }
.call-status { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; }
.status-dot { width: 8px; height: 8px; border-radius: 999px; background: var(--accent); box-shadow: 0 0 0 4px rgba(185, 255, 102, 0.1); }
.status-dot.connecting { background: #ffcc66; box-shadow: 0 0 0 4px rgba(255, 204, 102, 0.1); }
.status-dot.offline { background: var(--danger); box-shadow: 0 0 0 4px rgba(255, 92, 107, 0.1); }
.status-separator { color: #4b5563; }
.quiet-button { justify-self: end; padding: 9px 13px; border: 1px solid var(--border); border-radius: 10px; background: transparent; color: var(--text); cursor: pointer; }
.header-actions { justify-self: end; display: flex; align-items: center; gap: 8px; }
.chat-button { display: flex; align-items: center; gap: 6px; }
.chat-button svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }

.call-main { min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 340px; overflow: hidden; }
.video-grid { min-width: 0; min-height: 0; padding: 14px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-rows: minmax(0, 1fr); gap: 12px; overflow: auto; }
.video-grid:has(.video-card:only-child) { grid-template-columns: minmax(0, 1fr); }
.video-grid:has(.video-card:nth-child(5)) { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.video-card { position: relative; min-height: 180px; overflow: hidden; border: 1px solid var(--border); border-radius: 18px; background: #121720; }
.video-card video { width: 100%; height: 100%; display: block; object-fit: cover; background: #080a0e; }
.video-card.local-card video { transform: scaleX(-1); }
.video-placeholder { position: absolute; inset: 0; display: grid; place-items: center; background: radial-gradient(circle at 50% 30%, #28313e, #121720 68%); color: #dce3eb; }
.video-placeholder span { width: 72px; height: 72px; display: grid; place-items: center; border-radius: 50%; background: #2a3544; font-size: 18px; font-weight: 800; }
.video-card.has-video .video-placeholder { display: none; }
.play-overlay { position: absolute; inset: 50% auto auto 50%; z-index: 2; display: none; transform: translate(-50%, -50%); padding: 10px 14px; border: 1px solid var(--border); border-radius: 12px; background: rgba(5, 7, 10, 0.82); color: var(--text); cursor: pointer; }
.video-card.needs-play .play-overlay { display: block; }
.video-label { position: absolute; inset: auto 10px 10px 10px; display: flex; justify-content: space-between; gap: 10px; padding: 8px 10px; border-radius: 10px; background: rgba(5, 7, 10, 0.72); backdrop-filter: blur(12px); font-size: 12px; }
.media-state { color: var(--muted); }

.chat-panel { min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto; border-left: 1px solid var(--border); background: #0d1016; }
.chat-header { padding: 20px; display: flex; align-items: start; justify-content: space-between; border-bottom: 1px solid var(--border); }
.chat-header .eyebrow { margin-bottom: 5px; font-size: 9px; }
.chat-header h2 { margin: 0; font-size: 21px; }
.chat-list { min-height: 0; padding: 18px; overflow: auto; display: flex; flex-direction: column; gap: 12px; }
.empty-chat { margin: auto; max-width: 210px; color: var(--muted); text-align: center; line-height: 1.5; font-size: 13px; }
.empty-chat > span { width: 38px; height: 38px; margin: 0 auto 10px; display: grid; place-items: center; border-radius: 12px; background: var(--surface-raised); color: var(--accent); }
.chat-item { padding: 11px 12px; border-radius: 13px; background: var(--surface-raised); overflow-wrap: anywhere; }
.chat-item.own { background: #23311a; }
.chat-meta { margin-bottom: 5px; display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 10px; }
.chat-text { margin: 0; font-size: 14px; line-height: 1.45; white-space: pre-wrap; }
.file-row { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; align-items: center; gap: 9px; }
.file-icon { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 9px; background: rgba(255,255,255,0.07); color: var(--accent); font-weight: 800; }
.file-info { min-width: 0; }
.file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 700; }
.file-size { margin-top: 2px; color: var(--muted); font-size: 10px; }
.download-link { color: var(--accent); font-size: 12px; text-decoration: none; }
.download-link.pending { color: var(--muted); pointer-events: none; }
.chat-form { padding: 12px; display: grid; grid-template-columns: 36px minmax(0, 1fr) 36px; align-items: center; gap: 6px; border-top: 1px solid var(--border); }
.chat-form input[type="text"] { width: 100%; height: 40px; border: 0; border-radius: 10px; padding: 0 11px; background: var(--surface-raised); color: var(--text); }
.attachment-button, .send-button { width: 36px; height: 36px; border: 0; display: grid; place-items: center; border-radius: 10px; background: var(--surface-raised); color: var(--text); cursor: pointer; }
.send-button { background: var(--accent); color: var(--accent-text); font-weight: 900; }
.chat-error { margin: 0; padding: 0 12px 10px; color: #ffabb2; font-size: 11px; }
.chat-close-button { display: none; }

.call-controls { display: flex; justify-content: center; align-items: center; gap: 10px; padding: 10px max(16px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: rgba(8, 10, 14, 0.94); backdrop-filter: blur(18px); }
.control-button { min-width: 72px; height: 54px; padding: 7px 11px; border: 1px solid var(--border); border-radius: 14px; display: grid; place-items: center; gap: 3px; background: var(--surface-raised); color: var(--text); cursor: pointer; }
.control-button.off { background: #2b2025; color: #ffbdc3; }
.control-button.leave { background: var(--danger); color: white; border-color: transparent; }
.control-button:disabled { opacity: 0.38; cursor: not-allowed; }
.control-icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.control-label { color: currentColor; font-size: 9px; }
.mobile-only { display: none; }

.fatal-overlay { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 24px; background: rgba(5, 7, 10, 0.92); backdrop-filter: blur(20px); }
.fatal-overlay[hidden] { display: none; }
.fatal-card { width: min(100%, 430px); padding: 36px; border: 1px solid var(--border); border-radius: 24px; background: var(--surface); text-align: center; box-shadow: var(--shadow); }
.fatal-card .brand-mark { margin: 0 auto 22px; }
.fatal-card h1 { margin: 0; font-size: 30px; letter-spacing: -0.04em; }
.fatal-card p { margin: 12px 0 26px; color: var(--muted); line-height: 1.5; }
.fatal-card .primary-button { width: 100%; justify-content: center; }

@media (max-width: 850px) {
  .call-shell { grid-template-rows: 58px minmax(0, 1fr) 78px; }
  .call-header { grid-template-columns: auto 1fr auto; padding: 0 12px; }
  .brand.compact > span:last-child { display: none; }
  .call-status { justify-self: center; }
  .status-separator, #participant-count { display: none; }
  .quiet-button { padding: 8px 10px; font-size: 12px; }
  .call-main { display: block; position: relative; overflow: hidden; }
  .video-grid { height: 100%; grid-template-columns: minmax(0, 1fr); padding: 8px; gap: 8px; }
  .video-grid:has(.video-card:nth-child(2)):not(:has(.video-card:nth-child(3))) { grid-template-columns: minmax(0, 1fr); grid-template-rows: repeat(2, minmax(0, 1fr)); }
  .video-grid:has(.video-card:nth-child(3)) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .video-card { min-height: 0; border-radius: 14px; }
  .video-placeholder span { width: 52px; height: 52px; font-size: 15px; }
  .video-label { inset: auto 6px 6px 6px; align-items: flex-start; flex-direction: column; gap: 2px; padding: 6px 8px; }
  .media-state { display: block; font-size: 9px; }
  .chat-panel { position: fixed; inset: 58px 0 0; z-index: 30; border-left: 0; visibility: hidden; pointer-events: none; transform: translateX(100%); transition: transform 180ms ease, visibility 0s linear 180ms; }
  .chat-panel.open { visibility: visible; pointer-events: auto; transform: translateX(0); transition-delay: 0s; }
  .chat-close-button { width: 36px; height: 36px; flex: 0 0 auto; border: 1px solid var(--border); display: grid; place-items: center; padding: 0; border-radius: 50%; background: transparent; color: var(--muted); cursor: pointer; transition: border-color 150ms ease, background 150ms ease, color 150ms ease; }
  .chat-close-button:hover { border-color: rgba(255, 255, 255, 0.18); background: var(--surface-raised); color: var(--text); }
  .chat-close-button:active { background: rgba(255, 255, 255, 0.1); }
  .chat-close-button svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
  .chat-form { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .mobile-only { display: flex; }
  .call-controls { justify-content: space-evenly; gap: 5px; overflow-x: auto; }
  .control-button { min-width: 59px; height: 52px; padding: 6px 8px; }
}

@media (max-width: 520px) {
  .home-page { padding: 12px; }
  .home-card { min-height: calc(100svh - 24px); padding: 24px; border-radius: 24px; }
  .home-copy { padding: 44px 0; }
  .home-copy h1 { font-size: clamp(44px, 15vw, 64px); }
  .home-copy > p:last-child { font-size: 16px; }
  .video-grid:has(.video-card:nth-child(3)) .video-card { min-height: 115px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
