:root {
  color-scheme: dark;
  --bg: #0b0f14;
  --panel: #10151c;
  --surface-2: #151b23;
  --line: #29313b;
  --muted: #8995a4;
  --text: #e8edf4;
  --reference: #39d353;
  --recreation: #ff4038;
  --accent: #6ea8ff;
  --lime: #b9ff66;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; min-height: 100%; }
html { min-width: 320px; background: var(--bg); }
body {
  margin: 0;
  min-width: 320px;
  overflow: hidden;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, select { font: inherit; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.shell { width: 100%; height: 100vh; display: grid; grid-template-rows: auto auto minmax(0, 1fr); }

.topbar {
  position: relative;
  z-index: 30;
  grid-row: 1;
  min-height: 64px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  border-bottom: 1px solid #252d36;
  background: #0d1218;
}
.topbar-left { min-width: 0; }
.brand { flex: 0 0 auto; color: inherit; text-decoration: none; }
.brand-copy > span { display: flex; align-items: baseline; gap: 9px; }
.brand strong { font-size: 22px; line-height: 1.05; letter-spacing: 0; }
.brand small { color: var(--muted); font-size: 12px; }
.brand em { display: block; margin-top: 6px; color: var(--recreation); font-size: 13px; font-style: normal; font-weight: 750; }

.controls {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 18px;
}
.controls .control-field { display: flex; align-items: center; gap: 10px; }
.controls .control-field > span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  white-space: nowrap;
}
.controls select, .custom-select-trigger {
  width: 180px;
  height: 34px;
  padding: 0 30px 0 10px;
  border: 1px solid #303c49;
  border-radius: 7px;
  outline: 0;
  color: #dbe2eb;
  background: #131a22;
  cursor: pointer;
  font-size: 12px;
}
.controls select:focus, .custom-select-trigger:focus-visible { border-color: #5d94e8; box-shadow: 0 0 0 2px rgb(110 168 255 / 15%); }
.controls select:disabled, .custom-select-trigger:disabled { color: #7d8796; cursor: default; opacity: .75; }
.language-control select { width: 112px; }
.custom-select { position: relative; width: 180px; }
.custom-select-source { display: none; }
.custom-select-trigger {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  text-align: left;
}
.custom-select-trigger > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.custom-select-trigger > i {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-right: 1.5px solid #a7b1bf;
  border-bottom: 1.5px solid #a7b1bf;
  transform: translateY(-2px) rotate(45deg);
  transition: transform .16s ease;
}
.custom-select.open .custom-select-trigger > i { transform: translateY(2px) rotate(225deg); }
.custom-select-menu {
  position: absolute;
  z-index: 100;
  top: calc(100% + 6px);
  right: 0;
  width: 100%;
  max-height: min(320px, calc(100vh - 92px));
  padding: 5px;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid #354251;
  border-radius: 8px;
  background: #151c24;
  box-shadow: 0 18px 48px rgba(0, 0, 0, .48);
}
.custom-select-option {
  position: relative;
  width: 100%;
  min-height: 31px;
  padding: 7px 25px 7px 9px;
  border: 0;
  border-radius: 5px;
  outline: 0;
  color: #dbe2eb;
  background: transparent;
  cursor: pointer;
  text-align: left;
  font-size: 12px;
}
.custom-select-option:hover, .custom-select-option:focus-visible { background: #202b37; }
.custom-select-option[aria-selected="true"] { color: #f2f6fb; background: #26384d; }
.custom-select-option[aria-selected="true"]::after { content: "✓"; position: absolute; top: 7px; right: 9px; color: var(--lime); font-weight: 850; }
.system-status { display: flex; align-items: center; gap: 7px; color: #929baa; font-size: 10px; white-space: nowrap; }
.system-status i { width: 7px; height: 7px; border-radius: 50%; background: #e8ad56; box-shadow: 0 0 0 4px rgba(232, 173, 86, .09); }
.system-status.ready i { background: var(--reference); box-shadow: 0 0 0 4px rgba(95, 224, 111, .09); }
.primary {
  min-width: 132px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 0 13px;
  border: 0;
  border-radius: 7px;
  color: #0b0d10;
  background: var(--lime);
  font-size: 11px;
  font-weight: 850;
  cursor: pointer;
}
.primary:hover { filter: brightness(1.05); }
.primary:disabled { cursor: wait; filter: grayscale(.55); opacity: .62; }
.primary b { font-size: 17px; }

.service-notice {
  grid-row: 2;
  margin: 10px 24px 0;
  padding: 11px 14px;
  display: flex;
  align-items: center;
  gap: 11px;
  border: 1px solid #34404e;
  border-radius: 9px;
  background: rgba(18, 23, 30, .94);
}
.service-notice > i { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; background: #e8ad56; box-shadow: 0 0 0 4px rgba(232, 173, 86, .1); }
.service-notice strong, .service-notice span { display: block; }
.service-notice strong { color: #e8edf2; font-size: 11px; }
.service-notice span { margin-top: 3px; color: #8f98a5; font-size: 10px; line-height: 1.4; }
.service-notice.initializing > i { background: var(--accent); box-shadow: 0 0 0 4px rgba(121, 168, 255, .1); }
.service-notice.warning { border-color: rgba(232, 173, 86, .38); }

.stage {
  grid-row: 3;
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(18px, 3vw, 56px);
  align-items: stretch;
  padding: 20px 24px 16px;
  overflow: hidden;
  background: radial-gradient(circle at 50% 10%, #131a23 0, var(--bg) 46%);
}
.phone-panel { min-width: 0; min-height: 0; display: grid; grid-template-rows: 32px minmax(0, 1fr); overflow: hidden; }
.panel-title {
  min-width: 0;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 0 4px 9px;
}
.panel-heading { min-width: 0; display: flex; align-items: center; gap: 10px; }
.pane-label { overflow: hidden; color: var(--text); font-size: 15px; text-overflow: ellipsis; white-space: nowrap; }
.panel-actions { min-width: 0; display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
.stream-dot { width: 12px; height: 12px; flex: 0 0 12px; border-radius: 50%; box-shadow: 0 0 0 4px rgba(255,255,255,.04); }
.stream-dot.waiting { background: #697382; }
.stream-dot.connecting { background: #e8ad56; box-shadow: 0 0 0 4px rgba(232,173,86,.09); }
.stream-dot.connected { background: var(--reference); box-shadow: 0 0 0 4px rgba(95,224,111,.09); }
.stream-dot.disconnected, .stream-dot.error { background: var(--recreation); box-shadow: 0 0 0 4px rgba(255,73,73,.09); }
.variant-control { min-width: 0; display: flex; align-items: center; gap: 8px; }
.variant-control > span { color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; white-space: nowrap; }
.variant-control select {
  width: min(220px, 22vw);
  height: 30px;
  padding: 0 30px 0 10px;
  border: 1px solid #303c49;
  border-radius: 7px;
  outline: 0;
  color: #dbe2eb;
  background: #101720;
  cursor: pointer;
  font-size: 12px;
}
.variant-control select:focus { border-color: #5d94e8; box-shadow: 0 0 0 2px rgb(110 168 255 / 15%); }
.variant-control select:disabled { color: #7d8796; opacity: .72; }
.phone-status { flex: 0 0 auto; color: #828c9b; font-size: 9px; }
.phone-status.online { color: var(--reference); }

.phone-shell {
  position: relative;
  width: min(100%, calc((100vh - 126px) * .4787));
  min-width: 250px;
  aspect-ratio: 9 / 18.8;
  margin: 0 auto;
  padding: 8px;
  border: 1px solid #303846;
  border-radius: 34px;
  background: linear-gradient(145deg, #252b34, #11151a 23%, #050607 82%);
  box-shadow: 0 16px 44px rgb(0 0 0 / 34%), inset 0 0 0 1px rgb(255 255 255 / 4%);
}
.phone-shell::after { content: ""; position: absolute; inset: 5px; pointer-events: none; border: 1px solid rgba(255,255,255,.06); border-radius: 29px; }
.phone-shell iframe { width: 100%; height: 100%; border: 0; border-radius: 26px; background: #080a0d; }
.phone-shell.switch-locked iframe { pointer-events: none; }
.speaker { position: absolute; z-index: 2; top: 14px; left: 50%; width: 58px; height: 17px; transform: translateX(-50%); border-radius: 20px; background: #050607; box-shadow: inset 0 0 0 1px rgba(255,255,255,.04); }

.phone-switch-overlay {
  position: absolute;
  z-index: 5;
  inset: 8px;
  display: grid;
  place-content: center;
  justify-items: center;
  padding: 28px;
  overflow: hidden;
  border-radius: 26px;
  text-align: center;
  background: rgba(7, 10, 14, .86);
  backdrop-filter: blur(12px) saturate(.75);
  cursor: wait;
}
.phone-switch-overlay::before { content: ""; position: absolute; inset: 0; background: radial-gradient(circle at 50% 42%, rgba(185,255,102,.11), transparent 38%); pointer-events: none; }
.switch-spinner { position: relative; width: 38px; height: 38px; margin-bottom: 17px; border: 3px solid rgba(185,255,102,.18); border-top-color: var(--lime); border-radius: 50%; animation: switch-spin .8s linear infinite; }
.switch-overlay-title { position: relative; color: #f3f6f8; font-size: 15px; }
.switch-overlay-message { position: relative; max-width: 250px; margin: 8px 0 0; color: #929ca9; font-size: 11px; line-height: 1.6; }
.switch-retry { position: relative; min-width: 112px; margin-top: 19px; padding: 9px 16px; border: 1px solid rgba(185,255,102,.45); border-radius: 999px; color: #10140c; background: var(--lime); font: inherit; font-size: 11px; font-weight: 850; cursor: pointer; }
.phone-switch-overlay.failed { cursor: default; background: rgba(12, 9, 10, .9); }
.phone-switch-overlay.failed::before { background: radial-gradient(circle at 50% 42%, rgba(232,173,86,.12), transparent 38%); }
.phone-switch-overlay.failed .switch-spinner { border: 0; animation: none; }
.phone-switch-overlay.failed .switch-spinner::before { content: "!"; display: grid; width: 38px; height: 38px; place-items: center; border: 1px solid rgba(232,173,86,.5); border-radius: 50%; color: #e8ad56; font-size: 18px; font-weight: 900; }
@keyframes switch-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .switch-spinner { animation-duration: 1.8s; } }

.toast { position: fixed; z-index: 20; right: 20px; bottom: 20px; max-width: 380px; padding: 12px 15px; border: 1px solid #3a414d; border-radius: 9px; color: #e7ebef; background: #171b21; box-shadow: 0 20px 60px rgba(0,0,0,.45); font-size: 11px; line-height: 1.5; opacity: 0; transform: translateY(14px); pointer-events: none; transition: .2s ease; }
.toast.visible { opacity: 1; transform: none; }
@media (max-width: 1200px) {
  body { overflow: auto; }
  .shell { height: auto; min-height: 100vh; display: block; }
  .topbar { grid-template-columns: 1fr; align-items: flex-start; gap: 10px; }
  .controls { width: 100%; justify-content: flex-start; flex-wrap: wrap; }
  .stage { min-height: calc(100vh - 120px); overflow: visible; }
  .phone-shell { width: min(100%, 360px); }
}

@media (max-width: 760px) {
  .topbar { padding: 12px 16px; }
  .brand-copy > span { align-items: flex-start; flex-direction: column; gap: 1px; }
  .controls .control-field { width: calc(50% - 7px); }
  .controls .control-field select, .controls .custom-select { width: 100%; }
  .system-status { display: none; }
  .stage { grid-template-columns: 1fr; padding: 14px 16px 24px; }
  .phone-panel { padding: 0 0 36px; }
  .phone-panel + .phone-panel { padding-top: 18px; border-top: 1px solid var(--line); border-left: 0; }
  .phone-shell { width: min(100%, 360px); min-width: 0; }
  .service-notice { margin-right: 16px; margin-left: 16px; }
}
