:root {
  --bg: #f6f5fb;
  --surface: rgba(255, 255, 255, .78);
  --surface-solid: #ffffff;
  --surface-2: #f3f1fc;
  --text: #17142e;
  --muted: #6b6886;
  --border: rgba(23, 20, 46, .09);
  --accent: #6d5efc;
  --accent-2: #22c3a6;
  --accent-ink: #ffffff;
  --accent-soft: rgba(109, 94, 252, .1);
  --warm: #ff8a5b;
  --danger: #e5484d;
  --grad: linear-gradient(120deg, #6d5efc 0%, #8b5cf6 45%, #22c3a6 100%);
  --shadow: 0 1px 2px rgba(23, 20, 46, .04), 0 12px 40px -12px rgba(52, 40, 160, .18);
  --shadow-sm: 0 1px 2px rgba(23, 20, 46, .05), 0 4px 14px -6px rgba(52, 40, 160, .15);
  --radius: 22px;
  --radius-sm: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0c1a;
    --surface: rgba(28, 26, 50, .72);
    --surface-solid: #1c1a32;
    --surface-2: #221f3d;
    --text: #eceaff;
    --muted: #9f9cc0;
    --border: rgba(255, 255, 255, .08);
    --accent: #8f84ff;
    --accent-2: #34d8bb;
    --accent-ink: #ffffff;
    --accent-soft: rgba(143, 132, 255, .14);
    --danger: #ff6b70;
    --grad: linear-gradient(120deg, #7c6dff 0%, #9b6cf7 45%, #22c3a6 100%);
    --shadow: 0 1px 0 rgba(255, 255, 255, .04) inset, 0 20px 50px -20px rgba(0, 0, 0, .6);
    --shadow-sm: 0 8px 24px -12px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
#count { white-space: nowrap; }
.spacer { flex: 1; }
[hidden] { display: none !important; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
kbd { font: 600 11px/1 inherit; padding: 3px 6px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-solid); }

/* background */
.bg { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.blob { position: absolute; border-radius: 50%; filter: blur(80px); opacity: .55; animation: float 22s ease-in-out infinite alternate; }
.b1 { width: 520px; height: 520px; background: #c7bfff; top: -180px; left: -140px; }
.b2 { width: 460px; height: 460px; background: #a6f0e1; top: 120px; right: -180px; animation-delay: -7s; }
.b3 { width: 380px; height: 380px; background: #ffd3c2; bottom: -160px; left: 30%; animation-delay: -14s; opacity: .45; }
@media (prefers-color-scheme: dark) {
  .blob { opacity: .22; }
  .b1 { background: #5b4bff; } .b2 { background: #0fa58a; } .b3 { background: #b4527a; }
}
@keyframes float { to { transform: translate(60px, 40px) scale(1.12); } }

/* header + hero */
.top { display: flex; align-items: center; height: 72px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; font-size: 20px; letter-spacing: -.02em; color: var(--text); text-decoration: none; }
.logo { width: 38px; height: 38px; border-radius: 12px; background: var(--grad); display: grid; place-items: center; box-shadow: 0 6px 18px -6px rgba(109, 94, 252, .7); }
.logo svg { width: 26px; height: 26px; stroke: #fff; stroke-width: 3.4; }
.hero { text-align: center; padding: 18px 0 26px; }
.hero h1 { margin: 0; font-size: clamp(30px, 5.4vw, 52px); line-height: 1.08; letter-spacing: -.035em; font-weight: 800; }
.hero p { margin: 12px auto 0; max-width: 520px; color: var(--muted); font-size: clamp(15px, 2vw, 17px); }
.grad { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* app shell */
.app {
  background: var(--surface);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  border: 1px solid var(--border);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 48px;
}

/* tabs */
.tabs {
  --i: 0;
  position: relative; display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--surface-2); border-radius: 16px; padding: 5px; max-width: 420px; margin: 0 auto 18px;
}
.tab-indicator {
  position: absolute; top: 5px; bottom: 5px; left: 5px; width: calc((100% - 10px) / 3);
  background: var(--surface-solid); border-radius: 12px; box-shadow: var(--shadow-sm);
  transform: translateX(calc(var(--i) * 100%)); transition: transform .35s cubic-bezier(.3, 1.3, .5, 1);
}
.tab {
  position: relative; z-index: 1; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 8px; border: 0; background: transparent; color: var(--muted);
  font: inherit; font-weight: 700; font-size: 15px; cursor: pointer; border-radius: 12px; transition: color .2s;
}
.tab svg { width: 18px; height: 18px; }
.tab.active { color: var(--text); }
.tab.active svg { color: var(--accent); }

/* language bar */
.langbar { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: end; }
.lang-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.lbl { font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .08em; padding-left: 4px; }
select {
  -webkit-appearance: none; appearance: none; width: 100%;
  font: inherit; font-weight: 700; font-size: 15px; color: var(--text);
  background: var(--surface-solid) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a87a8' 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 14px center / 16px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 40px 12px 14px; min-height: 48px; cursor: pointer;
  box-shadow: var(--shadow-sm); transition: border-color .2s;
}
select:hover { border-color: var(--accent); }
select:focus-visible, textarea:focus-visible, button:focus-visible, .drop:focus-visible, .btn:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.swap {
  width: 48px; height: 48px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--grad); color: #fff; display: grid; place-items: center;
  box-shadow: 0 8px 20px -8px rgba(109, 94, 252, .8); transition: transform .4s cubic-bezier(.3, 1.4, .5, 1), opacity .2s;
}
.swap:hover:not(:disabled) { transform: rotate(180deg); }
.swap:disabled { opacity: .35; cursor: not-allowed; box-shadow: none; }

/* quick language chips */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 12px 2px 4px; margin-bottom: 14px; scrollbar-width: none; justify-content: flex-end; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--border); background: var(--surface-solid); color: var(--muted);
  font: inherit; font-size: 13px; font-weight: 700; padding: 6px 12px; border-radius: 99px; cursor: pointer; transition: all .2s;
}
.chip:hover { color: var(--text); border-color: var(--accent); }
.chip.on { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

/* cards */
.panel { animation: fade .35s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.card {
  position: relative; background: var(--surface-solid); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); display: flex; flex-direction: column; min-width: 0; transition: box-shadow .25s, border-color .25s;
}
.card.in:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow-sm); }
.card.out { background: linear-gradient(var(--surface-2), var(--surface-2)) padding-box, var(--grad) border-box; border: 1.5px solid transparent; }
.card-head { padding: 14px 18px 0; font-weight: 700; font-size: 13px; color: var(--muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; text-transform: uppercase; letter-spacing: .06em; }
.card-foot { display: flex; align-items: center; gap: 4px; padding: 6px 8px 8px 14px; min-height: 52px; }
textarea {
  border: 0; outline: none; background: transparent; color: var(--text); font: inherit; font-size: 20px; line-height: 1.5; resize: none;
  min-height: 230px; padding: 18px; border-radius: var(--radius) var(--radius) 0 0;
}
textarea::placeholder { color: var(--muted); opacity: .7; }
.output { flex: 1; padding: 18px; font-size: 20px; line-height: 1.5; min-height: 140px; white-space: pre-wrap; word-wrap: break-word; }
#panel-text .output { min-height: 230px; }
.placeholder { color: var(--muted); opacity: .7; }
.output.loading { color: var(--muted); }
.output.loading::after { content: ""; display: inline-block; width: 1.2em; animation: dots 1.2s steps(4) infinite; overflow: hidden; vertical-align: bottom; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }
.pill-detect:empty { display: none; }
.pill-detect {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; text-transform: none; letter-spacing: 0;
  color: var(--accent); background: var(--accent-soft); padding: 4px 10px; border-radius: 99px;
}
.pill-detect::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--accent-2); }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; font: inherit; font-weight: 700; font-size: 15px;
  border-radius: 14px; padding: 12px 20px; min-height: 48px; cursor: pointer; border: 1px solid var(--border);
  background: var(--surface-solid); color: var(--text); white-space: nowrap; transition: transform .15s, box-shadow .2s, opacity .2s, border-color .2s;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); border-color: var(--accent); }
.btn:active:not(:disabled) { transform: translateY(0) scale(.98); }
.btn.primary { background: var(--grad); border: 0; color: #fff; box-shadow: 0 10px 24px -10px rgba(109, 94, 252, .9); padding: 12px 24px; }
.btn.primary svg { transition: transform .2s; }
.btn.primary:hover:not(:disabled) svg { transform: translateX(3px); }
.btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 0; background: transparent; color: var(--muted);
  display: inline-grid; place-items: center; cursor: pointer; transition: background .2s, color .2s;
}
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }
.actions { display: flex; align-items: center; justify-content: flex-end; gap: 14px; margin-top: 16px; }

/* switch */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; font-weight: 600; font-size: 14px; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.track { position: relative; width: 40px; height: 24px; border-radius: 99px; background: var(--border); transition: background .2s; flex: none; }
.track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .25s cubic-bezier(.3, 1.4, .5, 1); }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* voice */
.stage { align-items: center; text-align: center; padding: 28px 20px 18px; gap: 6px; }
.rec-wrap { position: relative; width: 120px; height: 120px; display: grid; place-items: center; margin-bottom: 10px; }
.rec-btn {
  position: relative; z-index: 1; width: 92px; height: 92px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--grad); color: #fff; display: grid; place-items: center;
  box-shadow: 0 16px 36px -12px rgba(109, 94, 252, .9); transition: transform .2s, background .3s;
}
.rec-btn:hover { transform: scale(1.05); }
.rec-btn svg { width: 36px; height: 36px; }
.rec-btn .i-stop { display: none; fill: currentColor; stroke: none; width: 30px; height: 30px; }
.rec-btn.recording { background: var(--danger); box-shadow: 0 16px 36px -12px rgba(229, 72, 77, .9); }
.rec-btn.recording .i-mic { display: none; }
.rec-btn.recording .i-stop { display: block; }
.ring { position: absolute; inset: 14px; border-radius: 50%; border: 2px solid var(--danger); opacity: 0; }
.rec-wrap:has(.recording) .ring { animation: ripple 1.8s ease-out infinite; }
.rec-wrap:has(.recording) .r2 { animation-delay: .9s; }
@keyframes ripple { from { transform: scale(.85); opacity: .7; } to { transform: scale(1.45); opacity: 0; } }
.rec-status { font-weight: 800; font-size: 18px; font-variant-numeric: tabular-nums; }
.or { display: flex; align-items: center; gap: 12px; width: min(320px, 100%); color: var(--muted); font-size: 13px; margin: 14px 0 10px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--border); }
audio { width: 100%; max-width: 560px; margin-top: 14px; }
.row-opts { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; width: 100%; margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--border); text-align: left; }
.results { margin-top: 14px; }

