/* ==========================================================================
   LingoSync — device-style front end
   A physical-looking translator gadget: glossy orange body, black glass
   screen, analog scroll wheel, tactile switches, push-to-talk button.
   Vanilla CSS, mobile-first (360–430px = thumb-reachable controls below the
   screen), CSS variables, prefers-reduced-motion respected throughout.
   ========================================================================== */

:root {
  --font-sans: "Space Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --color-page-bg: #ece9e2;
  --color-page-text: #2a2620;

  --orange-50: #fff1ea;
  --orange-300: #ff8a51;
  --orange-400: #ff6c30;
  --orange-500: #ff5a1f;
  --orange-600: #e6480f;
  --orange-700: #c23a0c;
  --orange-900: #7a2607;

  --screen-bg: #0a0a0c;
  --screen-bg-2: #151318;
  --screen-line: rgba(255, 255, 255, 0.08);
  --screen-text: #f3f1ee;
  --screen-text-dim: rgba(243, 241, 238, 0.55);

  --card-pink: #ff4f9e;
  --card-cyan: #1fc9dd;
  --card-violet: #8b5cf6;
  --card-green: #33c46a;
  --card-red: #ff4d4d;
  --card-orange: #ff8a3d;
  --card-blue: #3d7dff;
  --card-purple: #b15cff;

  --color-idle: #8993a4;
  --color-listening: var(--orange-400);
  --color-speech: #33c46a;
  --color-busy: #e8b64a;
  --color-error: #ff5d5d;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --radius-xl: 34px;

  --shadow-pop: 0 18px 40px rgba(40, 20, 5, 0.22);

  --gutter: 16px;
  --transition-fast: 140ms ease;
  --transition-med: 260ms cubic-bezier(0.34, 1.56, 0.64, 1);
  --transition-spring: 420ms cubic-bezier(0.34, 1.56, 0.64, 1);

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-page-bg: #17140f;
    --color-page-text: #efece5;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--color-page-bg);
  color: var(--color-page-text);
  font-family: var(--font-sans);
  max-width: 100vw;
  overflow-x: hidden;
}

body {
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-transform: lowercase;
}

h1, h2, h3, p {
  margin: 0;
}

button, select, input {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  text-transform: lowercase;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--orange-500);
  color: #fff;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  z-index: 100;
}
.skip-link:focus {
  left: var(--gutter);
  top: var(--gutter);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------------------------- Page ---------------------------- */

.page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: max(20px, env(safe-area-inset-top)) max(var(--gutter), env(safe-area-inset-right)) 24px
    max(var(--gutter), env(safe-area-inset-left));
  gap: 18px;
}

.page-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-align: center;
}

.page-title {
  font-weight: 700;
  font-size: 22px;
  letter-spacing: -0.02em;
}

.page-subtitle {
  font-size: 12px;
  color: var(--color-page-text);
  opacity: 0.55;
}

main {
  width: 100%;
  display: flex;
  justify-content: center;
}

/* ============================================================
   DEVICE BODY
   ============================================================ */

.device {
  position: relative;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px 18px 22px;
  border-radius: var(--radius-xl);
  background: linear-gradient(160deg, var(--orange-300) 0%, var(--orange-500) 45%, var(--orange-700) 100%);
  box-shadow:
    var(--shadow-pop),
    inset 0 2px 0 rgba(255, 255, 255, 0.35),
    inset 0 -10px 24px rgba(120, 30, 0, 0.35),
    inset 10px 0 24px rgba(255, 255, 255, 0.06);
  isolation: isolate;
}

.device-sheen {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: radial-gradient(120% 60% at 15% 0%, rgba(255, 255, 255, 0.45), transparent 60%),
    radial-gradient(80% 40% at 100% 100%, rgba(0, 0, 0, 0.25), transparent 60%);
  mix-blend-mode: overlay;
  z-index: 0;
}

@media (min-width: 700px) {
  .device {
    max-width: 760px;
    flex-direction: row;
    align-items: stretch;
    padding: 24px;
  }
}

