:root {
  --bg: #0f1115;
  --surface: #16181d;
  --surface2: #1c1f26;
  --surface3: #232732;
  --line: #262a33;
  --line2: #343a46;
  --ink: #e7e9ee;
  --muted: #98a0ad;
  --faint: #666e7c;
  --accent: #5b8def;
  --live: #3ecf8e;
  --danger: #f0616d;
  --warn: #e8b33d;
  --on-accent: #fff;
  --paper: #fff;
  --warn-ink: #d9be86;
  --r-sm: 8px;
  --r: 10px;
  --r-lg: 12px;
  --ctl: 40px;
  --ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 var(--ui);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.spacer { flex: 1; }

/* ---------- top bar ---------- */
.appBar {
  display: flex; align-items: center; gap: 12px;
  height: 52px; padding: 0 14px; flex: none;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand {
  display: flex; align-items: center; gap: 9px;
  font-size: 13.5px; font-weight: 600; letter-spacing: -.01em;
}
.brand em { color: var(--muted); font-style: normal; font-weight: 500; }
.brandDot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); flex: none; }

/* ---------- segmented control ---------- */
.segCtrl {
  display: inline-flex; gap: 2px; padding: 3px; flex: none;
  background: var(--surface2); border: 1px solid var(--line); border-radius: 9px;
}
.segCtrl button {
  font: 500 12.5px/1 var(--ui); color: var(--muted);
  background: transparent; border: 0; border-radius: 6px;
  padding: 7px 14px; cursor: pointer;
}
.segCtrl button.active {
  background: var(--surface3); color: var(--ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .3);
}
.segCtrl button:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- status pill ---------- */
#statusPill {
  display: inline-flex; align-items: center; gap: 7px; flex: none;
  height: 28px; padding: 0 11px; border-radius: 99px;
  background: var(--surface2); border: 1px solid var(--line);
  font-size: 12px; color: var(--muted);
  max-width: 40ch; overflow: hidden;
}
#statusPill i { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); flex: none; }
#statusPill span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#statusPill[data-state="connecting"] { color: var(--warn); border-color: rgba(232, 179, 61, .3); }
#statusPill[data-state="connecting"] i { background: var(--warn); }
#statusPill[data-state="live"] {
  color: var(--live); border-color: rgba(62, 207, 142, .3); background: rgba(62, 207, 142, .09);
}
#statusPill[data-state="live"] i { background: var(--live); box-shadow: 0 0 0 3px rgba(62, 207, 142, .18); }
#statusPill[data-state="error"] {
  color: var(--danger); border-color: rgba(240, 97, 109, .35); background: rgba(240, 97, 109, .09);
}
#statusPill[data-state="error"] i { background: var(--danger); }

/* ---------- buttons ---------- */
button {
  font: 500 13px/1 var(--ui); color: var(--ink);
  background: var(--surface2); border: 1px solid var(--line2);
  border-radius: var(--r-sm); padding: 0 14px; height: 36px; cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--faint); }
button:disabled { opacity: .45; cursor: not-allowed; }
.iconBtn {
  width: 32px; height: 32px; padding: 0; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted); border-color: var(--line); font-size: 14px;
}

/* ---------- language bar ---------- */
.langBar {
  display: flex; align-items: center; gap: 10px; flex: none;
  padding: 14px; border-bottom: 1px solid var(--line);
}
.field { flex: 1 1 140px; min-width: 0; position: relative; display: block; }
.fieldLabel {
  position: absolute; top: 6px; left: 14px; z-index: 1; pointer-events: none;
  font-size: 9.5px; font-weight: 700; letter-spacing: .09em;
  text-transform: uppercase; color: var(--faint);
}
.field select {
  width: 100%; height: 52px; padding: 18px 34px 4px 13px;
  font: 500 14.5px/1 var(--ui); color: var(--ink);
  background: var(--surface); border: 1px solid var(--line2); border-radius: var(--r);
  appearance: none; -webkit-appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path d='M1 1.5L6 6.5L11 1.5' stroke='%23666e7c' stroke-width='1.6' fill='none' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat; background-position: right 13px center;
}
.field select:disabled { opacity: .5; cursor: not-allowed; }
#swap {
  width: 38px; height: 38px; padding: 0; flex: none; border-radius: 99px;
  color: var(--muted); font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center;
}

