:root {
  --bg: #f6f4ef; --surface: #ffffff; --ink: #1d1b16; --muted: #7a7466; --line: #e6e1d6;
  --accent: #0f766e; --accent-soft: #ccebe7; --user: #1d1b16; --user-ink: #f6f4ef; --danger: #b42318;
  --radius: 14px; --ease: cubic-bezier(.2, .8, .2, 1);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141412; --surface: #1e1e1b; --ink: #efece4; --muted: #9a9486; --line: #2e2d29;
    --accent: #2dd4bf; --accent-soft: #134e48; --user: #efece4; --user-ink: #141412; --danger: #f97066;
  }
}
* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.6 "SF Arabic", "Geeza Pro", "Noto Sans Arabic", "Segoe UI", system-ui, sans-serif;
  display: flex; justify-content: center;
}
.app { width: 100%; max-width: 520px; height: 100dvh; display: grid; grid-template-rows: auto 1fr auto; }

/* ---------- screens ---------- */
.screen { width: 100%; max-width: 720px; min-height: 100dvh; padding: 24px 16px; }
.gate-screen { display: grid; place-items: center; }
.app { grid-template-rows: auto auto 1fr auto; }

/* ---------- lobby ---------- */
.lobby-head { margin: 12px 0 20px; }
.lobby-head h1 { font-size: 26px; }
.lobby-head p { color: var(--muted); max-width: 560px; }
.room-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.room-card {
  display: grid; gap: 4px; text-align: start; padding: 18px 16px; cursor: pointer;
  border: 1px solid var(--line); border-radius: 18px; background: var(--surface);
  transition: transform .15s var(--ease), border-color .2s ease, box-shadow .2s ease;
}
.room-card:hover { border-color: var(--accent); box-shadow: 0 6px 24px rgba(15, 118, 110, .12); transform: translateY(-2px); }
.room-card:active { transform: scale(.98); }
.room-icon { font-size: 30px; line-height: 1.2; }
.room-card-name { font-size: 19px; }
.room-sector { color: var(--accent); font-size: 13px; font-weight: 600; }
.room-desc { color: var(--muted); font-size: 14px; }
.room-agent { margin-top: 6px; font-size: 13px; color: var(--muted); border-top: 1px dashed var(--line); padding-top: 8px; }

