/* Live Translate — Glass Blue + simultaneous mic */
:root {
  --tr-night: #020617;
  --tr-glass: rgba(15, 23, 42, 0.42);
  --tr-glass-2: rgba(30, 58, 138, 0.28);
  --tr-stroke: rgba(186, 230, 253, 0.35);
  --tr-cyan: #22d3ee;
  --tr-sky: #38bdf8;
  --tr-ice: #e0f2fe;
  --tr-text: #f8fafc;
  --tr-muted: #94a3b8;
  --thai: #5eead4;
  --font-display: 'Outfit', system-ui, sans-serif;
  --font-thai: 'Sarabun', 'Thai', sans-serif;
  --tr-blur: blur(18px) saturate(1.35);
  --tr-radius: 22px;
  --tr-shadow: 0 18px 50px rgba(2, 6, 23, 0.45);
  --accent: #22d3ee;
  --border: var(--tr-stroke);
  --muted: var(--tr-muted);
  --text: var(--tr-text);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body.translate-page {
  font-family: var(--font-display);
  color: var(--tr-text);
  background: var(--tr-night);
  position: relative;
  overflow-x: hidden;
  padding: 12px 14px 56px;
}
.tr-ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(900px 520px at 12% -10%, rgba(56, 189, 248, 0.22), transparent 58%),
    radial-gradient(760px 480px at 95% 8%, rgba(37, 99, 235, 0.32), transparent 55%),
    radial-gradient(600px 400px at 50% 100%, rgba(14, 165, 233, 0.12), transparent 60%),
    linear-gradient(180deg, #020617 0%, #0b1229 45%, #020617 100%);
}
.wrap {
  position: relative;
  z-index: 1;
  max-width: 720px;
  margin: 0 auto;
}
.tr-glass-card {
  background: linear-gradient(155deg, rgba(255, 255, 255, 0.09), rgba(255, 255, 255, 0.02) 40%, var(--tr-glass-2));
  border: 1px solid var(--tr-stroke);
  backdrop-filter: var(--tr-blur);
  -webkit-backdrop-filter: var(--tr-blur);
  box-shadow: var(--tr-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  border-radius: var(--tr-radius);
}

.tm-hero-translate {
  margin: 0 0 14px;
  padding: 16px 16px 18px;
  background: linear-gradient(155deg, rgba(56, 189, 248, 0.14), transparent 42%, rgba(37, 99, 235, 0.18)) !important;
}
.tm-hero-translate .tm-kicker {
  color: var(--tr-cyan);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.68rem;
  margin: 0 0 6px;
}
.tm-hero-translate h1 {
  margin: 0 0 8px;
  font-size: clamp(1.55rem, 4.2vw, 2.1rem);
  font-weight: 800;
  color: #fff;
}
.tm-hero-translate h1 .th {
  display: block;
  font-family: var(--font-thai);
  font-size: 0.72em;
  margin-top: 4px;
  color: var(--tr-ice);
}
.tm-lead {
  color: var(--tr-muted);
  font-weight: 600;
  line-height: 1.4;
  margin: 0;
}
.tm-lead .th {
  display: block;
  font-family: var(--font-thai);
  margin-top: 4px;
}
.tm-nav a { color: var(--tr-ice); opacity: 0.85; }
.tm-nav a.active { color: var(--tr-cyan); opacity: 1; }
.tm-dark-btn {
  border: 1px solid var(--tr-stroke);
  background: rgba(255,255,255,0.08);
  color: var(--tr-ice);
  border-radius: 10px;
  padding: 6px 10px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}

.tr-panel {
  margin-top: 0;
  padding: 14px;
  display: flex;
  flex-direction: column;
  min-height: min(72vh, 680px);
}
.tr-panel-head h2 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 800;
  color: #fff;
}
.tr-sub {
  margin: 4px 0 12px;
  color: var(--tr-muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.tr-dir-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  margin: 0 0 8px;
}
.tr-dir-btn, #trFlip {
  border: 1px solid var(--tr-stroke);
  background: rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  padding: 8px 6px;
  cursor: pointer;
  font: inherit;
  text-align: center;
  color: var(--tr-ice);
}
.tr-dir-btn.active, #trFlip {
  border-color: var(--tr-cyan);
  background: rgba(34, 211, 238, 0.15);
}
.tr-dir-btn strong, #trFlip strong { display: block; font-size: 0.85rem; color: #fff; }
.tr-dir-btn em, #trFlip em {
  display: block;
  font-style: normal;
  font-size: 0.72rem;
  color: var(--tr-muted);
  font-family: var(--font-thai);
  margin-top: 2px;
}
#trFlip { width: 100%; margin-bottom: 10px; }

