/* ==========================================================
   SpeakBridge AI — mobile-first interpreter UI
   Design idea: a bridge between two languages. The Spanish side
   is warm, the English side is cool, and the live panel is the
   span between them.
   ========================================================== */

:root {
  --bg:        #0a1020;
  --bg-2:      #0e1728;
  --surface:   #141f36;
  --surface-2: #1b2843;
  --line:      rgba(255, 255, 255, 0.10);
  --line-soft: rgba(255, 255, 255, 0.06);

  --text:  #eef3fb;
  --muted: #93a3c0;
  --dim:   #64748b;

  --es:    #ffa96b;   /* Spanish side  */
  --es-dim:rgba(255, 169, 107, 0.14);
  --en:    #64cdff;   /* English side  */
  --en-dim:rgba(100, 205, 255, 0.14);

  /* Brand gradient. Fixed in both themes: --es/--en darken for text contrast
     in light mode, and blending those two darkened values makes mud. */
  --brand-a: #ff8f4d;
  --brand-b: #3aa9ff;

  --live:  #ff4d5e;   /* microphone-active red */
  --ok:    #4ade80;
  --warn:  #fbbf24;

  --deck-h: 132px;
  --r-sm: 12px;
  --r-md: 18px;
  --r-lg: 26px;

  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg:        #f4f7fc;
    --bg-2:      #eaf0f9;
    --surface:   #ffffff;
    --surface-2: #f0f4fb;
    --line:      rgba(15, 30, 60, 0.12);
    --line-soft: rgba(15, 30, 60, 0.07);
    --text:  #0d1729;
    --muted: #56637d;
    --dim:   #8794ab;
    --es:    #c2591c;
    --es-dim:rgba(194, 89, 28, 0.10);
    --en:    #0a6ea8;
    --en-dim:rgba(10, 110, 168, 0.10);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior-y: none;
}

body {
  background:
    radial-gradient(120% 60% at 8% 0%,  var(--es-dim), transparent 55%),
    radial-gradient(120% 60% at 92% 0%, var(--en-dim), transparent 55%),
    var(--bg);
  color: var(--text);
  font: 400 16px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }

:focus-visible {
  outline: 2px solid var(--en);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ---------------------------------------------------------
   Layout shell
   --------------------------------------------------------- */
.app {
  min-height: 100%;
  padding:
    calc(var(--sat) + 10px)
    calc(var(--sar) + 16px)
    calc(var(--deck-h) + var(--sab) + 20px)
    calc(var(--sal) + 16px);
  max-width: 560px;
  margin: 0 auto;
}

/* The type bar is fixed above the deck, so the page needs room for it. */
body.is-typing .app {
  padding-bottom: calc(var(--deck-h) + var(--sab) + 92px);
}

/* ---------------------------------------------------------
   Top bar — the bridge
   --------------------------------------------------------- */
.topbar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 14px;
}

.bridge {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 8px;
  position: relative;
  overflow: hidden;
}

.bridge::after {            /* the span of the bridge */
  content: "";
  position: absolute;
  left: 18%; right: 18%;
  bottom: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--brand-a), var(--brand-b));
  opacity: 0.55;
}

.lang {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 8px;
  border-radius: var(--r-md);
  min-height: 44px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.lang-flag { font-size: 20px; line-height: 1; }
.lang-name { font-size: 15px; }
#langSource .lang-name { color: var(--es); }
#langTarget .lang-name { color: var(--en); }

.swap {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--muted);
  transition: transform 0.35s var(--ease), color 0.2s;
}
.swap svg { width: 20px; height: 20px; }
.swap:active { transform: rotate(180deg) scale(0.92); color: var(--text); }

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

/* Microphone privacy indicator — always visible, never ambiguous */
.mic-state {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 13px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
}
.mic-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--dim);
  flex: none;
}
.mic-state.mic-on {
  color: var(--live);
  border-color: color-mix(in srgb, var(--live) 45%, transparent);
  background: color-mix(in srgb, var(--live) 12%, var(--surface));
}
.mic-state.mic-on .mic-dot {
  background: var(--live);
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1;   box-shadow: 0 0 0 0 color-mix(in srgb, var(--live) 60%, transparent); }
  50%      { opacity: 0.6; box-shadow: 0 0 0 7px transparent; }
}

.icon-btn {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
}
.icon-btn svg { width: 21px; height: 21px; }
.icon-btn:active { background: var(--surface-2); }

/* ---------------------------------------------------------
   Banner
   --------------------------------------------------------- */
.banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  margin-bottom: 14px;
  border-radius: var(--r-md);
  background: color-mix(in srgb, var(--warn) 16%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent);
  font-size: 14px;
  line-height: 1.45;
}
.banner[hidden] { display: none; }
.banner-x {
  margin-left: auto;
  font-size: 22px;
  line-height: 1;
  color: inherit;
  opacity: 0.7;
  padding: 0 4px;
}

/* ---------------------------------------------------------
   Stage
   --------------------------------------------------------- */
.stage { margin-bottom: 20px; }

