:root {
  color-scheme: dark;
  --bg: #080a0f;
  --panel: rgba(14, 17, 24, .88);
  --line: rgba(255, 255, 255, .12);
  --text: #f7f8fb;
  --muted: #9ba3b5;
  --lime: #c9ff59;
  --cyan: #70e8ff;
  --red: #ff5d67;
  --amber: #ffc857;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
button, input { font: inherit; }
button { color: inherit; cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); line-height: 1.55; }
.tiny { font-size: .75rem; }
.eyebrow { margin: 0 0 .35rem; color: var(--lime); font-size: .68rem; font-weight: 800; letter-spacing: .18em; }
.wide { width: 100%; }
.primary, .secondary {
  border: 1px solid var(--line); border-radius: 14px; padding: .9rem 1rem; font-weight: 800; letter-spacing: .04em;
}
.primary { border-color: var(--lime); background: var(--lime); color: #11150a; }
.secondary { background: #151923; }

.landing { min-height: 100vh; display: grid; place-items: center; padding: 1.25rem; background: radial-gradient(circle at 80% 10%, #253536 0, transparent 32%), var(--bg); }
.landing-card { width: min(100%, 480px); padding: clamp(1.4rem, 5vw, 3rem); border: 1px solid var(--line); border-radius: 28px; background: rgba(11, 14, 20, .86); box-shadow: 0 30px 90px #0009; }
.landing-card h1 { margin: .2rem 0 1rem; font-size: clamp(3rem, 15vw, 5.8rem); line-height: .83; letter-spacing: -.075em; }
.landing-card label { display: block; margin: 1.5rem 0 .45rem; font-size: .75rem; color: var(--muted); }
.room-form-row { display: grid; grid-template-columns: 1fr auto; gap: .5rem; margin-bottom: .7rem; }
input { min-width: 0; border: 1px solid var(--line); border-radius: 14px; padding: .95rem 1rem; background: #0d1118; color: var(--text); outline: none; }
input:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px #70e8ff18; }

.call-page { height: 100dvh; overflow: hidden; }
.call-shell { position: relative; width: 100%; height: 100%; background: #050609; }
.stage { position: absolute; inset: 0; overflow: hidden; }
#remote-video { width: 100%; height: 100%; object-fit: cover; background: #050609; }
.stage-gradient { pointer-events: none; position: absolute; inset: 0; background: linear-gradient(180deg, #0009 0, transparent 25%, transparent 60%, #000c 100%); }
.topbar { position: absolute; z-index: 3; top: 0; left: 0; right: 0; display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; padding: max(1rem, env(safe-area-inset-top)) 1rem 1rem; }
.topbar h1 { margin: 0; max-width: 65vw; overflow: hidden; text-overflow: ellipsis; font-size: 1.15rem; letter-spacing: -.02em; white-space: nowrap; }
.quality-pill { border: 1px solid var(--line); border-radius: 999px; padding: .45rem .7rem; background: #0e121ad9; color: var(--muted); font-size: .64rem; font-weight: 900; letter-spacing: .08em; }
.quality-pill[data-level="excellent"] { color: var(--lime); border-color: #c9ff5966; }
.quality-pill[data-level="good"] { color: var(--cyan); }
.quality-pill[data-level="unstable"] { color: var(--amber); }
.quality-pill[data-level="bad"] { color: var(--red); }
#local-video { position: absolute; z-index: 4; top: max(4.5rem, calc(env(safe-area-inset-top) + 3.5rem)); right: .8rem; width: min(28vw, 150px); aspect-ratio: 3 / 4; object-fit: cover; border: 1px solid #ffffff40; border-radius: 18px; background: #151820; box-shadow: 0 10px 40px #000b; transform: scaleX(-1); }
#local-video.environment-camera { transform: none; }
#local-video.track-off { opacity: .35; }
.call-shell.self-primary #local-video { z-index: 1; inset: 0; width: 100%; height: 100%; aspect-ratio: auto; border: 0; border-radius: 0; object-fit: cover; }
.call-shell.self-primary #remote-video { position: absolute; z-index: 4; top: max(4.5rem, calc(env(safe-area-inset-top) + 3.5rem)); right: .8rem; width: min(28vw, 150px); height: auto; aspect-ratio: 3 / 4; border: 1px solid #ffffff40; border-radius: 18px; object-fit: cover; box-shadow: 0 10px 40px #000b; }
#local-video, #remote-video { cursor: pointer; }
.stage-message { position: absolute; z-index: 2; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .55rem; padding: 2rem; text-align: center; background: radial-gradient(circle, #1e2932 0, #07090ddd 58%); }
.stage-message strong { max-width: 360px; font-size: 1rem; letter-spacing: .08em; }
.stage-message small { max-width: 320px; color: var(--muted); line-height: 1.45; }
.pulse-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--lime); box-shadow: 0 0 0 0 #c9ff5966; animation: pulse 1.6s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 14px #c9ff5900; } }
.enable-audio { position: absolute; z-index: 8; left: 50%; top: 50%; translate: -50% -50%; width: min(88%, 390px); border: 1px solid var(--lime); border-radius: 18px; padding: 1.1rem; background: var(--lime); color: #101308; font-weight: 900; }

.control-dock { position: absolute; z-index: 7; left: 0; right: 0; bottom: 0; padding: .75rem .75rem max(.75rem, env(safe-area-inset-bottom)); background: linear-gradient(180deg, transparent, #080a0ff2 18%); }
.quality-switch { display: flex; width: fit-content; margin: 0 auto .55rem; padding: 3px; border: 1px solid var(--line); border-radius: 12px; background: #090c12cc; }
.quality-switch button { border: 0; border-radius: 9px; padding: .42rem .8rem; background: transparent; color: var(--muted); font-size: .67rem; font-weight: 900; }
.quality-switch button.active { background: var(--text); color: #0a0c11; }
.controls { display: flex; justify-content: center; gap: .42rem; overflow-x: auto; scrollbar-width: none; }
.control { flex: 0 0 54px; min-height: 50px; border: 1px solid var(--line); border-radius: 15px; background: #171b24e8; }
.control span, .control b { display: block; font-size: .58rem; line-height: 1.25; }
.control span { color: var(--muted); }
.control b { font-size: .63rem; }
.control.off { background: #3a2529; border-color: #ff5d6755; }
.control.danger { background: var(--red); border-color: var(--red); color: #170406; }
.control:disabled { opacity: .45; cursor: wait; }
.network-test-status { position: absolute; z-index: 10; left: 50%; bottom: calc(6.4rem + env(safe-area-inset-bottom)); translate: -50% 0; width: min(calc(100% - 1.5rem), 430px); border: 1px solid var(--line); border-radius: 14px; padding: .75rem 1rem; background: #0c1119f2; color: var(--text); text-align: center; box-shadow: 0 8px 30px #000a; font-size: .74rem; font-weight: 750; }

.hud, .debug-panel { position: absolute; z-index: 6; left: .7rem; top: max(4.4rem, calc(env(safe-area-inset-top) + 3.5rem)); width: min(66vw, 330px); max-height: calc(100dvh - 14rem); overflow: auto; padding: .8rem; border: 1px solid var(--line); border-radius: 18px; background: var(--panel); backdrop-filter: blur(18px); box-shadow: 0 14px 50px #0008; }
.hud-head { display: flex; align-items: flex-start; justify-content: space-between; gap: .5rem; }
.hud-actions { display: flex; gap: .35rem; }
.hud h2, .debug-panel h2 { margin: 0; font-size: .9rem; }
.icon-button { width: 30px; height: 30px; border: 1px solid var(--line); border-radius: 9px; background: #ffffff08; }
.hud-grid { display: grid; gap: .5rem; margin-top: .7rem; }
.hud-grid section { padding: .65rem; border: 1px solid #ffffff0d; border-radius: 12px; background: #080b11aa; }
.hud-label { margin: 0 0 .4rem; color: var(--muted); font-size: .57rem; font-weight: 800; letter-spacing: .09em; }
.metric-large { display: inline-flex; align-items: baseline; gap: .25rem; margin-right: .45rem; }
.metric-large span { color: var(--lime); }
.metric-large strong { font-size: 1.25rem; }
.metric-large small { color: var(--muted); font-size: .55rem; }
.metric-line { margin: .22rem 0; color: var(--muted); font-size: .64rem; }
.metric-line b { color: var(--text); font-weight: 750; }
.debug-panel { z-index: 12; right: .7rem; left: auto; width: min(92vw, 430px); max-height: calc(100dvh - 7rem); }
.debug-panel pre { overflow: auto; padding: .6rem; border-radius: 10px; background: #05070a; color: #b8c5d8; font-size: .62rem; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.name-dialog { width: min(calc(100% - 2rem), 420px); border: 1px solid var(--line); border-radius: 24px; padding: 1.4rem; background: #0f131b; color: var(--text); box-shadow: 0 25px 100px #000; }
.name-dialog::backdrop { background: #050609e8; backdrop-filter: blur(10px); }
.name-dialog h2 { margin: .3rem 0 1rem; }
.name-dialog input { width: 100%; margin-bottom: .7rem; }

@media (min-width: 760px) {
  .hud-grid { grid-template-columns: 1fr 1fr; }
  .hud-grid section:last-child { grid-column: 1 / -1; }
  .hud { width: 410px; }
  #local-video { width: 180px; }
  .control { flex-basis: 68px; min-height: 56px; }
}

@media (orientation: landscape) and (max-height: 600px) {
  .hud { max-height: calc(100dvh - 5.5rem); width: min(42vw, 380px); }
  .hud-grid { grid-template-columns: 1fr 1fr; }
  .hud-grid section:last-child { grid-column: 1 / -1; }
  .control-dock { left: auto; width: 58%; }
  #local-video { top: .7rem; }
}
