:root {
  color-scheme: dark;
  --bg: #07110f;
  --panel: rgba(19, 38, 33, 0.7);
  --line: rgba(174, 255, 220, 0.14);
  --text: #f1fff9;
  --muted: #94aaa2;
  --mint: #8fffd0;
  --green: #38e5a0;
  --danger: #ff8e83;
  --app-viewport-height: var(--tg-viewport-stable-height, 100dvh);
  --app-safe-top: max(
    env(safe-area-inset-top, 0px),
    var(--tg-safe-area-inset-top, 0px),
    var(--tg-content-safe-area-inset-top, 0px)
  );
  --app-safe-bottom: max(
    env(safe-area-inset-bottom, 0px),
    var(--tg-safe-area-inset-bottom, 0px),
    var(--tg-content-safe-area-inset-bottom, 0px)
  );
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { min-height: 100%; margin: 0; }

body {
  color: var(--text);
  background:
    radial-gradient(circle at 50% 24%, rgba(51, 221, 160, 0.16), transparent 35%),
    linear-gradient(165deg, #0a1714 0%, var(--bg) 58%, #040908 100%);
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.16;
  background-image: linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 40px 40px;
  mask-image: linear-gradient(to bottom, black, transparent 72%);
}

button { font: inherit; }

.shell {
  position: relative;
  min-height: 100vh;
  min-height: var(--app-viewport-height);
  max-width: 760px;
  margin: 0 auto;
  padding: max(20px, var(--app-safe-top)) 22px max(24px, var(--app-safe-bottom));
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.topbar { display: flex; justify-content: space-between; align-items: center; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 36px; height: 36px; border: 1px solid rgba(143, 255, 208, 0.48); border-radius: 11px;
  background: linear-gradient(145deg, rgba(143,255,208,.28), rgba(56,229,160,.04));
  box-shadow: inset 0 0 18px rgba(143,255,208,.18);
  position: relative;
}
.brand-mark::after { content: ""; position: absolute; inset: 9px; border: 2px solid var(--mint); border-left-color: transparent; border-radius: 50%; transform: rotate(-32deg); }
.brand strong { display: block; font-size: 15px; letter-spacing: .02em; }
.brand span { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }

.icon-button {
  width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--line);
  display: inline-grid; place-items: center; padding: 0;
  background: var(--panel); color: var(--mint); cursor: pointer;
}
.icon-button:disabled { opacity: .35; cursor: default; }
.icon-button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.stage { align-self: center; text-align: center; padding: 42px 0 20px; }
.orb { width: 168px; height: 168px; position: relative; margin: 0 auto 40px; display: grid; place-items: center; }
.orb-core {
  width: 74px; height: 74px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #e9fff6, var(--mint) 18%, #20b47d 52%, #0b4232 80%);
  box-shadow: 0 0 24px rgba(143,255,208,.58), 0 0 80px rgba(56,229,160,.24);
  z-index: 3;
}
.wave { position: absolute; border: 1px solid rgba(143,255,208,.23); border-radius: 50%; inset: 26px; }
.wave-b { inset: 10px; opacity: .65; }
.wave-c { inset: -10px; opacity: .32; }
.orb.connected .wave { animation: breathe 2.5s ease-in-out infinite; }
.orb.connected .wave-b { animation-delay: -.8s; }
.orb.connected .wave-c { animation-delay: -1.6s; }
.orb.speaking .orb-core { animation: pulse .75s ease-in-out infinite alternate; }
.orb.thinking .orb-core { animation: think 1.4s ease-in-out infinite; }
.orb.thinking .wave { animation: breathe 1.2s ease-in-out infinite; }
.orb.thinking .wave-b { animation-delay: -.4s; }
.orb.thinking .wave-c { animation-delay: -.8s; }
.orb.connecting .orb-core { animation: connect 1.1s ease-in-out infinite; }
.orb.connecting .wave { animation: breathe 1.1s ease-in-out infinite; }
.orb.connecting .wave-b { animation-delay: -.35s; }
.orb.connecting .wave-c { animation-delay: -.7s; }

@keyframes breathe { 50% { transform: scale(1.12); opacity: .08; } }
@keyframes pulse { to { transform: scale(1.16); filter: brightness(1.18); } }
@keyframes think { 50% { transform: scale(.9); filter: hue-rotate(18deg) brightness(1.15); } }
@keyframes connect { 50% { transform: scale(.88); filter: brightness(1.25); } }

.eyebrow { color: var(--green); font-weight: 700; font-size: 11px; letter-spacing: .22em; }
h1 { font-size: clamp(34px, 8vw, 58px); line-height: .98; letter-spacing: -.045em; margin: 14px auto 18px; max-width: 650px; }
.status-text { max-width: 500px; margin: 0 auto; color: var(--muted); line-height: 1.55; font-size: 15px; }

.transcript {
  border: 1px solid var(--line); background: var(--panel); backdrop-filter: blur(16px);
  border-radius: 18px; padding: 15px 17px; margin: 12px 0; max-height: 28dvh;
  overflow-y: auto;
}
.transcript-label { color: var(--green); font-size: 10px; font-weight: 800; letter-spacing: .16em; }
.transcript p { margin: 7px 0 0; line-height: 1.45; white-space: pre-wrap; }

.controls { text-align: center; }
html.autostart-pending .controls { visibility: hidden; }
.call-controls { display: flex; justify-content: center; align-items: center; gap: 14px; }
.call-button {
  width: min(100%, 430px); min-height: 64px; border: 0; border-radius: 20px;
  display: inline-flex; justify-content: center; align-items: center; gap: 12px;
  color: #04120d; font-weight: 800; font-size: 17px; cursor: pointer;
  background: linear-gradient(120deg, var(--mint), var(--green));
  box-shadow: 0 16px 44px rgba(31,206,139,.22);
  transition: transform .16s ease, filter .16s ease;
}
.call-button:active { transform: scale(.98); }
.call-button.hangup {
  width: 64px; min-height: 64px; border-radius: 50%; padding: 0; color: #fff;
  background: #e84c4c; border: 0; box-shadow: 0 12px 32px rgba(232, 76, 76, .28);
}
.call-button.hangup span:last-child { display: none; }
.call-button.hangup .call-icon { font-size: 34px; line-height: 1; font-weight: 300; }
.call-button.hangup + .privacy { visibility: hidden; }
.call-button:disabled { opacity: .55; cursor: wait; }
.call-icon { font-size: 24px; }
.mute-button { width: 56px; height: 56px; color: var(--text); background: rgba(255,255,255,.075); }
.mute-button.muted { color: #fff; background: rgba(232, 76, 76, .8); border-color: transparent; }
.mute-slash { display: none; }

body.in-call {
  height: 100vh;
  height: var(--app-viewport-height);
  overflow: hidden;
}
body.in-call .shell {
  height: 100vh;
  height: var(--app-viewport-height);
  min-height: 0;
  overflow: hidden;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  row-gap: 10px;
}
body.in-call .stage {
  align-self: start;
  padding: 16px 0 0;
}
body.in-call .orb {
  width: 112px;
  height: 112px;
  margin-bottom: 14px;
}
body.in-call .orb-core { width: 56px; height: 56px; }
body.in-call .eyebrow { margin: 0; }
body.in-call h1 {
  margin: 8px auto 0;
  font-size: clamp(28px, 7vw, 40px);
  line-height: 1.04;
}
body.in-call .status-text:empty { display: none; }
body.in-call .transcript {
  min-height: 0;
  height: 100%;
  max-height: none;
  margin: 0;
  padding: 18px 20px;
  font-size: 16px;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}
body.in-call .transcript-label {
  position: sticky;
  top: -18px;
  display: block;
  margin: -18px -20px 0;
  padding: 15px 20px 9px;
  background: linear-gradient(#10241e 72%, transparent);
  z-index: 1;
}
body.in-call .transcript p {
  margin-top: 9px;
  line-height: 1.55;
}
body.in-call .controls { padding-top: 2px; }

.approval-dialog { border: 0; padding: 0; background: transparent; color: var(--text); width: min(92vw, 520px); }
.approval-dialog::backdrop { background: rgba(1, 6, 5, .76); backdrop-filter: blur(9px); }
.approval-card { background: #0d1c18; border: 1px solid rgba(143,255,208,.22); border-radius: 26px; padding: 25px; box-shadow: 0 30px 100px #000; }
.approval-kicker { color: #ffd38f; font-size: 10px; font-weight: 800; letter-spacing: .13em; }
.approval-card h2 { font-size: 24px; margin: 10px 0; }
.approval-card > p { color: #c9d8d2; line-height: 1.5; white-space: pre-line; }
.approval-meta { display: grid; gap: 1px; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; margin: 18px 0; }
.approval-meta div { background: rgba(255,255,255,.025); padding: 11px 13px; }
.approval-meta dt { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .1em; }
.approval-meta dd { margin: 4px 0 0; font-size: 13px; line-height: 1.4; }
.hold-button { position: relative; overflow: hidden; width: 100%; height: 58px; border: 0; border-radius: 16px; background: #21483a; color: white; font-weight: 800; cursor: pointer; }
.hold-progress { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, #2bc58d, #74efbd); }
.hold-button.holding .hold-progress { width: 100%; transition: width 1.6s linear; }
.hold-label { position: relative; z-index: 1; }
.deny-button { width: 100%; border: 0; background: transparent; color: var(--muted); padding: 16px 0 0; cursor: pointer; }

@media (max-height: 690px) {
  .orb { width: 125px; height: 125px; margin-bottom: 20px; }
  .orb-core { width: 58px; height: 58px; }
  .stage { padding-top: 20px; }
  h1 { font-size: 34px; }
  body.in-call .shell { grid-template-rows: auto auto minmax(0, 1fr) auto; }
  body.in-call .orb { width: 92px; height: 92px; margin-bottom: 9px; }
  body.in-call .orb-core { width: 48px; height: 48px; }
  body.in-call .stage { padding-top: 8px; }
  body.in-call h1 { font-size: 27px; margin-top: 5px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

.admin-shell { position: relative; max-width: 1040px; margin: 0 auto; padding: 28px 24px 120px; }
.admin-header { display: flex; align-items: center; justify-content: space-between; }
.admin-back { color: var(--mint); text-decoration: none; font-size: 13px; }
.admin-hero { padding: 74px 0 34px; max-width: 760px; }
.admin-hero h1 { margin: 12px 0 16px; font-size: clamp(40px, 7vw, 68px); }
.admin-hero > p:last-child { color: var(--muted); line-height: 1.6; max-width: 650px; }
.admin-notice { margin-bottom: 22px; padding: 14px 16px; border: 1px solid rgba(56,229,160,.28); border-radius: 14px; background: rgba(56,229,160,.08); color: #cffff0; }
.admin-notice.error { border-color: rgba(255,142,131,.35); background: rgba(255,142,131,.09); color: #ffd0cb; }
.settings-group { margin: 0 0 24px; padding: 22px; border: 1px solid var(--line); border-radius: 22px; background: var(--panel); backdrop-filter: blur(18px); }
.settings-group h2 { margin: 0 0 18px; font-size: 18px; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.setting-field { min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.setting-name { color: var(--mint); font-size: 10px; font-weight: 800; letter-spacing: .09em; overflow-wrap: anywhere; }
.setting-field input[type="text"], .setting-field input[type="number"] { width: 100%; min-height: 44px; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; color: var(--text); background: rgba(2,10,8,.54); font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; }
.setting-field input:focus { outline: 2px solid rgba(56,229,160,.35); border-color: var(--green); }
.setting-field input:disabled { opacity: .48; }
.setting-field small { color: #688079; font-size: 10px; }
.boolean-field { display: grid; grid-template-columns: 1fr auto; align-items: center; padding: 12px; border: 1px solid var(--line); border-radius: 12px; }
.boolean-field input { width: 20px; height: 20px; accent-color: var(--green); }
.boolean-field small { grid-column: 1 / -1; }
.admin-actions { position: sticky; bottom: 16px; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-top: 30px; padding: 14px 16px 14px 20px; border: 1px solid rgba(143,255,208,.2); border-radius: 18px; background: rgba(7,17,15,.92); box-shadow: 0 18px 60px rgba(0,0,0,.45); backdrop-filter: blur(20px); }
.admin-actions span { color: var(--muted); font-size: 12px; }
.save-button { min-height: 46px; border: 0; border-radius: 13px; padding: 0 20px; color: #03110c; background: linear-gradient(120deg, var(--mint), var(--green)); font-weight: 800; cursor: pointer; }
.save-button:disabled { opacity: .5; cursor: wait; }

@media (max-width: 680px) {
  .admin-shell { padding-inline: 16px; }
  .admin-hero { padding-top: 52px; }
  .settings-grid { grid-template-columns: 1fr; }
  .settings-group { padding: 17px; }
  .admin-actions { align-items: stretch; flex-direction: column; }
  .save-button { width: 100%; }
}
