:root {
  --slate: #50484b;
  --teal: #1d6c82;
  --blue: #1c76a6;
  --navy: #114c74;
  --deep: #062c41;
  --text: #eaf4fb;
  --muted: #b9cfdd;
  --line: rgba(185, 207, 221, 0.2);
  --line-strong: rgba(185, 207, 221, 0.34);
  --ok: #5fd189;
  --danger: #ff7e88;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: Inter, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  background:
    radial-gradient(circle at 15% 10%, rgba(28, 118, 166, 0.32), transparent 35%),
    radial-gradient(circle at 85% 85%, rgba(29, 108, 130, 0.26), transparent 34%),
    linear-gradient(165deg, #041f2f 0%, #062c41 45%, #0b3752 100%);
}

img, video { display: block; max-width: 100%; }
button, input { font: inherit; }

.hidden { display: none !important; }

.app-shell {
  width: min(1320px, calc(100vw - 24px));
  margin: 0 auto;
  padding: 14px 0 20px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(80, 72, 75, 0.45), rgba(6, 44, 65, 0.72));
  backdrop-filter: blur(8px);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-lockup img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 10px;
}

.brand-lockup h1,
.brand-lockup p,
.chat-meta h3,
.chat-meta p { margin: 0; }

.brand-kicker, .label, .help-copy, .typing-indicator { color: var(--muted); }
.brand-kicker, .label {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
  font-weight: 700;
}

.status-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.presence-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 6px rgba(95, 209, 137, 0.16);
}

.panel {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(6, 44, 65, 0.8), rgba(17, 76, 116, 0.45));
  box-shadow: 0 20px 34px rgba(0, 0, 0, 0.2);
}

.intro-panel {
  max-width: 760px;
  margin: 4vh auto 0;
  padding: 18px;
  display: grid;
  gap: 12px;
}

.intro-panel h2 { margin: 0; font-size: clamp(1.4rem, 2.8vw, 2rem); }

.mode-chooser {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.mode-card {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(6, 44, 65, 0.5);
  cursor: pointer;
}

.mode-card span { font-weight: 700; }
.mode-card small { color: var(--muted); }
.mode-card input { accent-color: var(--blue); }

.stage-panel { padding: 12px; }

.stage-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.video-card {
  position: relative;
  overflow: hidden;
  min-height: 360px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #072338;
}

.video-card__head {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  color: #f4fbff;
  font-size: 0.82rem;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

.mode-badge {
  padding: 4px 9px;
  border-radius: 999px;
  color: #ecf8ff;
  font-size: 0.72rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--blue), var(--teal));
  border: 1px solid rgba(255,255,255,0.2);
}

.mode-badge-muted { background: rgba(80,72,75,0.75); }

video {
  width: 100%;
  height: 360px;
  object-fit: cover;
  background: #061a27;
}

.video-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 14px;
  text-align: center;
  color: #d5e8f4;
  background: linear-gradient(180deg, rgba(5,21,31,0.22), rgba(5,21,31,0.82));
}

.video-overlay.is-hidden { display: none; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.button {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  color: var(--text);
  cursor: pointer;
  transition: transform 120ms ease, opacity 120ms ease;
}

.button:hover:not(:disabled), .button:focus-visible:not(:disabled) {
  opacity: 0.96;
  transform: translateY(-1px);
}

.button:disabled { opacity: 0.5; cursor: not-allowed; }
.button-primary { font-weight: 700; background: linear-gradient(135deg, var(--blue), var(--teal)); }
.button-secondary { font-weight: 700; background: linear-gradient(135deg, var(--navy), var(--deep)); }
.button-ghost { background: rgba(80,72,75,0.45); }
.button-danger { font-weight: 700; background: linear-gradient(135deg, #b44757, var(--danger)); }

.chat-under {
  margin-top: 10px;
  padding: 12px;
  display: grid;
  gap: 8px;
}

.chat-meta h3 { font-size: 1.1rem; }
.chat-meta .muted { color: var(--muted); margin-top: 4px; }

.chat-feed {
  display: grid;
  gap: 8px;
  min-height: 160px;
  max-height: 280px;
  overflow: auto;
}

.chat-row {
  max-width: 92%;
  padding: 10px 12px;
  border-radius: 11px;
  line-height: 1.45;
}

.chat-row-self {
  justify-self: end;
  color: #f2fbff;
  background: linear-gradient(135deg, var(--teal), var(--blue));
}

.chat-row-peer { background: rgba(80,72,75,0.58); }
.chat-row-system { max-width: 100%; padding: 0; color: var(--muted); background: transparent; }

.message-form {
  display: flex;
  align-items: center;
  gap: 8px;
}

.text-input {
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  color: var(--text);
  background: rgba(5, 28, 41, 0.72);
}

.message-form .text-input { flex: 1; }
.text-input::placeholder { color: #9eb9cb; }
.text-input:focus { outline: 2px solid rgba(28,118,166,0.38); outline-offset: 1px; }

.typing-indicator { min-height: 18px; margin: 0; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.checkbox-row input { width: 16px; height: 16px; accent-color: var(--blue); }

.stats-row {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.stat-card {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(6,44,65,0.52);
}

.stat-card strong { display: block; margin-top: 4px; font-size: 1.32rem; }

@media (max-width: 980px) {
  .mode-chooser,
  .stage-grid,
  .stats-row { grid-template-columns: 1fr; }

  .video-card,
  video { min-height: 280px; height: 280px; }
}

@media (max-width: 640px) {
  .app-shell { width: calc(100vw - 10px); padding-top: 8px; }
  .topbar { flex-direction: column; align-items: flex-start; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .button { width: 100%; }
  .intro-panel { margin-top: 1vh; padding: 14px; }
}