/* ---------- Page ---------- */
.demo {
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
  padding: 28px var(--gutter) 56px;
}
.demo-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 20px;
  margin-bottom: 20px;
}
/* The one display line on the page, in the story's wide face. */
.demo-head h1 {
  font-family: 'Archivo', var(--font);
  font-size: 2.25rem;
  font-weight: 750;
  font-stretch: 118%;
  letter-spacing: -0.02em;
  line-height: 1.05;
}
.demo-head p {
  color: var(--ink-3);
  text-wrap: pretty;
}

.demo-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(330px, 1fr);
  gap: 32px;
  align-items: start;
}

/* ---------- Camera ---------- */
.viewport {
  /* Mouth window, set every frame by mouth-tracker.js */
  --mx: 50%;
  --my: 66%;
  --mw: 0px;
  --mh: 0px;

  position: relative;
  /* Fits the camera, its controls and the page title in one laptop screen. */
  height: clamp(340px, calc(100svh - 290px), 680px);
  overflow: hidden;
  border-radius: 16px;
  background: #ebe9e5;
  isolation: isolate;
}
.viewport::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 4;
  border-radius: inherit;
  box-shadow: inset 0 0 0 3px var(--accent);
  opacity: 0;
  transition: opacity 160ms var(--ease);
  pointer-events: none;
}
.viewport[data-recording='true']::after {
  opacity: 1;
}

.cam {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  /* Mirror like a selfie camera. The slight zoom keeps blurred edges inside the frame;
     both layers share it, so the sharp mouth window still lines up. */
  transform: scale(-1.06, 1.06);
  opacity: 0;
}
.viewport[data-camera='on'] .cam-base {
  opacity: 1;
  transition:
    opacity 300ms var(--ease),
    filter 350ms var(--ease);
}

/* The highlight: the rest of the face goes soft, the mouth stays sharp. */
.viewport[data-focus='true'] .cam-base {
  filter: blur(14px) brightness(0.9);
}
.cam-focus {
  transition: opacity 350ms var(--ease);
  -webkit-mask-image: radial-gradient(ellipse var(--mw) var(--mh) at var(--mx) var(--my), #000 64%, transparent 100%);
  mask-image: radial-gradient(ellipse var(--mw) var(--mh) at var(--mx) var(--my), #000 64%, transparent 100%);
}
.viewport[data-focus='true'] .cam-focus {
  opacity: 1;
}

/* Face boxes when several people are in view (drawn by demo.js, unmirrored coords;
   the .cam transform mirrors it to line up with the video). */
.faces-overlay {
  pointer-events: none;
  z-index: 2;
}
.viewport[data-camera='on'] .faces-overlay {
  opacity: 1;
}
.viewport[data-camera='on'][data-people='many'] {
  cursor: pointer;
}
.people-hint {
  position: absolute;
  left: 50%;
  bottom: 18px;
  z-index: 3;
  transform: translateX(-50%);
  max-width: calc(100% - 28px);
  margin: 0;
  padding: 7px 12px;
  border-radius: 8px;
  background: rgb(0 0 0 / 0.62);
  color: #fff;
  font-size: 13px;
  line-height: 1.35;
  text-align: center;
  pointer-events: none;
}

/* Where to put your mouth, until one is found */
.guide {
  position: absolute;
  left: 36%;
  top: 57%;
  width: 28%;
  height: 19%;
  border: 2px dashed rgb(255 255 255 / 0.8);
  border-radius: 999px;
  display: none;
  pointer-events: none;
}
.viewport[data-camera='on'][data-track='search'] .guide,
.viewport[data-camera='on'][data-track='guide'] .guide {
  display: block;
}

.hud {
  position: absolute;
  top: 14px;
  left: 14px;
  right: 14px;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}
.viewport:not([data-camera='on']) .hud {
  display: none;
}
.chip {
  padding: 6px 11px;
  border-radius: 8px;
  background: rgb(255 255 255 / 0.94);
  color: var(--ink);
  font-size: 0.8125rem;
  font-weight: 500;
  box-shadow: 0 1px 3px rgb(20 21 24 / 0.12);
}
.chip-rec {
  margin-left: auto;
  color: var(--accent);
}
.chip-rec span {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.camera-gate {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 32px;
  text-align: center;
}
.viewport[data-camera='on'] .camera-gate {
  display: none;
}
.gate-icon {
  width: 44px;
  height: 44px;
  margin-bottom: 6px;
  color: var(--ink-3);
  stroke-width: 1.6;
}
.viewport[data-camera='error'] .gate-icon {
  color: var(--error);
}
.gate-title {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.015em;
}
.gate-body {
  max-width: 40ch;
  margin-bottom: 12px;
  color: var(--ink-2);
}

.progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3;
  height: 4px;
}
.progress span {
  display: block;
  height: 100%;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
}

/* ---------- Record controls ---------- */
.controls {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 18px;
}
.controls-text {
  min-width: 0;
  display: grid;
  gap: 2px;
}
.model-tag {
  color: var(--ink-3);
  font: 400 0.75rem/1.5 var(--mono);
  overflow-wrap: anywhere;
}
.handsfree-toggle {
  flex-basis: 100%;
  min-height: 32px;
}
.record-btn[data-listening='true'] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--line-strong);
}
.record-btn[data-listening='true']:hover:not(:disabled) {
  background: var(--line);
}
.record-btn {
  min-width: 210px;
  min-height: 52px;
  padding: 0 26px;
  border: 0;
  border-radius: 12px;
  background: var(--ink);
  color: #fff;
  font-size: 1rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition:
    background-color 150ms var(--ease),
    transform 150ms var(--ease);
}
.record-btn:hover:not(:disabled) {
  background: #2b2d32;
}
.record-btn:active:not(:disabled) {
  transform: translateY(1px);
}
.record-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.record-btn[aria-pressed='true'] {
  background: var(--accent);
}
.record-btn[aria-pressed='true']:hover {
  background: #a92f25;
}