.wave-wrap {
  height: 74px;
  display: grid;
  place-items: center;
  margin-bottom: 4px;
}
.wave {
  width: 100%;
  height: 74px;
  opacity: 0.25;
  transition: opacity 0.3s var(--ease);
}
body.is-listening .wave { opacity: 1; }

.state-line {
  text-align: center;
  margin: 0 0 18px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted);
  min-height: 20px;
  transition: color 0.2s;
}
body.is-listening .state-line { color: var(--live); }
body.is-speaking  .state-line { color: var(--en); }

/* Cards ---------------------------------------------------- */
.cards { display: flex; flex-direction: column; gap: 12px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 16px 18px;
  animation: rise 0.28s var(--ease);
}
.card[hidden] { display: none; }
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

.card-source { border-left: 3px solid var(--es); }
.card-target { border-left: 3px solid var(--en); }

.card-label {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.card-source .card-label { color: var(--es); }
.card-target .card-label { color: var(--en); }

.card-text {
  margin: 0;
  font-size: 20px;
  line-height: 1.4;
  letter-spacing: -0.01em;
  white-space: pre-wrap;
  word-break: break-word;
}
.card-target .card-text { font-size: 24px; font-weight: 600; }
.card-text .interim { color: var(--muted); font-weight: 400; }
.card-text .gap {
  color: var(--warn);
  background: color-mix(in srgb, var(--warn) 15%, transparent);
  border-radius: 5px;
  padding: 0 4px;
}

.card-flags { margin-top: 10px; }
.card-flags[hidden] { display: none; }
.flag-uncertain {
  display: inline-block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--warn);
  background: color-mix(in srgb, var(--warn) 14%, transparent);
  border-radius: 999px;
  padding: 5px 11px;
}

.card-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.chip {
  min-height: 40px;
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}
.chip:active { transform: scale(0.96); }
.chip.is-done { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, transparent); }

/* Empty state ---------------------------------------------- */
.empty {
  text-align: center;
  padding: 22px 20px 8px;
  color: var(--muted);
}
.empty[hidden] { display: none; }
.empty-icon {
  width: 118px;
  height: 63px;
  display: block;
  margin: 0 auto 16px;
  color: var(--muted);
  opacity: 0.85;
}
.empty-title { margin: 0 0 6px; font-size: 17px; font-weight: 700; color: var(--text); }
.empty-sub { margin: 0; font-size: 14.5px; line-height: 1.5; max-width: 30ch; margin-inline: auto; }

/* ---------------------------------------------------------
   Control deck
   --------------------------------------------------------- */
.deck {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  padding: 12px calc(var(--sar) + 16px) calc(var(--sab) + 12px) calc(var(--sal) + 16px);
  /* Opaque enough that text scrolling underneath never reads through. */
  background: linear-gradient(to top, var(--bg) 82%, color-mix(in srgb, var(--bg) 45%, transparent));
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
.deck-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  max-width: 560px;
  margin: 0 auto;
}

.deck-side {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 6px;
  border-radius: var(--r-md);
  color: var(--muted);
  min-height: 60px;
  justify-content: center;
  transition: color 0.2s, background 0.2s;
}
.deck-side-icon { display: block; line-height: 0; }
.deck-side-icon svg { width: 22px; height: 22px; display: block; }
.deck-side-label { font-size: 12px; font-weight: 600; letter-spacing: 0.01em; }
.deck-side[aria-pressed="true"],
.deck-side[aria-expanded="true"] {
  color: var(--en);
  background: var(--en-dim);
}

/* The microphone ------------------------------------------- */
.mic {
  position: relative;
  width: 96px; height: 96px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(145deg, var(--brand-a), var(--brand-b));
  box-shadow: 0 10px 30px -8px color-mix(in srgb, var(--brand-b) 55%, transparent);
  transition: transform 0.18s var(--ease), box-shadow 0.25s;
}
.mic:active { transform: scale(0.94); }
.mic-glyph svg { width: 38px; height: 38px; display: block; }