.tr-live-cta {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  margin: 0 0 12px;
  padding: 16px 18px;
  border-radius: 18px;
  border: 1px solid rgba(34, 211, 238, 0.55);
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.45), rgba(29, 78, 216, 0.4));
  color: #fff;
  cursor: pointer;
  font: inherit;
  text-align: left;
  overflow: hidden;
  box-shadow: 0 10px 28px rgba(14, 165, 233, 0.25);
}
.tr-live-cta:hover { filter: brightness(1.06); }
.tr-live-pulse {
  position: absolute;
  width: 64px;
  height: 64px;
  left: 10px;
  border-radius: 50%;
  background: rgba(34, 211, 238, 0.25);
  animation: trPulse 1.6s ease-out infinite;
  pointer-events: none;
}
@keyframes trPulse {
  0% { transform: scale(0.6); opacity: 0.7; }
  100% { transform: scale(1.8); opacity: 0; }
}
body.tr-listening .tr-live-pulse {
  animation-duration: 0.9s;
  background: rgba(248, 113, 113, 0.35);
}
.tr-live-ico { font-size: 1.8rem; position: relative; z-index: 1; }
.tr-live-copy { display: flex; flex-direction: column; gap: 2px; position: relative; z-index: 1; }
.tr-live-copy strong { font-size: 1.05rem; font-weight: 800; }
.tr-live-copy em { font-style: normal; font-size: 0.8rem; color: #bae6fd; font-weight: 600; }

.tr-live-preview {
  margin-bottom: 10px;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid rgba(34, 211, 238, 0.45);
  background: rgba(8, 47, 73, 0.55);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.06);
}
.tr-live-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.tr-live-badge {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #042f2e;
  background: var(--tr-cyan);
  border-radius: 999px;
  padding: 3px 8px;
}
body.tr-listening .tr-live-badge {
  background: #fb7185;
  color: #fff;
  animation: trBlink 1s ease infinite;
}
@keyframes trBlink {
  50% { opacity: 0.65; }
}
.tr-live-hint { font-size: 0.72rem; color: var(--tr-muted); font-weight: 700; }
.tr-live-lbl {
  display: block;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--tr-muted);
  margin-bottom: 2px;
}
.tr-live-heard {
  margin: 0 0 10px;
  font-weight: 700;
  font-size: 1rem;
  color: #e0f2fe;
  line-height: 1.35;
  min-height: 1.35em;
}
.tr-live-out {
  margin: 0;
  font-family: var(--font-thai);
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--thai);
  line-height: 1.4;
  min-height: 1.4em;
}
.tr-live-out.pending { opacity: 0.55; }

.tr-chat {
  flex: 1;
  min-height: 180px;
  max-height: min(36vh, 320px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 6px;
  margin-bottom: 8px;
  border-radius: 14px;
  border: 1px solid rgba(186, 230, 253, 0.2);
  background: rgba(2, 6, 23, 0.35);
}
.tr-empty {
  margin: auto;
  text-align: center;
  color: var(--tr-muted);
  padding: 24px 12px;
}
.tr-empty strong { display: block; color: #fff; margin-bottom: 6px; font-size: 1.05rem; }
.tr-empty p { margin: 0; font-size: 0.9rem; line-height: 1.45; }
.tr-bubble {
  max-width: 92%;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--tr-stroke);
  background: rgba(15, 23, 42, 0.65);
  animation: trIn 0.2s ease;
}
@keyframes trIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
.tr-bubble.you {
  align-self: flex-end;
  background: rgba(56, 189, 248, 0.16);
  border-color: rgba(56, 189, 248, 0.45);
}
.tr-bubble.bot { align-self: flex-start; }
.tr-meta { font-size: 0.7rem; font-weight: 700; color: var(--tr-muted); margin-bottom: 3px; }
.tr-text { font-weight: 700; font-size: 1rem; line-height: 1.35; word-break: break-word; color: #fff; }
.tr-text.th { font-family: var(--font-thai); color: var(--thai); font-size: 1.1rem; }
.tr-actions { display: flex; gap: 6px; margin-top: 6px; }
.tr-act {
  border: 1px solid var(--tr-stroke);
  background: rgba(255,255,255,0.08);
  border-radius: 8px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--tr-ice);
}

.tr-compose {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 6px;
  align-items: end;
  margin-bottom: 8px;
}
.tr-compose textarea {
  width: 100%;
  min-height: 52px;
  resize: vertical;
  border: 1px solid var(--tr-stroke);
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
  font-weight: 600;
  background: rgba(15, 23, 42, 0.65);
  color: var(--tr-ice);
}
#trMicBtn, #trSendBtn {
  min-height: 56px;
  min-width: 64px;
  border-radius: 14px;
  border: 1px solid var(--tr-stroke);
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  color: var(--tr-ice);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 6px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
#trSendBtn {
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.55), rgba(59, 130, 246, 0.5));
  border-color: var(--tr-cyan);
  color: #fff;
  font-size: 1.2rem;
}
#trMicBtn.listening {
  background: rgba(248, 113, 113, 0.25);
  border-color: #fb7185;
  color: #fecaca;
  box-shadow: 0 0 0 2px rgba(248, 113, 113, 0.35);
}
#trMicBtn.holding {
  transform: scale(1.04);
  background: rgba(239, 68, 68, 0.4);
}
.tr-mic-ico { font-size: 1.2rem; line-height: 1; }
.tr-mic-lbl { font-size: 0.62rem; line-height: 1.1; }

