/* =============================================================
   Fonatrixx.ca – The Future of Communication
   Fonatrixx SecureCall · 1999 "digital rain" theme
   (Layout rules match the original; only the look has changed.)
   ============================================================= */
:root {
  /* Softened palette: muted sage green on a near-black, easier on the eyes. */
  --bg: #070a08;
  --card: rgba(12, 18, 14, .86);
  --ink: #d3ded6;
  --muted: #86a493;
  --line: #24382c;
  --accent: #6cc68a;
  --accent-dim: #3f7d56;
  --accent-ink: #0c1a12;
  --accent-soft: rgba(108, 198, 138, .1);
  --glow: 0 0 8px rgba(108,198,138,.22);
  --danger: #d9625b;
  --call-bg: #070a08;
  --panel: #0a0f0c;
  --radius: 6px;
  --mono: "Share Tech Mono", ui-monospace, "Courier New", monospace;
  --pixel: "VT323", "Share Tech Mono", ui-monospace, monospace;
  font-family: var(--mono);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
::selection { background: var(--accent); color: var(--accent-ink); }

/* ---------- Background: rain canvas + CRT scanlines ---------- */
#rain { position: fixed; inset: 0; z-index: 0; display: block; pointer-events: none; }
.scan {
  position: fixed; inset: 0; z-index: 50; pointer-events: none;
  background:
    repeating-linear-gradient(to bottom, rgba(8,12,10,0) 0, rgba(8,12,10,0) 2px, rgba(0,0,0,.08) 3px),
    radial-gradient(ellipse at center, rgba(8,12,10,0) 55%, rgba(0,0,0,.45) 100%);
  mix-blend-mode: multiply;
}
/* Scanlines off during a live call so video stays clean. */
html:has(#call:not([hidden]) #waiting[hidden]) .scan { display: none; }

/* ---------- Home ---------- */
#home {
  position: relative; z-index: 1;
  min-height: 100vh; min-height: 100dvh; margin: 0 auto; padding: 32px 20px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
}
#home > * { width: 100%; max-width: 480px; }

.brand { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.boot { margin: 0 0 14px; min-height: 1.4em; font-size: .95rem; color: var(--accent); text-shadow: var(--glow); letter-spacing: .04em; }
.caret { display: inline-block; margin-left: 2px; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.brand-row { display: flex; align-items: center; justify-content: center; gap: 14px; }
.logo {
  width: 46px; height: 46px; border-radius: var(--radius); display: grid; place-items: center; flex: none;
  background: transparent; color: var(--accent); border: 1px solid var(--accent);
  box-shadow: var(--glow), inset 0 0 12px rgba(108,198,138,0.14);
}
.logo svg { filter: drop-shadow(0 0 4px var(--accent)); }

h1 {
  font-family: var(--pixel); font-weight: 400; font-size: clamp(1.9rem, 9.5vw, 3.6rem); line-height: .9; margin: 0;
  letter-spacing: .06em; color: #e4ebe6; text-shadow: var(--glow);
}
.tld { color: var(--accent); }
/* Subtle RGB-split glitch, mostly still, occasionally twitching */
.glitch { position: relative; }
.glitch::before, .glitch::after {
  content: attr(data-text); position: absolute; inset: 0; pointer-events: none; opacity: .3;
}
.glitch::before { color: #8fc2b4; animation: glitchA 6s infinite steps(1); clip-path: inset(0 0 60% 0); }
.glitch::after  { color: #a9c98f; animation: glitchB 6s infinite steps(1); clip-path: inset(55% 0 0 0); }
@keyframes glitchA { 0%, 91%, 100% { transform: none; opacity: 0; } 92% { transform: translate(-3px, -1px); opacity: .8; } 94% { transform: translate(2px, 1px); } 96% { transform: translate(-1px, 0); opacity: 0; } }
@keyframes glitchB { 0%, 92%, 100% { transform: none; opacity: 0; } 93% { transform: translate(3px, 1px); opacity: .8; } 95% { transform: translate(-2px, 0); } 97% { opacity: 0; } }

.tagline {
  margin: 10px 0 0; font-size: .9rem; text-transform: uppercase; letter-spacing: .38em; color: var(--accent);
  text-shadow: 0 0 6px rgba(108,198,138,0.24);
}
.product {
  margin: 14px 0 0; display: inline-flex; align-items: center; gap: 8px; padding: 5px 12px;
  border: 1px solid var(--line); background: rgba(18,22,20,.7); border-radius: var(--radius);
  font-size: .82rem; letter-spacing: .14em; text-transform: uppercase; color: var(--ink);
}
.product span { color: var(--accent); }
.nw { white-space: nowrap; }
@media (max-width: 400px) {
  #home h1 { white-space: nowrap; }
  .logo { width: 38px; height: 38px; }
  .tagline { letter-spacing: .22em; font-size: .78rem; }
}
.lede { color: var(--ink); opacity: .85; font-size: 1.02rem; line-height: 1.5; margin: 18px 0 22px; }

.card {
  position: relative;
  background: var(--card); border: 1px solid var(--accent-dim); border-radius: var(--radius); padding: 24px 22px 22px;
  display: flex; flex-direction: column;
  box-shadow: 0 0 0 1px rgba(8,12,10,.6), 0 0 30px rgba(108,198,138,0.06), inset 0 0 40px rgba(108,198,138,0.02);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
/* Terminal corner brackets */
.card::before, .card::after { content: ""; position: absolute; width: 14px; height: 14px; border: 2px solid var(--accent); pointer-events: none; filter: drop-shadow(0 0 4px var(--accent)); }
.card::before { top: -2px; left: -2px; border-right: 0; border-bottom: 0; }
.card::after  { bottom: -2px; right: -2px; border-left: 0; border-top: 0; }
.card h2 { font-size: 1.1rem; margin: 0 0 6px; display: flex; align-items: center; gap: 10px; }
.card.single { gap: 0; text-align: center; }
.card.single label { text-align: center; }
.card.single input { text-align: center; }
.card.single .primary { margin-top: 16px; }
.card.single label.second { margin-top: 16px; }
.optional { font-weight: 400; opacity: .7; text-transform: none; letter-spacing: 0; }
#myName { letter-spacing: normal; font-size: 1.05rem; }
.card.single .hint { margin: 14px 0 0; flex: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
input::placeholder { letter-spacing: 0; font-size: .95rem; color: #5f7c69; opacity: 1; }
@media (max-width: 400px) { input::placeholder { font-size: .8rem; } }
.step { width: 24px; height: 24px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 0.8rem; display: grid; place-items: center; font-weight: 700; }
.hint { color: var(--muted); margin: 0 0 18px; font-size: 0.88rem; line-height: 1.5; flex: 1; }
label { font-size: 0.78rem; font-weight: 400; color: var(--accent); margin-bottom: 7px; text-transform: uppercase; letter-spacing: .16em; }
label::before { content: "> "; opacity: .7; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; min-width: 0; }

input {
  font: inherit; font-size: 1.2rem; letter-spacing: 0.08em; font-variant-numeric: tabular-nums;
  padding: 12px 14px; border-radius: var(--radius); border: 1px solid var(--line);
  background: rgba(8,12,10,.85); color: #e4ebe6; width: 100%; caret-color: var(--accent);
  text-shadow: 0 0 4px rgba(108,198,138,0.2);
  transition: border-color .15s, box-shadow .15s;
}
input:focus { outline: none; border-color: var(--accent); box-shadow: var(--glow); }

button { font: inherit; cursor: pointer; border: 0; border-radius: var(--radius); }
button:disabled { opacity: 0.5; cursor: default; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.primary {
  position: relative; overflow: hidden;
  margin-top: 14px; padding: 14px; font-weight: 400; font-size: 1.05rem; letter-spacing: .2em; text-transform: uppercase;
  background: var(--accent); color: var(--accent-ink);
  box-shadow: 0 0 14px rgba(108,198,138,0.22), 0 0 40px rgba(108,198,138,0.08);
  transition: box-shadow .15s, transform .05s;
}
.primary::after { /* scanning light sweep */
  content: ""; position: absolute; top: 0; bottom: 0; width: 40%; left: -60%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.14), transparent);
  animation: sweep 7s ease-in-out infinite;
}
@keyframes sweep { 0%, 75% { left: -60%; } 100% { left: 130%; } }
.primary:hover:not(:disabled) { box-shadow: 0 0 22px rgba(108,198,138,0.34), 0 0 60px rgba(108,198,138,0.14); }
.primary:active:not(:disabled) { transform: translateY(1px); }
.ghost { padding: 0 14px; background: transparent; color: var(--accent); border: 1px solid var(--accent-dim); font-weight: 400; letter-spacing: .08em; text-transform: uppercase; }
.ghost:hover { background: var(--accent-soft); box-shadow: 0 0 10px rgba(108,198,138,0.14); }
.ghost.small { padding: 6px 12px; font-size: 0.8rem; }

.error {
  margin: 16px 0 0; text-align: center; padding: 12px 14px; border-radius: var(--radius);
  background: rgba(60,0,0,.75); border: 1px solid var(--danger); color: #e3a09b; font-weight: 400;
  text-shadow: 0 0 6px rgba(217,98,91,0.36);
}
.error::before { content: "[ERROR] "; color: var(--danger); }
.foot { color: var(--muted); font-size: 0.8rem; line-height: 1.55; margin: 24px 0 0; }
.foot::after { content: "© Fonatrixx.ca · The Future of Communication"; display: block; margin-top: 10px; color: #55705f; letter-spacing: .1em; text-transform: uppercase; font-size: .7rem; }

/* ---------- Call ---------- */
#call { position: fixed; inset: 0; z-index: 1; background: var(--call-bg); color: var(--ink); display: flex; flex-direction: column; }
/* While waiting for others, let the rain show through. */
#call:has(#waiting:not([hidden])) { background: transparent; }
#call:has(#waiting:not([hidden])) .grid { background: transparent; }
.callmain { flex: 1; display: flex; min-height: 0; }
.stage { position: relative; flex: 1; min-width: 0; overflow: hidden; }

/* ---------- Diagnostics panel (PC / wide screens only) ---------- */
.diag {
  width: 380px; flex: none; display: flex; flex-direction: column; min-height: 0;
  background: var(--panel); border-left: 1px solid var(--line); color: var(--ink);
}
.diag-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 18px 12px; border-bottom: 1px solid var(--line); }
.diag-head h2 { margin: 0; font-family: var(--pixel); font-weight: 400; font-size: 1.5rem; letter-spacing: .08em; color: var(--accent); text-shadow: var(--glow); }
.diag-head .ghost { color: var(--accent); border-color: var(--accent-dim); }
.diag-body { flex: 1; overflow-y: auto; padding: 6px 18px 12px; scrollbar-color: var(--accent-dim) transparent; }
.diag-sec { padding: 12px 0; border-bottom: 1px dashed var(--line); }
.diag-sec:last-child { border-bottom: 0; }
.diag-sec h3 { margin: 0 0 8px; font-size: .74rem; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); font-weight: 400; }
.diag-sec h3::before { content: "// "; opacity: .6; }
.diag-sec dl { display: grid; grid-template-columns: 128px 1fr; gap: 5px 12px; margin: 0; font-size: .82rem; line-height: 1.35; }
.diag-sec dt { color: var(--muted); }
.diag-sec dd { margin: 0; overflow-wrap: anywhere; }
.diag-sec dd.mono { overflow-wrap: normal; word-break: normal; }
.diag-sec dd.mono { font-family: var(--mono); font-size: .74rem; letter-spacing: .01em; color: #b8cbbf; }
.diag-sec .note { margin: 8px 0 0; font-size: .75rem; color: var(--muted); line-height: 1.4; }
.diag .ok { color: var(--accent); text-shadow: 0 0 5px rgba(108,198,138,0.24); }
.diag .bad { color: #e08a84; }
.diag .muted { color: var(--muted); }
.diag-foot { margin: 0; padding: 10px 18px 14px; font-size: .72rem; color: #55705f; border-top: 1px solid var(--line); }
.diag-foot a { color: var(--muted); }
#infoBtn[aria-pressed="true"] svg { background: var(--accent); color: var(--accent-ink); box-shadow: var(--glow); }
@media (max-width: 999px) { .diag, #infoBtn { display: none !important; } }

/* ---------- Participant grid ---------- */
.grid {
  position: absolute; inset: 0; display: flex; flex-wrap: wrap; gap: 6px; padding: 6px; background: #000;
  justify-content: center; align-content: center;
}
.grid > .tile { width: var(--tw, 100%); height: var(--th, 100%); flex: none; }
.grid.solo { gap: 0; padding: 0; }
.tile { position: relative; overflow: hidden; border-radius: var(--radius); background: #000; border: 1px solid var(--line); }
.grid.solo .tile { border-radius: 0; border: 0; }
.tile video { width: 100%; height: 100%; object-fit: contain; background: #000; display: block; }
.tile-name {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: var(--nb, 8px);
  max-width: calc(100% - 16px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: 3px 10px; border-radius: var(--radius); background: rgba(8,12,10,.75); border: 1px solid var(--accent-dim);
  color: var(--accent); font-size: .8rem; letter-spacing: .06em; text-shadow: 0 0 4px rgba(108,198,138,0.24);
}
.tile-status {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 12px;
  color: var(--accent); font-size: .92rem; background: rgba(12,16,14,.88); text-shadow: 0 0 5px rgba(108,198,138,0.24);
}
.tile-status[hidden] { display: none; }

/* Passcode chip for inviting more people */
.invite {
  grid-column: 1; justify-self: start; display: flex; align-items: center; gap: 8px; min-width: 0;
  padding: 6px 8px 6px 12px; border-radius: var(--radius); background: rgba(18,22,20,.9); border: 1px solid var(--line);
  font-size: .8rem; color: var(--muted);
}
.invite strong { white-space: nowrap; color: #e4ebe6; letter-spacing: .1em; font-variant-numeric: tabular-nums; text-shadow: 0 0 5px rgba(108,198,138,0.24); font-weight: 400; }
.invite .ghost { color: var(--accent); border-color: var(--accent-dim); padding: 3px 10px; font-size: .74rem; }
.invite-label { text-transform: uppercase; letter-spacing: .12em; font-size: .68rem; color: var(--muted); }
.people { padding-left: 8px; border-left: 1px solid var(--line); white-space: nowrap; }

/* Lobby: people waiting to be let in */
.lobby { position: absolute; top: 12px; right: 12px; z-index: 4; display: flex; flex-direction: column; gap: 8px; width: min(340px, calc(100% - 24px)); }
.knock {
  background: rgba(13,17,15,.95); border: 1px solid var(--accent); border-radius: var(--radius); padding: 12px 14px;
  box-shadow: 0 8px 28px rgba(8,12,10,.6), 0 0 18px rgba(108,198,138,0.12); color: var(--ink);
  animation: knockIn .35s ease-out;
}
@keyframes knockIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.knock strong { display: block; font-size: .95rem; color: #e4ebe6; font-weight: 400; }
.knock strong::before { content: "▶ "; color: var(--accent); }
.knock span { display: block; font-size: .8rem; color: var(--muted); margin-top: 2px; }
.knock .row { display: flex; gap: 8px; margin-top: 10px; }
.knock button { flex: 1; padding: 8px; font-size: .82rem; letter-spacing: .14em; text-transform: uppercase; }
.knock .admit { background: var(--accent); color: var(--accent-ink); box-shadow: 0 0 10px rgba(108,198,138,0.2); }
.knock .deny { background: transparent; color: #e3a09b; border: 1px solid #5a2a28; }
@media (max-width: 600px) {
  .invite-label { display: none; }
  .lobby { left: 12px; right: 12px; width: auto; top: 12px; }
}
.preview {
  position: absolute; right: 16px; bottom: 16px; width: min(26vw, 240px); aspect-ratio: 4 / 3; z-index: 2;
  border-radius: var(--radius); overflow: hidden; background: #000;
  box-shadow: 0 6px 24px rgba(8,12,10,.6), 0 0 14px rgba(108,198,138,0.1); border: 1px solid var(--accent-dim);
  cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
}
.preview.dragging { cursor: grabbing; box-shadow: 0 10px 32px rgba(8,12,10,.7), var(--glow); border-color: var(--accent); }
#localVideo { display: block; width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); pointer-events: none; }
@media (max-width: 600px) { .preview { width: 34vw; aspect-ratio: 3 / 4; right: 12px; bottom: 12px; } }
html:has(#call:not([hidden])), html:has(#call:not([hidden])) body { overflow: hidden; overscroll-behavior: none; }

.waiting { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 20px; text-align: center; padding: 20px; background: radial-gradient(ellipse at center, rgba(8,12,10,.82) 0, rgba(8,12,10,.55) 60%, rgba(8,12,10,.3) 100%); }
.waiting p { margin: 0; font-size: 1.15rem; color: var(--accent); max-width: 440px; line-height: 1.5; text-shadow: var(--glow); letter-spacing: .04em; }
.waiting p::after { content: "█"; margin-left: 4px; animation: blink 1s steps(1) infinite; }
/* Targeting-ring "pulse" */
.pulse {
  position: relative; width: 72px; height: 72px; border-radius: 50%;
  border: 2px solid var(--accent); box-shadow: var(--glow), inset 0 0 14px rgba(108,198,138,0.2);
  animation: pulse 1.8s ease-out infinite;
}
.pulse::before { content: ""; position: absolute; inset: 14px; border-radius: 50%; background: var(--accent); box-shadow: var(--glow); }
.pulse::after { content: ""; position: absolute; inset: -10px; border-radius: 50%; border: 1px dashed var(--accent-dim); animation: spin 8s linear infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(108,198,138,0.24), inset 0 0 14px rgba(108,198,138,0.2); } 100% { box-shadow: 0 0 0 40px rgba(108,198,138,0.0), inset 0 0 14px rgba(108,198,138,0.2); } }
@keyframes spin { to { transform: rotate(360deg); } }
.codebox { display: flex; align-items: center; gap: 12px; background: rgba(14,18,16,.92); border: 1px solid var(--accent); padding: 12px 16px; border-radius: var(--radius); box-shadow: 0 0 22px rgba(108,198,138,0.1); }
.codelabel { font-size: .74rem; text-transform: uppercase; letter-spacing: .14em; color: var(--muted); }
.codebox strong { font-family: var(--pixel); font-weight: 400; font-size: 2.2rem; line-height: 1; letter-spacing: .12em; font-variant-numeric: tabular-nums; white-space: nowrap; color: #e4ebe6; text-shadow: var(--glow); }
.codebox .ghost { color: var(--accent); border-color: var(--accent-dim); }

.sec {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%); z-index: 3;
  width: min(480px, calc(100% - 24px)); padding: 16px 18px; border-radius: var(--radius);
  background: rgba(13,17,15, .92); border: 1px solid var(--accent);
  box-shadow: 0 10px 34px rgba(8,12,10,.6), 0 0 22px rgba(108,198,138,0.12); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  transition: opacity .6s ease, transform .6s ease; cursor: pointer;
}
.sec.fade { opacity: 0; transform: translate(-50%, -8px); }
.sec-head { display: flex; gap: 12px; align-items: flex-start; }
.sec-icon { flex: none; width: 38px; height: 38px; border-radius: var(--radius); display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); box-shadow: var(--glow); }
.sec-head strong { display: block; font-size: 1.05rem; margin-bottom: 2px; color: var(--accent); font-weight: 400; letter-spacing: .08em; text-transform: uppercase; text-shadow: 0 0 6px rgba(108,198,138,0.24); }
.sec-head span { font-size: .85rem; color: var(--ink); opacity: .85; line-height: 1.4; }
.sec dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 14px 0 0; padding-top: 12px; border-top: 1px dashed var(--line); font-size: .85rem; }
.sec dt { color: var(--muted); }
.sec dd { margin: 0; font-variant-numeric: tabular-nums; color: #e4ebe6; }
.sec.warn { border-color: var(--danger); box-shadow: 0 10px 34px rgba(8,12,10,.6), 0 0 22px rgba(217,98,91,0.18); }
.sec.warn .sec-icon { background: var(--danger); color: #fff; box-shadow: 0 0 10px rgba(217,98,91,0.42); }
.sec.warn .sec-head strong { color: #e3a09b; text-shadow: none; }
@media (max-width: 420px) { .sec { top: 10px; padding: 14px; } .sec dl { grid-template-columns: 1fr; gap: 2px; } .sec dd { margin-bottom: 6px; } }

.badge { position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 3; white-space: nowrap; background: rgba(8,12,10,.75); border: 1px solid var(--accent-dim); color: var(--accent); padding: 6px 12px; border-radius: var(--radius); font-size: .85rem; letter-spacing: .06em; }

.controls {
  position: relative; z-index: 2;
  display: grid; grid-template-columns: minmax(max-content, 1fr) auto 1fr; align-items: center; gap: 12px;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, #0c120e, #000); border-top: 1px solid var(--line);
  box-shadow: 0 -1px 0 rgba(108,198,138,0.06), 0 -10px 30px rgba(108,198,138,0.024);
}
.ctl-row { grid-column: 2; display: flex; justify-content: center; gap: 14px; }
/* Passcode chip above the buttons once both no longer fit on one row. */
@media (max-width: 1100px) {
  .controls { grid-template-columns: 1fr; gap: 10px; padding-top: 10px; }
  .invite { grid-column: 1; justify-self: center; }
  .ctl-row { grid-column: 1; }
}
.ctl { width: 64px; display: flex; flex-direction: column; align-items: center; gap: 5px; background: transparent; color: var(--muted); font-size: .7rem; letter-spacing: .1em; text-transform: uppercase; padding: 0; }
.ctl svg {
  width: 52px; height: 52px; padding: 14px; border-radius: 50%;
  background: #000; color: var(--accent); border: 1px solid var(--accent-dim);
  box-shadow: inset 0 0 10px rgba(108,198,138,0.08); transition: box-shadow .15s, background .15s;
}
.ctl:hover { color: var(--accent); }
.ctl:hover svg { background: #121c16; box-shadow: var(--glow), inset 0 0 10px rgba(108,198,138,0.14); }
.ctl .off { display: none; }
.ctl[aria-pressed="true"] .on { display: none; }
.ctl[aria-pressed="true"] .off { display: block; background: #e4ebe6; color: #0c1a12; border-color: #e4ebe6; }
.ctl.share[aria-pressed="true"] svg { background: var(--accent); color: var(--accent-ink); box-shadow: var(--glow); }
#localVideo.screen { transform: none; object-fit: contain; background: #000; }
/* A back/rear camera is shown as it is, not mirrored like a selfie camera. */
#localVideo.rear { transform: none; }.ctl.hang { color: #e3a09b; }
.ctl.hang svg { background: var(--danger); color: #fff; border-color: var(--danger); box-shadow: 0 0 12px rgba(217,98,91,0.33); }
@media (max-width: 420px) {
  .controls .ctl { width: 52px; font-size: .62rem; }
  .controls .ctl svg { width: 48px; height: 48px; padding: 13px; }
  .codebox { gap: 8px; padding: 10px 12px; }
  .codebox strong { font-size: 1.6rem; letter-spacing: .06em; }
  .codelabel { display: none; }
  .controls { padding-left: 8px; padding-right: 8px; }
  .ctl-row { gap: 6px; }
  .ctl { width: 58px; }
}
.ctl.hang:hover svg { filter: brightness(1.15); box-shadow: 0 0 18px rgba(217,98,91,0.48); }

@media (prefers-reduced-motion: reduce) {
  .glitch::before, .glitch::after, .primary::after, .caret, .waiting p::after, .pulse, .pulse::after, .knock { animation: none !important; }
  .glitch::before, .glitch::after { display: none; }
}

/* =============================================================
   Video call / Text chat picker (home)
   ============================================================= */
.modepick { border: 0; margin: 16px 0 0; padding: 0; min-width: 0; transition: opacity .2s; }
.modepick legend { padding: 0; margin: 0 auto 7px; font-size: .78rem; color: var(--accent); text-transform: uppercase; letter-spacing: .16em; }
.modepick legend::before { content: "> "; opacity: .7; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 0; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: rgba(8,12,10,.85); }
.seg input { position: absolute; opacity: 0; pointer-events: none; width: 1px; height: 1px; }
.card.single .seg label, .seg label {
  display: flex; align-items: center; justify-content: center; gap: 8px; margin: 0; padding: 11px 8px; cursor: pointer;
  font-size: .9rem; letter-spacing: .08em; color: var(--muted); text-transform: uppercase; transition: background .15s, color .15s;
}
.seg label::before { content: none; }
.seg label + input + label { border-left: 1px solid var(--line); }
.seg svg { width: 18px; height: 18px; flex: none; }
.card.single .seg label:hover { color: var(--accent); background: rgba(108,198,138,0.024); }
.card.single .seg input:checked + label { background: var(--accent); color: var(--accent-ink); box-shadow: inset 0 0 12px rgba(8,12,10,.25); }
.seg input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: -3px; }
.modenote { margin: 7px 0 0; font-size: .78rem; color: var(--muted); line-height: 1.4; }
.modepick.locked .seg { opacity: .35; }
.modepick.locked .seg label { cursor: default; }
.card.single .modepick.locked .seg label:hover { background: none; color: var(--muted); }
.card.single .modepick.locked .seg input:checked + label { background: transparent; color: var(--muted); box-shadow: none; }

/* =============================================================
   Chat panel
   ============================================================= */
/* Stacking: grid · chat · waiting screen · self-preview (same layer, later wins). */
.waiting { z-index: 2; }
.chat {
  position: absolute; z-index: 2; top: 12px; right: 12px; bottom: 12px; width: min(360px, calc(100% - 24px));
  display: flex; flex-direction: column; min-height: 0;
  background: rgba(13,17,15,.94); border: 1px solid var(--accent-dim); border-radius: var(--radius);
  box-shadow: 0 10px 34px rgba(8,12,10,.6), 0 0 22px rgba(108,198,138,0.072);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.chat-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.chat-head h2 { margin: 0; font-family: var(--pixel); font-weight: 400; font-size: 1.45rem; letter-spacing: .08em; color: var(--accent); text-shadow: var(--glow); }
.chat-people { flex: 1; min-width: 0; font-size: .76rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-people::before { content: "●"; margin-right: 6px; color: #33493b; }
.chat-people.live::before { color: var(--accent); text-shadow: 0 0 6px var(--accent); }
.chat-log { list-style: none; margin: 0; padding: 14px; flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; scrollbar-color: var(--accent-dim) transparent; }
.chat-log li { max-width: 86%; display: flex; flex-direction: column; gap: 3px; }
.chat-log li p { margin: 0; padding: 8px 11px; border-radius: var(--radius); white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.4; font-size: .95rem; }
.chat-log .meta { font-size: .68rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.chat-log .theirs { align-self: flex-start; }
.chat-log .theirs p { background: rgba(28,32,30,.85); border: 1px solid var(--line); color: #e4ebe6; }
.chat-log .mine { align-self: flex-end; align-items: flex-end; }
.chat-log .mine p { background: var(--accent); color: var(--accent-ink); box-shadow: 0 0 10px rgba(108,198,138,0.12); }
.chat-log .sys { align-self: center; max-width: 92%; text-align: center; }
.chat-log .sys p { padding: 2px 6px; font-size: .76rem; color: var(--muted); background: none; }
.chat-log .sys p::before { content: "// "; opacity: .6; }
.chat-form { display: flex; gap: 8px; align-items: flex-end; padding: 10px; border-top: 1px solid var(--line); }
.chat-form textarea {
  flex: 1; min-width: 0; resize: none; font: inherit; font-size: 1rem; line-height: 1.4; max-height: 140px;
  padding: 10px 12px; border-radius: var(--radius); border: 1px solid var(--line);
  background: rgba(8,12,10,.85); color: #e4ebe6; caret-color: var(--accent);
}
.chat-form textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--glow); }
.chat-form textarea::placeholder { color: #5f7c69; }
.chat-send { margin: 0; padding: 11px 16px; font-size: .85rem; letter-spacing: .14em; flex: none; }
.chat-send:disabled { box-shadow: none; }
.chat-send::after { display: none; }

/* Keep the self-preview clear of the open chat panel (until it has been dragged). */
#call:has(#chat:not([hidden])) .preview { right: 384px; }
@media (max-width: 600px) {
  .chat { top: 8px; left: 8px; right: 8px; bottom: 8px; width: auto; }
  #call:has(#chat:not([hidden])) .preview { display: none; }
}

/* Chat button badge */
.ctl { position: relative; }
.unread {
  position: absolute; top: -4px; right: 2px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px;
  display: grid; place-items: center; font-size: .7rem; font-weight: 400; letter-spacing: 0;
  background: #e4ebe6; color: var(--accent-ink); box-shadow: var(--glow);
}
#chatBtn[aria-pressed="true"] svg { background: var(--accent); color: var(--accent-ink); box-shadow: var(--glow); }

/* Text-chat-only mode: the chat fills the screen; no video, no preview. */
#call.textmode { background: transparent; }
#call.textmode .grid, #call.textmode .preview { display: none !important; }
#call.textmode .chat {
  top: 16px; bottom: 16px; left: 50%; right: auto; transform: translateX(-50%);
  width: min(820px, calc(100% - 32px));
}
#call.textmode .chat-log li { max-width: 78%; }
#call.textmode .controls { background: linear-gradient(to bottom, rgba(1,13,4,.95), #000); }
html:has(#call.textmode:not([hidden])) .scan { display: block; }
@media (max-width: 600px) {
  #call.textmode .chat { top: 8px; bottom: 8px; width: calc(100% - 16px); }
}

/* Phones: room for up to seven call buttons (incl. Chat) on one row. */
@media (max-width: 420px) {
  .controls .ctl { width: 48px; font-size: .56rem; letter-spacing: .06em; }
  .controls .ctl svg { width: 44px; height: 44px; padding: 11px; }
  .ctl-row { gap: 3px; }
  .unread { right: -2px; }
}
.badge { max-width: calc(100% - 24px); overflow: hidden; text-overflow: ellipsis; }
/* When there are more buttons than fit on one row (e.g. Flip and Full screen on a phone),
   they shrink evenly instead of running off the screen. */
.ctl-row { min-width: 0; }
.controls .ctl { flex: 0 1 auto; min-width: 0; }
.controls .ctl svg { max-width: 100%; height: auto; aspect-ratio: 1; }
@media (max-width: 700px) { .ctl-row { gap: 6px; } }
@media (max-width: 420px) { .ctl-row { gap: 3px; } }

/* ---------- Softening layer ---------- */
/* Dim, calm background rain. */
#rain { opacity: .38; }
/* Reading text stays a soft off-white; green is kept for accents. */
.lede, .hint, .foot, .modenote { text-shadow: none; }
h1 { color: #e4ebe6; text-shadow: 0 0 14px rgba(108,198,138,.18); }
.boot, .tagline, .waiting p, .tile-status, .sec-head strong, .knock strong,
.invite strong, .codebox strong, .diag-head h2, .chat-head h2, input, .badge, .tile-name { text-shadow: none; }
.tagline { color: var(--muted); }
.waiting p { color: var(--ink); }
.tile-status { color: var(--ink); }
.badge { color: var(--ink); }
.ctl svg { color: #a9cbb5; }
.ctl:hover svg { color: var(--accent); }
.chat-log .theirs p { color: var(--ink); }
.primary { box-shadow: none; }
.primary:hover:not(:disabled) { box-shadow: 0 0 12px rgba(108,198,138,.25); filter: brightness(1.05); }
.chat-log .mine p { box-shadow: none; }
.pulse::before { opacity: .85; }
