:root {
  --bg: #0b0b12;
  --panel: #15151f;
  --panel-2: #1b1b29;
  --text: #f4f4f8;
  --muted: #9a9ab0;
  --src: #8ab4ff;
  --dst: #7ef0c2;
  --accent: #6366f1;
  --danger: #ff5c72;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --ease: cubic-bezier(0.5, 0.15, 0.2, 1);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  user-select: none;
}

.app {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding: calc(var(--safe-top) + 12px) 16px calc(var(--safe-bottom) + 12px);
  max-width: 720px;
  margin: 0 auto;
  overflow: hidden;
}

/* ---- Status pill (top-right; only connecting/error) ---- */
.status {
  position: fixed;
  top: calc(var(--safe-top) + 16px);
  right: 16px;
  z-index: 30;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  white-space: nowrap;
  max-width: 60vw;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.status.show {
  opacity: 1;
}
.status--connecting {
  color: #ffd479;
}
.status--error {
  color: var(--danger);
  background: rgba(255, 92, 114, 0.12);
}

/* ---- Stage: hidden when idle, fades in when active ---- */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  opacity: 0;
  transform: translateY(16px);
  pointer-events: none;
  transition: opacity 0.4s ease 0.08s, transform 0.4s ease 0.08s;
}
.app.live .stage {
  opacity: 1;
  transform: none;
  pointer-events: auto;
  padding-top: 52px;
}

/* ---- Translation: the streaming hero (bounded + scrolls) ---- */
.translation {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--panel-2);
  border: 1px solid rgba(126, 240, 194, 0.18);
  border-radius: 18px;
  padding: 18px;
}
.translation__lang {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
  position: sticky;
  top: 0;
}
.translation__text {
  margin: 0;
  font-size: 26px;
  line-height: 1.42;
  font-weight: 600;
  color: var(--dst);
  white-space: pre-wrap;
  user-select: text;
  -webkit-user-select: text;
}
.translation__text:empty::before {
  content: "Listening…";
  color: var(--muted);
  font-weight: 500;
  opacity: 0.6;
}

/* ---- Original (heard): collapsible, collapsed by default ---- */
.original {
  flex: none;
  margin-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}
.dock {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 12px;
}
.orig-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  cursor: pointer;
  padding: 6px 4px;
}
.orig-toggle__chev {
  display: inline-block;
  transition: transform 0.25s var(--ease);
  font-size: 11px;
}
.original[data-open="true"] .orig-toggle__chev {
  transform: rotate(90deg);
}
.original__body {
  max-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transition: max-height 0.3s var(--ease);
}
.original[data-open="true"] .original__body {
  max-height: 34vh;
  margin-top: 8px;
}
.original__text {
  margin: 0;
  font-size: 17px;
  line-height: 1.45;
  color: var(--src);
  white-space: pre-wrap;
  user-select: text;
  -webkit-user-select: text;
}

/* ---- Language picker: idle only, centered under the mic ---- */
.lang-dock {
  position: fixed;
  left: 50%;
  top: calc(50% + 100px);
  transform: translateX(-50%);
  z-index: 30;
  transition: opacity 0.3s ease;
}
.app.live .lang-dock {
  opacity: 0;
  pointer-events: none;
}
.lang {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}
.lang__label {
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.lang select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--panel);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  padding: 8px 30px 8px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%239a9ab0' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

/* ---- Mute toggle (in the original dock) ---- */
.speaker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: var(--panel);
  font-size: 18px;
  cursor: pointer;
  touch-action: manipulation;
  flex: none;
}
.speaker .speaker__off {
  display: none;
}
.speaker[aria-pressed="true"] .speaker__on {
  display: none;
}
.speaker[aria-pressed="true"] .speaker__off {
  display: inline;
}
.speaker[aria-pressed="true"] {
  opacity: 0.6;
}

/* ---- Mic / Stop button: fixed; morphs big-center -> small top-left ---- */
.mic {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 128px;
  height: 128px;
  border-radius: 50%;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(99, 102, 241, 0.4);
  z-index: 40;
  touch-action: manipulation;
  transition: top 0.5s var(--ease), left 0.5s var(--ease), width 0.5s var(--ease),
    height 0.5s var(--ease), transform 0.5s var(--ease), background 0.3s ease,
    box-shadow 0.3s ease;
}
.mic:active {
  transform: translate(-50%, -50%) scale(0.96);
}
.app.live .mic {
  left: calc(var(--safe-left) + 16px);
  top: calc(var(--safe-top) + 12px);
  width: 48px;
  height: 48px;
  transform: translate(0, 0);
  background: var(--danger);
  box-shadow: 0 4px 16px rgba(255, 92, 114, 0.45);
  animation: live-pulse 2s infinite;
}
.app.live .mic:active {
  transform: scale(0.92);
  animation: none;
}
.mic.is-busy {
  background: #4b4b66;
  box-shadow: none;
  animation: none;
}
.mic__icons {
  display: grid;
}
.mic__icon {
  grid-area: 1 / 1;
  width: 36px;
  height: 36px;
  transition: width 0.5s var(--ease), height 0.5s var(--ease);
}
.app.live .mic__icon {
  width: 20px;
  height: 20px;
}
.icon-stop {
  display: none;
}
.app.live .icon-mic {
  display: none;
}
.app.live .icon-stop {
  display: block;
}
.app.live .mic__label {
  display: none;
}

@keyframes live-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(255, 92, 114, 0.5);
  }
  70% {
    box-shadow: 0 0 0 12px rgba(255, 92, 114, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(255, 92, 114, 0);
  }
}
@media (prefers-reduced-motion: reduce) {
  .mic,
  .cluster,
  .stage,
  .lang-dock {
    transition: none;
  }
  .app.live .mic {
    animation: none;
  }
}

/* ---- Access-key gate ---- */
.keygate {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(8, 8, 14, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.keygate[hidden] {
  display: none;
}
.keygate__card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  padding: 22px;
}
.keygate__title {
  margin: 0 0 4px;
  font-size: 18px;
}
.keygate__hint {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 14px;
}
.keygate__input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}
.keygate__row {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}
.keygate__btn {
  flex: 1;
  padding: 12px;
  border-radius: 12px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.keygate__btn--ghost {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--muted);
}
