/* Alligator — porcelain & graphite. One accent, used only for "live". */

:root {
  --bg: #f3f1ec;
  --bg-deep: #ebe8e1;
  --ink: #141414;
  --ink-2: #6d6a64;
  --ink-3: #a9a59d;
  --hair: rgba(20, 20, 20, 0.09);
  --glass: rgba(250, 249, 246, 0.72);
  --glass-edge: rgba(255, 255, 255, 0.9);
  --shadow:
    0 1px 1px rgba(0, 0, 0, 0.04), 0 12px 32px -8px rgba(40, 32, 20, 0.18);
  --btn: #141414;
  --btn-ink: #f6f4ef;
  --live: #ff4f1f;
  --pause: #c9a15a;

  --serif:
    "Newsreader", "Iowan Old Style", "Palatino", "Noto Serif", Georgia, serif;
  --sans: "Geist", "Helvetica Neue", "Noto Sans", sans-serif;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --gutter: clamp(20px, 4vw, 56px);
  --lv: 0;

  color-scheme: light;
}

/* Dark tokens: follow the system in Auto, or force with data-theme. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0d0e;
    --bg-deep: #141415;
    --ink: #eeebe4;
    --ink-2: #8f8b83;
    --ink-3: #56534e;
    --hair: rgba(238, 235, 228, 0.1);
    --glass: rgba(28, 28, 30, 0.66);
    --glass-edge: rgba(255, 255, 255, 0.07);
    --shadow:
      0 1px 1px rgba(0, 0, 0, 0.3), 0 16px 40px -10px rgba(0, 0, 0, 0.7);
    --btn: #eeebe4;
    --btn-ink: #0d0d0e;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d0d0e;
  --bg-deep: #141415;
  --ink: #eeebe4;
  --ink-2: #8f8b83;
  --ink-3: #56534e;
  --hair: rgba(238, 235, 228, 0.1);
  --glass: rgba(28, 28, 30, 0.66);
  --glass-edge: rgba(255, 255, 255, 0.07);
  --shadow:
    0 1px 1px rgba(0, 0, 0, 0.3), 0 16px 40px -10px rgba(0, 0, 0, 0.7);
  --btn: #eeebe4;
  --btn-ink: #0d0d0e;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
  background:
    radial-gradient(120% 80% at 50% 120%, var(--bg-deep), transparent 60%),
    var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* A whisper of grain so the surface reads as material, not a screen. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  z-index: 10;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}
button:focus-visible,
select:focus-visible + *,
.lang:focus-within {
  outline: 2px solid color-mix(in srgb, var(--ink) 40%, transparent);
  outline-offset: 3px;
}

/* ───────────── Header ───────────── */

.bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: max(18px, env(safe-area-inset-top)) var(--gutter) 18px;
  animation: rise 0.9s var(--ease) both;
}

.brand {
  position: relative;
  justify-self: start;
}
.mark {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: -6px -10px -6px -6px;
  padding: 6px 10px 6px 6px;
  border: 0;
  border-radius: 12px;
  background: none;
  color: var(--ink);
  font-weight: 500;
  letter-spacing: -0.01em;
  font-size: 16px;
  transition: background 0.25s var(--ease);
}
.mark:hover,
.mark[aria-expanded="true"] {
  background: var(--hair);
}
.mark[aria-expanded="true"] .mark-glyph {
  animation: chomp 0.7s var(--ease);
}
.mark-glyph {
  display: inline-block;
  font-size: 22px;
  line-height: 1;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
  transform-origin: 50% 80%;
}
/* While listening, the gator swims gently along. */
body[data-state="live"] .mark-glyph {
  animation: swim 2.4s var(--ease) infinite;
}

.pair {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: var(--glass);
  box-shadow: inset 0 0 0 1px var(--hair);
  transition: opacity 0.4s var(--ease);
}

.lang {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.25s var(--ease);
  border-radius: 999px;
}
.lang:hover {
  background: var(--hair);
}
.lang::after {
  content: "";
  width: 5px;
  height: 5px;
  border-right: 1.5px solid var(--ink-2);
  border-bottom: 1.5px solid var(--ink-2);
  transform: translateY(-2px) rotate(45deg);
  margin-left: 2px;
}
.lang select {
  position: absolute;
  inset: 0;
  width: 100%;
  opacity: 0;
  cursor: pointer;
  font-size: 16px; /* prevents iOS zoom */
}
.lang-name {
  white-space: nowrap;
}