/* ---------- transcript ---------- */
main { flex: 1; display: grid; grid-template-columns: 1fr 1fr; min-height: 0; }
.col { padding: 0 0 24px; overflow-y: auto; min-height: 0; }
.col + .col { border-left: 1px solid var(--line); }
.col h2 {
  position: sticky; top: 0; z-index: 1;
  padding: 11px 20px; margin-bottom: 6px;
  background: var(--bg); border-bottom: 1px solid var(--line);
  font-size: 10.5px; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: var(--faint);
}
.col > div { padding: 0 20px; }
.seg { margin-bottom: 14px; font-size: 15.5px; line-height: 1.62; }
.partial { color: var(--muted); }
.partial:not(:empty)::after {
  content: ""; display: inline-block; width: 2px; height: 1em;
  background: var(--accent); vertical-align: -2px; margin-left: 3px;
}

/* ---------- action bar ---------- */
.actionBar {
  display: flex; align-items: center; gap: 12px; flex: none;
  padding: 12px 14px; background: var(--surface); border-top: 1px solid var(--line);
}
button.rec {
  height: 44px; padding: 0 20px; font: 600 14px/1 var(--ui);
  background: var(--accent); border-color: var(--accent); color: var(--on-accent);
  box-shadow: 0 2px 10px rgba(91, 141, 239, .3);
}
button.rec:hover:not(:disabled) { border-color: var(--accent); filter: brightness(1.08); }
button.rec.live {
  background: var(--danger); border-color: var(--danger);
  box-shadow: 0 2px 10px rgba(240, 97, 109, .28);
}
#micMeter {
  display: none; flex: 1; max-width: 180px; height: 6px;
  background: var(--surface3); border-radius: 99px; overflow: hidden;
}
#micMeter.show { display: block; }
#micLevel { height: 100%; width: 0%; background: var(--live); border-radius: 99px; transition: width 80ms linear; }
body.is-live .brandDot { box-shadow: 0 0 0 3px rgba(91, 141, 239, .18); }

/* ---------- settings drawer ---------- */
#settingsDrawer {
  margin: 0 0 0 auto; height: 100vh; max-height: 100vh; width: min(100vw, 400px);
  padding: 0; border: 0; border-left: 1px solid var(--line2);
  background: var(--surface); color: var(--ink);
  box-shadow: -24px 0 60px rgba(0, 0, 0, .5);
}
#settingsDrawer[open] { display: flex; flex-direction: column; }
#settingsDrawer::backdrop { background: rgba(8, 10, 12, .6); }
.drawerHead {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px 14px; border-bottom: 1px solid var(--line);
}
.drawerHead h3 { font-size: 15px; font-weight: 600; letter-spacing: -.01em; }
.drawerBody {
  padding: 18px; display: flex; flex-direction: column; gap: 24px;
  overflow-y: auto; flex: 1; min-height: 0;
}
.groupLabel {
  display: block; margin-bottom: 10px;
  font-size: 10.5px; font-weight: 700; letter-spacing: .11em;
  text-transform: uppercase; color: var(--faint);
}
.group .field { flex: none; margin-bottom: 12px; }
.group .field select { height: var(--ctl); padding: 16px 34px 3px 12px; font-size: 13.5px; }
.group .fieldLabel { top: 4px; left: 12px; }