.controls-hint {
  color: var(--ink-2);
  font-size: 0.875rem;
}
kbd {
  padding: 1px 6px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface);
  color: var(--ink-2);
  font: 500 0.75rem/1.4 var(--mono);
}

/* ---------- Transcript panel ---------- */
.side {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 32px;
}
.panel {
  padding: 22px 24px 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
}
.panel-head,
.section-head {
  min-height: 32px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.panel-head h2,
.section-head h2 {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9375rem;
  font-weight: 600;
}
.meta {
  color: var(--ink-3);
  font: 400 0.8125rem/1.4 var(--mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.transcript {
  min-height: 2.5em;
  font-size: clamp(1.5rem, 1.1rem + 1vw, 2rem);
  font-weight: 500;
  line-height: 1.25;
  letter-spacing: -0.025em;
  text-wrap: pretty;
  overflow-wrap: anywhere;
}
.latest[data-state='empty'] .transcript {
  color: var(--ink-3);
  font-size: 1.25rem;
  letter-spacing: -0.01em;
}

.skeleton,
.loading-note,
.error-box {
  display: none;
}
.latest[data-state='loading'] .transcript,
.latest[data-state='error'] .transcript {
  display: none;
}
.latest[data-state='loading'] .skeleton {
  display: grid;
  gap: 10px;
  min-height: 2.5em;
  padding-top: 6px;
}
.skeleton span {
  height: 26px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--bg-muted) 0%, var(--line) 50%, var(--bg-muted) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.3s linear infinite;
}
.skeleton span:last-child {
  width: 60%;
}
@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}
.latest[data-state='loading'] .loading-note {
  display: block;
  margin-top: 12px;
  color: var(--ink-3);
  font-size: 0.875rem;
}
.latest[data-state='error'] .error-box {
  display: grid;
  justify-items: start;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 10px;
  background: var(--error-soft);
  color: var(--error);
}

.actions {
  margin-top: 20px;
  display: flex;
  gap: 10px;
}

/* ---------- Voice settings ---------- */
.voice,
.history {
  padding-top: 18px;
  border-top: 1px solid var(--line);
}
.voice-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 20px;
}
.field {
  flex: 1 1 100%;
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.field-label {
  flex: none;
  min-width: 88px;
  color: var(--ink-3);
  font-size: 0.875rem;
}
.field select {
  flex: 1;
  width: 100%;
  min-width: 0;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  font-size: 0.875rem;
  text-overflow: ellipsis;
  cursor: pointer;
}
.toggle {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-2);
  font-size: 0.875rem;
  cursor: pointer;
}
.toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--ink);
  cursor: pointer;
}