.swap {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  transition:
    transform 0.5s var(--ease),
    background 0.25s;
}
.swap:hover {
  background: var(--hair);
}
.swap:active {
  transform: rotate(180deg);
}
.swap svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: var(--ink-2);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.source {
  position: relative;
  justify-self: end;
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  border-radius: 999px;
  background: var(--hair);
  font-size: 13px;
  transition: opacity 0.4s var(--ease);
}
.source button {
  position: relative;
  z-index: 1;
  border: 0;
  background: none;
  padding: 7px 14px;
  border-radius: 999px;
  color: var(--ink-2);
  white-space: nowrap;
  transition: color 0.3s var(--ease);
}
.source button[aria-checked="true"] {
  color: var(--ink);
}
.source-thumb {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 3px;
  width: calc(50% - 3px);
  border-radius: 999px;
  background: var(--bg);
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.08),
    0 0 0 0.5px var(--hair);
  transition: transform 0.45s var(--ease);
}
body[data-source="meeting"] .source-thumb {
  transform: translateX(100%);
}

body:not([data-state="idle"]) .pair,
body:not([data-state="idle"]) .source {
  opacity: 0.4;
  pointer-events: none;
}

/* ───────────── Stage ───────────── */

.stage {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1px 1fr;
  grid-template-areas: "a seam b";
  min-height: 0;
}

.pane {
  position: relative;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 8px var(--gutter) 0;
  animation: fade 1.1s var(--ease) 0.1s both;
}
#pane-a {
  grid-area: a;
}
#pane-b {
  grid-area: b;
  animation-delay: 0.18s;
}

.seam {
  grid-area: seam;
  margin: 24px 0 140px;
  background: linear-gradient(
    transparent,
    var(--hair) 20%,
    var(--hair) 80%,
    transparent
  );
}

.pane-label {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.feed {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: none;
  padding: 40px 0 180px;
  mask-image: linear-gradient(
    transparent,
    #000 90px,
    #000 calc(100% - 150px),
    transparent
  );
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.feed::-webkit-scrollbar {
  display: none;
}
.feed > :first-child {
  margin-top: auto;
}

.placeholder {
  position: absolute;
  left: var(--gutter);
  right: var(--gutter);
  top: 42%;
  margin: 0;
  font-family: var(--serif);
  font-weight: 300;
  font-style: italic;
  font-size: clamp(40px, 6vw, 84px);
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--ink-3);
  opacity: 0.55;
  pointer-events: none;
  transition:
    opacity 0.6s var(--ease),
    transform 0.8s var(--ease);
}
.pane.has-content .placeholder {
  opacity: 0;
  transform: translateY(-12px);
}

/* An utterance. Latest is large and dark; history recedes. */
.turn {
  position: relative;
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(18px, 1.5vw, 21px);
  line-height: 1.42;
  font-weight: 400;
  color: var(--ink-2);
  letter-spacing: -0.005em;
  transition:
    color 0.6s var(--ease),
    font-size 0.5s var(--ease);
  animation: enter 0.6s var(--ease) both;
  text-wrap: pretty;
}
.turn.recent {
  color: var(--ink);
  font-size: clamp(24px, 2.35vw, 34px);
  line-height: 1.28;
  letter-spacing: -0.012em;
}
.turn .p {
  opacity: 0.42;
  transition: opacity 0.3s;
}

/* Provenance: filled dot = spoken in this language, ring = translated.
   With diarization the dot takes the speaker's colour. */
.turn .line {
  position: relative;
  margin: 0;
}
.turn .line::before {
  content: "";
  position: absolute;
  left: -18px;
  top: 0.62em;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  box-sizing: border-box;
}
.turn.spoken .line::before {
  background: var(--spk, var(--ink-3));
}
.turn.translated .line::before {
  border: 1.2px solid var(--spk, var(--ink-3));
}

/* Speaker label: opens each run of turns by one speaker; click to rename. */
.who,
.who-edit {
  display: block;
  margin: 0 0 6px;
  padding: 0;
  border: 0;
  background: none;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  line-height: 1.4;
  color: var(--spk, var(--ink-2));
}
.who {
  cursor: text;
  text-decoration: underline dotted transparent;
  text-underline-offset: 3px;
  transition: text-decoration-color 0.2s, opacity 0.4s var(--ease);
}
.who:hover {
  text-decoration-color: currentColor;
}
.turn:not(.recent) .who {
  opacity: 0.75;
}
.turn[data-editing] .who {
  display: none;
}
.who-edit {
  width: 16ch;
  outline: none;
  border-bottom: 1px solid currentColor;
  text-transform: none;
  letter-spacing: 0.02em;
  font-size: 12px;
}
.who-edit::placeholder {
  color: var(--ink-3);
}
.turn .tag {
  font-family: var(--sans);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  vertical-align: 0.4em;
  margin-right: 8px;
  color: var(--ink-3);
}

.break {
  align-self: center;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
}
.break::before,
.break::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--hair);
}

