:root {
  color-scheme: dark;
  --bg: #202124;
  --card: #101112;
  --card-soft: #151617;
  --text: #f7f7f4;
  --muted: #aaaeb3;
  --line: rgba(255, 255, 255, 0.11);
  --accent: #aac7ff;
  --accent-ink: #12305a;
  --danger: #ff726f;
  --ok: #77e08e;
  --shadow: 0 18px 58px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

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

html {
  background: var(--bg);
}

body {
  margin: 0;
  height: 100dvh;
  min-height: 100svh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family:
    ui-rounded,
    -apple-system,
    BlinkMacSystemFont,
    "Hiragino Sans",
    "Noto Sans TC",
    "PingFang TC",
    sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button,
select,
input,
textarea {
  font: inherit;
}

.app-shell {
  width: min(620px, 100%);
  height: 100dvh;
  min-height: 0;
  margin: 0 auto;
  overflow: hidden;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

@media (display-mode: standalone) {
  .app-shell {
    padding-top: max(14px, env(safe-area-inset-top));
  }
}

.stage {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 28px;
}

.eyebrow {
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  font-weight: 760;
  letter-spacing: 0;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 28px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.status-pill span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.status-pill[data-state="live"] span {
  background: var(--ok);
  box-shadow: 0 0 16px var(--ok);
}

.status-pill[data-state="error"] span {
  background: var(--danger);
}

.conversation-board {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) 54px minmax(0, 1fr);
  gap: 10px;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.language-card {
  height: 100%;
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
  border-radius: 28px;
  background: var(--card);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.035);
}

.partner-card,
.user-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: clamp(18px, 5vw, 30px);
}

.rotated-card-content {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  flex-direction: column;
  transform: rotate(180deg);
}

.language-label {
  color: var(--text);
  font-size: clamp(15px, 4vw, 20px);
  font-weight: 720;
  letter-spacing: 0;
  text-align: center;
}

.card-transcript {
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  min-height: 0;
  max-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  color: var(--text);
  font-size: clamp(23px, 6vw, 34px);
  font-weight: 560;
  line-height: 1.28;
  overflow-wrap: anywhere;
  scrollbar-width: thin;
  white-space: pre-wrap;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.card-transcript::before {
  display: block;
  margin-top: auto;
  content: "";
}

.card-transcript[hidden] {
  display: none;
}

.partner-card .card-transcript {
  color: var(--muted);
  text-align: left;
}

.partner-card .language-label {
  order: 2;
  flex: 0 0 auto;
  margin-top: 12px;
}

.partner-card .card-transcript {
  order: 1;
  flex: 1 1 0;
}

.user-card .card-transcript {
  flex: 1 1 0;
  font-size: clamp(18px, 4.5vw, 24px);
  font-weight: 520;
  line-height: 1.22;
}

.user-card-footer {
  position: relative;
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  min-height: 76px;
  padding-top: 10px;
}

.ptt-button {
  position: absolute;
  right: 0;
  bottom: -4px;
  display: grid;
  width: 84px;
  height: 84px;
  min-height: 84px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.36);
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-touch-callout: none;
}

.ptt-button.recording {
  background: var(--danger);
  color: #240b0b;
  transform: scale(0.96);
}

.ptt-button.switching {
  opacity: 0.82;
}

.ptt-button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.speak-glyph {
  display: block;
  width: 44px;
  height: 44px;
  overflow: visible;
}

.speak-bubble,
.speak-dot {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3.4;
}

.speak-dot {
  stroke-width: 5.2;
}

.ptt-button.recording .speak-bubble {
  fill: currentColor;
  stroke-width: 0;
}

.ptt-button.recording .speak-dot {
  stroke: var(--danger);
}

.ptt-button.switching .speak-glyph {
  animation: speak-spin 760ms linear infinite;
}

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

.center-actions {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.icon-button {
  display: grid;
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  place-items: center;
  border-radius: 50%;
  color: var(--text);
}

.icon-button[hidden] {
  display: none;
}

.icon-button.primary {
  color: var(--accent-ink);
}

.record-toggle {
  position: relative;
}

.record-toggle.recording {
  border-color: var(--danger);
  background: var(--danger);
  color: #240b0b;
  animation: recordPulse 1.05s ease-in-out infinite;
}

.record-glyph {
  display: block;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: currentColor;
}

.record-toggle.recording .record-glyph {
  border-radius: 5px;
}

@keyframes recordPulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(255, 114, 111, 0.5);
  }

  50% {
    box-shadow: 0 0 0 8px rgba(255, 114, 111, 0);
  }
}

.play-glyph {
  display: block;
  width: 0;
  height: 0;
  margin-left: 3px;
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
  border-left: 14px solid currentColor;
}

.stop-glyph {
  display: block;
  width: 17px;
  height: 17px;
  border-radius: 3px;
  background: currentColor;
}

.settings-glyph {
  display: block;
  font-size: 25px;
  line-height: 1;
}

.history-glyph {
  position: relative;
  display: block;
  width: 22px;
  height: 22px;
  border: 2.5px solid currentColor;
  border-radius: 50%;
}

.history-glyph::before,
.history-glyph::after {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 2.5px;
  border-radius: 999px;
  background: currentColor;
  content: "";
  transform-origin: center bottom;
}

.history-glyph::before {
  height: 8px;
  transform: translate(-50%, -100%);
}

.history-glyph::after {
  height: 7px;
  transform: translate(-50%, -100%) rotate(118deg);
}

.batch-glyph {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border: 2.5px solid currentColor;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 850;
  line-height: 1;
}

.batch-icon {
  position: relative;
}

.batch-icon.active {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

.batch-icon.has-unread {
  border-color: #7ee7c8;
  background: #7ee7c8;
  color: #072a24;
  box-shadow: 0 0 0 3px rgba(126, 231, 200, 0.18);
}

.batch-icon.has-unread::after {
  position: absolute;
  top: -4px;
  right: -5px;
  display: grid;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  place-items: center;
  border: 2px solid var(--bg);
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  content: attr(data-badge);
  font-size: 11px;
  font-weight: 850;
  line-height: 1;
}

.batch-widget {
  display: flex;
  flex: 1 1 0;
  min-height: 0;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
}

.batch-widget[hidden] {
  display: none;
}

.batch-status {
  flex: 0 0 auto;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
  letter-spacing: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.batch-text {
  flex: 1 1 0;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  color: var(--text);
  font-size: clamp(18px, 4.5vw, 24px);
  font-weight: 520;
  line-height: 1.25;
  overflow-wrap: anywhere;
  scrollbar-width: thin;
  white-space: pre-wrap;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.batch-text::before {
  display: block;
  margin-top: auto;
  content: "";
}

.batch-panel {
  height: min(82svh, 720px);
}

.batch-panel .tool-panel-header {
  align-items: flex-start;
}

.batch-panel-text {
  flex: 1 1 0;
  min-height: 0;
  padding: 4px 2px 2px;
  font-size: clamp(18px, 4.4vw, 24px);
}

.settings-backdrop {
  position: fixed;
  inset: 0;
  z-index: 19;
  background: rgba(0, 0, 0, 0.44);
}

.settings-backdrop[hidden],
.tool-panel[hidden] {
  display: none;
}

.tool-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 20;
  display: flex;
  flex-direction: column;
  width: min(680px, calc(100vw - 24px));
  max-height: min(82svh, 720px);
  gap: 12px;
  padding: 16px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: color-mix(in srgb, var(--card-soft) 96%, transparent);
  box-shadow: var(--shadow);
  transform: translate(-50%, -50%);
}

.tool-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 40px;
}

.tool-panel-header strong {
  font-size: 17px;
}

.close-button {
  width: 38px;
  min-height: 38px;
  padding: 0;
  border-radius: 50%;
  color: var(--muted);
  font-size: 28px;
  line-height: 1;
}

.controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 9px;
}

button,
select,
input,
textarea,
.select-wrap,
.toggle-wrap {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}

button {
  min-height: 40px;
  padding: 0 12px;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 760;
}

.select-wrap,
.toggle-wrap,
.debug-toggle {
  display: grid;
  grid-template-columns: minmax(78px, 0.32fr) minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 44px;
  min-width: 0;
  padding: 0 12px;
  color: var(--muted);
  font-size: 13px;
}

.select-wrap span,
.toggle-wrap span,
.debug-toggle span {
  min-width: 0;
  white-space: nowrap;
  line-height: 1.15;
}

.auth-row {
  display: grid;
  grid-template-columns: minmax(78px, 0.32fr) minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 13px;
}

.auth-row strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-weight: 600;
}