.tr-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--tr-ice);
}
.tr-toolbar label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.tr-tool-sec {
  border: 1px solid var(--tr-stroke);
  background: rgba(255,255,255,0.06);
  border-radius: 10px;
  padding: 6px 10px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  color: var(--tr-ice);
}

.tr-status {
  min-height: 1.2em;
  margin: 0 0 10px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--tr-muted);
}
.tr-status.ok { color: #4ade80; }
.tr-status.bad { color: #fb7185; }
.tr-status.busy { color: var(--tr-cyan); }

.tr-tips {
  margin-top: 4px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(34, 211, 238, 0.08);
  border: 1px dashed rgba(34, 211, 238, 0.4);
  font-size: 0.82rem;
  color: var(--tr-ice);
}
.tr-tips strong { display: block; margin-bottom: 4px; color: var(--tr-cyan); }
.tr-tips ul { margin: 0; padding-left: 18px; color: var(--tr-muted); font-weight: 600; }
.tr-tips li { margin: 3px 0; }
.tr-tips b { color: #fff; }

.tr-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin-top: 18px;
  padding: 12px 4px 8px;
  font-size: 0.85rem;
  color: var(--tr-muted);
  border-top: 1px solid rgba(186, 230, 253, 0.15);
}
.tr-footer a { color: var(--tr-cyan); font-weight: 700; text-decoration: none; }

.mobile-dock {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 9998;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px));
  background: color-mix(in srgb, #020617 92%, transparent);
  backdrop-filter: blur(14px);
  border-top: 2px solid color-mix(in srgb, #22d3ee 55%, transparent);
}
.mobile-dock button, .mobile-dock a.dock-link {
  min-height: 56px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.08);
  color: #e2e8f0;
  border-radius: 14px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  font-size: 0.62rem;
  line-height: 1.1;
  padding: 4px 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  text-decoration: none;
}
.mobile-dock a.dock-link.primary {
  background: color-mix(in srgb, #0ea5e9 55%, transparent);
  border-color: #22d3ee;
}
.dock-ico { font-size: 1.1rem; }
.dock-th { font-family: var(--font-thai); font-size: 0.68rem; }

.tr-menu-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(2, 6, 23, 0.65);
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
}
.tr-menu-overlay.open { display: flex; }
.tr-menu-sheet {
  width: min(480px, 100%);
  background: linear-gradient(160deg, #0b1229, #020617);
  border: 1px solid var(--tr-stroke);
  border-radius: 18px;
  padding: 16px;
  color: var(--tr-text);
  box-shadow: var(--tr-shadow);
}
.tr-menu-sheet h3 { margin: 0 0 12px; }
.tr-menu-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.tr-menu-grid a {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--tr-stroke);
  text-decoration: none;
  color: inherit;
  font-weight: 700;
  background: rgba(255,255,255,0.04);
}
.tr-menu-grid a .th { font-family: var(--font-thai); }
.tr-menu-grid a .en { font-size: 0.75rem; color: var(--tr-muted); }
.tr-menu-close {
  width: 100%;
  margin-top: 12px;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--tr-stroke);
  background: rgba(34, 211, 238, 0.2);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
  font-family: inherit;
}

@media (max-width: 900px) {
  .mobile-dock { display: grid; }
  body.translate-page { padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px)); }
}
@media (max-width: 640px) {
  body.translate-page { padding: 10px; padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px)); }
  .tr-dir-row { grid-template-columns: 1fr; }
  #trMicBtn { min-width: 72px; min-height: 64px; }
}
@media (min-width: 901px) {
  .mobile-dock { display: none !important; }
}
