/* Teal is always English, amber is always Arabic. */
:root {
  --night: #0d1230;
  --dusk: #2a2363;
  --teal: #3fd6c6;
  --amber: #ffb86b;
  --violet: #8a6cff;
  --rose: #ff6b8a;
  --ink: #f4f6ff;
  --ink-soft: rgba(244, 246, 255, 0.64);
  --glass-top: rgba(255, 255, 255, 0.18);
  --glass-bottom: rgba(255, 255, 255, 0.06);
  --rim: rgba(255, 255, 255, 0.24);
  --shine: rgba(255, 255, 255, 0.55);
  --card: rgba(255, 255, 255, 0.075);
  --card-rim: rgba(255, 255, 255, 0.14);
  --shadow: rgba(4, 6, 28, 0.42);
  --blob-opacity: 0.55;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --night: #eef1fb;
    --dusk: #dfe3f7;
    --teal: #0f9e90;
    --amber: #d9822b;
    --violet: #7a5cf0;
    --rose: #e0435f;
    --ink: #13172e;
    --ink-soft: rgba(19, 23, 46, 0.6);
    --glass-top: rgba(255, 255, 255, 0.72);
    --glass-bottom: rgba(255, 255, 255, 0.42);
    --rim: rgba(255, 255, 255, 0.9);
    --shine: rgba(255, 255, 255, 1);
    --card: rgba(255, 255, 255, 0.5);
    --card-rim: rgba(255, 255, 255, 0.85);
    --shadow: rgba(40, 48, 110, 0.16);
    --blob-opacity: 0.45;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: radial-gradient(120% 80% at 50% 0%, var(--dusk), var(--night) 70%) fixed, var(--night);
  color: var(--ink);
  font: 400 16px/1.55 "Readex Pro", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, select, input { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--teal); outline-offset: 3px; }

/* ---------- Backdrop: the slow light the glass refracts ---------- */
.backdrop { position: fixed; inset: 0; overflow: hidden; z-index: -1; }
.blob {
  position: absolute;
  width: 70vmax;
  height: 70vmax;
  border-radius: 50%;
  filter: blur(70px);
  opacity: var(--blob-opacity);
  will-change: transform;
}
.blob-teal { background: radial-gradient(circle, var(--teal), transparent 65%); top: -25vmax; left: -25vmax; animation: drift-a 38s ease-in-out infinite alternate; }
.blob-amber { background: radial-gradient(circle, var(--amber), transparent 65%); bottom: -30vmax; right: -25vmax; animation: drift-b 44s ease-in-out infinite alternate; }
.blob-violet { background: radial-gradient(circle, var(--violet), transparent 65%); top: 30%; left: 35%; width: 45vmax; height: 45vmax; opacity: calc(var(--blob-opacity) * 0.7); animation: drift-c 52s ease-in-out infinite alternate; }
@keyframes drift-a { to { transform: translate(18vw, 22vh) scale(1.1); } }
@keyframes drift-b { to { transform: translate(-20vw, -18vh) scale(0.95); } }
@keyframes drift-c { to { transform: translate(-25vw, 10vh) scale(1.2); } }

/* ---------- Liquid glass material ---------- */
.glass {
  background: linear-gradient(180deg, var(--glass-top), var(--glass-bottom));
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid var(--rim);
  box-shadow:
    inset 0 1px 0 var(--shine),
    inset 0 -1px 1px rgba(255, 255, 255, 0.08),
    0 12px 36px var(--shadow);
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: calc(10px + var(--safe-top));
  z-index: 5;
  margin: calc(10px + var(--safe-top)) auto 0;
  width: min(720px, calc(100% - 32px));
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 8px 20px;
  border-radius: 999px;
}
.topbar h1 { margin: 0; font-size: 17px; font-weight: 500; letter-spacing: -0.01em; flex: 1; }
.status {
  font-size: 13px;
  color: var(--ink-soft);
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
  transition: color .3s, background .3s;
}
.status.live { color: var(--ink); background: rgba(255, 107, 138, 0.16); }
.status.live::before {
  content: "";
  display: inline-block;
  width: 7px; height: 7px;
  margin-inline-end: 7px;
  border-radius: 50%;
  background: var(--rose);
  vertical-align: 1px;
  box-shadow: 0 0 10px var(--rose);
}
.status.error { color: var(--rose); }

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  color: var(--ink-soft);
  transition: background .2s, color .2s;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.1); color: var(--ink); }