/* ---------------------------- Screen ---------------------------- */

.screen-bay {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  padding: 10px;
  border-radius: var(--radius-lg);
  background: linear-gradient(160deg, var(--orange-700), var(--orange-900));
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.4);
  display: flex; /* the screen fills the bay, no empty strip underneath */
}

.screen {
  position: relative;
  overflow: hidden;
  border-radius: calc(var(--radius-lg) - 6px);
  background: radial-gradient(120% 100% at 20% 0%, var(--screen-bg-2), var(--screen-bg) 70%);
  color: var(--screen-text);
  min-height: 420px;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 14px 10px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06), inset 0 2px 18px rgba(0, 0, 0, 0.6);
}

.screen-glow {
  position: absolute;
  inset: -20%;
  pointer-events: none;
  background: radial-gradient(45% 35% at 30% 15%, rgba(255, 106, 48, 0.28), transparent 70%);
  animation: screen-breathe 6s ease-in-out infinite;
  z-index: 0;
}

@keyframes screen-breathe {
  0%, 100% { opacity: 0.55; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.08); }
}

.screen > * {
  position: relative;
  z-index: 1;
}

.screen-topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--screen-text-dim);
  white-space: nowrap;
}

.pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-idle);
  flex: none;
}

.pill-conn[data-state="open"] .dot { background: var(--color-speech); }
.pill-conn[data-state="connecting"] .dot { background: var(--color-busy); animation: pulse 1.2s infinite; }
.pill-conn[data-state="reconnecting"] .dot { background: var(--color-busy); animation: pulse 1.2s infinite; }
.pill-conn[data-state="closed"] .dot { background: var(--color-error); }

.pill-pipeline[data-state="idle"] .dot { background: var(--color-idle); }
.pill-pipeline[data-state="loading"] .dot { background: var(--color-busy); animation: pulse 1.2s infinite; }
.pill-pipeline[data-state="listening"] .dot { background: var(--color-listening); }
.pill-pipeline[data-state="speech"] .dot { background: var(--color-speech); animation: pulse 0.9s infinite; }
.pill-pipeline[data-state="transcribing"] .dot,
.pill-pipeline[data-state="translating"] .dot,
.pill-pipeline[data-state="synthesizing"] .dot { background: var(--color-busy); animation: pulse 0.9s infinite; }
.pill-pipeline[data-state="error"] .dot { background: var(--color-error); }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.75); }
}

.screen-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 4px 0 10px;
  border-bottom: 1px solid var(--screen-line);
}

.lang-readout {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 15px;
  color: var(--screen-text);
}

.lang-readout-from { color: var(--screen-text-dim); }
.lang-readout-arrow { color: var(--orange-400); }
.lang-readout-to { font-weight: 600; font-size: 17px; }

.voice-cluster {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.voice-arc {
  --pct: 0;
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: conic-gradient(var(--orange-400) calc(var(--pct) * 1%), rgba(255, 255, 255, 0.1) 0);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 200ms linear;
}

.voice-arc-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--screen-bg);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.voice-meter {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.audio-bars {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 22px;
}

.audio-bars .bar {
  flex: 1;
  min-width: 2px;
  height: 15%;
  border-radius: 2px;
  background: linear-gradient(180deg, var(--orange-300), var(--orange-500));
  transform-origin: bottom;
  transition: height 90ms ease-out;
}

.level-meter-track {
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.level-meter-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--card-green), var(--orange-400));
  transition: width 90ms linear;
  border-radius: inherit;
}

.speech-indicator {
  align-self: flex-start;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--screen-text-dim);
}

.speech-indicator[data-speech="true"] {
  color: var(--color-speech);
}

.voice-status {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--screen-text-dim);
  text-align: center;
}

.voice-status.is-locked {
  color: var(--card-green);
}

/* ---------------------------- Transcript (in-screen) ---------------------------- */

