/* LangTai LiveTranslate (/live) — same white · pastel · thin-glass system as / and /developer.
 * Southern speech becomes Central Thai. No boxes: each line is coloured text with a big speaker number
 * on its left, one pastel hue per speaker. Southern lines are the main thing: left, big, in the speaker's
 * colour. Central lines (the original ASR text, no translation) sit on the right, smaller and quieter
 * (no labels). One speaker can have lines on both sides. The newest line is the biggest, low in the middle; as new lines arrive the older ones
 * slide up, shrink and fade. The heard (ASR) text is a light grey line above its translation.
 * Translation and ASR text use Noto Sans Thai; everything else keeps IBM Plex Sans Thai. Plain white page.
 * While listening, a pastel glow rises from the bottom edge of the screen like a sound wave: each
 * part of it follows its own band of the real mic spectrum, heavily blurred and faded upward. */

/* Noto Sans Thai (OFL 1.1, self-hosted from @fontsource/noto-sans-thai 5.3.0, Thai subset). */
@font-face { font-family: 'LangTai Read'; font-style: normal; font-weight: 500; font-display: swap;
  src: url('fonts/noto-sans-thai-500-thai.woff2') format('woff2'); unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: 'LangTai Read'; font-style: normal; font-weight: 600; font-display: swap;
  src: url('fonts/noto-sans-thai-600-thai.woff2') format('woff2'); unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC; }

.live-page {
  --fade: cubic-bezier(.45, 0, .25, 1);
  --dock-h: 176px;
  min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column;
  background: var(--white); overflow-x: clip;
}

.site-head { z-index: 30; }

/* ---------- icon buttons (same as /) ---------- */
.icon-btn {
  position: relative; width: 44px; height: 44px; flex: none; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 12px; background: transparent; color: var(--ink-2);
  transition: background-color .15s var(--ease), color .15s var(--ease), transform .15s var(--ease), opacity .3s var(--fade);
}
.icon-btn:not(:disabled):hover { background: rgba(29, 29, 31, .05); color: var(--ink); }
.icon-btn:not(:disabled):active { transform: scale(.96); }
.icon-btn:disabled { opacity: .32; cursor: default; }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
#clearBtn.is-armed { background: rgba(180, 35, 24, .08); color: var(--danger); }
#copyBtn .check-icon { display: none; }
#copyBtn.is-done .copy-icon { display: none; }
#copyBtn.is-done .check-icon { display: block; color: #146C43; stroke-width: 2.2; }
/* Keep the dock balanced: speaker button shows and supports sticky auto-speak */
.slot .speech-btn[hidden] { display: inline-flex !important; }
.speech-btn .speech-stop { display: none; }
.speech-btn[data-state="loading"]:not(.is-auto-speak) .speech-icon,
.speech-btn[data-state="playing"]:not(.is-auto-speak) .speech-icon { display: none; }
.speech-btn[data-state="loading"]:not(.is-auto-speak) .speech-stop,
.speech-btn[data-state="playing"]:not(.is-auto-speak) .speech-stop { display: block; }
.speech-btn[aria-pressed="true"] {
  color: var(--accent);
  background: rgba(18, 87, 168, .12);
  box-shadow: 0 0 0 2px rgba(18, 87, 168, .2);
}
.speech-btn.is-auto-speak .speech-icon { display: block !important; }
.speech-btn.is-auto-speak .speech-stop { display: none !important; }
.speech-btn.is-speaking {
  animation: speech-pulse 1.2s infinite ease-in-out;
}
@keyframes speech-pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.08); color: #1F7FD6; }
  100% { transform: scale(1); }
}

