:root {
  --bg: #0f1222;
  --panel: #14172b;
  --panel-2: #191d35;
  --muted: #98a2b3;
  --text: #e6e7ee;
  --accent: #6f8cff;
  --accent-2: #9a7bff;
  --green: #22c55e;
  --red: #ef4444;
}

* { box-sizing: border-box; }

html, body { height: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 10% 0%, #1b1e35 0%, transparent 60%),
    radial-gradient(800px 500px at 90% 10%, #212547 0%, transparent 60%),
    var(--bg);
}

/* Modal */
.blur { backdrop-filter: blur(4px); }
.modal { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; }
.modal.show { display: flex; }
.modal-card {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid #2a2f4f; border-radius: 16px; padding: 24px;
  width: min(92vw, 420px); box-shadow: 0 20px 50px rgba(0, 0, 0, .4);
}
.modal-card h1 { margin: 0 0 6px; font-size: 24px; }
.modal-card p { margin: 0 0 16px; color: var(--muted); }
.modal-card #nameForm { display: flex; gap: 10px; }
.modal-card input {
  flex: 1; padding: 12px 14px; border-radius: 12px; border: 1px solid #2b3153; background: #0e1030; color: var(--text); outline: none;
}
.modal-card button {
  padding: 12px 16px; border-radius: 12px; border: none; background: linear-gradient(90deg, var(--accent), var(--accent-2)); color: white; font-weight: 600; cursor: pointer;
}

/* Online count */
#onlineIndicator {
  font-size: 0.9em;
  color: #00ff66;
  margin-left: 10px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
#onlineIndicator .dot {
  height: 10px; width: 10px; background-color: #00ff66; border-radius: 50%;
  box-shadow: 0 0 5px #00ff66, 0 0 10px #00ff66;
}
#onlineCount { font-weight: bold; }

/* Layout */
.app {
  max-width: 1200px;
  margin: 20px auto;
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: calc(100vh - 60px);
  gap: 10px;
  padding: 0 10px;
}

.topbar {
  position: sticky; top: 10px; z-index: 3;
  display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 10px;
  background: rgba(255,255,255,0.03);
  border: 1px solid #2a2f4f; border-radius: 16px; padding: 10px 12px; backdrop-filter: blur(6px);
}
.brand { display: inline-flex; align-items: center; gap: 8px; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.status { color: var(--muted); font-size: 14px; }
.skip { border: 1px solid #2a2f4f; border-radius: 12px; padding: 10px 14px; background: #0e1130; color: #eaeaff; cursor: pointer; }
.skip:disabled { opacity: .5; cursor: not-allowed; }

.main-wrap {
  display: grid;
  grid-template-columns: 2fr 1fr; /* video : chat */
  gap: 12px;
  min-height: 0;
}

.video-wrap {
  border: 1px solid #2a2f4f; border-radius: 16px; padding: 12px; background: #0b0e23;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-content: start;
}

.video-tile {
  position: relative;
  border: 1px solid #2b3153;
  border-radius: 14px;
  overflow: hidden;
  background: #151939;
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 3; /* 4:3 rectangle */
}
.video-tile video {
  width: 100%; height: 100%;
  object-fit: cover; /* fill 4:3 */
  background: #0e1030;
}
.video-tile .label {
  position: absolute; left: 8px; bottom: 8px;
  font-size: 12px; color: var(--muted);
  background: rgba(0,0,0,.35);
  padding: 4px 8px; border-radius: 999px; border: 1px solid #2b3153;
}
.video-tile.self .controls {
  position: absolute; right: 8px; bottom: 8px; display: flex; gap: 6px;
}
.pill {
  border: 1px solid #2a2f4f; background: #0e1130; color: #eaeaff; cursor: pointer;
  padding: 6px 10px; border-radius: 999px; font-size: 12px;
}
.pill.active { outline: 2px solid var(--accent); }

.side-chat {
  display: grid;
  grid-template-rows: 1fr auto;
  min-height: 0;
}

.chat {
  position: relative;
  border: 1px solid #2a2f4f; border-radius: 16px; padding: 12px;
  background:
    radial-gradient(600px 300px at 80% 0%, rgba(255,255,255,0.04), transparent 60%),
    linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.0)),
    #0b0e23;
  overflow-y: auto;
}

/* Connecting Overlay */
.connecting { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; flex-direction: column; gap: 12px; }
.connecting.show { display: flex; }
.spinner {
  width: 38px; height: 38px; border: 4px solid #2b3153; border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Messages */
.msg {
  max-width: 70%; margin: 6px 0; padding: 10px 12px; border-radius: 14px; line-height: 1.3;
  background: #151939; border: 1px solid #2b3153; box-shadow: 0 4px 16px rgba(0,0,0,.2);
  word-wrap: break-word; white-space: pre-wrap;
}
.msg.me { margin-left: auto; background: linear-gradient(90deg, #2b47ff33, #7b46ff33); border-color: #4454ff; }
.msg .sender { display: block; font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.system { text-align: center; color: var(--muted); font-size: 13px; margin: 12px 0; }


.typing {
  margin: 6px 0; padding: 10px 12px; line-height: 1.3;
  word-wrap: break-word; white-space: pre-wrap;
  color: #fefeffa7;
}
/* Input bar (sticky to bottom of side-chat) */
.inputbar {
  position: sticky; bottom: 0; z-index: 1;
  display: grid; grid-template-columns: 1fr auto; gap: 10px;
  border: 1px solid #2a2f4f; border-radius: 16px; padding: 10px; background: rgba(255,255,255,0.03); margin-top: 10px;
}
.inputbar input {
  padding: 12px 14px; border-radius: 12px; border: 1px solid #2b3153; background: #0e1030; color: var(--text); outline: none;
}
.inputbar button {
  padding: 12px 16px; border-radius: 12px; border: none; background: linear-gradient(90deg, var(--accent), var(--accent-2)); color: white; font-weight: 600; cursor: pointer;
}

.foot { text-align: center; color: var(--muted); margin: 10px 0 20px; }

/* Responsive */
@media (max-width: 980px) {
  .main-wrap { grid-template-columns: 1fr; }
  .video-wrap { grid-template-columns: 1fr; }
}
