/* ── tokens ─────────────────────────────────────────────── */
:root {
  --bg: #0a0c11;
  --surface: #12151d;
  --surface-2: #1a1e29;
  --line: #262b39;
  --text: #f2f4f8;
  --muted: #8a92a6;

  --brand: #f0803c;
  --brand-hot: #ff9350;
  --top: #3d6ef5;
  --top-hot: #5b86ff;
  --bottom: #12a87f;
  --bottom-hot: #1dc796;
  --danger: #f05a5a;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, select { font: inherit; color: inherit; }
.hidden { display: none !important; }

.screen {
  position: fixed;
  inset: 0;
  height: 100dvh;
}

/* ── setup ──────────────────────────────────────────────── */
.setup {
  display: grid;
  justify-items: center;
  /* "safe" centres while it fits and falls back to the start once the paywall
     makes the content taller than the screen. Plain centring clips the
     overflow instead of letting it scroll. */
  align-content: safe center;
  padding: calc(24px + var(--safe-top)) 24px calc(32px + var(--safe-bottom));
  overflow-y: auto;
}

.setup-inner { width: 100%; max-width: 420px; text-align: center; }

.mark {
  display: block;
  margin: 0 auto 14px;
  border-radius: 22px;
  box-shadow: 0 10px 30px rgba(240, 128, 60, 0.28);
}

.logo {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.025em;
}
.logo span { color: var(--brand); }

.tagline {
  margin: 10px 0 30px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
}

.pickers { display: grid; gap: 10px; }

.picker {
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 18px;
  text-align: left;
}
.picker[data-side="top"]    { border-left: 4px solid var(--top); }
.picker[data-side="bottom"] { border-left: 4px solid var(--bottom); }

.picker-label {
  display: block;
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
  margin-bottom: 4px;
}
.picker-label em {
  font-style: normal;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0.01em;
  opacity: 0.75;
}

.picker-select {
  width: 100%;
  background: transparent;
  border: 0;
  font-size: 19px;
  font-weight: 600;
  padding: 2px 0;
  appearance: none;
}
.picker-select option { background: var(--surface-2); color: var(--text); }

.swap {
  justify-self: center;
  width: 42px;
  height: 42px;
  margin: -4px 0;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 17px;
  cursor: pointer;
}
.swap:active { transform: scale(0.92); }

.begin {
  width: 100%;
  margin-top: 28px;
  padding: 19px;
  border: 0;
  border-radius: 16px;
  background: var(--brand);
  color: #fff;
  font-size: 17px;
  font-weight: 650;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(240, 128, 60, 0.3);
}
.begin:active { transform: scale(0.985); filter: brightness(1.08); }

.setup-note {
  margin-top: 16px;
  min-height: 20px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
}
.setup-note.error { color: var(--danger); }

/* ── conversation layout ────────────────────────────────── */
.talk { display: flex; flex-direction: column; }

.talk-btn {
  flex: 0 0 17%;
  position: relative;
  border: 0;
  cursor: pointer;
  overflow: hidden;
  /* Stops the browser turning a long press into scroll, selection or a
     magnifier bubble -- all of which break hold-to-talk on phones. */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: flex-basis 0.25s ease, filter 0.15s ease;
}
.talk-btn.top    { background: var(--top);    padding-top: var(--safe-top); }
.talk-btn.bottom { background: var(--bottom); padding-bottom: var(--safe-bottom); }

/* A row rather than a stack: the button needs far less height this way, and
   every point it gives up goes to the translation. */
.talk-btn .btn-inner {
  height: 100%;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 0 18px;
}

.btn-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
}
.talk-btn.top.flipped .btn-inner { transform: rotate(180deg); }

.btn-flag { font-size: 50px; line-height: 1; }
.btn-name { font-size: 23px; font-weight: 700; letter-spacing: -0.015em; line-height: 1.1; }
.btn-hint {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13.5px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  opacity: 0.95;
}

.talk-btn.recording { flex-basis: 21%; }
.talk-btn.top.recording    { background: var(--top-hot); }
.talk-btn.bottom.recording { background: var(--bottom-hot); }
.talk-btn.recording .btn-hint { opacity: 1; font-weight: 700; }

/* The print is an instruction to press. Once they are pressing, it has served
   its purpose and the level bars take over as the feedback. */