/* ───────────── Controls ───────────── */

.deck {
  position: absolute;
  left: 50%;
  bottom: max(28px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  z-index: 5;
  animation: rise-deck 1.1s var(--ease) 0.25s both;
}

.controls {
  display: flex;
  align-items: center;
  padding: 8px;
  border-radius: 999px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(24px) saturate(1.6);
  backdrop-filter: blur(24px) saturate(1.6);
  box-shadow:
    var(--shadow),
    inset 0 0 0 0.5px var(--glass-edge),
    inset 0 0 0 1px var(--hair);
}

.ctl {
  position: relative;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}
.ctl svg {
  width: 22px;
  height: 22px;
}

.ctl-main {
  width: 68px;
  height: 68px;
  background: var(--btn);
  color: var(--btn-ink);
  transition:
    transform 0.35s var(--ease),
    background 0.3s;
}
.ctl-main:hover {
  transform: scale(1.04);
}
.ctl-main:active {
  transform: scale(0.96);
}
.ctl-main svg {
  fill: currentColor;
  grid-area: 1 / 1;
  transition:
    opacity 0.25s,
    transform 0.4s var(--ease);
}
.ctl-main .i-pause {
  opacity: 0;
  transform: scale(0.6);
}
body[data-state="live"] .ctl-main .i-play {
  opacity: 0;
  transform: scale(0.6);
}
body[data-state="live"] .ctl-main .i-pause {
  opacity: 1;
  transform: none;
}
body[data-state="connecting"] .ctl-main svg,
body[data-state="stopping"] .ctl-main svg {
  opacity: 0;
}

/* Input level: a soft halo that breathes with the voice. */
.level {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  pointer-events: none;
  box-shadow: 0 0 0 calc(2px + var(--lv) * 14px)
    color-mix(in srgb, var(--live) 18%, transparent);
  opacity: 0;
  transition:
    box-shadow 0.12s linear,
    opacity 0.4s;
}
body[data-state="live"] .level {
  opacity: 1;
}

.spinner {
  grid-area: 1 / 1;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--btn-ink) 30%, transparent);
  border-top-color: var(--btn-ink);
  opacity: 0;
  animation: spin 0.8s linear infinite;
  transition: opacity 0.2s;
}
body[data-state="connecting"] .spinner,
body[data-state="stopping"] .spinner {
  opacity: 1;
}

.ctl-stop {
  width: 0;
  height: 44px;
  margin: 0;
  background: transparent;
  color: var(--ink);
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
  transition:
    width 0.5s var(--ease),
    margin 0.5s var(--ease),
    opacity 0.3s,
    background 0.25s;
}
.ctl-stop svg {
  fill: currentColor;
  width: 18px;
  height: 18px;
}
.ctl-stop:hover {
  background: var(--hair);
}

.clock {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 0;
  overflow: hidden;
  opacity: 0;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
  white-space: nowrap;
  transition:
    width 0.5s var(--ease),
    opacity 0.3s,
    padding 0.5s var(--ease);
}
.clock .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink-3);
  flex: none;
}
body[data-state="live"] .clock .dot {
  background: var(--live);
  animation: pulse 1.6s ease-in-out infinite;
}
body[data-state="paused"] .clock .dot {
  background: var(--pause);
}

body:is([data-state="live"], [data-state="paused"]) .ctl-stop {
  width: 44px;
  margin: 0 12px 0 4px;
  opacity: 1;
  pointer-events: auto;
}
body:is([data-state="live"], [data-state="paused"], [data-state="stopping"])
  .clock {
  width: 76px;
  opacity: 1;
  padding-left: 16px;
}

.status {
  margin: 0;
  font-size: 12.5px;
  color: var(--ink-3);
  letter-spacing: 0.01em;
  text-align: center;
  min-height: 1.2em;
  transition: opacity 0.4s;
}

