:root {
  --bg: #050810;
  --panel: rgba(255, 255, 255, 0.045);
  --panel-strong: rgba(255, 255, 255, 0.085);
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);
  --text: #f4f7ff;
  --muted: #8b97b3;
  --accent: #6d9bff;
  --danger: #ff5f6d;
  --ok: #4fd1c5;
  --radius: 20px;
  --panel-accent: #6d9bff;
  --panel-glow: rgba(109, 155, 255, 0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.bg-mesh {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(ellipse 80% 50% at 20% -10%, rgba(59, 91, 219, 0.18), transparent 55%),
    radial-gradient(ellipse 60% 40% at 90% 10%, rgba(112, 72, 232, 0.14), transparent 50%),
    radial-gradient(ellipse 50% 30% at 50% 100%, rgba(12, 166, 120, 0.08), transparent 45%);
}

.bg-orbs { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.orb { position: absolute; border-radius: 50%; filter: blur(100px); opacity: .45; }
.orb-1 { width: 540px; height: 540px; background: #3b5bdb44; top: -180px; left: -140px; animation: drift1 24s ease-in-out infinite alternate; }
.orb-2 { width: 480px; height: 480px; background: #7048e844; bottom: -160px; right: -120px; animation: drift2 28s ease-in-out infinite alternate; }
.orb-3 { width: 360px; height: 360px; background: #0ca67833; top: 42%; left: 42%; animation: drift3 32s ease-in-out infinite alternate; }
@keyframes drift1 { to { transform: translate(80px, 50px) scale(1.12); } }
@keyframes drift2 { to { transform: translate(-70px, -40px) scale(1.08); } }
@keyframes drift3 { to { transform: translate(-50px, 60px) scale(.92); } }

#app {
  position: relative; z-index: 1;
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  display: flex; flex-direction: column;
  padding: 18px 22px 8px;
  padding-bottom: max(8px, env(safe-area-inset-bottom, 0px));
  gap: 12px;
  max-width: 1400px; margin: 0 auto; width: 100%;
  overflow: hidden;
}

.header {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap;
  padding: 4px 2px;
}
.brand { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.logo {
  height: 36px; width: auto; display: block; align-self: center;
  filter: drop-shadow(0 4px 16px rgba(109, 155, 255, .4));
}
.slogan {
  height: 22px; width: auto; display: block;
  opacity: .88;
  filter: drop-shadow(0 0 12px rgba(170, 85, 200, .4));
  transform: rotate(-2.5deg);
}

.langrow {
  display: flex; align-items: stretch; gap: 10px;
  flex-wrap: nowrap; min-width: 0; flex: 1 1 auto; justify-content: flex-end;
}

.lang-pick {
  --pick-accent: var(--accent);
  position: relative; flex: 1 1 160px; max-width: 240px; min-width: 0;
  display: flex; align-items: center;
  background: linear-gradient(135deg, rgba(255,255,255,.07), rgba(255,255,255,.03));
  border: 1px solid color-mix(in srgb, var(--pick-accent) 35%, transparent);
  border-radius: 14px;
  box-shadow: 0 4px 24px rgba(0,0,0,.25), inset 0 1px 0 rgba(255,255,255,.06);
  transition: border-color .25s, box-shadow .25s;
}
.lang-pick::before {
  content: ''; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--pick-accent);
  box-shadow: 0 0 12px var(--pick-accent);
}
.lang-pick:hover {
  border-color: color-mix(in srgb, var(--pick-accent) 55%, transparent);
  box-shadow: 0 6px 28px rgba(0,0,0,.3), 0 0 20px color-mix(in srgb, var(--pick-accent) 20%, transparent);
}
.lang-pick-flag {
  flex: 0 0 auto; font-size: 22px; line-height: 1;
  padding: 0 4px 0 14px; filter: drop-shadow(0 2px 4px rgba(0,0,0,.3));
  pointer-events: none; user-select: none;
}
.lang-pick select {
  appearance: none; -webkit-appearance: none;
  flex: 1; min-width: 0;
  background: transparent url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b97b3' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 12px center;
  color: var(--text); border: none;
  padding: 11px 32px 11px 6px; font-size: 14px; font-weight: 600;
  font-family: inherit; outline: none; cursor: pointer;
}
.lang-pick select option {
  background-color: #12182a;
  color: #eef2fb;
}

.swap-btn {
  width: 46px; align-self: center; flex: 0 0 46px;
  height: 46px; border-radius: 14px;
  border: 1px solid var(--line-strong);
  background: linear-gradient(145deg, rgba(255,255,255,.1), rgba(255,255,255,.04));
  color: var(--text); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: transform .25s, box-shadow .25s, border-color .25s, opacity .2s;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
.swap-btn svg { width: 20px; height: 20px; opacity: .9; }
.swap-btn:hover {
  transform: rotate(180deg);
  border-color: rgba(109,155,255,.5);
  box-shadow: 0 0 24px rgba(109,155,255,.25);
}
.swap-btn:active { transform: rotate(180deg) scale(.94); }
.swap-btn.disabled { opacity: .35; cursor: not-allowed; }
.swap-btn.disabled:hover { transform: none; box-shadow: 0 4px 16px rgba(0,0,0,.2); border-color: var(--line-strong); }

.main {
  flex: 1 1 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  min-height: 0;
  overflow: hidden;
}
@media (max-width: 820px) {
  .main {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  }
}

.panel {
  position: relative;
  --panel-accent: #6d9bff;
  --panel-glow: rgba(109, 155, 255, 0.35);
  background: linear-gradient(160deg, rgba(255,255,255,.07) 0%, rgba(255,255,255,.025) 100%);
  border: 1px solid color-mix(in srgb, var(--panel-accent) 22%, var(--line));
  border-radius: var(--radius);
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
  box-shadow:
    0 24px 60px rgba(0, 0, 0, .45),
    0 0 0 1px rgba(255,255,255,.04) inset,
    0 0 40px color-mix(in srgb, var(--panel-glow) 50%, transparent);
  transition: border-color .35s, box-shadow .35s;
}
.panel-accent {
  position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--panel-accent);
  box-shadow: 0 0 20px var(--panel-glow), 0 0 40px color-mix(in srgb, var(--panel-accent) 30%, transparent);
  border-radius: var(--radius) 0 0 var(--radius);
  transition: background .35s, box-shadow .35s;
}
.panel::after {
  content: ''; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: linear-gradient(135deg, color-mix(in srgb, var(--panel-accent) 8%, transparent), transparent 55%);
  opacity: .9;
}

.panel-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
  position: relative; z-index: 1;
  background: linear-gradient(180deg, rgba(255,255,255,.04), transparent);
}
.panel-title-wrap {
  display: flex; align-items: center; gap: 12px; min-width: 0;
}
.panel-flag {
  font-size: 28px; line-height: 1;
  filter: drop-shadow(0 3px 8px rgba(0,0,0,.35));
  flex-shrink: 0;
}
.panel-title-block { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.panel-label {
  font-size: 10px; font-weight: 700; letter-spacing: 1.2px;
  text-transform: uppercase; color: var(--muted); opacity: .85;
}
.panel-title {
  font-weight: 700; font-size: 15px; letter-spacing: -.2px;
  color: var(--text);
  text-shadow: 0 0 20px color-mix(in srgb, var(--panel-accent) 40%, transparent);
}
.panel-actions { display: flex; gap: 8px; position: relative; z-index: 1; }

textarea, .dst-text {
  flex: 1; width: 100%; padding: 20px 20px 20px 22px;
  font-size: clamp(18px, 2.4vw, 24px); line-height: 1.55;
  font-family: inherit; font-weight: 500;
  background: transparent; color: var(--text); border: none; outline: none; resize: none;
  position: relative; z-index: 1;
}
textarea::placeholder { color: #5a6680; font-weight: 400; }
.dst-text { overflow-y: auto; white-space: pre-wrap; word-break: break-word; }
.dst-text .wait { color: #5a6680; font-size: 15px; font-weight: 400; }

.panel-bottom {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 16px; border-top: 1px solid var(--line);
  position: relative; z-index: 1;
  background: rgba(0,0,0,.12);
}
.hint { color: var(--muted); font-size: 12px; font-weight: 500; }

.auto {
  display: flex; align-items: center; gap: 8px;
  color: var(--muted); font-size: 13px; font-weight: 500;
  user-select: none; cursor: pointer;
}
.auto input { accent-color: var(--panel-accent, var(--accent)); width: 16px; height: 16px; cursor: pointer; }

.icon-btn, .mic {
  background: rgba(255,255,255,.06); color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: 12px; width: 38px; height: 38px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: border-color .2s, background .2s, transform .12s, box-shadow .2s;
  backdrop-filter: blur(8px);
}
.icon-btn svg, .mic svg { width: 17px; height: 17px; }
.icon-btn:hover, .mic:hover {
  border-color: color-mix(in srgb, var(--panel-accent, var(--accent)) 50%, transparent);
  background: color-mix(in srgb, var(--panel-accent, var(--accent)) 12%, transparent);
  box-shadow: 0 0 16px color-mix(in srgb, var(--panel-accent, var(--accent)) 20%, transparent);
}
.icon-btn:active, .mic:active { transform: scale(.92); }
.mic { width: 42px; height: 42px; }
.mic.on {
  background: linear-gradient(135deg, #ff5f6d, #ff8a5c);
  border-color: transparent; color: #fff;
  animation: micPulse 1.4s ease-in-out infinite;
}
@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 95, 109, .55), 0 4px 16px rgba(255,95,109,.3); }
  50% { box-shadow: 0 0 0 12px rgba(255, 95, 109, 0), 0 4px 20px rgba(255,95,109,.4); }
}

.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.idle { background: #4a5568; }
.dot.busy { background: #ffb84f; animation: micPulse 1s infinite; }
.dot.ok { background: var(--ok); box-shadow: 0 0 12px rgba(79, 209, 197, .65); }
.dot.err { background: var(--danger); box-shadow: 0 0 10px rgba(255, 95, 109, .5); }

.statusbar {
  flex-shrink: 0;
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px;
  color: var(--muted); font-size: 12px; font-weight: 500;
  padding: 2px 6px;
}
.statusbar #micBadge,
.statusbar #engineBadge {
  min-width: 0;
  line-height: 1.35;
}
.mic-badge-icon { width: 13px; height: 13px; vertical-align: -2px; margin-right: 4px; }

.install-btn {
  flex-shrink: 0;
  align-self: center;
  background: linear-gradient(135deg, #4f8cff, #6d5cff);
  color: #fff; border: none; border-radius: 999px;
  padding: 11px 24px; font-size: 14px; font-weight: 700; cursor: pointer;
  font-family: inherit;
  box-shadow: 0 8px 28px rgba(79, 140, 255, .35);
  transition: transform .15s, box-shadow .15s;
}
.install-btn:hover { transform: translateY(-2px); box-shadow: 0 12px 32px rgba(79, 140, 255, .45); }

.footer-credit {
  flex-shrink: 0;
  text-align: center; color: #5c677f; font-size: 11.5px; letter-spacing: .25px;
  line-height: 1.5; padding: 4px 4px max(6px, env(safe-area-inset-bottom, 0px));
  user-select: none;
}
.footer-credit strong { color: #8fa8d8; font-weight: 600; }
.footer-credit .sep { margin: 0 8px; color: #3d4763; }

#diagPanel {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  background: rgba(8, 12, 22, .96);
  border-top: 1px solid var(--line-strong);
  backdrop-filter: blur(16px);
  max-height: 50vh;
}
.diag-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border-bottom: 1px solid var(--line);
  font-weight: 700; font-size: 13px; color: var(--muted);
}
.diag-head button {
  background: rgba(255,255,255,.06); border: 1px solid var(--line-strong);
  color: var(--text); border-radius: 8px; width: 28px; height: 28px; cursor: pointer;
}
#diagLog {
  margin: 0; padding: 12px 14px; max-height: 40vh; overflow-y: auto;
  font-family: ui-monospace, Consolas, monospace; font-size: 11px;
  color: var(--text); line-height: 1.55; white-space: pre-wrap;
}

@media (max-width: 820px) {
  .statusbar {
    flex-wrap: wrap;
    font-size: 11px;
  }
  .statusbar #engineBadge {
    flex: 1 1 100%;
    text-align: right;
    opacity: .92;
  }
  textarea, .dst-text {
    font-size: clamp(16px, 4.2vw, 20px);
    padding: 14px 14px 14px 16px;
  }
  .panel-bottom .auto {
    font-size: 12px;
  }
}

@media (max-width: 560px) {
  #app { padding: 10px 10px max(6px, env(safe-area-inset-bottom, 0px)); gap: 8px; }
  .logo { height: 30px; }
  .slogan { height: 15px; }
  .langrow { gap: 8px; }
  .lang-pick { max-width: none; }
  .lang-pick-flag { font-size: 20px; padding-left: 12px; }
  .lang-pick select { font-size: 13px; padding: 10px 28px 10px 4px; }
  .swap-btn { width: 42px; height: 42px; flex: 0 0 42px; }
  .panel-flag { font-size: 24px; }
  .panel-top { padding: 10px 12px; }
  .footer-credit {
    font-size: 10px;
    letter-spacing: 0;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 2px 6px;
  }
  .footer-credit .sep { margin: 0; }
}