.auth-row button {
  min-height: 32px;
  padding: 0 12px;
  border-radius: 999px;
}

.app-version {
  padding: 4px 2px 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
  text-align: right;
  font-variant-numeric: tabular-nums;
  opacity: 0.78;
}

.toggle-wrap,
.debug-toggle {
  grid-template-columns: 22px minmax(0, 1fr);
}

.select-wrap select {
  min-width: 0;
  width: 100%;
  height: 36px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 15px;
}

.select-wrap input {
  min-width: 0;
  width: 100%;
  height: 36px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 15px;
}

.prompt-wrap {
  display: grid;
  grid-template-columns: 1fr;
  align-items: stretch;
  min-height: 104px;
  gap: 8px;
  padding: 10px 12px;
}

.prompt-wrap span {
  white-space: nowrap;
}

.select-wrap textarea {
  min-width: 0;
  width: 100%;
  min-height: 78px;
  max-height: 150px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  resize: vertical;
}

.select-wrap textarea::placeholder {
  color: color-mix(in srgb, var(--muted) 68%, transparent);
}

.api-key-wrap {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
}

.toggle-wrap input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.debug-toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.input-meter {
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(16, 17, 18, 0.9);
}

.main-input-meter {
  flex: 0 0 auto;
}

.meter-header,
.meter-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.meter-header strong {
  color: var(--text);
  font-size: 15px;
}

