:root {
  color-scheme: dark;
  --bg: #0b1115;
  --panel: #131e25;
  --border: #2c414a;
  --text: #eef8f6;
  --muted: #b1c2c6;
  --accent: #81ecd0;
  --danger: #ffb7b9;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans CJK SC", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); }
button, input { font: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; opacity: .48; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.shell {
  width: min(100%, 54rem);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right))
    max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: clamp(.85rem, 2vh, 1.5rem);
}
.topbar { display: flex; align-items: center; min-height: 3.25rem; gap: .65rem; }
.brand-mark {
  width: 2.7rem;
  height: 2.7rem;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: .8rem;
  color: var(--accent);
  background: #152f2e;
}
.brand-mark svg { width: 1.5rem; }
h1 { margin: 0; font-size: clamp(1.15rem, 3vw, 1.55rem); letter-spacing: .02em; }
.identity { display: flex; align-items: center; margin-left: auto; gap: .55rem; }
.role-label { font-size: .9rem; white-space: nowrap; color: var(--muted); }
.text-button { min-height: 2.75rem; color: var(--muted); background: transparent; border: 0; padding: .45rem .6rem; }

.join {
  width: min(100%, 29rem);
  margin: min(6vh, 3rem) auto 0;
  padding: clamp(1.15rem, 5vw, 2rem);
  border: 1px solid var(--border);
  border-radius: 1.45rem;
  background: var(--panel);
  display: grid;
  gap: .8rem;
}
.join h2, .stage h2 { margin: 0; font-size: clamp(1.35rem, 4.5vw, 2rem); }
.join p, .stage p { margin: 0; color: var(--muted); line-height: 1.55; }
.role-choices { border: 0; margin: .4rem 0 0; padding: 0; display: flex; gap: .6rem; }
.role-choices legend, .key-label { margin-bottom: .3rem; color: var(--muted); font-size: .9rem; }
.role-choices label {
  flex: 1;
  display: flex;
  gap: .5rem;
  align-items: center;
  min-height: 2.8rem;
  padding: .55rem .7rem;
  border: 1px solid var(--border);
  border-radius: .65rem;
}
.role-choices input, .remember input { accent-color: var(--accent); margin: 0; }
.key-label { margin: .3rem 0 -.45rem; }
#accessKey {
  width: 100%;
  min-height: 2.9rem;
  padding: .6rem .7rem;
  border: 1px solid var(--border);
  border-radius: .65rem;
  background: #0e181d;
  color: var(--text);
  font-size: 1rem;
}
.remember { min-height: 2.5rem; display: flex; align-items: center; gap: .55rem; color: var(--muted); font-size: .9rem; }

.call-panel { display: grid; gap: .85rem; }
.stage {
  position: relative;
  display: grid;
  place-items: center;
  isolation: isolate;
  min-height: 15rem;
  height: clamp(15rem, 60vh, 45rem);
  height: clamp(15rem, 60dvh, 45rem);
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: clamp(1rem, 4vw, 1.65rem);
  background: radial-gradient(ellipse at 50% 33%, #20363c 0%, #121e25 65%, #10191f 100%);
}
.stage video { display: block; background: #0a1216; }
#remoteVideo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; opacity: 0; }
.stage.has-video #remoteVideo { opacity: 1; }
#localVideo {
  position: absolute;
  width: clamp(4.5rem, 24%, 9rem);
  max-height: 34%;
  aspect-ratio: 3 / 4;
  right: .7rem;
  bottom: .7rem;
  z-index: 1;
  border: 1px solid #ffffff69;
  border-radius: .8rem;
  object-fit: cover;
  transform: scaleX(-1);
}
.stage-state { max-width: 28rem; padding: 3rem 1rem 2.75rem; text-align: center; z-index: 1; pointer-events: none; }
.stage-state p { margin-top: .55rem; }
.peer-mark {
  width: clamp(4.4rem, 17vw, 7rem);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  margin: 0 auto 1rem;
  border: 1px solid #426762;
  border-radius: 36%;
  background: #284743;
  color: var(--accent);
}
.peer-mark svg { width: 50%; }
.presence {
  position: absolute;
  top: .65rem;
  left: .65rem;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: .45rem;
  padding: .43rem .64rem;
  border-radius: 2rem;
  background: #0c161eea;
  color: var(--muted);
  font-size: .82rem;
}
.presence span:first-child { width: .48rem; height: .48rem; background: #83979d; border-radius: 50%; }
.presence.online span:first-child { background: var(--accent); }

.controls { display: flex; gap: .65rem; flex-wrap: wrap; justify-content: center; }
.controls:empty { display: none; }
.button {
  min-height: 3rem;
  border: 1px solid transparent;
  border-radius: .82rem;
  padding: .65rem 1rem;
  font-weight: 650;
  text-align: center;
}
.controls .button { min-width: min(8rem, 100%); }
.primary { background: var(--accent); color: #06241e; }
.secondary { background: #20343d; border-color: #3b5962; color: var(--text); }
.danger { background: #482a32; border-color: #7b4752; color: var(--danger); }
.playback {
  position: absolute;
  z-index: 3;
  bottom: 1rem;
  max-width: calc(100% - 1rem);
  background: #eef8f6;
  color: #13242b;
}
.push-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .7rem 1rem;
  flex-wrap: wrap;
  padding: .85rem 1rem;
  border: 1px solid var(--border);
  border-radius: .9rem;
  background: var(--panel);
}
.push-panel h2 { margin: 0; font-size: 1rem; }
.push-panel p { margin: .35rem 0 0; color: var(--muted); font-size: .85rem; line-height: 1.5; }
.notice {
  margin: 0 auto;
  width: min(100%, 34rem);
  padding: .75rem .95rem;
  border: 1px solid #6c5148;
  border-radius: .75rem;
  background: #2a2322;
  color: #f6dcd3;
  line-height: 1.5;
}
.footer { margin: auto 0 0; text-align: center; font-size: .85rem; color: var(--muted); line-height: 1.5; }

@media (max-height: 480px) and (orientation: landscape) {
  .stage { min-height: 11.5rem; }
  .stage-state { padding-top: 2.5rem; padding-bottom: 1.2rem; }
  .peer-mark { width: 3.3rem; margin-bottom: .6rem; }
}

.filing { text-align: center; font-size: .8rem; }
.filing a { color: var(--muted); }