.save {
  position: fixed;
  right: var(--gutter);
  bottom: max(40px, env(safe-area-inset-bottom));
  border: 0;
  background: none;
  font-size: 13px;
  color: var(--ink-2);
  padding: 8px 4px;
  text-decoration: underline;
  text-decoration-color: var(--hair);
  text-underline-offset: 4px;
  z-index: 6;
}
.save:hover {
  color: var(--ink);
  text-decoration-color: currentColor;
}

.toast {
  position: fixed;
  top: 84px;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 32px));
  padding: 12px 18px;
  border-radius: 14px;
  background: var(--btn);
  color: var(--btn-ink);
  font-size: 13.5px;
  line-height: 1.4;
  box-shadow: var(--shadow);
  z-index: 20;
  animation: drop 0.5s var(--ease) both;
}

/* ───────────── Face-to-face (portrait, in the room) ─────────────
   Lay the device flat between two people. The top half turns to face
   the person across the table; the controls sit on the seam. */

@media (max-aspect-ratio: 1/1), (max-width: 760px) {
  .bar {
    grid-template-columns: 1fr auto;
    row-gap: 12px;
  }
  .pair {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-self: center;
  }
  .lang {
    padding: 7px 10px;
  }

  .stage {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto 1fr;
    grid-template-areas: "a" "seam" "b";
  }
  .seam {
    margin: 0 var(--gutter);
    height: 1px;
    background: var(--hair);
  }
  .feed {
    padding: 24px 0 24px;
    mask-image: linear-gradient(transparent, #000 48px);
  }
  .placeholder {
    top: 30%;
  }

  body[data-source="meeting"] .feed {
    padding-bottom: 150px;
  }
  body[data-source="meeting"] #pane-b .feed {
    padding-bottom: 150px;
  }
  body[data-source="meeting"] #pane-a .feed {
    padding-bottom: 24px;
  }

  body[data-layout="split"][data-source="room"] .stage {
    grid-template-rows: 1fr auto 1fr;
    grid-template-areas: "a" "deck" "b";
  }
  body[data-layout="split"][data-source="room"] .seam {
    display: none;
  }
  body[data-layout="split"][data-source="room"] #pane-a {
    transform: rotate(180deg);
  }
  body[data-layout="split"][data-source="room"] .deck {
    grid-area: deck;
    position: relative;
    left: auto;
    bottom: auto;
    transform: none;
    padding: 10px 0;
    animation: none;
  }
  body[data-layout="split"][data-source="room"] .deck::before,
  body[data-layout="split"][data-source="room"] .deck::after {
    content: "";
    position: absolute;
    top: 50%;
    width: calc(50vw - 150px);
    height: 1px;
    background: var(--hair);
  }
  body[data-layout="split"][data-source="room"] .deck::before {
    right: calc(100% + 16px);
  }
  body[data-layout="split"][data-source="room"] .deck::after {
    left: calc(100% + 16px);
  }
  body[data-layout="split"][data-source="room"] .status {
    display: none;
  }
  body[data-layout="split"][data-source="room"] .save {
    bottom: auto;
    top: max(18px, env(safe-area-inset-top));
    right: 50%;
    transform: translateX(50%);
  }

  .turn.recent {
    font-size: 24px;
  }
}

@media (max-width: 420px) {
  .source button {
    padding: 7px 10px;
  }
  .mark {
    font-size: 0;
    gap: 0;
  }
}

/* ───────────── Motion ───────────── */

@keyframes fade { from { opacity: 0; filter: blur(4px); } }
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}
@keyframes rise-deck {
  from {
    opacity: 0;
    transform: translate(-50%, 16px);
  }
}
@keyframes enter {
  from {
    opacity: 0;
    transform: translateY(8px);
    filter: blur(3px);
  }
}
@keyframes drop {
  from {
    opacity: 0;
    transform: translate(-50%, -8px);
  }
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}
@keyframes swim {
  50% {
    transform: translate(2px, -1.5px) rotate(-3deg);
  }
}

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

.turn .tag:empty {
  display: none;
}

/* Give the provenance dots room inside the scroll box. */
.feed {
  padding-inline: 20px;
  margin-inline: -20px;
}

/* ───────────── Header tools & options ───────────── */

.tools {
  position: relative;
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 8px;
}