.transcript-section {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

.transcript-empty-hint {
  font-size: 12px;
  color: var(--screen-text-dim);
  text-align: center;
  padding: 12px 0;
}

.transcript-feed {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1 1 auto;
  min-height: 220px;
  max-height: 46vh;
  overflow-y: auto;
  scroll-behavior: smooth;
  padding: 2px 2px 4px;
}

@media (min-width: 700px) {
  .transcript-feed {
    max-height: 380px;
  }
}

.transcript-card {
  position: relative;
  border-radius: var(--radius-md);
  padding: 12px 14px 10px 40px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: #1a1a1a;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  animation: card-in var(--transition-spring);
  transform-origin: bottom center;
}

@keyframes card-in {
  from { opacity: 0; transform: translateY(22px) scale(0.92); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .transcript-card { animation: none; }
}

.transcript-card::before {
  content: "";
  position: absolute;
  top: 12px;
  left: 12px;
  width: 12px;
  height: 12px;
  background-color: currentColor;
  opacity: 0.55;
  box-shadow:
    0 -4px 0 -1px currentColor, 0 4px 0 -1px currentColor,
    -4px 0 0 -1px currentColor, 4px 0 0 -1px currentColor;
  clip-path: polygon(30% 0, 70% 0, 70% 30%, 100% 30%, 100% 70%, 70% 70%, 70% 100%, 30% 100%, 30% 70%, 0 70%, 0 30%, 30% 30%);
  border-radius: 2px;
}

.card-c0 { background: var(--card-pink); color: #5c0030; }
.card-c1 { background: var(--card-cyan); color: #003338; }
.card-c2 { background: var(--card-violet); color: #24073f; }
.card-c3 { background: var(--card-green); color: #04331a; }
.card-c4 { background: var(--card-red); color: #400505; }
.card-c5 { background: var(--card-orange); color: #3f1c00; }
.card-c6 { background: var(--card-blue); color: #00133f; }
.card-c7 { background: var(--card-purple); color: #2a0740; }

.transcript-card.is-playing {
  animation: card-pulse 1.1s ease-in-out infinite;
}

@keyframes card-pulse {
  0%, 100% { box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 0 0 0 rgba(255, 255, 255, 0.5); }
  50% { box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 0 0 5px rgba(255, 255, 255, 0.18); }
}

@media (prefers-reduced-motion: reduce) {
  .transcript-card.is-playing { animation: none; }
}

.card-top-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.lang-badge {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.14);
}

.card-time {
  font-size: 10px;
  font-family: var(--font-mono);
  opacity: 0.7;
  margin-left: auto;
}

.card-source-text {
  font-size: 12px;
  opacity: 0.75;
}

.card-target-text {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.25;
}

.shimmer {
  display: inline-block;
  min-width: 120px;
  height: 1em;
  border-radius: 4px;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.08) 25%, rgba(0, 0, 0, 0.2) 50%, rgba(0, 0, 0, 0.08) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
  .shimmer { animation: none; }
}

.card-bottom-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 2px;
}

.latency-chips {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.chip {
  font-size: 9.5px;
  font-weight: 600;
  background: rgba(0, 0, 0, 0.12);
  border-radius: 999px;
  padding: 2px 7px;
  white-space: nowrap;
  font-family: var(--font-mono);
}

.play-again-btn {
  margin-left: auto;
  font-size: 11px;
  padding: 5px 11px;
  border-radius: 999px;
  border: none;
  background: rgba(0, 0, 0, 0.16);
  color: inherit;
  font-weight: 700;
  cursor: pointer;
  min-height: 28px;
}

.play-again-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.transcript-card.is-native { opacity: 0.55; filter: saturate(0.35); }
.transcript-card.is-native .card-target-text { font-size: 14px; font-style: italic; font-weight: 500; }
.transcript-card.is-native .play-again-btn { display: none; }

/* ============================================================
   DEVICE CONTROLS (right side / below screen)
   ============================================================ */

.device-controls {
  position: relative;
  z-index: 1;
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding-top: 6px;
}

@media (min-width: 700px) {
  .device-controls {
    width: 260px;
    justify-content: center;
  }
}

.hw-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #17140f;
  color: #fff;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 3px 9px;
  border-radius: 999px;
  margin-bottom: 6px;
}

.hw-pill-dark {
  background: rgba(23, 20, 15, 0.85);
}

/* ---------------------------- Wheel cluster ---------------------------- */

.wheel-cluster {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.wheel-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.wheel {
  position: relative;
  width: 78px;
  height: 176px;
  border-radius: 39px;
  background:
    repeating-linear-gradient(
      to bottom,
      rgba(0, 0, 0, 0.35) 0px,
      rgba(0, 0, 0, 0.35) 1px,
      transparent 1px,
      transparent 6px
    ),
    linear-gradient(100deg, #2b2b2e, #111113 45%, #050506 100%);
  box-shadow:
    inset 0 3px 8px rgba(0, 0, 0, 0.7),
    inset 0 -2px 4px rgba(255, 255, 255, 0.05),
    0 6px 14px rgba(0, 0, 0, 0.35);
  overflow: hidden;
  cursor: grab;
  user-select: none;
  outline: none;
}

.wheel:active {
  cursor: grabbing;
}

.wheel:focus-visible {
  box-shadow:
    inset 0 3px 8px rgba(0, 0, 0, 0.7),
    0 0 0 3px var(--orange-300);
}

.wheel--small {
  width: 62px;
  height: 132px;
  border-radius: 31px;
}

.wheel-track {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  will-change: transform;
}

.wheel-item {
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.32);
  text-align: center;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 150ms ease, opacity 150ms ease;
}

.wheel--small .wheel-item {
  height: 28px;
  font-size: 9.5px;
}

.wheel-item.is-selected {
  color: #fff;
  font-weight: 700;
}

.wheel-item.is-disabled {
  color: rgba(255, 255, 255, 0.12);
}

.wheel-frame {
  position: absolute;
  left: 6px;
  right: 6px;
  top: 50%;
  height: 34px;
  transform: translateY(-50%);
  border-top: 1px solid rgba(255, 255, 255, 0.28);
  border-bottom: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.06);
  pointer-events: none;
  border-radius: 6px;
}

.wheel--small .wheel-frame {
  height: 28px;
}

.wheel-shine {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(115deg, rgba(255, 255, 255, 0.16) 0%, transparent 30%, transparent 70%, rgba(255, 255, 255, 0.06) 100%);
}

.wheel.is-ticking .wheel-frame {
  animation: wheel-tick 160ms ease-out;
}

@keyframes wheel-tick {
  0% { transform: translateY(-50%) scaleX(1); }
  40% { transform: translateY(-50%) scaleX(1.06); }
  100% { transform: translateY(-50%) scaleX(1); }
}

@media (prefers-reduced-motion: reduce) {
  .wheel.is-ticking .wheel-frame { animation: none; }
}

/* ---------------------------- Toggle switches ---------------------------- */

.switch-panel {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px 8px;
  justify-items: center;
}

@media (max-width: 360px) {
  .switch-panel {
    grid-template-columns: repeat(2, 1fr);
  }
}

.switch-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.switch-label {
  display: inline-flex;
}

.switch {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 30px;
  flex: none;
}

.switch input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
  z-index: 2;
  width: 100%;
  height: 100%;
}

.switch-track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.28);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.4), inset 0 -1px 0 rgba(255, 255, 255, 0.08);
  transition: background var(--transition-med);
}

.switch-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: linear-gradient(180deg, #fdfdfd, #d8d8d8);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.45);
  transition: transform var(--transition-med), background var(--transition-fast);
}

.switch input:checked ~ .switch-track {
  background: linear-gradient(180deg, var(--orange-400), var(--orange-600));
}

.switch input:checked ~ .switch-track .switch-knob {
  transform: translateX(22px);
  background: linear-gradient(180deg, #ffffff, #fff2ea);
}

.switch input:disabled ~ .switch-track {
  opacity: 0.35;
}

.switch input:disabled {
  cursor: not-allowed;
}

.switch input:focus-visible ~ .switch-track {
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.4), 0 0 0 3px rgba(255, 255, 255, 0.6);
}

.consent-hint {
  font-size: 10.5px;
  color: rgba(23, 20, 15, 0.72);
  text-align: center;
  line-height: 1.4;
  padding: 0 8px;
}

/* ---------------------------- Push-to-talk button ---------------------------- */

.ptt-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}

.warm-hint {
  font-size: 12px;
  min-height: 16px;
  opacity: 0.75;
  text-align: center;
}

.warm-btn[data-state="warming"] {
  border-color: var(--color-busy);
}

.ptt-button {
  position: relative;
  width: 92px;
  height: 92px;
  border-radius: 50%;
  border: none;
  padding: 0;
  cursor: pointer;
  background: radial-gradient(circle at 35% 25%, #241f18, #0c0a08 70%);
  box-shadow:
    0 10px 22px rgba(0, 0, 0, 0.4),
    inset 0 2px 3px rgba(255, 255, 255, 0.12),
    inset 0 -6px 10px rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--transition-fast);
}

.ptt-button:active {
  transform: scale(0.94);
}

.ptt-face {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--orange-300), var(--orange-600) 75%);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.35), inset 0 -4px 8px rgba(0, 0, 0, 0.35);
}