/* image */
.img-stage { padding: 14px; }
.drop {
  width: 100%; border: 2px dashed color-mix(in srgb, var(--accent) 35%, transparent); border-radius: 18px; min-height: 260px;
  display: grid; place-items: center; background: var(--accent-soft); overflow: hidden; cursor: pointer; transition: all .2s;
}
.drop:hover, .drop.over { border-color: var(--accent); transform: scale(1.005); }
.drop img { max-width: 100%; max-height: 440px; display: block; border-radius: 12px; }
.drop-empty { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 28px; color: var(--text); }
.drop-icon { width: 64px; height: 64px; border-radius: 20px; background: var(--grad); display: grid; place-items: center; margin-bottom: 8px; box-shadow: 0 12px 28px -12px rgba(109, 94, 252, .9); }
.drop-icon svg { width: 30px; height: 30px; color: #fff; }
.img-stage .row-opts { margin-top: 12px; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); max-width: calc(100% - 32px);
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 14px; font-size: 14px; font-weight: 600; z-index: 10;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .25); animation: pop .3s cubic-bezier(.3, 1.4, .5, 1);
}
.toast.error { background: var(--danger); color: #fff; }
@keyframes pop { from { opacity: 0; transform: translate(-50%, 10px) scale(.96); } }

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

@media (max-width: 760px) {
  .top { height: 60px; }
  .hero { padding: 6px 0 18px; }
  .app { padding: 12px; border-radius: 22px; }
  .grid2 { grid-template-columns: 1fr; }
  textarea, #panel-text .output { min-height: 150px; font-size: 18px; }
  .output { font-size: 18px; }
  .langbar { gap: 8px; }
  .lbl { font-size: 10px; }
  select { padding: 10px 30px 10px 12px; font-size: 14px; background-position: right 10px center; }
  .swap { width: 42px; height: 42px; }
  .chips { justify-content: flex-start; }
  .actions .hint { display: none; }
  .actions .btn, .row-opts .btn.primary { width: 100%; }
  .row-opts .btn.ghost { flex: 1; }
  .tab span { font-size: 14px; }
  .pill-detect { font-size: 11px; padding: 3px 8px; }
}
