:root {
  --bg: #1e1f22;
  --panel: #2b2d31;
  --tile: #313338;
  --hover: #3a3c42;
  --text: #dbdee1;
  --muted: #949ba4;
  --blurple: #5865f2;
  --blurple-h: #4752c4;
  --green: #23a559;
  --yellow: #f0b232;
  --red: #f23f43;
  --radius: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Arabic", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
#app, .view { height: 100%; height: 100dvh; }
.ic { width: 22px; height: 22px; fill: currentColor; flex: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- home ---------- */
.home { display: grid; place-items: center; padding: 20px; background: radial-gradient(1200px 600px at 50% -10%, #2a2d4a 0%, var(--bg) 60%); }
.card { width: min(420px, 100%); background: var(--panel); border-radius: 18px; padding: 28px 24px 22px; box-shadow: 0 20px 60px #0008; text-align: center; }
.logo { width: 64px; height: 64px; margin: 0 auto 10px; border-radius: 20px; background: var(--blurple); display: grid; place-items: center; font-size: 34px; font-weight: 800; color: #fff; }
h1 { margin: 0; font-size: 26px; letter-spacing: .3px; }
.tag { margin: 4px 0 20px; color: var(--muted); }
.field { display: block; text-align: start; margin: 0 0 12px; }
.field > span { display: block; font-size: 12px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.field > span output { float: right; color: var(--text); letter-spacing: 0; text-transform: none; font-variant-numeric: tabular-nums; }
.fine.tight { margin: -4px 0 12px; }
.field.inline { display: flex; align-items: center; justify-content: space-between; }
.field.inline > span { margin: 0; }
input[type=text], select { width: 100%; background: #1e1f22; border: 1px solid transparent; border-radius: 10px; padding: 11px 12px; outline: none; }
input[type=text]:focus, select:focus { border-color: var(--blurple); }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-inline-end: 34px; }
#join-code { text-align: center; letter-spacing: 3px; font-weight: 700; text-transform: uppercase; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; min-width: 0; }
.btn { border: 0; border-radius: 10px; padding: 11px 18px; font-weight: 700; transition: background .12s, transform .05s; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--blurple); color: #fff; }
.btn.primary:hover { background: var(--blurple-h); }
.btn.secondary { background: #4e5058; color: #fff; }
.btn.secondary:hover { background: #5d6068; }
.btn.small { padding: 7px 12px; font-size: 13px; }
.btn.block { width: 100%; }
.or { display: flex; align-items: center; gap: 10px; margin: 18px 0 12px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: #3f4147; }
.banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: #1e1f22; border: 1px solid #3f4147; border-radius: 10px; padding: 10px 12px; margin-bottom: 16px; text-align: start; }
.error { margin: 14px 0 0; padding: 10px 12px; border-radius: 10px; background: #f23f4322; color: #ff8587; text-align: start; }
.fine { margin: 14px 0 0; font-size: 12px; color: var(--muted); text-align: start; }
.home.invited #btn-create { background: #4e5058; }
.home.invited #btn-create:hover { background: #5d6068; }
.home.invited #btn-join { background: var(--blurple); }
.home.invited #btn-join:hover { background: var(--blurple-h); }

/* ---------- call ---------- */
.call { display: flex; flex-direction: column; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
.topbar { display: flex; align-items: center; gap: 10px; padding: 12px 14px; }
.topbar .pill { margin-inline-start: auto; }
.chip { display: inline-flex; align-items: center; gap: 8px; background: var(--panel); border: 0; border-radius: 10px; padding: 8px 12px; font-weight: 700; letter-spacing: 2px; }
.chip:hover { background: var(--hover); }
.chip .ic { width: 16px; height: 16px; color: var(--muted); }
.icon-btn { width: 40px; height: 40px; border: 0; background: transparent; border-radius: 10px; display: grid; place-items: center; color: var(--muted); }
.icon-btn:hover { background: var(--panel); color: var(--text); }
.pill { display: inline-flex; align-items: center; gap: 8px; background: var(--panel); border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600; }
.pill .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.q-good .dot { background: var(--green); }
.q-ok .dot { background: var(--yellow); }
.q-bad .dot { background: var(--red); }
.q-busy .dot { background: var(--yellow); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; gap: 18px; padding: 10px 16px; flex-wrap: wrap; align-content: center; }
.tile { position: relative; width: min(300px, 44vw); aspect-ratio: 4 / 3; min-width: 150px; background: var(--tile); border-radius: var(--radius); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; transition: box-shadow .1s; }
.tile.speaking { box-shadow: 0 0 0 3px var(--green); }
.avatar { width: 88px; height: 88px; border-radius: 50%; display: grid; place-items: center; font-size: 38px; font-weight: 800; color: #fff; background: var(--blurple); transition: transform .1s; }
.tile.speaking .avatar { transform: scale(1.06); }
.tile.empty .avatar { background: transparent; border: 2px dashed #4e5058; color: #4e5058; }
.who { display: flex; align-items: center; gap: 6px; font-weight: 700; max-width: 90%; }
.who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { width: 18px; height: 18px; fill: var(--red); flex: none; }
#peer-invite { display: none; }
.tile.empty #peer-invite { display: inline-block; }
.tile:not(.empty) .who { color: var(--text); }
.tile.empty .who { color: var(--muted); font-weight: 600; }

.status { text-align: center; margin: 0; color: var(--muted); min-height: 1.4em; padding: 0 16px; }
.stats { text-align: center; margin: 2px 0 6px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; min-height: 1.3em; }

.controls { display: flex; justify-content: center; gap: 12px; padding: 12px 14px 22px; }
.ctl { min-width: 76px; display: flex; flex-direction: column; align-items: center; gap: 4px; border: 0; background: var(--panel); border-radius: 14px; padding: 12px 14px; font-size: 12px; font-weight: 600; user-select: none; -webkit-user-select: none; touch-action: manipulation; transition: background .12s; }
.ctl:hover { background: var(--hover); }
.ctl[aria-pressed=true] { background: var(--red); color: #fff; }
.ctl.danger { background: var(--red); color: #fff; }
.ctl.danger:hover { background: #d83539; }
.ctl.ptt.on { background: var(--green); color: #fff; }

/* ---------- settings ---------- */
dialog { border: 0; padding: 0; background: transparent; color: var(--text); max-width: none; max-height: none; }
dialog::backdrop { background: #000a; }
dialog[open] { position: fixed; inset: 0; margin: auto; width: min(460px, 100%); height: min(720px, 100dvh); }
.sheet { background: var(--panel); border-radius: 16px; height: 100%; display: flex; flex-direction: column; overflow: hidden; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid #3f4147; }
.sheet-head h2 { margin: 0; font-size: 18px; }
.sheet-body { padding: 4px 16px 20px; overflow-y: auto; }
.sheet-body h3 { margin: 20px 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.meter { height: 8px; border-radius: 4px; background: #1e1f22; overflow: hidden; margin: -2px 0 14px; }
.meter i { display: block; height: 100%; width: 0; background: var(--green); transition: width .05s linear; }
.seg { display: flex; background: #1e1f22; border-radius: 10px; padding: 3px; gap: 3px; margin-bottom: 10px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 8px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--blurple); color: #fff; }
.switch { display: flex; align-items: center; gap: 10px; padding: 8px 0; cursor: pointer; }
.switch input { width: 40px; height: 22px; appearance: none; background: #4e5058; border-radius: 11px; position: relative; transition: background .15s; flex: none; cursor: pointer; }
.switch input::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked { background: var(--green); }
.switch input:checked::after { transform: translateX(18px); }
html[dir=rtl] .switch input:checked::after { transform: translateX(-18px); }
input[type=range] { width: 100%; accent-color: var(--blurple); }

#toast { position: fixed; inset-inline: 0; bottom: 100px; display: flex; justify-content: center; pointer-events: none; z-index: 10; }
#toast span { background: #111214; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: 0 6px 24px #0008; max-width: min(420px, 92vw); animation: rise .18s ease-out; }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }

@media (max-width: 520px) {
  .tile { width: 42vw; min-width: 140px; }
  .avatar { width: 68px; height: 68px; font-size: 30px; }
  .ctl { min-width: 70px; padding: 11px 10px; }
  .controls { gap: 8px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