.ptt-icon {
  font-size: 22px;
  color: #fff;
  line-height: 1;
}

.ptt-ring {
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 3px solid var(--orange-300);
  opacity: 0;
  pointer-events: none;
}

#startStopBtn[aria-pressed="true"] .ptt-ring {
  opacity: 1;
  animation: ptt-glow 1.5s ease-in-out infinite;
}

#startStopBtn[aria-pressed="true"] .ptt-face {
  background: radial-gradient(circle at 35% 30%, #ff7a45, var(--color-error) 85%);
}

@keyframes ptt-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 138, 61, 0.55); transform: scale(1); }
  50% { box-shadow: 0 0 0 8px rgba(255, 138, 61, 0); transform: scale(1.04); }
}

@media (prefers-reduced-motion: reduce) {
  #startStopBtn[aria-pressed="true"] .ptt-ring { animation: none; opacity: 1; box-shadow: 0 0 0 6px rgba(255, 138, 61, 0.35); }
}

.ptt-label {
  font-size: 12px;
  font-weight: 700;
  color: #2a1305;
  letter-spacing: 0.02em;
}

/* ---------------------------- Drawer toggle ---------------------------- */

.drawer-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(23, 20, 15, 0.16);
  color: #2a1305;
  border: 1px solid rgba(23, 20, 15, 0.22);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
}

