:root {
  --bg: #020617;
  --card: rgba(255,255,255,.08);
  --border: rgba(255,255,255,.14);
  --text: #eef6ff;
  --muted: rgba(238,246,255,.68);
  --accent: #22d3ee;
  --danger: #fb7185;
  --off: #fbbf24;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
}

.app {
  width: 100%;
  height: 100vh;
  height: 100dvh;
}

.hidden { display: none !important; }

.joinBox {
  width: min(420px, calc(100% - 28px));
  margin: 10vh auto 0;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--card);
  box-shadow: 0 18px 60px rgba(0,0,0,.35);
}

.joinBox h1 { margin: 0 0 8px; }
.joinBox p { color: var(--muted); margin: 0 0 16px; }

input {
  width: 100%;
  margin: 8px 0;
  padding: 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,.35);
  color: var(--text);
  font-size: 16px;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 12px 15px;
  font-weight: 900;
  cursor: pointer;
  color: #001018;
  background: linear-gradient(135deg, #0891b2, var(--accent));
}

button.off {
  background: var(--off);
  color: #261600;
}

button.danger {
  background: var(--danger);
  color: white;
}

.joinBox button {
  width: 100%;
  margin-top: 10px;
  border-radius: 14px;
}

.error {
  color: #fecaca;
  margin-top: 10px;
  min-height: 20px;
}

.roomBox {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(circle at top left, rgba(34,211,238,.10), transparent 34%),
    linear-gradient(180deg, #07111f, #020617);
}

.topBar {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top, 0));
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(820px, calc(100% - 24px));
  padding: 8px 14px;
  border-radius: 18px;
  background: rgba(8, 15, 28, .62);
  border: 1px solid rgba(255,255,255,.14);
  box-shadow: 0 14px 38px rgba(0,0,0,.28);
  backdrop-filter: blur(16px);
  color: white;
  font-size: 13px;
}

.topBar strong { font-size: 14px; }

.topBar span {
  color: rgba(255,255,255,.76);
  margin-left: 5px;
  font-size: 12px;
}

.onlineText {
  margin-left: auto;
  max-width: 46%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: rgba(255,255,255,.76);
  font-size: 12px;
}

.videos {
  width: min(1280px, calc(100% - 28px));
  height: calc(100dvh - 118px);
  margin: 58px auto 0;
  padding: 0 0 calc(76px + env(safe-area-inset-bottom, 0)) 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 10px;
  background: transparent;
}

.tile {
  position: relative;
  overflow: hidden;
  background: #000;
  cursor: pointer;
  min-width: 0;
  min-height: 0;
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,.14);
  box-shadow: 0 16px 42px rgba(0,0,0,.30);
}

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

.focusVideoWrap video {
  object-fit: contain;
}

.label {
  position: absolute;
  left: 8px;
  bottom: 8px;
  max-width: calc(100% - 78px);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  background: rgba(0,0,0,.64);
  color: white;
  border-radius: 999px;
  padding: 5px 9px;
  font-weight: 800;
  font-size: 12px;
}

.indicators {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 5px;
}

.pill {
  background: rgba(0,0,0,.64);
  color: white;
  border-radius: 999px;
  padding: 5px 8px;
  font-weight: 900;
  font-size: 12px;
}

.pill.off {
  background: rgba(251,191,36,.95);
  color: #261600;
}

.noCam {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background: radial-gradient(circle at top, #1f2937, #020617);
  color: rgba(255,255,255,.78);
  font-weight: 900;
  text-align: center;
  padding: 20px;
}

.tile.cameraOff video { opacity: 0; }
.tile.cameraOff .noCam { display: grid; }

.focusBox {
  position: fixed;
  inset: 0;
  z-index: 20;
  background:
    radial-gradient(circle at top left, rgba(34,211,238,.10), transparent 34%),
    #000;
}

.focusTop {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top, 0));
  left: 50%;
  transform: translateX(-50%);
  z-index: 35;
  width: min(820px, calc(100% - 24px));
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px;
  border-radius: 18px;
  background: rgba(8, 15, 28, .62);
  border: 1px solid rgba(255,255,255,.14);
  backdrop-filter: blur(16px);
}

.focusVideoWrap {
  width: min(1280px, calc(100% - 28px));
  height: calc(100dvh - 118px);
  margin: 58px auto 0;
  padding-bottom: calc(76px + env(safe-area-inset-bottom, 0));
  background: transparent;
}

.focusVideoWrap video {
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,.14);
  box-shadow: 0 16px 42px rgba(0,0,0,.30);
}

.audioModeBox {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  background: #000;
  color: white;
  text-align: center;
  padding: 24px;
}

.audioCard { width: min(360px, 100%); }
.audioIcon { font-size: 54px; margin-bottom: 12px; }
.audioCard h2 { margin: 0 0 8px; }
.audioCard p { color: rgba(255,255,255,.65); }