.voice-note {
  flex-basis: 100%;
  margin: 0;
  color: var(--ink-3);
  font-size: 0.8125rem;
}
.voice-note[data-tone='error'] {
  color: var(--error);
}
.range-field input[type='range'] {
  flex: 1;
  min-width: 0;
  accent-color: var(--ink);
  cursor: pointer;
}
.range-field output {
  min-width: 3.5em;
  color: var(--ink-2);
  font: 500 0.8125rem var(--mono);
  text-align: right;
}
.mic-setup {
  flex-basis: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
.mic-setup p {
  flex: 1 1 220px;
  margin: 0;
  color: var(--ink-2);
  font-size: 0.8125rem;
}
.mic-help {
  flex-basis: 100%;
  color: var(--ink-2);
  font-size: 0.8125rem;
}
.mic-help summary {
  cursor: pointer;
  color: var(--ink-3);
}
.mic-help ol {
  margin: 8px 0 4px;
  padding-left: 20px;
}
.mic-help li + li {
  margin-top: 4px;
}
.mic-help p {
  margin: 6px 0 0;
}

/* ---------- Voice clone dialog ---------- */
.clone-dialog {
  width: min(560px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 24px 60px rgb(0 0 0 / 0.18);
}
.clone-dialog::backdrop {
  background: rgb(20 21 24 / 0.45);
}
.clone-inner {
  padding: 24px;
}
.clone-inner h2 {
  margin: 0 0 8px;
  font-size: 1.25rem;
}
.clone-inner p {
  margin: 0 0 10px;
  color: var(--ink-2);
  font-size: 0.9375rem;
}
.clone-inner .clone-small {
  color: var(--ink-3);
  font-size: 0.8125rem;
}
.clone-script {
  margin: 14px 0;
  padding: 14px 16px;
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  background: var(--bg-muted);
  font-size: 1.0625rem;
  line-height: 1.55;
}
.clone-consent {
  align-items: flex-start;
}
.clone-consent input {
  flex: none;
  margin-top: 1px;
}
.clone-meter {
  height: 6px;
  margin: 14px 0 8px;
  border-radius: 3px;
  background: var(--bg-muted);
  overflow: hidden;
}
.clone-meter span {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 60ms linear;
}
.clone-status {
  min-height: 1.4em;
}
.clone-status[data-tone='error'] {
  color: var(--error);
}
.clone-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.clone-close {
  margin-left: auto;
}

/* ---------- History ---------- */
.count {
  min-width: 24px;
  padding: 1px 7px;
  border-radius: 6px;
  background: var(--bg-muted);
  color: var(--ink-3);
  font: 500 0.75rem/1.5 var(--mono);
  text-align: center;
}
.history-clear {
  background: none;
  color: var(--ink-3);
}
.history-clear:hover:not(:disabled) {
  background: var(--bg-muted);
  color: var(--ink);
}
.history-empty {
  color: var(--ink-3);
}
.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 440px;
  overflow-y: auto;
  border-top: 1px solid var(--line);
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
.history-list:empty {
  border-top: 0;
}
.history-item {
  padding: 12px 0 8px;
  border-bottom: 1px solid var(--line);
}
.history-item[data-speaking='true'] .history-text {
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
}
.history-text {
  font-size: 1rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.history-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.history-meta {
  color: var(--ink-3);
  font: 400 0.75rem/1.4 var(--mono);
  font-variant-numeric: tabular-nums;
}
.history-actions {
  display: inline-flex;
  margin-right: -12px;
}
.icon-btn {
  width: 44px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-3);
  cursor: pointer;
  transition:
    background-color 150ms var(--ease),
    color 150ms var(--ease);
}
.icon-btn:hover {
  background: var(--bg-muted);
  color: var(--ink);
}
.icon-btn svg {
  width: 18px;
  height: 18px;
}
.icon-btn .i-check,
.icon-btn[data-copied='true'] .i-copy {
  display: none;
}
.icon-btn[data-copied='true'] .i-check {
  display: block;
  color: var(--ok);
}

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .demo-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .viewport {
    height: auto;
    aspect-ratio: 4 / 3;
  }
}

@media (max-width: 760px) {
  .demo {
    padding-top: 24px;
  }
  .demo-head h1 {
    font-size: 1.75rem;
  }
  .viewport {
    aspect-ratio: 4 / 5;
    border-radius: 12px;
  }
  .gate-icon {
    display: none;
  }
  .controls {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .hint-key {
    display: none;
  }
  .controls-text {
    text-align: center;
  }
  .panel {
    padding: 18px;
  }
  .actions .btn {
    flex: 1;
  }
}