.mic-ring {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid var(--live);
  opacity: 0;
  pointer-events: none;
}
body.is-listening .mic {
  background: linear-gradient(145deg, var(--live), #ff8a5b);
  box-shadow: 0 10px 34px -6px color-mix(in srgb, var(--live) 65%, transparent);
}
body.is-listening .mic-ring { animation: ring 1.6s ease-out infinite; }
@keyframes ring {
  0%   { opacity: 0.85; transform: scale(1); }
  100% { opacity: 0;    transform: scale(1.32); }
}
body.is-working .mic { background: linear-gradient(145deg, #6b7a99, #48566f); }
body.is-speaking .mic { background: linear-gradient(145deg, var(--brand-b), #7c8bff); }

.deck-hint {
  text-align: center;
  margin: 10px 0 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  min-height: 18px;
}

/* ---------------------------------------------------------
   Type bar
   --------------------------------------------------------- */
.typebar {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(var(--deck-h) + var(--sab));
  z-index: 41;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  /* Full-bleed backdrop, content still capped at the app width. */
  padding-block: 10px 12px;
  padding-left:  max(calc(var(--sal) + 16px), calc(50% - 264px));
  padding-right: max(calc(var(--sar) + 16px), calc(50% - 264px));
  background: var(--bg);
  border-top: 1px solid var(--line-soft);
  box-shadow: 0 -8px 20px -12px rgba(0, 0, 0, 0.5);
}
.typebar[hidden] { display: none; }
#typeInput {
  flex: 1;
  resize: none;
  max-height: 120px;
  padding: 12px 14px;
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 16px;   /* 16px stops iOS from zooming on focus */
  line-height: 1.4;
}
#typeInput::placeholder { color: var(--dim); }
.typebar-send {
  padding: 12px 18px;
  border-radius: var(--r-md);
  background: linear-gradient(145deg, var(--brand-a), var(--brand-b));
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  min-height: 46px;
  white-space: nowrap;
}

/* ---------------------------------------------------------
   History
   --------------------------------------------------------- */
.history { margin-top: 8px; }
.history[hidden] { display: none; }
.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.history-head h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--dim);
}
.link-btn {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  padding: 6px 4px;
}

.history-list { display: flex; flex-direction: column; gap: 10px; }

.entry {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  padding: 13px 15px;
  animation: rise 0.25s var(--ease);
}
.entry-src {
  margin: 0 0 6px;
  font-size: 14.5px;
  color: var(--muted);
  word-break: break-word;
}
.entry-tgt {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  line-height: 1.35;
  word-break: break-word;
}
.entry-actions {
  display: flex;
  gap: 6px;
  margin-top: 11px;
  flex-wrap: wrap;
}
.mini {
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  min-height: 34px;
}
.mini:active { transform: scale(0.95); }
.mini.is-danger { color: var(--live); }
.mini.is-done { color: var(--ok); }

.history-note {
  margin: 14px 0 0;
  font-size: 12.5px;
  color: var(--dim);
  text-align: center;
}

/* ---------------------------------------------------------
   Settings sheet
   --------------------------------------------------------- */
.sheet-scrim {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(3, 7, 18, 0.55);
  backdrop-filter: blur(3px);
  animation: fade 0.2s ease;
}
.sheet-scrim[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 61;
  max-height: 88vh;
  max-height: 88dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-2);
  border-top: 1px solid var(--line);
  border-radius: 26px 26px 0 0;
  padding: 8px calc(var(--sar) + 18px) calc(var(--sab) + 24px) calc(var(--sal) + 18px);
  animation: slide 0.3s var(--ease);
  max-width: 560px;
  margin: 0 auto;
}
.sheet[hidden] { display: none; }
@keyframes slide { from { transform: translateY(100%); } to { transform: none; } }

.sheet-grip {
  width: 40px; height: 4px;
  border-radius: 999px;
  background: var(--line);
  margin: 6px auto 10px;
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.sheet-head h2 { margin: 0; font-size: 19px; font-weight: 700; }
.sheet-body { display: flex; flex-direction: column; gap: 4px; }

.row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 2px;
  border-bottom: 1px solid var(--line-soft);
}
.row:last-of-type { border-bottom: none; }
.row-stack { flex-direction: column; align-items: stretch; gap: 9px; }
.row-main { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.row-title { font-size: 15.5px; font-weight: 600; }
.row-sub { font-size: 13px; color: var(--muted); line-height: 1.4; }

/* Toggle */
.row-toggle { cursor: pointer; }
.row-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.switch {
  flex: none;
  width: 51px; height: 31px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  position: relative;
  transition: background 0.22s var(--ease);
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 25px; height: 25px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  transition: transform 0.22s var(--ease);
}
.row-toggle input:checked ~ .switch { background: var(--en); border-color: transparent; }
.row-toggle input:checked ~ .switch::after { transform: translateX(20px); }
.row-toggle input:focus-visible ~ .switch { outline: 2px solid var(--en); outline-offset: 2px; }

/* Segmented control */
.segmented {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 4px;
}
.seg {
  flex: 1;
  min-height: 40px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  transition: background 0.18s, color 0.18s;
}
.seg.is-on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.2); }

.advanced {
  border-top: 1px solid var(--line-soft);
  margin-top: 6px;
  padding-top: 4px;
}
.advanced summary {
  padding: 14px 2px;
  font-size: 15.5px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}
.advanced summary::-webkit-details-marker { display: none; }
.advanced summary::after { content: " ›"; color: var(--muted); }
.advanced[open] summary::after { content: " ⌄"; }

.danger-btn {
  margin-top: 16px;
  padding: 14px;
  border-radius: var(--r-md);
  background: color-mix(in srgb, var(--live) 13%, transparent);
  border: 1px solid color-mix(in srgb, var(--live) 40%, transparent);
  color: var(--live);
  font-weight: 700;
  font-size: 15px;
  width: 100%;
  min-height: 48px;
}

.sheet-foot {
  margin: 18px 0 0;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--dim);
}

/* ---------------------------------------------------------
   Motion & larger screens
   --------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

@media (min-width: 600px) {
  .card-target .card-text { font-size: 27px; }
}