.meter-track {
  height: 8px;
  margin: 7px 0 6px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.36);
}

.meter-track div {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #7ee7c8);
  transition: width 80ms linear;
}

.meter-meta {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.debug-panel {
  min-width: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.035);
}

.debug-panel[hidden] {
  display: none;
}

.debug-panel > summary {
  min-height: 38px;
  padding: 0 10px;
  color: var(--muted);
  cursor: pointer;
  font-weight: 650;
  line-height: 38px;
}

.telemetry {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 0 10px 10px;
}

.telemetry div {
  min-width: 0;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.16);
}

.telemetry span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.telemetry strong {
  display: block;
  margin-top: 5px;
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
}

.log-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 10px 10px;
  color: var(--muted);
}

.log-title button {
  min-height: 34px;
  padding: 0 12px;
}

pre {
  min-width: 0;
  height: 220px;
  max-height: 220px;
  margin: 0 10px 10px;
  overflow: auto;
  color: #cfd6ca;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.history-view {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.history-view[hidden],
body[data-view="history"] .stage {
  display: none;
}

.history-header,
.history-detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.history-header h1,
.history-detail-header h2 {
  margin: 2px 0 0;
  overflow: hidden;
  color: var(--text);
  font-size: 24px;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-back-button {
  position: relative;
  display: grid;
  width: 42px;
  height: 42px;
  min-height: 42px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  color: var(--text);
}

.back-glyph {
  display: block;
  width: 13px;
  height: 13px;
  border-bottom: 3px solid currentColor;
  border-left: 3px solid currentColor;
  transform: rotate(45deg) translate(2px, -1px);
}

.history-list {
  display: grid;
  min-height: 0;
  align-content: start;
  gap: 10px;
  overflow: auto;
  padding-bottom: 18px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.history-item {
  display: grid;
  width: 100%;
  min-height: 126px;
  padding: 16px 14px 22px;
  gap: 11px;
  overflow: hidden;
  border-radius: 18px;
  text-align: left;
}

.history-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.history-item-top strong {
  min-width: 0;
  overflow: hidden;
  font-size: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item-body {
  display: grid;
  min-width: 0;
  gap: 7px;
}

.history-status {
  flex: 0 0 auto;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
  font-size: 11px;
  font-weight: 760;
}

.history-status-active,
.history-status-interrupted {
  color: #ffd3a6;
}

.history-status-failed {
  color: var(--danger);
}

.history-item-meta,
.history-item-summary,
.history-item-preview {
  overflow: hidden;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.history-item-preview {
  display: -webkit-box;
  margin: 0;
  color: color-mix(in srgb, var(--text) 82%, var(--muted));
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
}

.history-item-meta,
.history-item-summary {
  display: block;
  white-space: normal;
}

.history-empty,
.history-empty-inline {
  display: grid;
  min-height: 160px;
  place-items: center;
  color: var(--muted);
  font-size: 15px;
}

.history-empty-inline {
  min-height: 60px;
  margin: 0;
  justify-items: start;
}

.history-detail {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
}

.history-detail[hidden] {
  display: none;
}

.history-detail-body {
  display: flex;
  flex-direction: column;
  min-height: 0;
  gap: 12px;
  overflow: auto;
  padding-bottom: 16px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.history-meta-grid,
.history-section {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.045);
}

.history-meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
}

.history-meta-grid div {
  min-width: 0;
  padding: 10px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-map-link {
  color: var(--accent);
  text-decoration: none;
}

.history-section {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.history-section h3 {
  margin: 0;
  font-size: 16px;
}

.history-transcript {
  height: auto;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  color: var(--text);
  font-size: 16px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.history-pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.history-pair-pane {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.16);
}

.history-pair-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.history-pair-pane p {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 15px;
  line-height: 1.5;
  white-space: pre-wrap;
}

audio {
  position: fixed;
  left: -9999px;
  width: 1px;
  height: 1px;
}

@media (max-width: 460px) {
  .app-shell {
    padding-right: max(10px, env(safe-area-inset-right));
    padding-left: max(10px, env(safe-area-inset-left));
  }

  .stage {
    gap: 6px;
  }

  .input-meter {
    padding: 7px 9px;
  }

  .topbar {
    min-height: 24px;
  }

  .eyebrow {
    max-width: 210px;
    font-size: 10px;
  }

  .conversation-board {
    grid-template-rows: minmax(0, 1fr) 44px minmax(0, 1fr);
    gap: 8px;
  }

  .language-card {
    border-radius: 22px;
  }

  .partner-card,
  .user-card {
    padding: 20px;
  }

  .card-transcript {
    font-size: clamp(22px, 7vw, 30px);
  }

  .user-card .card-transcript {
    font-size: clamp(17px, 5.2vw, 22px);
    line-height: 1.2;
  }

  .batch-text {
    font-size: clamp(17px, 5.2vw, 22px);
    line-height: 1.2;
  }

  .ptt-button {
    width: 76px;
    height: 76px;
    min-height: 76px;
  }

  .speak-glyph {
    width: 40px;
    height: 40px;
  }

  .controls {
    grid-template-columns: 1fr;
  }

  .select-wrap {
    grid-column: 1 / -1;
  }

  .center-actions {
    gap: 10px;
  }

  .icon-button {
    width: 42px;
    height: 42px;
    min-height: 42px;
  }

  .history-meta-grid,
  .history-pair {
    grid-template-columns: 1fr;
  }
}