.opts-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--hair);
  color: var(--ink-2);
  transition: background 0.25s var(--ease), color 0.25s, transform 0.4s var(--ease);
}
.opts-btn:hover,
.opts-btn[aria-expanded="true"] {
  color: var(--ink);
  background: color-mix(in srgb, var(--ink) 14%, transparent);
}
.opts-btn[aria-expanded="true"] svg {
  transform: rotate(90deg);
}
.opts-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  transition: transform 0.5s var(--ease);
}

.opts {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 30;
  width: min(308px, calc(100vw - 32px));
  padding: 18px;
  border-radius: 20px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: blur(28px) saturate(1.6);
  backdrop-filter: blur(28px) saturate(1.6);
  box-shadow: var(--shadow), inset 0 0 0 0.5px var(--glass-edge), inset 0 0 0 1px var(--hair);
  transform-origin: top right;
  animation: pop 0.35s var(--ease) both;
}
.opts[hidden] {
  display: none;
}
.opt + .opt {
  margin-top: 18px;
}
.opt-label {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
  padding: 3px;
  border-radius: 12px;
  background: var(--hair);
}
.seg button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 8px 6px;
  border: 0;
  border-radius: 9px;
  background: none;
  color: var(--ink-2);
  font-size: 13px;
  transition: background 0.25s var(--ease), color 0.25s, box-shadow 0.25s;
}
.seg button:hover {
  color: var(--ink);
}
.seg button[aria-checked="true"] {
  background: var(--bg);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 0 0 0.5px var(--hair);
}
.seg svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
}

.opt-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--hair);
}
.opt-label-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 14px;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink);
}
.opt-note {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--ink-3);
}
.opt-note:empty {
  display: none;
}

.switch {
  position: relative;
  flex: none;
  width: 44px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: color-mix(in srgb, var(--ink) 16%, transparent);
  transition: background 0.3s var(--ease);
}
.switch span {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--bg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform 0.35s var(--ease), background 0.3s;
}
.switch[aria-checked="true"] {
  background: var(--ink);
}
.switch[aria-checked="true"] span {
  transform: translateX(18px);
}

/* Plain-language tooltip: hover or keyboard focus on desktop, tap on touch. */
.tip {
  position: relative;
  display: inline-flex;
}
.tip-btn {
  display: grid;
  place-items: center;
  width: 17px;
  height: 17px;
  padding: 0;
  border: 1px solid var(--ink-3);
  border-radius: 50%;
  background: none;
  color: var(--ink-2);
  font-family: var(--serif);
  font-style: italic;
  font-size: 11px;
  line-height: 1;
  cursor: help;
}
.tip-body {
  position: absolute;
  left: -14px;
  bottom: calc(100% + 10px);
  z-index: 40;
  width: min(260px, calc(100vw - 48px));
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--btn);
  color: var(--btn-ink);
  box-shadow: var(--shadow);
  font-size: 12.5px;
  font-weight: 400;
  line-height: 1.45;
  opacity: 0;
  visibility: hidden;
  transform: translateY(4px);
  transition: opacity 0.2s, transform 0.3s var(--ease), visibility 0.2s;
  pointer-events: none;
}
.tip:hover .tip-body,
.tip-btn:focus-visible + .tip-body,
.tip.open .tip-body {
  opacity: 1;
  visibility: visible;
  transform: none;
}

/* ───────────── Stacked view ─────────────
   One centred column: each turn shows what was said, then its translation. */

#pane-s {
  display: none;
  grid-area: s;
  width: 100%;
  max-width: 860px;
  justify-self: center;
}
body[data-layout="stacked"] .stage,
body[data-layout="stacked"][data-source] .stage {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
  grid-template-areas: "s";
}
body[data-layout="stacked"] #pane-a,
body[data-layout="stacked"] #pane-b,
body[data-layout="stacked"] .seam {
  display: none;
}
body[data-layout="stacked"] #pane-s {
  display: flex;
}

.pane-label-sep {
  margin: 0 4px;
}

#pane-s .feed {
  padding-left: 48px;
  margin-left: -48px;
}
.turn-s .line + .line {
  margin-top: 6px;
}
.turn-s .code {
  position: absolute;
  left: -40px;
  top: 0.55em;
  width: 28px;
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 500;
  font-style: normal;
  letter-spacing: 0.1em;
  line-height: 1;
  text-align: right;
  color: var(--ink-3);
}
.turn-s .dst {
  font-style: italic;
  color: color-mix(in srgb, currentColor 78%, transparent);
}
.turn-s .dst[hidden] {
  display: none;
}

