:root {
  --cloud: #f3f6fb;
  --paper: #ffffff;
  --ink: #18202b;
  --quiet: #7a8491;
  --line: #dce3ec;
  --voice: #2864dc;
  --voice-soft: #dce8ff;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% 42%, #fff 0 18rem, transparent 37rem),
    var(--cloud);
  font-family: "Avenir Next", Avenir, sans-serif;
}

button {
  font: inherit;
}

.stage {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 3rem 1.25rem;
}

.demo {
  width: min(44rem, 100%);
  text-align: center;
}

.intro {
  transition: opacity 240ms ease;
}

.eyebrow {
  margin: 0 0 0.75rem;
  color: var(--voice);
  font: 500 0.68rem/1 "SFMono-Regular", Menlo, monospace;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2.35rem, 7vw, 4.4rem);
  font-weight: 500;
  letter-spacing: -0.055em;
  line-height: 1;
}

.hint {
  margin: 1rem 0 0;
  color: var(--quiet);
  font-size: 0.95rem;
}

.recorder {
  position: relative;
  display: grid;
  justify-items: center;
  margin: 2.3rem auto 0;
  width: 7.5rem;
}

.mic {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 5.25rem;
  height: 5.25rem;
  padding: 0;
  color: white;
  background: var(--voice);
  border: 0;
  border-radius: 50%;
  box-shadow: 0 0.8rem 2.2rem rgb(40 100 220 / 22%);
  cursor: pointer;
  transition: transform 180ms ease, background 180ms ease;
}

.mic:hover {
  transform: translateY(-2px);
}

.mic:active {
  transform: scale(0.96);
}

.mic:focus-visible,
.play:focus-visible,
.again:focus-visible {
  outline: 3px solid rgb(40 100 220 / 32%);
  outline-offset: 4px;
}

.mic svg {
  width: 1.85rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mic::after {
  content: "";
  display: none;
  width: 1rem;
  height: 1rem;
  background: currentColor;
  border-radius: 0.16rem;
}

.pulse {
  position: absolute;
  top: 0;
  width: 5.25rem;
  height: 5.25rem;
  border: 1px solid var(--voice);
  border-radius: 50%;
  opacity: 0;
}

.recording .mic {
  background: #e3485f;
}

.recording .mic svg {
  display: none;
}

.recording .mic::after {
  display: block;
}

.recording .pulse {
  border-color: #e3485f;
  animation: listen 1.8s ease-out infinite;
}

.timer {
  margin-top: 0.8rem;
  color: var(--quiet);
  font: 400 0.72rem/1 "SFMono-Regular", Menlo, monospace;
  opacity: 0;
}

.recording .timer {
  opacity: 1;
}

.status {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.48rem;
  min-height: 1.2rem;
  margin-top: 1rem;
  color: var(--quiet);
  font-size: 0.78rem;
}

.status-dot {
  width: 0.38rem;
  height: 0.38rem;
  background: #a8b1bd;
  border-radius: 50%;
}

.busy .status-dot {
  background: var(--voice);
  animation: blink 1.25s ease-in-out infinite;
}

#progressText {
  font: 400 0.68rem/1 "SFMono-Regular", Menlo, monospace;
}

.result {
  margin-top: 2rem;
  padding: 1.05rem 1.15rem 1.2rem;
  text-align: left;
  background: rgb(255 255 255 / 88%);
  border: 1px solid var(--line);
  border-radius: 1.15rem;
  box-shadow: 0 1.2rem 4rem rgb(64 83 110 / 8%);
  animation: arrive 320ms ease-out both;
}

.playback {
  display: grid;
  grid-template-columns: 2rem 1fr 2.5rem;
  align-items: center;
  gap: 0.8rem;
  padding: 0.15rem 0 0.85rem;
  border-bottom: 1px solid var(--line);
}

.play {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  color: white;
  background: var(--ink);
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}

.play svg {
  width: 1rem;
  fill: currentColor;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.play .pause-icon,
.playing .play-icon {
  display: none;
}

.playing .pause-icon {
  display: block;
}

.track {
  height: 2px;
  overflow: hidden;
  background: var(--line);
  border-radius: 1rem;
}

.track span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--voice);
}

#playTime {
  color: var(--quiet);
  font: 400 0.68rem/1 "SFMono-Regular", Menlo, monospace;
  text-align: right;
}

.transcript {
  max-height: min(44svh, 25rem);
  overflow: auto;
  padding: 1.15rem 0.25rem 0.2rem;
  font-family: "Geeza Pro", "Noto Sans Arabic", Arial, sans-serif;
  font-size: clamp(1.2rem, 3.5vw, 1.55rem);
  line-height: 2.25;
  scrollbar-width: thin;
}

.word {
  position: relative;
  display: inline-block;
  margin-inline: 0.05em;
  padding: 0 0.12em;
  border-radius: 0.25em;
  cursor: pointer;
  transition: color 100ms ease, background 100ms ease;
}

.word::after {
  content: attr(data-time);
  position: absolute;
  inset-inline-start: 50%;
  bottom: -0.45rem;
  z-index: 2;
  padding: 0.22rem 0.35rem;
  color: white;
  background: var(--ink);
  border-radius: 0.25rem;
  font: 400 0.55rem/1 "SFMono-Regular", Menlo, monospace;
  direction: ltr;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 0.15rem);
  transition: opacity 120ms ease, transform 120ms ease;
}

.word:hover::after,
.word:focus-visible::after {
  opacity: 1;
  transform: translate(-50%, 0);
}

.word.active {
  color: var(--voice);
  background: color-mix(in srgb, var(--voice) 14%, white);
}

.partial {
  margin: 0;
  padding: 1rem 0.25rem 0.2rem;
  color: var(--quiet);
  font: 400 1.15rem/2 "Geeza Pro", "Noto Sans Arabic", Arial, sans-serif;
}

.partial:empty {
  display: none;
}

.downloads {
  display: flex;
  justify-content: center;
  gap: 0.45rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.downloads button {
  padding: 0.42rem 0.7rem;
  color: var(--quiet);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  font: 500 0.62rem/1 "SFMono-Regular", Menlo, monospace;
  transition: color 140ms ease, border-color 140ms ease, background 140ms ease;
}

.downloads button:hover:not(:disabled) {
  color: var(--voice);
  background: var(--voice-soft);
  border-color: color-mix(in srgb, var(--voice) 35%, var(--line));
}

.downloads button:focus-visible {
  outline: 3px solid rgb(40 100 220 / 25%);
  outline-offset: 2px;
}

.downloads button:disabled {
  cursor: default;
  opacity: 0.38;
}

.again {
  display: block;
  margin: 0.55rem auto 0;
  padding: 0.45rem 0.7rem;
  color: var(--quiet);
  background: transparent;
  border: 0;
  cursor: pointer;
  font-size: 0.75rem;
}

.again:hover {
  color: var(--ink);
}

.error {
  margin: 1.25rem 0 0;
  color: #b52f47;
  font-size: 0.82rem;
}

@keyframes listen {
  from { opacity: 0.45; transform: scale(1); }
  to { opacity: 0; transform: scale(1.65); }
}

@keyframes blink {
  50% { opacity: 0.25; }
}

@keyframes arrive {
  from { opacity: 0; transform: translateY(0.7rem); }
}

@media (max-width: 36rem) {
  .stage {
    align-items: start;
    padding-top: 12svh;
  }

  .result {
    margin-inline: -0.25rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