.hint-print { flex: none; margin-bottom: -1px; }
.talk-btn.recording .hint-print { display: none; }

.talk-btn.locked { filter: grayscale(0.55) brightness(0.62); pointer-events: none; }

/* live microphone level, so you can see it is actually hearing you */
.level { display: flex; align-items: center; justify-content: center; gap: 3px; width: 30px; height: 22px; opacity: 0; transition: opacity 0.15s; }
.talk-btn.recording .level { opacity: 1; }
.level i {
  display: block;
  width: 4px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.9);
  transform-origin: bottom;
  transition: height 0.07s linear;
}

/* ── stage ──────────────────────────────────────────────── */
.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.stage-controls {
  display: flex;
  justify-content: space-between;
  padding: 8px 10px 0;
  flex: 0 0 auto;
}
.stage-controls-right { display: flex; gap: 6px; }

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn.on { color: var(--text); border-color: var(--brand); }

/* Named rather than a glyph, so there is no doubt what it does -- and faded,
   because leaving is not the action we are encouraging. */
.exit-btn {
  width: auto;
  padding: 0 13px;
  color: rgba(240, 90, 90, 0.72);
  border-color: rgba(240, 90, 90, 0.34);
  font-size: 11.5px;
  font-weight: 750;
  letter-spacing: 0.1em;
}
.exit-btn:active { background: rgba(240, 90, 90, 0.12); color: rgba(240, 90, 90, 0.95); }

.stage-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 10px 22px 18px;
  text-align: center;
}
.stage-body.flipped { transform: rotate(180deg); }

.stage-idle { color: var(--muted); font-size: 15px; }

.stage-source {
  font-size: 15px;
  color: var(--muted);
  line-height: 1.45;
  max-width: 34ch;
}

.stage-translation {
  font-size: clamp(27px, 7.8vw, 46px);
  font-weight: 650;
  line-height: 1.22;
  letter-spacing: -0.015em;
  max-width: 20ch;
}
.stage-translation.long { font-size: clamp(21px, 5.6vw, 33px); max-width: 26ch; }

.stage-status {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 14px;
}

.dots { display: inline-flex; gap: 4px; }
.dots i {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: bounce 1.1s infinite ease-in-out;
}
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%, 70%, 100% { opacity: 0.25; transform: translateY(0); } 35% { opacity: 1; transform: translateY(-4px); } }

.replay {
  margin-top: 4px;
  padding: 9px 17px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}
.replay:active { background: var(--surface-2); }

.stage-error { color: var(--danger); font-size: 14px; line-height: 1.5; max-width: 36ch; }

/* ── log ────────────────────────────────────────────────── */
.log {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}
.log-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.log-head h2 { font-size: 16px; font-weight: 650; }
.log-body { flex: 1; overflow-y: auto; padding: 14px 16px 40px; display: grid; gap: 12px; align-content: start; }

.log-turn {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
}
.log-turn.top    { border-left: 3px solid var(--top); }
.log-turn.bottom { border-left: 3px solid var(--bottom); }
.log-turn .who { font-size: 11px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); margin-bottom: 6px; }
.log-turn .src { font-size: 14px; color: var(--muted); line-height: 1.45; }
.log-turn .dst { font-size: 16px; line-height: 1.4; margin-top: 5px; }
.log-empty { color: var(--muted); font-size: 14px; text-align: center; padding-top: 30px; }