.placeholder-stack span {
  display: block;
}
.placeholder-stack span + span {
  margin-top: 0.12em;
  margin-left: 0.6em;
  opacity: 0.6;
}

/* Theme & view changes crossfade (View Transitions; instant elsewhere). */
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 0.45s;
  animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(-6px) scale(0.97);
  }
}

@media (max-aspect-ratio: 1/1), (max-width: 760px) {
  body[data-layout="stacked"] #pane-s .feed {
    padding-bottom: 150px;
  }
  #pane-s .feed {
    padding-left: 20px;
    margin-left: -20px;
  }
  .turn-s .code {
    position: static;
    display: inline-block;
    width: auto;
    margin-right: 8px;
    vertical-align: 0.35em;
  }
  body[data-layout="stacked"] .deck {
    position: absolute;
    left: 50%;
    bottom: max(28px, env(safe-area-inset-bottom));
    transform: translateX(-50%);
  }
}

/* Keep the header (and its options panel and tooltip) above the transcript. */
.bar {
  position: relative;
  z-index: 20;
}

/* Anchor the tooltip to its whole row so it never runs off-screen. */
.opt-row {
  position: relative;
}
.opt-row .tip {
  position: static;
}
.opt-row .tip-body {
  left: -4px;
  right: -4px;
  width: auto;
}

/* ───────────── API key ───────────── */

.pill-btn {
  flex: none;
  padding: 7px 14px;
  border: 0;
  border-radius: 999px;
  background: color-mix(in srgb, var(--ink) 10%, transparent);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  transition: background 0.25s var(--ease);
}
.pill-btn:hover {
  background: color-mix(in srgb, var(--ink) 16%, transparent);
}
.opt-note-key {
  font-variant-numeric: tabular-nums;
}

.sheet {
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  margin: auto;
  padding: 28px 28px 22px;
  border: 0;
  border-radius: 24px;
  background: var(--bg);
  color: var(--ink);
  box-shadow: var(--shadow), 0 0 0 1px var(--hair);
  overflow: auto;
}
.sheet[open] {
  animation: sheet-in 0.45s var(--ease) both;
}
.sheet::backdrop {
  background: color-mix(in srgb, #000 35%, transparent);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  animation: fade-in 0.3s ease both;
}
.sheet-title {
  margin: 0 0 8px;
  font-family: var(--serif);
  font-weight: 400;
  font-size: 28px;
  letter-spacing: -0.015em;
  line-height: 1.15;
}
.sheet-lead {
  margin: 0 0 20px;
  color: var(--ink-2);
  font-size: 14px;
  line-height: 1.5;
}

.field {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 4px 4px 14px;
  border-radius: 14px;
  background: var(--hair);
  box-shadow: inset 0 0 0 1px transparent;
  transition: box-shadow 0.2s;
}
.field:focus-within {
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--ink) 45%, transparent);
}
.field input {
  flex: 1;
  min-width: 0;
  padding: 10px 0;
  border: 0;
  outline: none;
  background: none;
  color: var(--ink);
  font: 15px/1.2 ui-monospace, "SF Mono", Menlo, monospace;
}
.field input::placeholder {
  color: var(--ink-3);
  font-family: var(--sans);
}
.field-btn {
  padding: 8px 12px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--ink-2);
  font-size: 13px;
}
.field-btn:hover {
  color: var(--ink);
  background: var(--hair);
}

.key-status {
  min-height: 1.4em;
  margin: 8px 2px 4px;
  font-size: 13px;
  color: var(--ink-2);
}
.key-status[data-tone="error"] {
  color: #c4472b;
}
.key-status[data-tone="ok"] {
  color: #3f8f5a;
}
.key-status[data-tone="ok"]::before {
  content: "✓ ";
}

