/* Layout: dark video stage filling the screen; subtitle bubbles float over its lower half; controls docked at the bottom */
:root{
  --stage:#0d1513; --panel:#16201e; --panel-2:#1f2b28; --ink:#eef3f1; --muted:#9aaba6; --line:#2d3b38;
  --bubble:rgba(18,26,24,.78); --bubble-me:rgba(16,92,68,.82);
  --accent:#3fc093; --accent-ink:#04241a; --danger:#e5484d; --warn:#f0a35a;
  --font:"PingFang SC","Microsoft YaHei","Noto Sans SC",-apple-system,"Segoe UI",Roboto,Arial,sans-serif;
  --fs:17px;
  color-scheme:dark;
}
*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}
html,body{height:100%;margin:0}
body{background:var(--stage);color:var(--ink);font-family:var(--font);font-size:15px;overflow:hidden}
button,select,input,textarea{font:inherit;color:inherit}
button{cursor:pointer}
:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
[hidden]{display:none!important}

/* ---------- Join screen ---------- */
#join{height:100%;overflow-y:auto;display:flex;align-items:center;justify-content:center;padding:24px 16px calc(24px + env(safe-area-inset-bottom,0px))}
.card{width:100%;max-width:420px;display:flex;flex-direction:column;gap:18px}
.brand{font-size:12px;letter-spacing:.16em;text-transform:uppercase;color:var(--accent);font-weight:700}
.card h1{margin:0;font-size:26px;line-height:1.25;text-wrap:balance}
.card p{margin:0;color:var(--muted);line-height:1.6}
.field{display:flex;flex-direction:column;gap:8px}
.field > span{font-size:13px;color:var(--muted)}
.seg{display:grid;grid-template-columns:repeat(3,1fr);gap:8px}
.seg.two{grid-template-columns:1fr 1fr}
.seg button{border:1.5px solid var(--line);background:var(--panel);border-radius:10px;padding:12px 6px;font-weight:600;display:flex;flex-direction:column;align-items:center;gap:2px}
.seg button small{font-weight:400;color:var(--muted);font-size:11px}
.seg button[aria-pressed="true"]{border-color:var(--accent);background:color-mix(in srgb,var(--accent) 16%,var(--panel))}
.primary{border:none;background:var(--accent);color:var(--accent-ink);border-radius:12px;padding:15px;font-weight:700;font-size:16px}
.primary:disabled{opacity:.5}
.note{font-size:12px;color:var(--muted);line-height:1.6}
.err{color:var(--warn);font-size:13px;line-height:1.5}

/* ---------- Call screen ---------- */
#call{position:fixed;inset:0;display:flex;flex-direction:column}
#stage{position:relative;flex:1;min-height:0;background:#000;overflow:hidden}
#remoteVideo{position:absolute;inset:0;width:100%;height:100%;object-fit:cover;background:#000}
#localVideo{position:absolute;top:calc(56px + env(safe-area-inset-top,0px));right:12px;width:28%;max-width:170px;aspect-ratio:3/4;object-fit:cover;border-radius:10px;border:1.5px solid rgba(255,255,255,.35);background:#111;z-index:3;transform:scaleX(-1)}
#localVideo.rear{transform:none}
.waiting{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:10px;color:var(--muted);text-align:center;padding:0 24px;z-index:1}
.waiting .dot{width:10px;height:10px;border-radius:50%;background:var(--accent);animation:pulse 1.2s infinite}
@keyframes pulse{50%{opacity:.2}}