/* ── toast ──────────────────────────────────────────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20% + 14px);
  transform: translate(-50%, 8px);
  z-index: 30;
  max-width: 86vw;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(12px);
  border: 1px solid var(--line);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001s !important; transition-duration: 0.001s !important; }
}

/* ── voice picker ───────────────────────────────────────── */
.voice-row {
  margin-top: 18px;
  padding: 14px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  text-align: left;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-top: 8px;
  padding: 4px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.segmented button {
  padding: 10px 6px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.segmented button.on { background: var(--brand); color: #fff; }

.voice-pick {
  width: 100%;
  margin-top: 10px;
  padding: 11px 13px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 15px;
  appearance: none;
}
.voice-pick option { background: var(--surface-2); color: var(--text); }

.voice-hint {
  margin-top: 9px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--muted);
}

/* the replay button while the AI voice is still being fetched */
.replay.loading { opacity: 0.55; pointer-events: none; }

/* ── credits and paywall ────────────────────────────────── */
/* Everything here lives on the setup screen only. A conversation is never
   interrupted to ask for money -- see STRATEGY.md, finding 3. */
.balance {
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
}
.balance.low { color: var(--brand); }

.paywall {
  margin-top: 22px;
  padding: 22px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  text-align: left;
}
.paywall h2 { font-size: 19px; font-weight: 700; letter-spacing: -0.02em; }
.paywall-sub { margin-top: 7px; font-size: 14px; color: var(--muted); line-height: 1.5; }

.packs { margin-top: 18px; display: grid; gap: 11px; }
.pack {
  position: relative;
  display: block;
  width: 100%;
  padding: 16px 17px;
  border-radius: 14px;
  background: var(--bg);
  border: 1px solid var(--line);
  text-align: left;
  cursor: pointer;
}
.pack.featured { border-color: var(--brand); }
.pack-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.pack-name { font-size: 16px; font-weight: 650; }
.pack-price { font-size: 19px; font-weight: 750; color: var(--brand); }
.pack-blurb { margin-top: 3px; font-size: 13px; color: var(--muted); }
.pack-perks { margin-top: 9px; display: grid; gap: 4px; }
.pack-perks span { font-size: 12.5px; color: var(--muted); padding-left: 15px; position: relative; }
.pack-perks span::before { content: '✓'; position: absolute; left: 0; color: var(--bottom); }
.pack-tag {
  position: absolute; top: -9px; right: 14px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  font-size: 10.5px;
  font-weight: 650;
}

.redeem { margin-top: 16px; }
.redeem summary { font-size: 13px; color: var(--muted); cursor: pointer; }
.redeem form { margin-top: 10px; display: flex; gap: 8px; }
.redeem input {
  flex: 1;
  min-width: 0;
  padding: 11px 13px;
  border-radius: 11px;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 15px;
  text-transform: uppercase;
}
.redeem button {
  padding: 11px 17px;
  border: 0;
  border-radius: 11px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  font-weight: 620;
  cursor: pointer;
}
.redeem-note { margin-top: 9px; font-size: 13px; color: var(--muted); min-height: 18px; }
.redeem-note.good { color: var(--bottom); }
.redeem-note.bad { color: var(--danger); }

.begin[disabled] { opacity: 0.45; box-shadow: none; pointer-events: none; }

/* ── handoff ────────────────────────────────────────────── */
.handoff-link {
  margin-top: 14px;
  padding: 8px 4px;
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 13.5px;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.handoff-link:active { color: var(--text); }

.handoff {
  margin-top: 16px;
  padding: 22px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  text-align: center;
}
.handoff h2 { font-size: 18px; font-weight: 700; letter-spacing: -0.02em; }
.handoff-sub { margin-top: 7px; font-size: 13.5px; color: var(--muted); line-height: 1.5; }

.handoff-qr {
  width: 208px;
  height: 208px;
  margin: 18px auto 0;
  padding: 10px;
  background: #fff;
  border-radius: 14px;
}
.handoff-qr svg { display: block; width: 100%; height: 100%; }
.handoff-note { margin-top: 12px; font-size: 12.5px; color: var(--muted); line-height: 1.5; }

/* the paired-arrival confirmation */
.paired {
  margin-top: 16px;
  padding: 14px 16px;
  background: rgba(18, 168, 127, 0.1);
  border: 1px solid rgba(18, 168, 127, 0.4);
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  text-align: left;
}

/* ── credit counter ─────────────────────────────────────── */
/* Deliberately quiet: informative while testing, not a countdown that makes
   people ration their own conversation. */
.stage-controls-left { display: flex; align-items: center; gap: 8px; }
.credit-pill {
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.credit-pill.low { color: var(--brand); border-color: var(--brand); }
.credit-pill.out { color: var(--danger); border-color: var(--danger); }

/* ── group conversations ────────────────────────────────── */
/* In a group everyone is on their own phone, so there is only ever one
   button -- your own language. The two-button layout stays for the case this
   app started with: two people sharing one screen. */
.talk.group #btnTop { display: none; }
.talk.group #btnBottom { flex-basis: 19%; }
.talk.group .stage-body.flipped { transform: none; }

.group-bar {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 12px 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.group-bar::-webkit-scrollbar { display: none; }
.group-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.group-chip.me { border-color: var(--bottom); color: var(--text); }
.group-chip.speaking { border-color: var(--brand); color: var(--text); }
.group-chip .flag { font-size: 14px; }

.stage-speaker {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
}

/* ── share sheet and gifts ──────────────────────────────── */
.share-body { display: block; text-align: center; }
.share-lede { font-size: 14.5px; color: var(--muted); line-height: 1.5; max-width: 34ch; margin: 0 auto 18px; }
.share-actions, .gift-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 18px;
}
.mini-btn {
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}
.mini-btn:active { background: var(--line); }

.gift-amounts { display: flex; gap: 8px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.gift-amount {
  padding: 11px 17px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 15px;
  font-weight: 650;
  cursor: pointer;
}
.gift-amount:active, .gift-amount.on { border-color: var(--brand); color: var(--brand); }

.gift-result { margin-top: 16px; }
.gift-code {
  font-size: 26px;
  font-weight: 750;
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
  color: var(--brand);
}

#joinPanel .picker { margin-top: 14px; }
#joinPanel .begin { margin-top: 14px; }

.privacy-link { display: block; text-decoration: underline; }

/* ── arriving from an invitation ────────────────────────── */
/* Everything this app can otherwise do is noise to someone who has just been
   sent a link. One decision, one button. */
.setup.joining .pickers,
.setup.joining .voice-row,
.setup.joining .tagline,
.setup.joining #begin,
.setup.joining #balance,
.setup.joining #setupNote,
.setup.joining #giftOpen,
.setup.joining #gift,
.setup.joining .privacy-link,
.setup.joining #paywall { display: none; }

.setup.joining .mark { width: 62px; height: 62px; }
.setup.joining .logo { font-size: 25px; margin-bottom: 4px; }

.join-panel { margin-top: 20px; text-align: center; }
.join-panel h2 { font-size: 22px; line-height: 1.2; }
.join-panel .handoff-sub { font-size: 15px; margin-top: 9px; }
.join-panel .picker { margin-top: 20px; text-align: left; }
.join-panel .begin { margin-top: 16px; }
.join-how { margin-top: 14px; font-size: 13px; color: var(--muted); line-height: 1.5; }

/* ── slide off to cancel ────────────────────────────────── */
/* Holding and sliding off the button discards the recording, the way a voice
   note does. The colour change has to be unmistakable while your thumb is
   covering half the button. */
.talk-btn.top.cancelling,
.talk-btn.bottom.cancelling { background: #7f3434; }
.talk-btn.cancelling .btn-hint { opacity: 1; font-weight: 700; }
.talk-btn.cancelling .btn-flag { filter: grayscale(1); opacity: 0.55; }
.talk-btn.cancelling .level { opacity: 0.35; }

.stage-cancel {
  font-size: clamp(22px, 6vw, 32px);
  font-weight: 700;
  letter-spacing: -0.015em;
  color: #ff8a7a;
}

/* A gift is a price, not a slice of your own balance. */
.gift-amount { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 104px; }
.gift-amount b { font-size: 19px; font-weight: 750; }
.gift-amount span { font-size: 11.5px; font-weight: 500; color: var(--muted); }

/* ── choosing a voice ───────────────────────────────────── */
.voice-btn {
  width: auto;
  padding: 0 12px;
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.voice-btn.ai { color: var(--brand); border-color: rgba(240, 128, 60, 0.45); }

.voice-body { display: block; }
.voice-heading {
  margin: 22px 0 10px;
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
}
.voice-option {
  display: block;
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  margin-bottom: 8px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
  cursor: pointer;
}
.voice-option.on { border-color: var(--brand); }
.voice-option.on .voice-name::after { content: ' ✓'; color: var(--brand); }
.voice-name { display: block; font-size: 16px; font-weight: 620; }
.voice-note { display: block; margin-top: 3px; font-size: 12.5px; color: var(--muted); line-height: 1.4; }

/* Packs on the paywall are now buttons, not a price list. */
.pack { cursor: pointer; font: inherit; color: var(--text); }
.pack:active { transform: scale(0.99); }
.pack.featured:active { filter: brightness(1.06); }
