@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;500;700&display=swap');
:root {
  --bg: #0b0d10; --panel: #15181d; --panel2: #1c2027; --line: #2a2f38;
  --text: #eef1f5; --muted: #9aa3af; --accent: #22c55e; --accent2: #16a34a; --danger: #ef4444; --warn: #f59e0b;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.6 Vazirmatn, system-ui, sans-serif; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.err { color: var(--danger); }
[hidden] { display: none !important; }
.primary { display: inline-block; background: var(--accent); color: #04130a; border: 0; border-radius: 10px; padding: 11px 22px; font-weight: 700; cursor: pointer; text-decoration: none; }
.primary:hover { background: #34d46c; }
.primary:disabled { opacity: .5; cursor: default; }
.ghost { background: transparent; border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px; cursor: pointer; }
.ghost:hover { border-color: var(--muted); }

/* ---------------- call ---------------- */
body.call { overflow: hidden; }
#stage { position: fixed; inset: 0; display: grid; place-items: center; background: radial-gradient(ellipse at center, #1a1f27 0%, #07080a 70%); }
#replica { position: relative; height: min(100dvh - 24px, (100vw - 24px) * 16 / 9); aspect-ratio: 9 / 16; border-radius: 22px; overflow: hidden; background: #000; box-shadow: 0 20px 80px #000a; }
#replica video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transition: opacity .18s linear; }
#vTalk { opacity: 0; transition: none; } /* opacity driven per frame by lip sync */
#vLip { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; pointer-events: none; }
#lipBox { position: absolute; top: 52px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 6px; padding: 4px 6px 4px 10px; border-radius: 99px; background: #000a; font-size: 12px; white-space: nowrap; z-index: 2; }
#lipBox select { background: #ffffff14; border: 0; border-radius: 99px; padding: 2px 8px; font-size: 12px; color: var(--text); }
#lipBox select option { background: var(--panel); }
#lipState { color: var(--muted); max-width: 170px; overflow: hidden; text-overflow: ellipsis; }
#lipState[data-state=active] { color: var(--accent); }
#lipState[data-state=preparing], #lipState[data-state=loading] { color: var(--warn); }
#lipState[data-state=error], #lipState[data-state=unreachable], #lipState[data-state=not_configured] { color: #fca5a5; }
#caption { position: absolute; inset-inline: 14px; bottom: 96px; padding: 8px 14px; border-radius: 12px; background: #000b; font-size: 17px; text-align: center; opacity: 0; transform: translateY(6px); transition: .2s; pointer-events: none; }
#caption.show { opacity: 1; transform: none; }
#status { position: absolute; top: 14px; right: 14px; display: flex; gap: 8px; align-items: center; padding: 5px 12px; border-radius: 99px; background: #000a; font-size: 13px; }
#status .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
body[data-state=listening] #status .dot { background: var(--accent); }
body[data-state=user] #status .dot { background: #38bdf8; animation: pulse 1s infinite; }
body[data-state=thinking] #status .dot { background: var(--warn); animation: pulse .7s infinite; }
body[data-state=speaking] #status .dot { background: #a78bfa; animation: pulse 1s infinite; }
body[data-state=offline] #status .dot { background: var(--danger); }
@keyframes pulse { 50% { opacity: .3; } }
#timer { position: absolute; top: 14px; left: 14px; padding: 5px 12px; border-radius: 99px; background: #000a; font: 13px ui-monospace, monospace; direction: ltr; }
#self { position: fixed; top: 16px; left: 16px; width: 150px; aspect-ratio: 3/4; object-fit: cover; border-radius: 14px; background: #111; border: 2px solid #ffffff22; transform: scaleX(-1); display: none; z-index: 3; }
body.cam #self { display: block; }
#controls { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); display: flex; gap: 12px; padding: 10px 14px; border-radius: 99px; background: #0d0f13dd; border: 1px solid var(--line); backdrop-filter: blur(10px); z-index: 4; }
.ctl { width: 50px; height: 50px; border-radius: 50%; border: 0; background: var(--panel2); display: grid; place-items: center; cursor: pointer; }
.ctl svg { width: 23px; fill: currentColor; }
.ctl:hover { background: #2a303a; }
.ctl.off { background: #3b1d1d; color: #fca5a5; }
.ctl.end { background: var(--danger); width: 64px; border-radius: 99px; }
.ctl.end svg { width: 28px; }
#meter { position: fixed; bottom: 92px; left: 50%; width: 120px; height: 3px; transform: translateX(-50%); background: #ffffff14; border-radius: 3px; overflow: hidden; z-index: 4; }
#meter i { display: block; height: 100%; background: var(--accent); transform-origin: left; transform: scaleX(0); transition: transform 60ms; }
#transcript { position: fixed; top: 0; bottom: 0; inset-inline-end: 0; width: min(380px, 100vw); background: var(--panel); border-inline-start: 1px solid var(--line); display: flex; flex-direction: column; z-index: 5; }
#transcript header { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.icon { background: none; border: 0; cursor: pointer; font-size: 18px; }
#lines { flex: 1; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 10px; }
.line { padding: 8px 12px; border-radius: 12px; background: var(--panel2); max-width: 90%; }
.line small { display: block; color: var(--muted); font-size: 11px; }
.line.user { align-self: flex-end; background: #13304a; }
#chat { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
#chat input { flex: 1; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
#chat button { background: var(--accent); color: #04130a; border: 0; border-radius: 10px; padding: 0 14px; font-weight: 700; cursor: pointer; }
#lobby, #ended { position: fixed; inset: 0; display: grid; place-items: center; background: #07080aee; z-index: 10; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 28px; width: min(420px, 100%); text-align: center; }
.card img { width: 140px; height: 140px; object-fit: cover; object-position: top; border-radius: 50%; border: 3px solid var(--accent); }
.card h1 { font-size: 22px; margin: 12px 0 4px; }
.check { display: flex; gap: 8px; align-items: center; justify-content: center; margin: 14px 0 18px; color: var(--muted); }
.toast { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); background: #3b1d1d; color: #fecaca; padding: 8px 16px; border-radius: 10px; z-index: 20; }
@media (max-width: 640px) {
  #replica { height: 100dvh; width: 100vw; aspect-ratio: auto; border-radius: 0; }
  #self { width: 96px; top: 60px; }
}

/* ---------------- dashboard ---------------- */
.wrap { max-width: 1100px; margin: 0 auto; padding: 24px 16px 60px; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.top h1 { margin: 0; font-size: 24px; }
.top .tag { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 99px; padding: 2px 10px; }
section.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px; margin-bottom: 18px; }
section.panel h2 { margin: 0 0 12px; font-size: 17px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.rep { background: var(--panel2); border: 2px solid transparent; border-radius: 14px; overflow: hidden; cursor: pointer; text-align: start; padding: 0; }
.rep.sel { border-color: var(--accent); }
.rep .thumb { aspect-ratio: 3/4; background: #000; position: relative; }
.rep .thumb img, .rep .thumb video { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
.rep .meta { padding: 8px 10px; font-size: 13px; }
.rep .meta small { color: var(--muted); display: block; }
.badge { position: absolute; top: 8px; inset-inline-start: 8px; font-size: 11px; padding: 2px 8px; border-radius: 99px; background: #000b; }
.badge.training { color: var(--warn); }
.badge.error { color: var(--danger); }
.acts { display: flex; gap: 6px; margin-top: 6px; }
.ghost.sm { padding: 2px 8px; font-size: 12px; border-radius: 8px; display: inline-block; }
#btnReplica:disabled { opacity: .5; cursor: default; }
.form { display: grid; gap: 10px; }
.form label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.form input, .form textarea, .form select { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; color: var(--text); }
.form textarea { min-height: 90px; resize: vertical; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.cols { display: grid; grid-template-columns: 1.3fr 1fr; gap: 18px; }
@media (max-width: 860px) { .cols { grid-template-columns: 1fr; } }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
td, th { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: start; }
code, pre { font-family: ui-monospace, monospace; font-size: 12px; direction: ltr; text-align: left; }
pre { background: #0a0c0f; border: 1px solid var(--line); border-radius: 10px; padding: 12px; overflow-x: auto; }
.start { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

/* ---------------- login ---------------- */
.login { display: grid; gap: 12px; }
.login input[type=password] { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 11px 14px; text-align: center; }
.login .err { margin: 0; }
