:root {
  --bg: #F6F3EE;
  --surface: #ECE7DF;
  --ink: #1B1A17;
  --muted: #6F6A61;
  --faint: #A9A297;
  --line: #DDD6CB;
  --me: #2B4C7E;
  --them: #9E3039;
  --mic: #1B1A17;
  --mic-ink: #F6F3EE;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121110;
    --surface: #1F1D1B;
    --ink: #F2EEE7;
    --muted: #A39D93;
    --faint: #6B665E;
    --line: #2C2926;
    --me: #8FB3EA;
    --them: #EC8E97;
    --mic: #F2EEE7;
    --mic-ink: #121110;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.4 var(--font);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
[hidden] { display: none !important; }

/* Header */
header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
}
.pair { display: flex; align-items: center; gap: 8px; min-width: 0; }
.seg { display: flex; background: var(--surface); border-radius: 999px; padding: 3px; }
.seg button {
  padding: 7px 13px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
  transition: background .18s, color .18s;
}
.seg button[aria-checked="true"] { background: var(--me); color: var(--bg); }
.swap { width: 20px; height: 20px; color: var(--faint); flex: none; }
.them-chip {
  padding: 7px 13px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 600;
  color: var(--them);
  box-shadow: inset 0 0 0 1.5px var(--them);
  white-space: nowrap;
}
.tools { display: flex; gap: 2px; }
.icon { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; color: var(--muted); }
.icon svg { width: 24px; height: 24px; }
.icon:active { background: var(--surface); }
#sound {
  position: absolute; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 42px);
  display: flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 12px 0 13px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13px; font-weight: 600; white-space: nowrap;
}
#sound svg { width: 20px; height: 20px; flex: none; }
#sound .off { display: none; }
#sound[aria-checked="false"] .waves { display: none; }
#sound[aria-checked="false"] .off { display: block; }
#sound[aria-checked="false"] { background: none; box-shadow: inset 0 0 0 1.5px var(--line); color: var(--muted); }

/* Conversation */
main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 8px 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  mask-image: linear-gradient(to bottom, transparent 0, #000 18px, #000 calc(100% - 22px), transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 18px, #000 calc(100% - 22px), transparent 100%);
}
main > :first-child { margin-top: auto; }

#empty { margin: auto 0; display: grid; gap: 22px; padding: 0 4px; }
#empty p { margin: 0; font-size: 22px; line-height: 1.32; font-weight: 600; letter-spacing: -0.01em; text-wrap: balance; }
#empty .e-me { color: var(--me); }
#empty .e-them { color: var(--them); }

.turn {
  --c: var(--me);
  position: relative;
  padding-left: 14px;
  animation: in .22s ease-out;
  transition: opacity .3s;
}
.turn.them { --c: var(--them); }
.turn::before {
  content: "";
  position: absolute;
  left: 0; top: 4px; bottom: 4px;
  width: 3px;
  border-radius: 3px;
  background: var(--c);
}
.turn p { margin: 0; overflow-wrap: anywhere; }
.turn .orig { font-size: 16px; line-height: 1.35; color: var(--muted); }
.turn .trans {
  margin-top: 4px;
  font-size: 25px;
  line-height: 1.24;
  font-weight: 650;
  letter-spacing: -0.012em;
  color: var(--c);
  min-height: 31px;
}
.turn .nf { opacity: .45; }
.turn.old { opacity: .62; }
.turn.playing .trans { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 5px; text-decoration-color: color-mix(in srgb, var(--c) 40%, transparent); }
.turn .dots { display: inline-flex; gap: 4px; vertical-align: middle; }
.turn .dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--c); opacity: .35; animation: dot 1s infinite; }
.turn .dots i:nth-child(2) { animation-delay: .15s; }
.turn .dots i:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 30% { opacity: 1; transform: translateY(-2px); } }
@keyframes in { from { opacity: 0; transform: translateY(8px); } }

/* Footer */
#clear { position: absolute; left: 28px; bottom: calc(env(safe-area-inset-bottom) + 38px); }
footer {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 6px 16px calc(env(safe-area-inset-bottom) + 18px);
}
#status { margin: 0; min-height: 40px; text-align: center; font-size: 15px; line-height: 1.3; color: var(--muted); display: grid; }
#status-them { color: var(--faint); }
#status.error #status-me { color: var(--them); font-weight: 600; }

#mic {
  --lvl: 0;
  position: relative;
  width: 84px; height: 84px;
  border-radius: 50%;
  background: var(--mic);
  color: var(--mic-ink);
  display: grid;
  place-items: center;
  transition: transform .12s, background .2s;
}
#mic:active { transform: scale(.94); }
#mic svg { width: 34px; height: 34px; grid-area: 1 / 1; }
#mic .i-stop, #mic .i-bars, #mic .i-spin { display: none; grid-area: 1 / 1; }
#mic .ring {
  position: absolute; inset: 0;
  border-radius: 50%;
  background: var(--them);
  opacity: 0;
  z-index: -1;
  transform: scale(calc(1 + var(--lvl) * .55));
  transition: transform .09s linear, opacity .2s;
}
body[data-state="listening"] #mic { background: var(--them); color: #fff; }
body[data-state="listening"] #mic .ring { opacity: .22; }
body[data-state="listening"] #mic .i-mic { display: none; }
body[data-state="listening"] #mic .i-stop { display: block; }
body[data-state="speaking"] #mic .i-mic { display: none; }
body[data-state="speaking"] #mic .i-bars { display: flex; }
body[data-state="connecting"] #mic .i-mic { display: none; }
body[data-state="connecting"] #mic .i-spin { display: block; }
.i-bars { gap: 4px; align-items: center; height: 30px; }
.i-bars i { width: 5px; height: 100%; border-radius: 3px; background: currentColor; animation: bar .9s ease-in-out infinite; }
.i-bars i:nth-child(2) { animation-delay: .2s; }
.i-bars i:nth-child(3) { animation-delay: .4s; }
.i-bars i:nth-child(4) { animation-delay: .1s; }
@keyframes bar { 0%, 100% { transform: scaleY(.3); } 50% { transform: scaleY(1); } }
.i-spin { width: 28px; height: 28px; border-radius: 50%; border: 3px solid color-mix(in srgb, currentColor 25%, transparent); border-top-color: currentColor; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(1turn); } }

/* Access code */
dialog {
  border: 0;
  border-radius: 22px;
  padding: 24px;
  width: min(340px, calc(100vw - 32px));
  background: var(--bg);
  color: var(--ink);
  -webkit-user-select: auto;
  user-select: auto;
}
dialog::backdrop { background: rgb(0 0 0 / .5); }
dialog h2 { margin: 0 0 6px; font-size: 24px; letter-spacing: -0.02em; }
dialog p { margin: 0 0 14px; color: var(--muted); font-size: 15px; }
dialog input {
  width: 100%;
  font: 600 20px var(--font);
  letter-spacing: .08em;
  text-align: center;
  padding: 13px;
  border-radius: 14px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  outline: none;
}
dialog input:focus { border-color: var(--me); }
#lock-err { min-height: 20px; margin: 8px 0; color: var(--them); font-weight: 600; }
dialog button[type="submit"] { width: 100%; padding: 14px; border-radius: 14px; background: var(--mic); color: var(--mic-ink); font-weight: 650; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
@media (min-width: 700px) {
  main, header, footer { width: 100%; max-width: 640px; margin-inline: auto; }
}