/* engine cards */
.engineCard {
  display: flex; gap: 11px; width: 100%; height: auto; text-align: left;
  padding: 12px 13px; margin-bottom: 8px;
  background: var(--surface2); border: 1px solid var(--line); border-radius: 11px;
}
.engineCard.on {
  border-color: var(--accent); background: rgba(91, 141, 239, .09);
  box-shadow: 0 0 0 1px rgba(91, 141, 239, .35);
}
.engineCard.unavailable { opacity: .5; cursor: not-allowed; }
.engineRadio {
  width: 16px; height: 16px; margin-top: 2px; flex: none;
  border: 1.5px solid var(--line2); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.engineCard.on .engineRadio { border-color: var(--accent); }
.engineCard.on .engineRadio::after {
  content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
}
.engineBody { flex: 1; min-width: 0; }
.engineName {
  display: flex; align-items: center; gap: 7px; margin-bottom: 3px;
  font-size: 13.5px; font-weight: 600;
}
.engineDesc {
  display: block; margin-bottom: 8px;
  font: 400 12.5px/1.45 var(--ui); color: var(--muted);
}
.engineChips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  font-size: 10.5px; font-weight: 500; padding: 2.5px 7px; border-radius: 5px;
  background: var(--surface3); color: var(--muted); border: 1px solid var(--line);
}
.chip.off { color: var(--faint); text-decoration: line-through; opacity: .75; }
.engineBadge {
  font-size: 9.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  padding: 2px 6px; border-radius: 4px;
  background: rgba(232, 179, 61, .14); color: var(--warn); border: 1px solid rgba(232, 179, 61, .3);
}
.engineBadge[hidden] { display: none; }

/* toggle switch */
.switchRow {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 13px; border-radius: var(--r);
  background: var(--surface2); border: 1px solid var(--line); cursor: pointer;
}
.switchText { flex: 1; min-width: 0; }
.switchText b { display: block; font-size: 13.5px; font-weight: 500; margin-bottom: 2px; }
.switchText span { font-size: 12px; line-height: 1.4; color: var(--faint); }
.switchRow input { position: absolute; opacity: 0; width: 0; height: 0; }
.switchTrack {
  position: relative; width: 38px; height: 22px; flex: none; border-radius: 99px;
  background: var(--surface3); border: 1px solid var(--line2); transition: background 150ms;
}
.switchTrack::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%; background: var(--faint);
  transition: transform 150ms, background 150ms;
}
.switchRow input:checked ~ .switchTrack { background: var(--accent); border-color: var(--accent); }
.switchRow input:checked ~ .switchTrack::after { transform: translateX(16px); background: var(--on-accent); }

/* glossary + notes */
#glossary {
  width: 100%; min-height: 82px; resize: vertical; padding: 10px 12px;
  font: 12.5px/1.6 var(--mono); color: var(--ink);
  background: var(--surface2); border: 1px solid var(--line2); border-radius: 9px;
}
.help { margin-top: 7px; font-size: 12px; line-height: 1.45; color: var(--faint); }
.help code { font-family: var(--mono); font-size: 11.5px; }
#hint { margin-top: 10px; font-size: 12px; line-height: 1.45; color: var(--faint); }
.note {
  display: flex; gap: 8px; margin-top: 9px; padding: 9px 11px; border-radius: var(--r-sm);
  background: rgba(232, 179, 61, .08); border: 1px solid rgba(232, 179, 61, .22);
  font-size: 12px; line-height: 1.45; color: var(--warn-ink);
}
.note[hidden] { display: none; }
.is-muted { opacity: .5; }

/* ---------- talk mode ---------- */
#talkStyleWrap { display: none; flex: none; }
#talkStyleWrap.show { display: inline-flex; }
#talkBar { display: none; flex: none; background: var(--surface); border-top: 1px solid var(--line); }
#talkBar.show { display: block; }
.dirRow { display: flex; gap: 9px; padding: 11px 14px 0; }
.dirBtn {
  flex: 1; min-height: 74px; height: auto; padding: 10px 14px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  font: 600 14px/1.25 var(--ui); color: var(--muted);
  background: var(--surface2); border: 1px solid var(--line2); border-radius: var(--r-lg);
}
.dirBtn::before {
  content: "Tap to switch";
  font-size: 10px; font-weight: 600; letter-spacing: .09em;
  text-transform: uppercase; color: var(--faint);
}
.dirBtn.active {
  background: var(--accent); border-color: var(--accent); color: var(--on-accent);
  box-shadow: 0 3px 14px rgba(91, 141, 239, .32);
}
.dirBtn.active::before { content: "Speaking"; color: rgba(255, 255, 255, .72); }