.icon-btn:disabled { opacity: .35; cursor: not-allowed; }

/* ---------- Conversation feed ---------- */
.feed {
  width: min(720px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 calc(150px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.empty {
  margin-top: 18vh;
  text-align: center;
  color: var(--ink-soft);
  font-weight: 300;
  font-size: 18px;
  line-height: 1.6;
}
.empty p { margin: 0 0 18px; }

.utt {
  --lang: var(--teal);
  position: relative;
  padding: 16px 20px 18px;
  border-radius: 22px;
  background: var(--card);
  border: 1px solid var(--card-rim);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
  animation: settle .35s ease-out;
}
.utt[data-lang="ar"] { --lang: var(--amber); }
.utt::before {
  /* the speaker's colour, on the side the original text starts from */
  content: "";
  position: absolute;
  inset-block: 18px;
  inset-inline-start: 0;
  width: 3px;
  border-radius: 3px;
  background: var(--lang);
  box-shadow: 0 0 12px var(--lang);
}
.utt[data-lang="ar"]::before { inset-inline-start: auto; inset-inline-end: 0; }
@keyframes settle { from { opacity: 0; transform: translateY(8px) scale(.98); } }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--ink-soft);
  margin-bottom: 6px;
}
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--lang); }
.utt[data-lang="ar"] .chip { float: right; }
.utt[data-lang="ar"] .chip + .orig { clear: both; }

.orig { margin: 0 0 8px; font-size: 15px; color: var(--ink-soft); font-weight: 300; }
.trans { margin: 0; font-size: 22px; line-height: 1.45; font-weight: 400; letter-spacing: -0.005em; }
[dir="rtl"].orig, [dir="rtl"].trans { text-align: right; }
[dir="rtl"].trans { font-size: 24px; line-height: 1.6; }
.utt.partial .trans { opacity: .62; }
.utt.partial .trans:not(:empty)::after {
  content: "";
  display: inline-block;
  width: 2px; height: 1em;
  margin-inline-start: 3px;
  vertical-align: -0.15em;
  background: var(--lang);
  animation: caret 1s steps(2) infinite;
}
@keyframes caret { 50% { opacity: 0; } }

/* ---------- Dock ---------- */
.dock {
  position: fixed;
  left: 50%;
  bottom: calc(16px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 12px;
  border-radius: 30px;
  width: max-content;
  max-width: calc(100% - 32px);
}

.seg {
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.1);
}
.seg label { position: relative; cursor: pointer; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span {
  display: block;
  min-width: 44px;
  padding: 8px 12px;
  border-radius: 999px;
  text-align: center;
  font-size: 14px;
  color: var(--ink-soft);
  transition: background .25s, color .25s, box-shadow .25s;
}
.seg span[lang="ar"] { font-size: 17px; line-height: 21px; padding-block: 6px; }
.seg input:checked + span {
  color: var(--ink);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0.12));
  box-shadow: inset 0 1px 0 var(--shine), 0 2px 8px var(--shadow);
}
.seg input:focus-visible + span { outline: 2px solid var(--teal); outline-offset: 2px; }
.seg input:disabled + span { opacity: .45; }
.seg-wide { display: flex; }
.seg-wide label { flex: 1; }