.bottomControls {
  position: fixed;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom, 0));
  transform: translateX(-50%);
  z-index: 70;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px;
  border-radius: 999px;
  background: rgba(8, 15, 28, .68);
  border: 1px solid rgba(255,255,255,.14);
  box-shadow: 0 18px 50px rgba(0,0,0,.38);
  backdrop-filter: blur(18px);
}

.roundBtn {
  width: 52px;
  height: 52px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.12);
  color: #fff;
  font-size: 20px;
  line-height: 1;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.12);
}

.roundBtn.off {
  background: rgba(251,191,36,.95);
  color: #1f1300;
}

.roundBtn.danger {
  background: rgba(251,113,133,.95);
  color: white;
}

body.gridMode .gridOnly { display: none; }
body.focusMode .gridOnly { display: grid; }
body.focusMode .videos { display: none; }
body.focusMode .focusBox { display: block !important; }
body.gridMode .videos { display: grid; }
body.gridMode .focusBox { display: none !important; }

body.audioMode .videos,
body.audioMode .focusBox,
body.audioMode .topBar,
body.audioMode .bottomControls {
  display: none !important;
}

@media (orientation: portrait) and (max-width: 760px) {
  .roomBox { background: #000; }

  .topBar {
    top: calc(4px + env(safe-area-inset-top, 0));
    width: calc(100% - 10px);
    padding: 5px 8px;
    border-radius: 12px;
    font-size: 11px;
  }

  .topBar strong { font-size: 12px; }

  .topBar span,
  .onlineText {
    font-size: 10px;
  }

  .onlineText {
    max-width: 42%;
  }

  .videos {
    width: 100vw;
    height: 100dvh;
    margin: 0;
    padding-top: calc(38px + env(safe-area-inset-top, 0));
    padding-bottom: calc(66px + env(safe-area-inset-bottom, 0));
    padding-left: 2px;
    padding-right: 2px;
    gap: 2px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
  }

  .tile {
    border-radius: 6px;
    border: 0;
    box-shadow: none;
  }

  .label {
    bottom: 6px;
    left: 6px;
    font-size: 10px;
    padding: 3px 7px;
    max-width: calc(100% - 58px);
  }

  .indicators {
    top: 6px;
    right: 6px;
  }

  .pill {
    font-size: 10px;
    padding: 3px 6px;
  }

  .bottomControls {
    bottom: calc(8px + env(safe-area-inset-bottom, 0));
    gap: 7px;
    padding: 7px;
  }

  .roundBtn {
    width: 46px;
    height: 46px;
    font-size: 18px;
  }

  .focusTop {
    top: calc(4px + env(safe-area-inset-top, 0));
    width: calc(100% - 10px);
    padding: 5px 8px;
    border-radius: 12px;
  }

  .focusVideoWrap {
    width: 100vw;
    height: 100dvh;
    margin: 0;
    padding-top: calc(38px + env(safe-area-inset-top, 0));
    padding-bottom: calc(66px + env(safe-area-inset-bottom, 0));
    padding-left: 2px;
    padding-right: 2px;
  }

  .focusVideoWrap video {
    border-radius: 6px;
    border: 0;
    box-shadow: none;
  }
}

@media (orientation: landscape) and (max-width: 950px) {
  .roomBox { background: #000; }

  .topBar {
    top: calc(3px + env(safe-area-inset-top, 0));
    width: min(620px, calc(100% - 14px));
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 10px;
  }

  .videos {
    width: 100vw;
    height: 100dvh;
    margin: 0;
    padding-top: calc(28px + env(safe-area-inset-top, 0));
    padding-bottom: calc(52px + env(safe-area-inset-bottom, 0));
    padding-left: 2px;
    padding-right: 2px;
    gap: 2px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
  }

  .tile {
    border-radius: 6px;
    border: 0;
    box-shadow: none;
  }

  .label {
    font-size: 10px;
    padding: 3px 7px;
  }

  .pill {
    font-size: 10px;
    padding: 3px 6px;
  }

  .bottomControls {
    bottom: calc(5px + env(safe-area-inset-bottom, 0));
    padding: 6px;
  }

  .roundBtn {
    width: 40px;
    height: 40px;
    font-size: 16px;
  }

  .focusTop {
    top: calc(3px + env(safe-area-inset-top, 0));
    width: min(620px, calc(100% - 14px));
    padding: 4px 8px;
    border-radius: 12px;
  }

  .focusVideoWrap {
    width: 100vw;
    height: 100dvh;
    margin: 0;
    padding-top: calc(28px + env(safe-area-inset-top, 0));
    padding-bottom: calc(52px + env(safe-area-inset-bottom, 0));
    padding-left: 2px;
    padding-right: 2px;
  }

  .focusVideoWrap video {
    border-radius: 6px;
    border: 0;
    box-shadow: none;
  }
}