/* ---------- main column: a fixed stage between header and dock ---------- */
.live-main {
  position: relative; z-index: 1; width: 100%; max-width: calc(820px + var(--gutter) * 2);
  height: calc(100vh - 64px); height: calc(100dvh - 64px);
  margin: 0 auto; padding: 0 var(--gutter) calc(var(--dock-h) + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column;
}

/* ---------- welcome (dissolves when the first line lands) ---------- */
.welcome {
  position: absolute; inset: 0 var(--gutter) calc(var(--dock-h) + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  transition: opacity .7s var(--fade), filter .7s var(--fade), transform .7s var(--fade);
}
.welcome.is-gone { opacity: 0; filter: blur(10px); transform: translateY(-12px) scale(.985); pointer-events: none; }
.welcome-logo { display: inline-flex; margin-bottom: 14px; }
.welcome-logo .lt-logo { width: 64px; height: 64px; }
.welcome-title { font-size: clamp(26px, 3.6vw, 36px); line-height: 1.4; font-weight: 600; letter-spacing: 0; text-wrap: balance; }
.seg { white-space: nowrap; }
.welcome-sub { margin-top: 10px; font-size: 17px; line-height: 1.7; color: var(--ink-2); }

.motion .welcome-logo { animation: lv-rise .8s var(--ease) both; }
.motion .welcome-title { animation: lv-rise .8s var(--ease) .06s both; }
.motion .welcome-sub { animation: lv-rise .7s var(--ease) .14s both; }
@keyframes lv-rise { from { opacity: 0; transform: translateY(18px); filter: blur(6px); } }

/* ---------- conversation: bottom-anchored, older lines stay readable ---------- */
.stream {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: none;
  display: flex; flex-direction: column; gap: 22px; padding: 96px 0 28px;
}
.stream::-webkit-scrollbar { display: none; }
.stream > :first-child { margin-top: auto; }

/* Speaker hues: --n is the big pastel numeral, --c the readable text tone of the same hue. */
.line { --n: #F6B3CF; --c: #C2588A; }
.line[data-hue="1"] { --n: #A9D2F7; --c: #3E7FC2; }
.line[data-hue="2"] { --n: #CDBDF5; --c: #7B5FCB; }
.line[data-hue="3"] { --n: #A8E2C9; --c: #2C916D; }
.line[data-hue="4"] { --n: #FBDB8E; --c: #B27D12; }
.line[data-hue="5"] { --n: #FFC4A8; --c: #C8683E; }

.line {
  display: flex; align-items: flex-start; gap: 14px; max-width: 86%;
  opacity: .72; transition: opacity .8s var(--fade), filter .8s var(--fade), transform .6s var(--ease);
  animation: line-in .8s var(--ease) backwards;
}
.line.is-left { align-self: flex-start; }
.line.is-right { align-self: flex-end; }
.line.is-right .line-body { text-align: right; }
.line:hover { opacity: .8; }
.line.is-latest { opacity: 1; }
@keyframes line-in { from { opacity: 0; transform: translateY(24px); filter: blur(10px); } }
/* Heard, translation still on its way: a quiet breathing ellipsis in the big slot. */
.line.is-pending .line-text { color: var(--ink-3); animation: pending 1.4s ease-in-out infinite; }
@keyframes pending { 50% { opacity: .35; } }
.line.is-failed .line-text { color: var(--ink-3); font-size: 15px; font-weight: 500; }
.line.is-leaving { opacity: 0 !important; filter: blur(8px); transform: translateY(-10px); }

/* Live partial speech recognition (Step 3: faint, neutral placement, no flickering) */
.line.is-partial {
  align-self: center;
  max-width: 82%;
  opacity: .55;
  filter: blur(0.2px);
  animation: line-in .3s var(--ease) backwards;
  transition: opacity .3s var(--fade);
}
.line.is-partial .line-num {
  font-size: 22px;
  color: var(--ink-3);
  opacity: .6;
}
.line.is-partial .line-body {
  text-align: center;
}
.line.is-partial .line-heard {
  font-size: 18px;
  font-weight: 500;
  line-height: 1.5;
  color: var(--ink-2);
}

.line-num {
  flex: none; min-width: .62em; font-family: var(--font); font-size: 30px; font-weight: 700; line-height: 1.12;
  color: var(--n); font-variant-numeric: tabular-nums;
  transition: font-size .7s var(--ease);
}
.line-body { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.line-heard, .line-text { font-family: 'LangTai Read', var(--font); overflow-wrap: anywhere; }
.line-heard { font-size: 14px; font-weight: 500; line-height: 1.6; color: #A3A6AC; transition: font-size .7s var(--ease); }
.line-text, .line.is-central .line-heard { font-size: 19px; font-weight: 600; line-height: 1.5; color: var(--c); transition: font-size .7s var(--ease); }
.line.is-central .line-heard { color: var(--ink-3); }
.is-latest .line-num { font-size: clamp(52px, 7vw, 68px); }
.is-latest .line-heard { font-size: 17px; }
.is-latest .line-text { font-size: clamp(28px, 4.4vw, 42px); line-height: 1.42; }

/* Central is the secondary side: what the other person said, shown as heard, never as big as Southern. */
.line.is-central { max-width: 74%; }
.line.is-central .line-num { font-size: 22px; opacity: .8; }
.line.is-central .line-heard { font-size: 16px; font-weight: 500; }
.is-latest.is-central .line-num { font-size: clamp(26px, 3.4vw, 32px); }
.is-latest.is-central .line-heard { font-size: clamp(17px, 2.2vw, 21px); line-height: 1.5; color: var(--ink-2); }

.line-meta {
  font-size: 11px; font-weight: 500; line-height: 1.4; color: #A3A6AC; opacity: .78;
  display: inline-flex; align-items: center; gap: 5px; margin-top: 3px; font-family: var(--font);
}
.line.is-right .line-meta { justify-content: flex-end; }
.line-meta-arm { font-weight: 600; }
.line-meta-score { font-variant-numeric: tabular-nums; opacity: .88; }

/* ---------- dock: glass pill, dark mic ---------- */
.live-dock {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); z-index: 20;
  transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 10px;
  width: max-content; max-width: calc(100vw - 32px);
}
.motion .live-dock { animation: dock-in .8s var(--ease) .2s both; }
@keyframes dock-in { from { opacity: 0; transform: translate(-50%, 18px); filter: blur(6px); } }

.dock-ring { position: relative; border-radius: var(--r-pill); }

/* ---------- voice wave: pastel light along the bottom edge of the screen ---------- */
/* Drawn small on a canvas by live.js, then blurred and faded upward here. It runs a little past both
 * sides so the blur never shows an edge. */
.voice-wave {
  position: fixed; left: -48px; bottom: 0; z-index: 0; width: calc(100% + 96px); height: 260px; pointer-events: none;
  opacity: 0; filter: blur(28px) saturate(110%);
  -webkit-mask-image: linear-gradient(to top, #000 0%, rgba(0, 0, 0, .6) 38%, transparent 92%);
          mask-image: linear-gradient(to top, #000 0%, rgba(0, 0, 0, .6) 38%, transparent 92%);
  transition: opacity 1.1s var(--fade);
}
.live-page[data-mode="listening"] .voice-wave { opacity: 1; }

.dock-pill {
  position: relative; display: flex; align-items: center; padding: 10px; border-radius: var(--r-pill);
  background: rgba(255, 255, 255, .92); border: 1px solid rgba(255, 255, 255, .9);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .95), 0 1px 2px rgba(29, 29, 31, .05), 0 18px 44px rgba(29, 29, 31, .1);
}
@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .dock-pill { background: rgba(255, 255, 255, .62); backdrop-filter: blur(20px) saturate(160%); -webkit-backdrop-filter: blur(20px) saturate(160%); }
}
/* At first the dock is just the mic; speaker and copy slide out once listening starts. */
.slot {
  width: 0; height: 44px; margin: 0; flex: none; display: inline-flex; justify-content: center; overflow: hidden;
  opacity: 0; visibility: hidden; transform: scale(.6);
  transition: width .6s var(--ease), margin .6s var(--ease), opacity .4s var(--fade), transform .6s var(--ease), visibility 0s linear .6s;
}
.live-page.is-open .slot {
  width: 44px; margin: 0 8px; opacity: 1; visibility: visible; transform: none;
  transition: width .6s var(--ease), margin .6s var(--ease), opacity .5s var(--fade) .12s, transform .6s var(--ease), visibility 0s;
}

.live-mic {
  position: relative; width: 72px; height: 72px; flex: none; padding: 0; border: 0; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center; background: var(--ink); color: #fff;
  box-shadow: 0 1px 2px rgba(29, 29, 31, .16), 0 10px 24px rgba(29, 29, 31, .18);
  transition: background-color .2s var(--ease), box-shadow .5s var(--fade);
}
.live-mic:hover { background: #343437; }
.live-mic svg { position: relative; z-index: 1; width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round;
  transition: opacity .3s var(--fade), transform .4s var(--ease); }
.live-mic .pause-icon { position: absolute; fill: currentColor; stroke: none; opacity: 0; transform: scale(.7); }
.live-page[data-mode="listening"] .live-mic .mic-icon { opacity: 0; transform: scale(.7); }
.live-page[data-mode="listening"] .live-mic .pause-icon { opacity: 1; transform: none; }
.live-page[data-mode="starting"] .live-mic { background: #55555A; cursor: progress; }

.dock-notes { position: relative; display: flex; flex-direction: column; align-items: center; min-height: 24px; }
.live-status { margin: 0; min-height: 24px; max-width: calc(100vw - 32px); padding: 0 12px; font-size: 14px; line-height: 1.7; color: var(--ink-2); text-align: center;
  transition: opacity .3s var(--fade); }
.live-status.error { color: var(--danger); }
.dock-notes:has(.speech-note:not([hidden])) #status { display: none; }

/* ---------- phone ---------- */
@media (max-width: 600px) {
  .live-page { --dock-h: 172px; }
  .line { max-width: 92%; gap: 10px; }
  .line-num { font-size: 24px; }
  .is-latest .line-num { font-size: 48px; }
  .is-latest .line-heard { font-size: 15px; }
  .is-latest .line-text { font-size: 28px; }
  .line.is-central { max-width: 84%; }
  .is-latest.is-central .line-num { font-size: 24px; }
  .is-latest.is-central .line-heard { font-size: 16px; }
  .live-page.is-open .slot { margin: 0 4px; }
}