.howto {
  margin: 4px 0 0;
  border-top: 1px solid var(--hair);
  border-bottom: 1px solid var(--hair);
  font-size: 14px;
  line-height: 1.5;
}
.howto summary {
  padding: 13px 2px;
  cursor: pointer;
  font-weight: 500;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.howto summary::-webkit-details-marker {
  display: none;
}
.howto summary::after {
  content: "";
  width: 6px;
  height: 6px;
  border-right: 1.5px solid var(--ink-2);
  border-bottom: 1.5px solid var(--ink-2);
  transform: translateY(-2px) rotate(45deg);
  transition: transform 0.3s var(--ease);
}
.howto[open] summary::after {
  transform: translateY(1px) rotate(225deg);
}
.howto ol {
  margin: 0 0 10px;
  padding-left: 22px;
}
.howto li + li {
  margin-top: 6px;
}
.howto li::marker {
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.howto p {
  margin: 0 0 14px;
  color: var(--ink-2);
  font-size: 13px;
}
.howto a {
  color: inherit;
  text-underline-offset: 3px;
}

.sheet-fine {
  margin: 14px 2px 20px;
  font-size: 12.5px;
  color: var(--ink-3);
  line-height: 1.45;
}

.sheet-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.sheet-actions .spacer {
  flex: 1;
}
.btn {
  padding: 10px 18px;
  border: 0;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.2s, opacity 0.2s, transform 0.2s var(--ease);
}
.btn:active {
  transform: scale(0.97);
}
.btn-solid {
  background: var(--btn);
  color: var(--btn-ink);
}
.btn-solid:disabled {
  opacity: 0.5;
  cursor: progress;
}
.btn-ghost {
  background: var(--hair);
  color: var(--ink);
}
.btn-quiet {
  padding-inline: 4px;
  background: none;
  color: var(--ink-2);
  font-weight: 400;
}
.btn-quiet:hover {
  color: #c4472b;
}
.btn[hidden] {
  display: none;
}

@keyframes sheet-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
}
@keyframes fade-in {
  from {
    opacity: 0;
  }
}

/* ───────────── Privacy & open source ───────────── */

.lock {
  position: relative;
  display: inline-block;
  flex: none;
  width: 9px;
  height: 7px;
  margin-top: 4px;
  border-radius: 1.5px;
  background: currentColor;
}
.lock::before {
  content: "";
  position: absolute;
  left: 1.5px;
  bottom: 100%;
  width: 6px;
  height: 5px;
  box-sizing: border-box;
  border: 1.4px solid currentColor;
  border-bottom: 0;
  border-radius: 3.5px 3.5px 0 0;
}

.about-link {
  position: fixed;
  left: var(--gutter);
  bottom: max(40px, env(safe-area-inset-bottom));
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 4px;
  border: 0;
  background: none;
  color: var(--ink-3);
  font-size: 13px;
  transition: color 0.25s, opacity 0.4s var(--ease);
}
.about-link:hover {
  color: var(--ink);
}
/* Out of the way while a session runs. */
body:not([data-state="idle"]) .about-link {
  opacity: 0;
  pointer-events: none;
}

.opts-about {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin-top: 16px;
  padding: 14px 0 0;
  border: 0;
  border-top: 1px solid var(--hair);
  background: none;
  color: var(--ink-2);
  font-size: 13px;
  text-align: left;
}
.opts-about:hover {
  color: var(--ink);
}

.facts {
  margin: 0 0 22px;
  padding: 0;
  list-style: none;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink-2);
}
.facts li {
  padding: 12px 0;
  border-top: 1px solid var(--hair);
}
.facts b {
  display: block;
  margin-bottom: 2px;
  color: var(--ink);
  font-weight: 500;
}
.facts a {
  color: inherit;
  text-underline-offset: 3px;
}
a.btn {
  display: inline-block;
  text-decoration: none;
}

.inline-link {
  display: inline;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-2);
  font-size: inherit;
  text-decoration: underline;
  text-decoration-color: var(--hair);
  text-underline-offset: 3px;
}
.inline-link:hover {
  color: var(--ink);
  text-decoration-color: currentColor;
}

@media (max-aspect-ratio: 1/1), (max-width: 760px) {
  /* Face-to-face layout puts text right at the bottom edge; the link stays in Options. */
  body[data-layout="split"][data-source="room"] .about-link {
    display: none;
  }
}

/* ───────────── Why "Alligator"? ───────────── */