/* ---------- room bar / status orb ---------- */
.room-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 12px 0; }
.room-title { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-actions { display: flex; gap: 6px; align-items: center; }
.chip {
  height: 36px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-size: 14px; white-space: nowrap;
}
.chip:hover { border-color: var(--muted); }
.status-area { padding: 18px 16px 10px; text-align: center; }
.icon-button {
  width: 38px; height: 38px; flex: none; border: 1px solid var(--line); border-radius: 50%;
  background: var(--surface); color: var(--muted); display: grid; place-items: center; cursor: pointer;
  transition: color .2s ease, border-color .2s ease;
}
.icon-button:hover { color: var(--ink); border-color: var(--muted); }
.orb {
  width: 132px; height: 132px; margin: 0 auto 14px; border-radius: 50%; position: relative;
  display: grid; place-items: center; background: var(--surface); border: 1px solid var(--line);
  transition: background .3s ease, border-color .3s ease;
}
.orb::before { content: ""; position: absolute; inset: -10px; border-radius: 50%; border: 2px solid var(--accent); opacity: 0; }
.bars { display: flex; gap: 5px; align-items: center; height: 40px; direction: ltr; }
.bars i { width: 6px; height: 36px; border-radius: 3px; background: var(--muted); transform: scaleY(.28); transition: background .3s ease; }
.status { font-size: 20px; font-weight: 600; }
.detail { color: var(--muted); font-size: 13px; min-height: 20px; }

[data-status="listening"] .orb { border-color: var(--accent); }
[data-status="listening"] .orb::before { animation: breathe 2.4s ease-in-out infinite; }
[data-status="hearing"] .orb, [data-status="speaking"] .orb { background: var(--accent-soft); border-color: var(--accent); }
[data-status="hearing"] .orb::before { animation: breathe .9s ease-in-out infinite; }
[data-status="hearing"] .bars i, [data-status="speaking"] .bars i { background: var(--accent); animation: wave .9s ease-in-out infinite; }
[data-status="thinking"] .orb::before, [data-status="checking"] .orb::before { opacity: 1; border-style: dashed; animation: spin 2.2s linear infinite; }
[data-status="thinking"] .bars i, [data-status="checking"] .bars i { animation: dots 1.2s ease-in-out infinite; }
[data-status="checking"] .orb { border-color: var(--accent); }
[data-status="error"] .orb { border-color: var(--danger); }
.bars i:nth-child(2) { animation-delay: .12s !important; }
.bars i:nth-child(3) { animation-delay: .24s !important; }
.bars i:nth-child(4) { animation-delay: .36s !important; }
.bars i:nth-child(5) { animation-delay: .48s !important; }
@keyframes breathe { 0%,100% { opacity: 0; transform: scale(.94); } 50% { opacity: .55; transform: scale(1.04); } }
@keyframes wave { 0%,100% { transform: scaleY(.28); } 50% { transform: scaleY(1); } }
@keyframes dots { 0%,100% { opacity: .35; } 50% { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { *, *::before { animation: none !important; } }

/* ---------- conversation ---------- */
main { overflow-y: auto; padding: 8px 16px 16px; display: flex; flex-direction: column; gap: 10px; }
.empty { margin: auto; color: var(--muted); text-align: center; font-size: 14px; max-width: 320px; display: grid; gap: 8px; }
.empty .hint { font-size: 13px; }
.msg.system { align-self: center; background: transparent; border: 1px dashed var(--line); color: var(--muted); font-size: 14px; }
.msg { max-width: 84%; padding: 10px 14px; border-radius: 16px; animation: rise .25s var(--ease); white-space: pre-wrap; }
.msg.agent { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-start-start-radius: 4px; }
.msg.user { align-self: flex-end; background: var(--user); color: var(--user-ink); border-start-end-radius: 4px; }
.msg.pending { opacity: .5; }
.msg.cut { opacity: .6; }
.msg.cut::after { content: " ⏸"; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

/* ---------- controls ---------- */
footer { padding: 14px 16px calc(18px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
button, input, select, textarea { font: inherit; color: inherit; }
.primary {
  width: 100%; height: 54px; border: 0; border-radius: var(--radius); font-size: 18px; font-weight: 600;
  cursor: pointer; background: var(--accent); color: #fff; transition: transform .1s ease, opacity .2s ease;
}
.primary:active { transform: scale(.98); }
.primary:disabled { opacity: .45; cursor: default; }
.primary.stop { background: var(--ink); color: var(--bg); }
.ghost {
  height: 42px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line);
  background: transparent; cursor: pointer; white-space: nowrap;
}
.ghost:hover { border-color: var(--muted); }
:focus-visible { outline: 3px solid var(--accent-soft); outline-offset: 2px; }

/* ---------- access gate ---------- */
.gate { display: grid; gap: 12px; margin: auto; width: 100%; max-width: 320px; text-align: center; }
.gate h1 { font-size: 22px; }
.gate p { color: var(--muted); font-size: 14px; }
.gate input { height: 54px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); padding: 0 14px; text-align: center; direction: ltr; }
.error { color: var(--danger); min-height: 22px; font-size: 14px; }
[hidden] { display: none !important; }

/* ---------- settings sheet ---------- */
dialog {
  border: 0; padding: 0; width: min(520px, 100%); max-height: 92dvh; margin: auto auto 0;
  border-radius: 20px 20px 0 0; background: var(--bg); color: var(--ink);
  box-shadow: 0 -12px 40px rgba(0, 0, 0, .18);
}
dialog[open] { animation: sheet .28s var(--ease); }
dialog::backdrop { background: rgba(0, 0, 0, .35); }
@keyframes sheet { from { transform: translateY(24px); opacity: 0; } }
@media (min-width: 600px) { dialog { margin: auto; border-radius: 20px; } }
.sheet { padding: 18px 16px 20px; display: grid; gap: 14px; }
.sheet h3 { font-size: 14px; color: var(--muted); margin-top: 4px; }
.brief-intro { color: var(--muted); }
.cheat { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; padding: 12px 14px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); font-size: 14px; }
.cheat dt { font-weight: 700; color: var(--accent); white-space: nowrap; }
.cheat dd { margin: 0; }
.scenarios { display: grid; gap: 10px; padding: 0; list-style: none; counter-reset: sc; }
.scenario { display: grid; gap: 3px; padding: 12px 14px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); font-size: 14px; }
.scenario strong { font-size: 15px; }
.sc-say { color: var(--ink); }
.sc-expect { color: var(--muted); font-size: 13px; }
.edges { display: grid; gap: 6px; padding-inline-start: 20px; color: var(--muted); font-size: 14px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { font-size: 18px; }
.sheet-head .icon-button { position: static; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px 14px; display: grid; gap: 12px; background: var(--surface); }
legend { padding: 0 6px; color: var(--muted); font-size: 13px; font-weight: 600; }
label { display: grid; gap: 6px; font-size: 14px; }
label small { color: var(--muted); font-size: 12px; }
select, input:not([type]), input[type="text"], textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); padding: 9px 12px;
}
select { height: 42px; padding-block: 0; }
textarea { resize: vertical; line-height: 1.5; }
.row { display: flex; gap: 8px; }
.row select { flex: 1; }
input[type="range"] { accent-color: var(--accent); width: 100%; }
output { color: var(--accent); font-weight: 600; }
.switch { grid-template-columns: auto 1fr; align-items: center; gap: 10px; cursor: pointer; }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); }
.sheet-foot { display: grid; grid-template-columns: auto 1fr; gap: 10px; }
.sheet-foot .primary { height: 46px; font-size: 16px; }