/* The orb: the one loud thing on the page. --level is live input volume, 0–1. */
.orb {
  --level: 0;
  position: relative;
  display: grid;
  place-items: center;
  width: 72px; height: 72px;
  flex: none;
  border-radius: 50%;
  border: 1px solid var(--rim);
  cursor: pointer;
  color: var(--ink);
  background:
    radial-gradient(circle at 32% 26%, rgba(255, 255, 255, 0.55), transparent 42%),
    linear-gradient(160deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0.05));
  -webkit-backdrop-filter: blur(16px) saturate(200%);
  backdrop-filter: blur(16px) saturate(200%);
  box-shadow: inset 0 1px 1px var(--shine), inset 0 -6px 14px rgba(0, 0, 0, 0.18), 0 10px 28px var(--shadow);
  transition: transform .15s ease-out, box-shadow .3s;
}
.orb svg { width: 28px; height: 28px; position: relative; z-index: 1; }
.orb .icon-stop { display: none; fill: currentColor; stroke: none; }
.orb::before {
  /* liquid core: teal meets amber, swells with the voice */
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  background: conic-gradient(from 200deg, var(--teal), var(--violet), var(--amber), var(--teal));
  opacity: 0;
  filter: blur(2px) saturate(130%);
  transform: scale(calc(0.86 + var(--level) * 0.14));
  transition: opacity .35s, transform .08s linear;
}
.orb::after {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  border: 2px solid var(--teal);
  opacity: 0;
  transform: scale(calc(1 + var(--level) * 0.45));
  transition: transform .08s linear, opacity .3s;
  pointer-events: none;
}
.orb:active { transform: scale(.94); }
.orb.live { color: #fff; box-shadow: inset 0 1px 1px var(--shine), 0 0 calc(18px + var(--level) * 46px) rgba(63, 214, 198, 0.55), 0 10px 28px var(--shadow); }
.orb.live::before { opacity: .95; animation: swirl 6s linear infinite; }
.orb.live::after { opacity: calc(0.15 + var(--level) * 0.7); }
.orb.live .icon-mic { display: none; }
.orb.live .icon-stop { display: block; }
.orb.busy::before { opacity: .5; animation: swirl 1.2s linear infinite; }
@keyframes swirl { to { rotate: 360deg; } }

/* ---------- File player ---------- */
.player {
  position: fixed;
  left: 50%;
  bottom: calc(110px + var(--safe-bottom));
  transform: translateX(-50%);
  width: min(420px, calc(100% - 32px));
  height: 44px;
  border-radius: 999px;
  z-index: 6;
}

/* ---------- Settings sheet ---------- */
.sheet {
  margin: auto auto 0;
  width: min(560px, 100%);
  max-height: 85dvh;
  padding: 8px 22px calc(26px + var(--safe-bottom));
  border-radius: 28px 28px 0 0;
  border-bottom: 0;
  color: var(--ink);
  background: linear-gradient(180deg, var(--glass-top), var(--glass-bottom)), color-mix(in srgb, var(--night) 55%, transparent);
}
.sheet[open] { animation: rise .32s cubic-bezier(.2, .9, .3, 1); }
.sheet::backdrop { background: rgba(5, 8, 30, 0.35); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 0 8px; }
.sheet-head h2 { margin: 0; font-size: 19px; font-weight: 500; }

.field { display: grid; gap: 7px; margin: 14px 0; }
.field-label { font-size: 13.5px; color: var(--ink-soft); }
select {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  font-size: 16px; /* 16px stops iOS zooming in on focus */
  padding: 12px 40px 12px 16px;
  border-radius: 14px;
  border: 1px solid var(--card-rim);
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none' stroke='%23999' stroke-width='1.8' stroke-linecap='round'%3E%3Cpath d='M1 1.5 6 6.5l5-5'/%3E%3C/svg%3E") no-repeat right 16px center,
    var(--card);
  cursor: pointer;
}
select option { color: #13172e; }
.file-row { display: flex; align-items: center; gap: 12px; min-width: 0; }
.pill-btn {
  flex: none;
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid var(--card-rim);
  background: var(--card);
  cursor: pointer;
}
.file-name { color: var(--ink-soft); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hint { margin: 18px 0 0; font-size: 13.5px; line-height: 1.55; color: var(--ink-soft); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  top: calc(76px + var(--safe-top));
  transform: translateX(-50%);
  z-index: 7;
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 10px 18px;
  border-radius: 16px;
  font-size: 14px;
  border-color: color-mix(in srgb, var(--rose) 50%, transparent);
}

@media (prefers-reduced-motion: reduce) {
  .blob, .orb.live::before, .orb.busy::before, .utt, .sheet[open] { animation: none; }
  .utt.partial .trans::after { animation: none; }
}