.drawer-toggle:hover {
  background: rgba(23, 20, 15, 0.26);
}

/* ---------------------------- Hidden native controls ---------------------------- */

.native-controls {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

/* ============================================================
   SETTINGS DRAWER
   ============================================================ */

.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 5, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-med);
  z-index: 40;
}

.drawer-overlay.is-open {
  opacity: 1;
  pointer-events: auto;
}

.settings-drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  height: 100dvh;
  width: min(340px, 90vw);
  background: var(--color-page-bg);
  box-shadow: -12px 0 40px rgba(0, 0, 0, 0.3);
  transform: translateX(100%);
  transition: transform var(--transition-spring);
  z-index: 41;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 18px 18px;
  overflow-y: auto;
}

.settings-drawer.is-open {
  transform: translateX(0);
}

@media (prefers-reduced-motion: reduce) {
  .settings-drawer, .drawer-overlay { transition: none; }
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.drawer-header h2 {
  font-size: 16px;
  font-weight: 700;
}

.drawer-close {
  background: rgba(0, 0, 0, 0.08);
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  cursor: pointer;
  font-size: 14px;
}

.drawer-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.drawer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn {
  appearance: none;
  border: 1px solid rgba(0, 0, 0, 0.14);
  background: #fff;
  color: var(--color-page-text);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  transition: filter var(--transition-fast), transform var(--transition-fast);
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--orange-500);
  border-color: var(--orange-500);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  border-color: rgba(0, 0, 0, 0.14);
}

