:root {
  color-scheme: dark;
  --bg: #101213;
  --surface: #191c1d;
  --surface-raised: #222627;
  --line: #353a3b;
  --text: #e9ebea;
  --muted: #9da3a1;
  --accent: #87978f;
  --danger: #b86670;
  --warning: #b59a65;
  --active: #7890a2;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

h1,
h2,
strong,
button {
  font-weight: 400;
}

.call-stage {
  position: relative;
  min-height: 100svh;
  display: flex;
  justify-content: center;
  padding: 76px 20px 32px;
}

.call-time {
  position: absolute;
  top: 22px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--muted);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  opacity: 1;
  transition: opacity .2s ease;
}

body.subtitles-active .call-time {
  opacity: 0;
}

.call-content {
  width: min(520px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.portrait-area {
  position: relative;
  width: 178px;
  height: 178px;
}

.portrait {
  display: block;
  width: 178px;
  height: 178px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 50%;
}

.live-subtitles {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: calc(100% + 18px);
  width: min(620px, calc(100vw - 40px));
  min-height: 50px;
  transform: translate(-50%, 10px) scale(.98);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 12px 18px;
  background: rgb(16 18 19 / 88%);
  color: var(--text);
  font-size: 21px;
  line-height: 1.4;
  text-align: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  backdrop-filter: blur(10px);
  transition: opacity .22s ease, transform .32s ease, border-color .32s ease, visibility 0s linear .32s;
}

.live-subtitles.visible {
  transform: translate(-50%, 0) scale(1);
  border-color: var(--line);
  opacity: 1;
  visibility: visible;
  transition: opacity .22s ease, transform .32s ease, border-color .32s ease;
}

.live-subtitles span {
  display: inline-block;
  transform: translateY(7px);
  opacity: 0;
  filter: blur(3px);
  transition: opacity .28s ease, transform .35s ease, filter .35s ease;
}

.live-subtitles span.shown {
  transform: translateY(0);
  opacity: 1;
  filter: blur(0);
}

.live-subtitles.complete {
  border-color: #4b5451;
}

.call-content h1 {
  margin: 16px 0 8px;
  font-size: 32px;
  line-height: 1.1;
}

.status-row {
  min-height: 24px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.status-row strong {
  font-size: 14px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.trust-meter {
  width: min(360px, 100%);
  margin-top: 18px;
}

.trust-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: #c8ccca;
  font-size: 14px;
}

.trust-heading output {
  color: var(--text);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.trust-track {
  height: 9px;
  margin-top: 9px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #0b0d0e;
}

.trust-track span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--active);
  transition: width .7s cubic-bezier(.22, 1, .36, 1), background .3s ease;
}

.trust-track.complete span {
  background: #75937c;
}

.trust-meter p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.status-row.listening .status-dot {
  background: var(--danger);
  animation: blink 1s infinite;
}

.status-row.processing .status-dot {
  background: var(--warning);
  animation: blink .7s infinite;
}

.status-row.responding .status-dot {
  background: var(--active);
}

.status-row.error .status-dot {
  background: var(--danger);
}

@keyframes blink {
  50% {
    opacity: .25;
  }
}

.secure-warning {
  width: 100%;
  margin-top: 14px;
  border-left: 3px solid var(--warning);
  padding: 10px 12px;
  background: #211f1a;
  color: #d8ccb3;
  font-size: 13px;
  line-height: 1.4;
}

.recorder {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 26px 0 24px;
}

.mic-control {
  position: relative;
  width: 144px;
  height: 144px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mic-button {
  position: relative;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 114px;
  height: 114px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #101312;
  touch-action: none;
  user-select: none;
  transition: transform .15s, background .15s;
}

.mic-button:hover {
  transform: scale(1.03);
}

.mic-button:active,
.mic-button.recording {
  transform: scale(.97);
  background: var(--danger);
  color: var(--text);
}

.mic-button:disabled {
  opacity: .4;
  cursor: not-allowed;
  transform: none;
}

.mic-shape {
  position: relative;
  width: 27px;
  height: 41px;
  border: 4px solid currentColor;
  border-radius: 18px;
}

.mic-shape::before {
  content: "";
  position: absolute;
  top: 36px;
  left: 50%;
  width: 4px;
  height: 14px;
  transform: translateX(-50%);
  background: currentColor;
}

.mic-shape::after {
  content: "";
  position: absolute;
  top: 47px;
  left: 50%;
  width: 24px;
  height: 4px;
  transform: translateX(-50%);
  background: currentColor;
  border-radius: 2px;
}

.pulse-ring {
  position: absolute;
  inset: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
}

.recorder.recording .pulse-ring {
  border-color: var(--danger);
  animation: pulse 1.4s infinite;
}

@keyframes pulse {
  50% {
    transform: scale(1.1);
    opacity: .25;
  }
}

.recorder p {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.text-control {
  width: 100%;
  display: flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface);
}

.text-control input {
  min-width: 0;
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  padding: 13px 14px;
}

.text-control input::placeholder {
  color: #7f8583;
}

.text-control button {
  min-width: 86px;
  border: 0;
  background: var(--accent);
  color: #101312;
  padding: 0 16px;
}

.text-control button:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.drawer-toggle {
  position: fixed;
  z-index: 30;
  top: 18px;
  right: 18px;
  height: 40px;
  display: flex;
  align-items: center;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-raised);
  color: var(--text);
  padding: 0 13px;
}

.drawer-chevron {
  display: block;
  font-size: 22px;
  line-height: 1;
  transition: transform .25s ease;
}

.drawer-toggle[aria-expanded="true"] .drawer-chevron {
  transform: rotate(180deg);
}

.conversation-drawer {
  position: fixed;
  z-index: 20;
  top: 0;
  right: 0;
  width: min(440px, 100vw);
  height: 100svh;
  overflow-y: auto;
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: -18px 0 50px #0006;
  transform: translateX(100%);
  visibility: hidden;
  transition: transform .3s ease, visibility 0s linear .3s;
}

.conversation-drawer.open {
  transform: translateX(0);
  visibility: visible;
  transition: transform .3s ease;
}

.drawer-header,
.history-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.drawer-header {
  min-height: 76px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.drawer-header h2,
.history-heading h2 {
  margin: 0;
  font-size: 20px;
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px;
  font-size: 13px;
}

.text-button:hover {
  color: var(--text);
}

.text-button:disabled {
  opacity: .35;
  cursor: not-allowed;
}

.text-button.danger:hover {
  color: var(--danger);
}

.conversation,
.history-panel {
  padding: 22px 20px;
}

.history-panel {
  border-top: 1px solid var(--line);
}

.dialogue-block {
  border-left: 2px solid var(--line);
  padding-left: 14px;
  margin-bottom: 20px;
}

.dialogue-block.carmen {
  border-color: var(--accent);
}

.dialogue-block span {
  color: var(--muted);
  font-size: 14px;
}

.dialogue-block p {
  margin: 6px 0 0;
  font-size: 14px;
  line-height: 1.5;
}

#audioPlayer {
  width: 100%;
  height: 38px;
}

.metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-top: 22px;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.metrics div {
  padding: 12px;
  background: var(--surface-raised);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.metrics div:nth-child(2n) {
  border-right: 0;
}

.metrics div:nth-last-child(-n+2) {
  border-bottom: 0;
}

.metrics span,
.metrics strong {
  display: block;
}

.metrics span {
  color: var(--muted);
  font-size: 11px;
}

.metrics strong {
  margin-top: 4px;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.history-heading {
  margin-bottom: 14px;
}

.history-list {
  max-height: 320px;
  overflow-y: auto;
}

.history-item {
  padding: 13px 0;
  border-top: 1px solid var(--line);
}

.history-item:first-child {
  border-top: 0;
}

.history-item strong {
  color: var(--muted);
  font-size: 12px;
}

.history-item p {
  margin: 5px 0 0;
  color: #d6d9d7;
  font-size: 13px;
  line-height: 1.4;
}

.empty {
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 600px) {
  .call-stage {
    padding: 66px 18px 26px;
  }

  .call-time {
    top: 18px;
  }

  .portrait-area,
  .portrait {
    width: 146px;
    height: 146px;
  }

  .live-subtitles {
    bottom: calc(100% + 14px);
    width: calc(100vw - 28px);
    padding: 10px 14px;
    font-size: 18px;
  }

  .call-content h1 {
    margin-top: 13px;
    font-size: 27px;
  }

  .recorder {
    margin: 20px 0;
  }

  .mic-control {
    width: 132px;
    height: 132px;
  }

  .mic-button {
    width: 104px;
    height: 104px;
  }

  .drawer-toggle {
    top: 12px;
    right: 12px;
    height: 38px;
  }

  .conversation-drawer {
    width: 100vw;
  }
}