#talkAutoPanel { display: none; padding: 11px 14px 0; }
#talkAutoPanel.show { display: block; }
.autoTiles { display: flex; gap: 9px; }
.autoTile {
  flex: 1; min-height: 74px; padding: 10px 14px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
  background: var(--surface2); border: 1px solid var(--line); border-radius: var(--r-lg);
  font-size: 14px; font-weight: 600; color: var(--muted);
}
.autoTile small {
  font-size: 10px; font-weight: 600; letter-spacing: .08em;
  text-transform: uppercase; color: var(--faint);
}
body.is-live .autoTile {
  border-color: var(--live); background: rgba(62, 207, 142, .08); color: var(--ink);
}
#talkAutoStatus {
  padding: 9px 2px 0; text-align: center;
  font-size: 12px; color: var(--faint);
}
body.talk-manual #swap, body.talk-auto #swap { display: none; }

/* ---------- share ---------- */
#shareRow {
  display: none; align-items: center; gap: 10px; flex: none;
  padding: 10px 14px; border-bottom: 1px solid var(--line);
  background: rgba(91, 141, 239, .06);
}
#shareRow.show { display: flex; }
.shareTag {
  font-size: 10px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
  color: var(--accent); flex: none;
}
#shareUrl {
  flex: 1; min-width: 140px; height: 34px; padding: 0 11px;
  font: 12px/1 var(--mono); color: var(--muted);
  background: var(--surface); border: 1px solid var(--line2); border-radius: var(--r-sm);
}
#shareRow button { height: 34px; font-size: 12px; }

#shareModal {
  margin: auto;
  padding: 0; border: 1px solid var(--line2); border-radius: 14px;
  background: var(--surface); color: var(--ink); max-width: min(92vw, 360px);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .5);
}
#shareModal::backdrop { background: rgba(8, 10, 12, .65); }
#shareModal .sheet {
  padding: 22px 22px 18px; display: flex; flex-direction: column; gap: 14px; align-items: center;
}
#shareModal h3 {
  align-self: stretch; font-size: 15px; font-weight: 600; letter-spacing: -.01em;
}
#shareQr {
  width: 240px; height: 240px; padding: 10px; object-fit: contain;
  background: var(--paper); border-radius: var(--r);
}
#shareModalUrl {
  width: 100%; padding: 9px 11px;
  font: 12px/1.4 var(--mono); color: var(--muted);
  background: var(--bg); border: 1px solid var(--line2); border-radius: var(--r-sm);
}
#shareModal .actions { display: flex; gap: 8px; width: 100%; }
#shareModal .actions button { flex: 1; height: var(--ctl); }

/* ---------- focus and motion ---------- */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.switchRow input:focus-visible ~ .switchTrack {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
button, .switchTrack, .engineCard, #statusPill {
  transition: background 150ms, border-color 150ms, color 150ms, box-shadow 150ms;
}

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

/* ---------- small screens ---------- */
@media (max-width: 720px) {
  .appBar { height: auto; padding: 10px 12px; flex-wrap: wrap; gap: 10px; }
  .appBar .spacer { display: none; }
  .appBar .segCtrl { order: 1; }
  #settingsBtn { order: 2; }
  #statusPill { order: 3; max-width: none; flex: 1 1 100%; }
  .langBar { flex-wrap: wrap; padding: 12px; gap: 8px; }
  .field { flex: 1 1 40%; }
  #talkStyleWrap { flex: 1 1 100%; }
  #talkStyleWrap .segCtrl { width: 100%; }
  #talkStyleWrap .segCtrl button { flex: 1; padding: 9px 12px; }
  .field select { height: 54px; }
  #swap { width: 44px; height: 44px; }

  main { grid-template-columns: 1fr; }
  .col + .col { border-left: 0; border-top: 1px solid var(--line); }

  .actionBar { padding: 10px 12px; gap: 9px; }
  .actionBar button { min-height: 44px; }
  button.rec { flex: 1; min-height: 48px; }
  #micMeter { max-width: 70px; }

  .dirBtn { min-height: 84px; font-size: 15px; }
  .autoTile { min-height: 78px; }

  #settingsDrawer {
    margin: auto 0 0; width: 100vw; height: auto; max-height: 88vh;
    border-left: 0; border-top: 1px solid var(--line2);
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -20px 50px rgba(0, 0, 0, .5);
  }
  #shareRow { flex-wrap: wrap; }
  #shareUrl { flex: 1 1 100%; }
  #shareRow button { flex: 1; min-height: 40px; }
}