.btn-icon {
  padding: 8px;
  border-radius: 999px;
  min-width: 44px;
  justify-content: center;
}

.drawer-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.drawer-field-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--color-page-text);
  opacity: 0.6;
  letter-spacing: 0.02em;
}

select {
  width: 100%;
  padding: 10px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(0, 0, 0, 0.16);
  background: #fff;
  color: var(--color-page-text);
  min-height: 44px;
}

select:disabled {
  opacity: 0.5;
}

.volume-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--orange-500);
  height: 44px;
}

/* ---------------------------- Toasts ---------------------------- */

.toast-container {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 60;
  width: calc(100% - 32px);
  max-width: 420px;
  align-items: center;
}

.toast {
  width: 100%;
  background: #2a0505;
  color: #ffdada;
  border: 1px solid var(--color-error);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-pop);
  animation: toast-in var(--transition-med);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.toast button {
  background: transparent;
  border: none;
  color: inherit;
  font-weight: 700;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  flex: none;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .toast { animation: none; }
}

/* ---------------------------- Footer ---------------------------- */

.app-footer {
  text-align: center;
  padding: 4px var(--gutter) max(10px, env(safe-area-inset-bottom));
  font-size: 11px;
  color: var(--color-page-text);
  opacity: 0.55;
}

/* ---------------------------- Small screens ---------------------------- */

@media (max-width: 420px) {
  .device {
    border-radius: 28px;
    padding: 14px 14px 18px;
  }
  .screen {
    min-height: 360px;
  }
  .ptt-button {
    width: 84px;
    height: 84px;
  }
  .ptt-face {
    width: 62px;
    height: 62px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 120ms !important;
  }
  .screen-glow { display: none; }
}

/* Phone: keep the language wheels and the big button within thumb reach under a shorter screen. */
@media (max-width: 699px) {
  .page-header { display: none; }
  .device {
    padding-top: max(14px, env(safe-area-inset-top));
    padding-bottom: max(18px, env(safe-area-inset-bottom));
  }
  .screen { min-height: 0; height: 40vh; height: 40dvh; }
  .transcript-feed { min-height: 0; max-height: none; }
  .device-controls {
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-areas:
      "wheels ptt"
      "switches switches"
      "hint hint"
      "settings settings";
    align-items: center;
    justify-items: center;
    gap: 14px 12px;
  }
  .wheel-cluster { grid-area: wheels; }
  .ptt-row { grid-area: ptt; }
  .switch-panel { grid-area: switches; }
  .consent-hint { grid-area: hint; }
  .drawer-toggle { grid-area: settings; }
}


/* ---------------------------- Speakers (who is talking, their voice) ---------------------------- */
.speaker-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 8px;
}

.speaker-chip {
  --spk: var(--card-cyan);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--screen-line);
  background: var(--screen-bg-2);
  color: var(--screen-text);
  font-family: var(--font-mono);
  font-size: 12px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.speaker-chip.is-speaking,
.speaker-chip.is-playing {
  border-color: var(--spk);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--spk) 35%, transparent);
}

.speaker-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--spk);
  opacity: 0.5;
}

.speaker-chip.is-speaking .speaker-dot,
.speaker-chip.is-playing .speaker-dot {
  opacity: 1;
}

.speaker-name,
.speaker-name-input {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}

.speaker-name-input {
  width: 12ch;
  border-bottom: 1px solid var(--spk);
  text-decoration: none;
  outline: none;
  cursor: text;
}

.speaker-voice {
  color: var(--screen-text-dim);
}

.speaker-chip.is-locked .speaker-voice {
  color: var(--card-green);
}

.card-speaker {
  --spk: var(--card-cyan);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--spk);
}

.usage-meter {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--screen-text-dim);
  text-align: center;
  margin-top: 6px;
}
