:root {
  --bg: #f5f2ea;
  --paper: #fffdf8;
  --ink: #1d1b17;
  --muted: #6b655a;
  --faint: #9c958a;
  --line: #e2dccf;
  --hover: #ece7dc;
  --accent: #d2402b;
  --accent-ring: rgb(210 64 43 / 0.22);
  --focus: #2d68d8;
  --shadow: 0 1px 2px rgb(45 35 15 / 0.05), 0 10px 30px rgb(45 35 15 / 0.06);
  --serif: "Iowan Old Style", "Charter", "Sitka Text", Cambria, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151412;
    --paper: #1c1b18;
    --ink: #ece7dc;
    --muted: #a39c8f;
    --faint: #6f695f;
    --line: #2e2c27;
    --hover: #26241f;
    --accent: #f05a43;
    --accent-ring: rgb(240 90 67 / 0.25);
    --focus: #7aa5ff;
    --shadow: none;
  }
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-underline-offset: 2px;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.page {
  max-width: 780px;
  margin: 0 auto;
  padding: 0 16px 200px;
}

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 16px;
  padding: 28px 0 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font: 600 21px/1 var(--sans);
  letter-spacing: -0.01em;
}

.brand em {
  font: italic 500 23px/1 var(--serif);
  letter-spacing: 0;
}

.mark {
  width: 28px;
  height: 28px;
  align-self: center;
}

.mark rect:first-child {
  fill: var(--ink);
}

.mark rect + rect,
.mark path {
  fill: none;
  stroke: var(--bg);
  stroke-width: 2.2;
  stroke-linecap: round;
}

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

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.spacer {
  flex: 1;
}

.toolbar button,
.toolbar select,
.words button {
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.toolbar select {
  padding-right: 30px;
  appearance: none;
  background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5l3 3 3-3' fill='none' stroke='%23888' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 12px center / 12px;
}

.toolbar select option {
  background: var(--paper);
  color: var(--ink);
}

.toolbar button:hover,
.toolbar select:hover,
.words button:hover {
  background: var(--hover);
}

.count {
  color: var(--faint);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  margin-right: 4px;
}

.sheet {
  min-height: 46vh;
  padding: 28px 34px 32px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--paper);
  box-shadow: var(--shadow);
  cursor: text;
}

#editor {
  display: block;
  width: 100%;
  min-height: 3.3em;
  padding: 0;
  border: 0;
  outline: 0;
  resize: none;
  overflow: hidden;
  background: transparent;
  color: var(--ink);
  font: 19px/1.65 var(--serif);
  caret-color: var(--accent);
}

#editor::placeholder {
  color: var(--faint);
}

.live {
  margin: 6px 0 0;
  color: var(--muted);
  font: italic 19px/1.65 var(--serif);
  scroll-margin-bottom: 170px;
}

.live.waiting::after {
  content: "";
  display: inline-block;
  width: 1.6em;
  height: 0.5em;
  background: radial-gradient(circle, var(--faint) 2.5px, transparent 3px) 0 50% / 0.53em 100% repeat-x;
  animation: dots 1.2s steps(4) infinite;
  clip-path: inset(0 100% 0 0);
}

@keyframes dots {
  to {
    clip-path: inset(0 -10% 0 0);
  }
}

.about {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
  margin: 44px 0 0;
}

.about h2 {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: 600;
}

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

.foot {
  margin-top: 36px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-size: 13px;
}

.foot p {
  margin: 0;
}

.dock {
  position: fixed;
  inset: auto 0 0;
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 28px 16px calc(16px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 62%, transparent);
  pointer-events: none;
}

.dock > * {
  pointer-events: auto;
}

.mic {
  --level: 0;
  position: relative;
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--ink);
  color: var(--bg);
  cursor: pointer;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.18);
  transition: background-color 0.2s, transform 0.15s, box-shadow 0.12s linear;
  -webkit-tap-highlight-color: transparent;
}

.mic:hover {
  transform: scale(1.04);
}

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

.mic:focus-visible {
  outline-offset: 4px;
}

.mic svg {
  width: 30px;
  height: 30px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.mic .i-stop {
  display: none;
  fill: currentColor;
  stroke: none;
}

.mic[aria-pressed="true"] {
  background: var(--accent);
  color: #fff;
}

.mic[aria-pressed="true"] .i-mic {
  display: none;
}

.mic[aria-pressed="true"] .i-stop {
  display: block;
}

.mic[aria-pressed="true"] {
  box-shadow: 0 0 0 calc(5px + var(--level) * 22px) var(--accent-ring), 0 6px 20px rgb(0 0 0 / 0.18);
}

body[data-rec="starting"] .mic,
body[data-rec="finishing"] .mic {
  animation: pulse 1.1s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.7;
  }
}

.status {
  max-width: 520px;
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  text-wrap: balance;
}

.status.error {
  color: var(--accent);
}

.words {
  width: min(460px, calc(100vw - 32px));
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 20px 60px rgb(0 0 0 / 0.25);
}

.words::backdrop {
  background: rgb(20 18 15 / 0.35);
}

.words h2 {
  margin: 0 0 4px;
  font-size: 17px;
}

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

.words textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
  resize: vertical;
}

.words .actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
}

.words button {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}

.words button:hover {
  background: var(--ink);
  opacity: 0.88;
}

@media (max-width: 640px) {
  .top {
    padding: 20px 0 14px;
  }

  .tagline {
    font-size: 13px;
  }

  .sheet {
    padding: 20px 18px 24px;
    border-radius: 14px;
  }

  #editor,
  .live {
    font-size: 18px;
  }

  .about {
    grid-template-columns: 1fr;
    gap: 18px;
  }

  .count {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