.name-note {
  position: absolute;
  top: calc(100% + 12px);
  left: -6px;
  z-index: 30;
  width: min(300px, calc(100vw - 32px));
  padding: 16px 18px;
  border-radius: 18px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: blur(28px) saturate(1.6);
  backdrop-filter: blur(28px) saturate(1.6);
  box-shadow: var(--shadow), inset 0 0 0 0.5px var(--glass-edge), inset 0 0 0 1px var(--hair);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink-2);
  transform-origin: top left;
  animation: pop 0.35s var(--ease) both;
}
.name-note[hidden] {
  display: none;
}
.name-note p {
  margin: 0;
}
.name-note b {
  color: var(--ink);
  font-weight: 500;
}
.name-note-title {
  margin-bottom: 6px !important;
  font-family: var(--serif);
  font-size: 20px;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.name-note-fine {
  margin-top: 10px !important;
  font-size: 12.5px;
  color: var(--ink-3);
}

@keyframes chomp {
  20% {
    transform: rotate(-12deg) scale(1.1);
  }
  45% {
    transform: rotate(8deg) scale(1.1);
  }
  70% {
    transform: rotate(-4deg);
  }
}

/* ───────────── Pop-out ───────────── */

.ctl[hidden] {
  display: none;
}
.ctl-pop {
  width: 44px;
  height: 44px;
  margin-left: 6px;
  background: transparent;
  color: var(--ink-2);
  transition: background 0.25s, color 0.25s;
}
.ctl-pop:hover,
.ctl-pop[aria-pressed="true"] {
  background: var(--hair);
  color: var(--ink);
}
.ctl-pop svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
}
.ctl-pop svg .fill {
  fill: currentColor;
  stroke: none;
}

/* Main window while the conversation is popped out (stacked view). */
.popped {
  grid-area: s;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 var(--gutter) 160px;
  text-align: center;
  animation: fade 0.8s var(--ease) both;
}
body[data-pip][data-layout="stacked"] .popped {
  display: flex;
}
.popped-title {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(24px, 3vw, 34px);
  font-weight: 400;
  letter-spacing: -0.015em;
  color: var(--ink);
}
.popped-text {
  max-width: 38ch;
  margin: 0 0 8px;
  color: var(--ink-2);
  font-size: 14px;
  line-height: 1.5;
}

/* The pop-out window itself: a compact bar, then the stacked conversation. */
body.pip {
  grid-template-rows: auto auto 1fr;
}
.pip-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 10px 10px 10px 16px;
  border-bottom: 1px solid var(--hair);
  font-size: 12.5px;
  color: var(--ink-2);
}
.pip-bar .spacer {
  flex: 1;
}
.pip-status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-variant-numeric: tabular-nums;
}
.pip-status .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink-3);
}
body.pip[data-state="live"] .pip-status .dot {
  background: var(--live);
  animation: pulse 1.6s ease-in-out infinite;
}
body.pip[data-state="paused"] .pip-status .dot {
  background: var(--pause);
}
.pip-langs,
.pip-hint {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.pip-hint {
  display: none;
  color: var(--ink-3);
}
body.pip[data-state="idle"] .pip-hint {
  display: block;
}
body.pip[data-state="idle"] .pip-langs,
body.pip[data-state="idle"] .pip-status {
  display: none;
}
.pip-btn {
  display: grid;
  place-items: center;
  flex: none;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--hair);
  color: var(--ink);
}
.pip-btn svg {
  grid-area: 1 / 1;
  width: 14px;
  height: 14px;
  fill: currentColor;
}
.pip-main {
  background: var(--btn);
  color: var(--btn-ink);
}
.pip-main .i-pause,
body.pip[data-state="live"] .pip-main .i-play {
  display: none;
}
body.pip[data-state="live"] .pip-main .i-pause {
  display: block;
}
body.pip:is([data-state="idle"], [data-state="connecting"], [data-state="stopping"]) .pip-btn {
  display: none;
}
.pip-msg {
  margin: 0;
  padding: 8px 16px;
  background: var(--btn);
  color: var(--btn-ink);
  font-size: 12.5px;
  line-height: 1.4;
}
.pip-msg[hidden] {
  display: none;
}

.pip #pane-s {
  display: flex;
  max-width: none;
  padding: 0 16px;
}
.pip #pane-s .pane-label {
  display: none;
}
.pip #pane-s .feed {
  padding: 14px 20px 18px;
  margin-inline: -20px;
  gap: 16px;
  mask-image: linear-gradient(transparent, #000 28px);
}
.pip .turn {
  font-size: 15px;
}
.pip .turn.recent {
  font-size: 20px;
  line-height: 1.3;
}
.pip .turn-s .code {
  position: static;
  display: inline-block;
  width: auto;
  margin-right: 8px;
  vertical-align: 0.3em;
}
.pip .placeholder {
  top: 26%;
  font-size: 34px;
}
.pip .pip-bar {
  grid-row: 1;
}
.pip .pip-msg {
  grid-row: 2;
}
.pip #pane-s {
  grid-area: 3 / 1; /* not the main window's named "s" area */
  justify-self: stretch;
  min-height: 0;
}