.topbar{position:absolute;top:0;left:0;right:0;z-index:4;display:flex;align-items:center;gap:10px;padding:calc(10px + env(safe-area-inset-top,0px)) 12px 10px;background:linear-gradient(rgba(0,0,0,.65),rgba(0,0,0,0))}
.pair{display:flex;align-items:center;gap:6px;font-weight:600;font-size:14px;background:rgba(0,0,0,.4);padding:6px 10px;border-radius:8px}
.state{font-size:12px;color:var(--muted);display:flex;align-items:center;gap:6px;min-width:0}
.state i{width:8px;height:8px;border-radius:50%;background:var(--muted);flex:none}
.state.ok i{background:var(--accent)}
.state.bad i{background:var(--warn)}
.state span{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.topbar .sp{flex:1}
.timer{font-variant-numeric:tabular-nums;font-size:13px;color:var(--muted)}
.iconbtn{border:none;background:rgba(0,0,0,.4);border-radius:8px;padding:6px 10px;font-size:13px}

#subs{position:absolute;left:0;right:0;bottom:0;max-height:62%;overflow-y:auto;z-index:2;padding:40px 12px 12px;display:flex;flex-direction:column;gap:8px;
  -webkit-mask-image:linear-gradient(transparent 0,#000 40px);mask-image:linear-gradient(transparent 0,#000 40px);scrollbar-width:none}
#subs::-webkit-scrollbar{display:none}
.subsonly #stage{background:var(--stage)}
.subsonly #subs{max-height:none;top:calc(52px + env(safe-area-inset-top,0px))}
.msg{max-width:min(86%,640px);display:flex;flex-direction:column;align-self:flex-start}
.msg.mine{align-self:flex-end;align-items:flex-end}
.bubble{background:var(--bubble);-webkit-backdrop-filter:blur(6px);backdrop-filter:blur(6px);border-radius:12px;padding:8px 12px;font-size:var(--fs);line-height:1.4;word-break:break-word}
.mine .bubble{background:var(--bubble-me)}
.bubble .main{font-weight:600}
.bubble .sub{font-size:.8em;opacity:.78;margin-top:3px}
.bubble.live .main{opacity:.75;font-weight:400}
.bubble .wait{font-style:italic;opacity:.6}
.who{font-size:10.5px;color:rgba(255,255,255,.6);margin:0 4px 2px;letter-spacing:.04em}

.invite{position:absolute;left:12px;right:12px;top:calc(64px + env(safe-area-inset-top,0px));z-index:5;background:var(--panel);border:1px solid var(--line);border-radius:14px;padding:14px;display:flex;flex-direction:column;gap:10px;max-width:460px;margin:0 auto}
.invite h3{margin:0;font-size:15px}
.invite .link{font-size:12px;color:var(--muted);word-break:break-all;background:var(--stage);padding:8px 10px;border-radius:8px;user-select:all}
.invite .row{display:flex;gap:8px;flex-wrap:wrap}
.invite .row > *{flex:1;min-width:120px;text-align:center;border-radius:10px;padding:10px;font-weight:600;font-size:14px;text-decoration:none}
.btn-wa{background:#25d366;color:#05301a;border:none}
.btn-ghost{background:var(--panel-2);border:1px solid var(--line)}

.dock{background:var(--panel);border-top:1px solid var(--line);padding:10px 12px calc(10px + env(safe-area-inset-bottom,0px));display:flex;flex-direction:column;gap:8px}
.ctrls{display:flex;justify-content:center;gap:8px;flex-wrap:wrap}
.cbtn{width:50px;height:50px;border-radius:50%;border:none;background:var(--panel-2);display:flex;flex-direction:column;align-items:center;justify-content:center;gap:1px;font-size:10px;color:var(--muted)}
.cbtn svg{width:22px;height:22px;stroke:var(--ink);fill:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}
.cbtn.off{background:#3a2a2a}
.cbtn.off svg{stroke:var(--danger)}
.cbtn.end{background:var(--danger)}
.cbtn.end svg{stroke:#fff}
.typerow{display:flex;gap:8px}
.typerow input{flex:1;min-width:0;border:1px solid var(--line);background:var(--stage);border-radius:10px;padding:10px 12px;font-size:16px}
.typerow button{border:none;background:var(--accent);color:var(--accent-ink);border-radius:10px;padding:0 16px;font-weight:700}
.hearing{font-size:12px;color:var(--muted);text-align:center;min-height:16px}
.hearing.bad{color:var(--warn)}

/* ---------- Ended ---------- */
#ended{height:100%;display:flex;align-items:center;justify-content:center;padding:24px 16px}
@media (prefers-reduced-motion:reduce){.waiting .dot{animation:none}}
@media (min-width:900px){#localVideo{width:200px}}

.nolink{display:flex;flex-direction:column;gap:14px}
.nolink p{margin:0;color:var(--muted);line-height:1.6}
