:root {
  --bg: #07070d;
  --glass-bg: rgba(255, 255, 255, 0.06);
  --glass-stroke: rgba(255, 255, 255, 0.14);
  --text: rgba(255, 255, 255, 0.92);
  --muted: rgba(255, 255, 255, 0.5);
  --accent: #6ea8ff;
  --accent-2: #b58bff;
  --listening: #4cd6a0;
  --speaking: #ffb86b;
  --translating: #b58bff;
  --radius: 22px;
  --blur: 22px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI',
    Roboto, sans-serif;
  overflow: hidden;
}

body {
  background:
    radial-gradient(120% 80% at 50% -10%, #16162a 0%, #07070d 60%) fixed;
}

/* ambient blobs */
.blobs {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.55;
  animation: drift 18s ease-in-out infinite alternate;
}

.blob-1 {
  width: 50vmax;
  height: 50vmax;
  left: -10vmax;
  top: -12vmax;
  background: radial-gradient(circle, #3a5bff, transparent 70%);
}

.blob-2 {
  width: 42vmax;
  height: 42vmax;
  right: -12vmax;
  top: 18vmax;
  background: radial-gradient(circle, #b14bff, transparent 70%);
  animation-delay: -6s;
}

.blob-3 {
  width: 46vmax;
  height: 46vmax;
  left: 10vmax;
  bottom: -18vmax;
  background: radial-gradient(circle, #16c7a0, transparent 70%);
  animation-delay: -11s;
}

@keyframes drift {
  from {
    transform: translate3d(0, 0, 0) scale(1);
  }
  to {
    transform: translate3d(4vmax, 5vmax, 0) scale(1.15);
  }
}

/* glass primitive */
.glass {
  background: var(--glass-bg);
  border: 1px solid var(--glass-stroke);
  backdrop-filter: blur(var(--blur)) saturate(160%);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(160%);
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

/* layout */
.app {
  position: relative;
  z-index: 1;
  height: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 18px) 18px
    calc(env(safe-area-inset-bottom) + 18px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.topbar {
  border-radius: var(--radius);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.title {
  font-size: 17px;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.2px;
}

.lang-flow {
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* controls */
.controls {
  display: flex;
  gap: 12px;
  align-items: stretch;
}

.segmented {
  flex: 1;
  display: flex;
  border-radius: 16px;
  padding: 4px;
  gap: 4px;
}

.seg-btn {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  padding: 10px 6px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.25s ease;
}

.seg-btn.active {
  color: var(--text);
  background: rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.intercept {
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 16px;
  padding: 0 14px;
  cursor: pointer;
  user-select: none;
}

.intercept-label {
  font-size: 12px;
  color: var(--muted);
  max-width: 70px;
  line-height: 1.2;
}

.intercept input {
  display: none;
}

.switch {
  width: 42px;
  height: 24px;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.15);
  position: relative;
  transition: background 0.25s ease;
  flex: none;
}

.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.25s ease;
}

.intercept input:checked + .switch {
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
}

.intercept input:checked + .switch::after {
  transform: translateX(18px);
}

/* stage */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
}

.mic-btn {
  position: relative;
  width: 196px;
  height: 196px;
  border-radius: 50%;
  border: 0;
  cursor: pointer;
  background: transparent;
  display: grid;
  place-items: center;
  touch-action: none;
}

.ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  transition: all 0.4s ease;
}

.ring-outer {
  background: radial-gradient(
    circle at 30% 25%,
    rgba(255, 255, 255, 0.12),
    rgba(255, 255, 255, 0.02) 60%
  );
  border: 1px solid var(--glass-stroke);
  backdrop-filter: blur(8px);
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.45),
    inset 0 2px 1px rgba(255, 255, 255, 0.25);
}

.ring-inner {
  inset: 26px;
  background: linear-gradient(160deg, rgba(110, 168, 255, 0.18), rgba(181, 139, 255, 0.12));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.mic-core {
  position: relative;
  z-index: 2;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(160deg, var(--accent), var(--accent-2));
  box-shadow:
    0 10px 30px rgba(58, 91, 255, 0.5),
    inset 0 2px 2px rgba(255, 255, 255, 0.4);
  transition: transform 0.2s ease, box-shadow 0.3s ease;
}

.mic-icon {
  width: 38px;
  height: 38px;
  fill: #fff;
  stroke: #fff;
}

/* state: listening */
.mic-btn.listening .ring-outer {
  border-color: var(--listening);
  box-shadow:
    0 0 0 0 rgba(76, 214, 160, 0.5),
    inset 0 2px 1px rgba(255, 255, 255, 0.25);
  animation: pulse 1.4s ease-out infinite;
}

.mic-btn.listening .mic-core {
  background: linear-gradient(160deg, #4cd6a0, #29b3b0);
  transform: scale(1.05);
}

@keyframes pulse {
  0% {
    box-shadow:
      0 0 0 0 rgba(76, 214, 160, 0.5),
      inset 0 2px 1px rgba(255, 255, 255, 0.25);
  }
  100% {
    box-shadow:
      0 0 0 26px rgba(76, 214, 160, 0),
      inset 0 2px 1px rgba(255, 255, 255, 0.25);
  }
}

/* state: translating */
.mic-btn.translating .ring-inner {
  animation: spin 1s linear infinite;
  border: 2px solid transparent;
  border-top-color: var(--translating);
}

.mic-btn.translating .mic-core {
  background: linear-gradient(160deg, var(--accent-2), #8b5bff);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* state: speaking */
.mic-btn.speaking .mic-core {
  background: linear-gradient(160deg, var(--speaking), #ff8f4b);
  animation: breathe 0.9s ease-in-out infinite alternate;
}

.mic-btn.speaking .ring-outer {
  border-color: var(--speaking);
}

@keyframes breathe {
  from {
    transform: scale(1);
  }
  to {
    transform: scale(1.12);
  }
}

.status {
  font-size: 14px;
  color: var(--muted);
  margin: 0;
  min-height: 20px;
  text-align: center;
  transition: color 0.3s ease;
}

/* panel */
.panel {
  border-radius: var(--radius);
  padding: 18px;
  min-height: 140px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.badge-row {
  display: flex;
}

.lang-badge {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--accent);
  background: rgba(110, 168, 255, 0.14);
  border: 1px solid rgba(110, 168, 255, 0.3);
  padding: 4px 10px;
  border-radius: 999px;
}

.source-text {
  font-size: 19px;
  line-height: 1.4;
  margin: 0;
  color: var(--text);
  min-height: 26px;
}

.source-text.interim {
  color: var(--muted);
}

.divider {
  border: 0;
  height: 1px;
  background: var(--glass-stroke);
  margin: 4px 0;
}

.translated-text {
  font-size: 16px;
  line-height: 1.4;
  margin: 0;
  color: var(--muted);
  min-height: 22px;
}

.translated-text.ready {
  color: var(--accent);
}

/* preset selector */
.preset-row {
  display: flex;
}

.preset {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  border-radius: 16px;
  padding: 8px 14px;
}

.preset-label {
  font-size: 12px;
  color: var(--muted);
  flex: none;
}

.preset-select {
  flex: 1;
  appearance: none;
  -webkit-appearance: none;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid var(--glass-stroke);
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.preset-select option {
  background: #16162a;
  color: var(--text);
}

/* transcript history */
.history {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 26vh;
  overflow-y: auto;
  margin-top: 4px;
}

.history:empty {
  display: none;
}

.hist-item {
  border-top: 1px solid var(--glass-stroke);
  padding-top: 8px;
}

.hist-src {
  font-size: 13px;
  line-height: 1.35;
  color: var(--muted);
  margin: 0 0 2px;
}

.hist-dst {
  font-size: 14px;
  line-height: 1.35;
  color: var(--text);
  margin: 0;
}

/* access-token gate */
.gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(7, 7, 13, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.gate[hidden] {
  display: none;
}

.gate-card {
  width: 100%;
  max-width: 360px;
  padding: 24px;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.gate-title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.gate-sub {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.4;
}

.gate-input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--glass-stroke);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 15px;
  outline: none;
}

.gate-input:focus {
  border-color: var(--accent);
}

.gate-error {
  margin: 0;
  font-size: 13px;
  color: #ff7a7a;
}

.gate-error[hidden] {
  display: none;
}

.gate-btn {
  margin-top: 4px;
  padding: 12px;
  border-radius: 14px;
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0a0a12;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
