@import "fonts/fonts.css";

:root {
  /* Yak Identity v2 color palette */
  --yak-ground: #f1ece2;        /* page ground */
  --yak-paper: #fbf9f4;         /* editor, boxes */
  --yak-sand: #e8e2d5;          /* container panel */
  --yak-sand-2: #efeae0;        /* panel inner */
  --yak-rule: #d8d0bf;          /* 1px rules */
  --yak-rule-2: #d6cdbc;        /* panel outer border */
  --yak-grey: #5f594f;          /* secondary text: >= 4.5:1 on ground, paper and sand */
  --yak-grey-soft: #6b645a;     /* tentative/preview text and placeholder: >= 4.5:1 on paper */
  --yak-grey-3: #b9b2a4;
  --yak-ink: #3a3733;           /* primary ink */
  --yak-vermilion: #b33a1c;     /* accent, recording state, mark stop: >= 4.5:1 as text on sand */
  --yak-vermilion-tint: #f2d8cd;
  --yak-vermilion-wash: #f7e9e3;
  --yak-unsure: #c87a1e;        /* light warm amber for unsure words */

  /* Typography */
  --font-serif: "Source Serif 4", Georgia, serif;
  --font-mono: "Source Code Pro", ui-monospace, monospace;

  /* Elevation and radii */
  --shadow-panel: 0 10px 34px rgba(58, 55, 51, 0.10);
  --shadow-hero: 0 14px 44px rgba(58, 55, 51, 0.16);
  --radius-btn: 2px;
  --radius-panel: 6px;

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --duration-short: 180ms;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background-color: var(--yak-ground);
  background-image: radial-gradient(rgba(0, 0, 0, 0.018) 0.6px, transparent 0.7px);
  background-size: 5px 5px;
  color: var(--yak-ink);
  font-family: var(--font-serif);
  font-size: 17px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Page wrapper filling viewport */
.app-layout {
  max-width: 980px;
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 20px min(4vw, 36px) 24px;
}

/* Header with baseline / centered alignment */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding-bottom: 14px;
  border-bottom: 2px solid var(--yak-ink);
  margin-bottom: 18px;
  flex-shrink: 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.brand-left {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.diane-mark {
  width: 38px;
  height: 26px;
  transform: translateY(3px);
  display: block;
}

.brand-title {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 26px;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--yak-ink);
}

.brand-title .dot {
  color: var(--yak-vermilion);
}

.brand-host {
  font-family: var(--font-mono);
  font-weight: 400;
  font-size: 13px;
  line-height: 1;
  color: var(--yak-grey);
}

#load {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1;
  color: var(--yak-grey);
  white-space: nowrap;
}

.header-nav {
  display: inline-flex;
  align-items: baseline;
  position: relative;
}

.header-docs {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
}

.overflow-btn {
  display: none;
}

.docs-link {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1;
  color: var(--yak-grey);
  text-decoration: none;
  white-space: nowrap;
  transition: color var(--duration-short) var(--ease-out);
}

.docs-link:hover {
  color: var(--yak-ink);
  text-decoration: underline;
}

.docs-link:focus-visible {
  outline: 2px solid var(--yak-ink);
  outline-offset: 2px;
}

.header-sep {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1;
  color: var(--yak-grey);
  user-select: none;
}

.soon-short {
  display: none;
}

.soon-long {
  display: inline;
}

/* Main workspace */
.main-content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: relative;
}

/* Panel surface filling vertical space */
.panel {
  background: var(--yak-sand);
  border: 1px solid var(--yak-rule-2);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow-panel);
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
  z-index: 2;
  transition: box-shadow var(--duration-short) var(--ease-out);
}

.panel:focus-within {
  box-shadow: var(--shadow-hero);
}

/* Editor */
/* The editor takes whatever height is left after the fixed header, footer and mic dock */
#editor {
  flex: 1;
  min-height: 96px;
  height: auto;
  overflow-y: auto;
  background: var(--yak-paper);
  padding: 24px 28px;
  font-family: var(--font-serif);
  font-size: 19.5px;
  line-height: 1.6;
  color: var(--yak-ink);
  outline: none;
  word-break: break-word;
  white-space: pre-wrap;
  user-select: text;
  transition: font-size 250ms ease;
}

@media (prefers-reduced-motion: reduce) {
  #editor {
    transition: none;
  }
}

#editor[data-fontstep="0"] {
  font-size: 19.5px;
}

#editor[data-fontstep="1"] {
  font-size: 17.5px;
}

#editor[data-fontstep="2"] {
  font-size: 15.5px;
}

#editor[data-fontstep="3"] {
  font-size: 15px;
}

#editor:focus-visible {
  outline: 2px solid var(--yak-ink);
  outline-offset: -2px;
}

#editor:empty::before {
  content: attr(data-placeholder);
  color: var(--yak-grey-soft);
  pointer-events: none;
}

/* Committed, tentative and preview text */
#editor span.committed {
  color: var(--yak-ink);
}

#editor span.tentative {
  color: var(--yak-grey-soft);
  transition: opacity var(--duration-short) var(--ease-out);
}

#editor span.preview {
  color: var(--yak-grey-soft);
  transition: color var(--duration-short) var(--ease-out), opacity var(--duration-short) var(--ease-out);
}

#editor span.listening {
  color: var(--yak-grey-soft);
  user-select: none;
  -webkit-user-select: none;
  pointer-events: none;
}

#editor span.uncertain,
span.uncertain {
  text-decoration: underline 2px;
  text-decoration-color: var(--yak-unsure);
  text-underline-offset: 3px;
  text-decoration-skip-ink: auto;
}

#editor span.pending-take,
span.pending-take {
  display: inline-block;
  font-family: var(--font-mono, monospace);
  font-size: 0.85em;
  color: var(--yak-grey, #5f594f);
  background: rgba(0, 0, 0, 0.04);
  padding: 1px 6px;
  border-radius: 3px;
  margin: 0 4px;
  user-select: none;
  -webkit-user-select: none;
  cursor: default;
}

/* Stopping shimmer on active dictation spans */
@keyframes stopping-shimmer {
  0% {
    opacity: 0.45;
  }
  50% {
    opacity: 0.95;
  }
  100% {
    opacity: 0.45;
  }
}

body[data-state="stopping"] #editor span.committed,
body[data-state="stopping"] #editor span.tentative,
body[data-state="stopping"] #editor span.preview {
  animation: stopping-shimmer 1.4s ease-in-out infinite;
}

body[data-state="stopping"] #editor span.tentative {
  animation-delay: 0.25s;
}

body[data-state="stopping"] #editor span.preview {
  animation-delay: 0.5s;
}

.dictation-final-fade {
  display: inline;
}

/* Panel footer strip */
.panel-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 16px;
  padding: 12px 24px 14px;
  background: var(--yak-sand);
  border-top: 1px solid var(--yak-rule);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--yak-grey);
  flex-shrink: 0;
}

.word-count {
  white-space: nowrap;
}

.actions-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Buttons */
.btn-action {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.2;
  padding: 4px 10px;
  border: 1px solid var(--yak-ink);
  border-radius: var(--radius-btn);
  background: transparent;
  color: var(--yak-ink);
  cursor: pointer;
  transition: background var(--duration-short) var(--ease-out),
              color var(--duration-short) var(--ease-out),
              border-color var(--duration-short) var(--ease-out);
}

.btn-action:hover {
  background: var(--yak-ink);
  color: var(--yak-ground);
}

.btn-action:focus-visible {
  outline: 2px solid var(--yak-ink);
  outline-offset: 2px;
}

.btn-action.copied {
  background: var(--yak-ink);
  color: var(--yak-ground);
  border-color: var(--yak-ink);
}

.btn-action.copy-failed {
  border-color: var(--yak-vermilion);
  color: var(--yak-vermilion);
}

#copy {
  min-width: 5.5em;
  text-align: center;
}

/* Controls section: mic dock (below card) */
.controls-area {
  position: relative;
  margin-top: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 0 0 20px;
  flex-shrink: 0;
}

/* Fixed-size stage for mic and visual rings */
.mic-stage {
  position: relative;
  width: 140px;
  height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.visual-halo {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.halo-soft {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(1);
  width: 110px;
  height: 110px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(195, 64, 31, 0.45) 0%, rgba(195, 64, 31, 0.12) 55%, transparent 72%);
  filter: blur(8px);
  pointer-events: none;
  opacity: 0;
  will-change: transform, opacity;
}

.halo-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(1);
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
  will-change: transform, opacity;
}

.halo-ring-1 {
  width: 106px;
  height: 106px;
  border: 1.5px solid var(--yak-vermilion);
}

.halo-ring-2 {
  width: 126px;
  height: 126px;
  border: 1px dashed var(--yak-vermilion);
}

/* Queued breath animation */
@keyframes queued-breathe {
  0% { transform: translate(-50%, -50%) scale(0.96); opacity: 0.35; }
  50% { transform: translate(-50%, -50%) scale(1.08); opacity: 0.75; }
  100% { transform: translate(-50%, -50%) scale(0.96); opacity: 0.35; }
}

body[data-state="queued"] .halo-ring-1 {
  border-color: var(--yak-ink);
  opacity: 0.5;
  animation: queued-breathe 2s ease-in-out infinite;
}

/* Mic button (88-96px hero button on desktop) */
#mic {
  position: relative;
  width: 92px;
  height: 92px;
  border-radius: 50%;
  border: 2px solid var(--yak-ink);
  background: var(--yak-paper);
  color: var(--yak-ink);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: background var(--duration-short) var(--ease-out),
              border-color 150ms var(--ease-out),
              color var(--duration-short) var(--ease-out);
  z-index: 4;
}

body[data-state="idle"] #mic:hover {
  border-color: var(--yak-vermilion);
}

body[data-state="idle"] #mic:hover .mic-icon {
  transform: scale(1.06);
}

#mic:active .mic-icon {
  transform: scale(0.94);
}

#mic:focus-visible {
  outline: 2px solid var(--yak-ink);
  outline-offset: 4px;
}

.mic-icon {
  width: 36px;
  height: 36px;
  display: block;
  transition: transform 120ms var(--ease-out);
}

/* Starting mic state: neutral pulsing ring visibly distinct from live recording */
body[data-state="connecting"]:not([data-cue="speak-now"]) #mic,
body[data-state="queued"]:not([data-cue="speak-now"]) #mic,
body[data-state="reconnecting"]:not([data-cue="speak-now"]) #mic,
body[data-state="recording"]:not([data-cue="speak-now"]) #mic {
  border-color: var(--yak-rule);
  background: var(--yak-ground);
  color: var(--yak-grey);
  box-shadow: 0 0 0 3px var(--yak-sand);
  animation: mic-starting-pulse 1.4s ease-in-out infinite;
}

@keyframes mic-starting-pulse {
  0%, 100% { box-shadow: 0 0 0 2px var(--yak-sand); }
  50% { box-shadow: 0 0 0 9px rgba(180, 175, 165, 0.45); }
}

/* Capturing / live active states */
body[data-cue="speak-now"] #mic,
body[data-state="queued"][data-cue="speak-now"] #mic,
body[data-state="recording"][data-cue="speak-now"] #mic,
body[data-state="connecting"][data-cue="speak-now"] #mic,
body[data-state="reconnecting"][data-cue="speak-now"] #mic {
  border-color: var(--yak-vermilion);
  background: var(--yak-vermilion);
  color: var(--yak-paper);
}

body[data-cue="speak-now"] #mic .mic-icon {
  animation: speak-now-pop 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes speak-now-pop {
  0% { transform: scale(0.92); }
  60% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

body[data-state="recording"] #mic:focus-visible,
body[data-state="connecting"] #mic:focus-visible,
body[data-state="queued"] #mic:focus-visible,
body[data-state="reconnecting"] #mic:focus-visible {
  outline-color: var(--yak-vermilion);
}

/* Spinner for stopping */
.stopping-spinner {
  display: none;
  width: 38px;
  height: 38px;
  border: 2px solid var(--yak-sand);
  border-top-color: var(--yak-ink);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Level meter canvas in dock */
.level-meter {
  display: block;
  width: 160px;
  height: 8px;
  margin: 8px auto 4px;
  pointer-events: none;
  position: relative;
  z-index: 1;
}

body[data-state="stopping"] #mic .mic-icon {
  display: none;
}

body[data-state="stopping"] #mic .stopping-spinner {
  display: block;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Status block holding hints, timer row, and status rows */
.status-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 36em;
  min-height: 76px;
  height: 76px;
  box-sizing: border-box;
}

/* Quiet idle hint under mic */
.mic-hint {
  font-family: var(--font-mono);
  font-size: 15px;
  line-height: 1.35;
  color: var(--yak-grey);
  margin: 0;
  user-select: none;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hint-tap {
  display: none;
}

.hint-click {
  display: inline;
  text-align: center;
}

@media (hover: none) and (pointer: coarse) {
  .hint-click {
    display: none;
  }
  .hint-tap {
    display: inline;
    text-align: center;
  }
}

.kbd-hint {
  display: none;
  font-family: var(--font-mono);
  font-size: 14.5px;
  line-height: 1.35;
  color: var(--yak-grey);
  text-align: center;
  margin-top: 2px;
}

body:not([data-state="idle"]) .mic-hint {
  display: none !important;
}

body[data-state="idle"] #timer {
  display: none !important;
}

body[data-state="idle"] .status-row {
  min-height: 24px;
  height: 24px;
}

/* Timer readout */
#timer {
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.2;
  color: var(--yak-grey);
  letter-spacing: 0.04em;
  min-height: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#timer:empty {
  visibility: hidden;
}

/* Status row containing status message and retry button */
.status-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  min-height: 48px;
  height: 48px;
  width: 100%;
}

/* Status line */
#status {
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 400;
  font-size: 15.5px;
  line-height: 1.45;
  color: var(--yak-grey);
  text-align: center;
  max-width: 34em;
  text-wrap: balance;
}

#status .mono {
  font-family: var(--font-mono);
  font-style: normal;
  font-size: 13.5px;
}

body[data-state="error"] #status {
  color: var(--yak-vermilion);
}

body[data-state="error"][data-error-kind="calm"] #status {
  color: var(--yak-grey);
}

/* Retry button placed next to error status */
.btn-retry {
  border-color: var(--yak-vermilion);
  color: var(--yak-vermilion);
  padding: 3px 10px;
}

.btn-retry:hover {
  background: var(--yak-vermilion);
  color: var(--yak-ground);
}

body[data-state="error"][data-error-kind="calm"] .btn-retry {
  border-color: var(--yak-ink);
  color: var(--yak-ink);
}

body[data-state="error"][data-error-kind="calm"] .btn-retry:hover {
  background: var(--yak-ink);
  color: var(--yak-ground);
}

body:not([data-state="error"]) #retry {
  display: none !important;
}

body[data-state="error"] #retry {
  display: inline-flex !important;
}

/* Language badge next to #status */
#lang-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  width: 32px;
  min-width: 32px;
  height: 20px;
  padding: 0 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--yak-ink);
  background: var(--yak-sand-2);
  border: 1px solid var(--yak-rule);
  border-radius: 10px;
  line-height: 1;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

#lang-badge[hidden] {
  display: inline-flex !important;
  visibility: hidden;
}

#lang-badge.detecting {
  width: auto;
  min-width: 32px;
  padding: 0 8px;
  text-transform: none;
  font-size: 10.5px;
  letter-spacing: 0.02em;
}

/* Header language flag buttons */
.header-flags {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.flag-btn {
  position: relative;
  width: 28px;
  height: 20px;
  padding: 0;
  margin: 0;
  border: 1px solid rgba(58, 55, 51, 0.25);
  border-radius: 2px;
  background: transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-sizing: border-box;
  outline: none;
  transition: transform var(--duration-short) var(--ease-out), box-shadow var(--duration-short) var(--ease-out);
}

/* Tap target expander: at least 32px (and 36px on mobile) */
.flag-btn::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 36px;
  height: 36px;
  transform: translate(-50%, -50%);
}

.flag-btn img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}

/* Active (on): full colour, with a clear ring in ink colour */
.flag-btn[aria-pressed="true"] {
  border-color: var(--yak-ink);
  box-shadow: 0 0 0 1.5px var(--yak-ink);
}

/* Off: the flag sits behind a half-opaque grey overlay and is visibly inactive */
.flag-btn[aria-pressed="false"]::after {
  content: "";
  position: absolute;
  inset: 0;
  background-color: rgba(120, 120, 120, 0.55);
  pointer-events: none;
}

.flag-btn[aria-pressed="false"] {
  opacity: 0.7;
}

.flag-btn:hover:not(:disabled) {
  opacity: 1;
}

.flag-btn:focus-visible {
  outline: 2px solid var(--yak-ink);
  outline-offset: 2px;
}

@keyframes flag-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

.flag-btn.shake {
  animation: flag-shake 200ms ease-in-out;
}

/* While a dictation is running, flags are disabled (no toggling mid-stream) */
body:not([data-state="idle"]):not([data-state="done"]):not([data-state="error"]) .flag-btn,
.flag-btn:disabled {
  pointer-events: none;
  cursor: not-allowed;
  opacity: 0.45;
}

@keyframes flag-detecting-pulse {
  0%, 100% {
    opacity: 0.85;
    transform: scale(1);
  }
  50% {
    opacity: 0.45;
    transform: scale(0.96);
  }
}

.flag-btn.detecting {
  opacity: 0.85 !important;
  border-color: var(--yak-grey);
  animation: flag-detecting-pulse 1.4s ease-in-out infinite;
  box-shadow: none !important;
}

.flag-btn.detecting::after {
  display: none !important;
}

.flag-btn.take-active {
  border-color: var(--yak-ink);
  box-shadow: 0 0 0 2px var(--yak-ink);
  opacity: 1 !important;
}

.flag-btn.take-active::after {
  display: none !important;
}

/* Hidden debug panel */
#debug-panel {
  display: none;
  margin-top: 16px;
  padding: 14px 18px;
  background: var(--yak-sand);
  border: 1px solid var(--yak-rule);
  border-radius: var(--radius-panel);
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--yak-grey);
  flex-shrink: 0;
}

body.debug-visible #debug-panel {
  display: block;
}

.debug-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px 16px;
  margin-bottom: 10px;
}

.debug-log {
  max-height: 120px;
  overflow-y: auto;
  border-top: 1px solid var(--yak-rule);
  padding-top: 8px;
  font-size: 11px;
}

/* Compact dock: short or narrow viewports put the status beside the mic */
@media (max-height: 880px), (max-width: 700px) {
  .app-layout {
    padding-top: 14px;
    padding-bottom: 10px;
  }

  .app-header {
    margin-bottom: 12px;
    padding-bottom: 10px;
  }

  .main-content {
    gap: 10px;
  }

  .controls-area {
    display: grid;
    grid-template-columns: auto minmax(0, 24em);
    grid-template-areas:
      "mic status"
      "meter status";
    justify-content: center;
    align-items: center;
    column-gap: 18px;
    row-gap: 0;
    margin-top: 0;
    padding: 0 0 4px;
  }

  .mic-stage {
    grid-area: mic;
    width: 96px;
    height: 96px;
  }

  #mic {
    width: 64px;
    height: 64px;
  }

  .mic-icon,
  .stopping-spinner {
    width: 28px;
    height: 28px;
  }

  .halo-soft {
    width: 78px;
    height: 78px;
  }

  .halo-ring-1 {
    width: 72px;
    height: 72px;
  }

  .halo-ring-2 {
    width: 88px;
    height: 88px;
  }

  .status-block {
    grid-area: status;
    align-items: flex-start;
    align-self: center;
    justify-content: center;
    max-width: none;
    min-height: 0;
    height: auto;
    max-height: 104px;
    overflow: hidden;
  }

  .level-meter {
    grid-area: meter;
    justify-self: center;
    width: 84px;
    height: 6px;
    margin: 0;
  }

  .mic-hint {
    align-items: flex-start;
    text-align: left;
    font-size: 14px;
  }

  .hint-click,
  .hint-tap,
  .kbd-hint {
    text-align: left;
  }

  .kbd-hint {
    font-size: 13px;
  }

  #timer {
    justify-content: flex-start;
  }

  .status-row,
  body[data-state="idle"] .status-row {
    justify-content: flex-start;
    flex-wrap: nowrap;
    min-height: 40px;
    height: 40px;
  }

  #status {
    text-align: left;
    font-size: 14.5px;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
}

/* Mobile dock (<700px) */
@media (max-width: 700px) {
  .app-layout {
    height: 100dvh;
    padding: 16px 14px 0;
  }

  .app-header {
    margin-bottom: 12px;
    padding-bottom: 10px;
    row-gap: 4px;
    column-gap: 8px;
  }

  .brand-title {
    font-size: 22px;
  }

  .diane-mark {
    width: 32px;
    height: 22px;
  }

  .main-content {
    flex: 1;
    min-height: 0;
    gap: 0;
  }

  .panel {
    flex: 1;
    min-height: 0;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    margin-bottom: 0;
  }

  #editor {
    flex: 1;
    min-height: 120px;
    height: auto;
    max-height: none;
    padding: 16px 18px;
    font-size: 18px;
    line-height: 1.5;
  }

  #editor[data-fontstep="0"] {
    font-size: 18px;
  }

  #editor[data-fontstep="1"] {
    font-size: 16px;
  }

  #editor[data-fontstep="2"] {
    font-size: 15px;
  }

  #editor[data-fontstep="3"] {
    font-size: 15px;
  }

  .controls-area {
    position: sticky;
    bottom: 0;
    left: 0;
    right: 0;
    margin-top: 0;
    background: var(--yak-ground);
    border-top: 1px solid var(--yak-rule);
    padding: 10px 14px calc(12px + env(safe-area-inset-bottom, 0px));
    z-index: 10;
  }

  .mic-stage {
    width: 96px;
    height: 96px;
  }

  #mic {
    width: 62px;
    height: 62px;
  }

  .mic-icon {
    width: 28px;
    height: 28px;
  }

  .stopping-spinner {
    width: 28px;
    height: 28px;
  }

  .halo-soft {
    width: 76px;
    height: 76px;
  }

  .halo-ring-1 {
    width: 70px;
    height: 70px;
  }

  .halo-ring-2 {
    width: 84px;
    height: 84px;
  }

  .level-meter {
    width: 84px;
    height: 6px;
  }
}

@media (max-width: 520px) {
  .header-right {
    display: contents;
  }
  .brand-left {
    order: 1;
  }
  .header-flags {
    order: 2;
  }
  .header-nav {
    order: 3;
    display: inline-flex;
    align-items: center;
    position: relative;
    margin-left: 6px;
  }
  #load {
    order: 4;
    width: 100%;
    text-align: right;
    font-size: 13px;
    margin-top: 2px;
  }
  .overflow-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 20px;
    padding: 0;
    margin: 0;
    border: 1px solid var(--yak-grey);
    border-radius: 2px;
    background: transparent;
    color: var(--yak-ink);
    cursor: pointer;
    position: relative;
    box-sizing: border-box;
    outline: none;
    transition: transform var(--duration-short) var(--ease-out), box-shadow var(--duration-short) var(--ease-out), border-color var(--duration-short) var(--ease-out);
  }
  .overflow-btn::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 36px;
    height: 36px;
    transform: translate(-50%, -50%);
  }
  .overflow-btn:hover {
    border-color: var(--yak-ink);
  }
  .overflow-btn:focus-visible {
    outline: 2px solid var(--yak-ink);
    outline-offset: 2px;
  }
  .overflow-btn[aria-expanded="true"],
  .header-nav.open .overflow-btn {
    box-shadow: 0 0 0 1.5px var(--yak-ink);
    background: var(--yak-sand-2);
  }
  .header-docs {
    display: none;
  }
  .header-nav.open .header-docs,
  .overflow-btn[aria-expanded="true"] + .header-docs,
  .header-docs.open {
    display: flex;
    flex-direction: column;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: var(--yak-sand);
    border: 1px solid var(--yak-rule-2);
    border-radius: var(--radius-sm, 4px);
    box-shadow: 0 4px 14px rgba(58, 55, 51, 0.15);
    padding: 8px 12px;
    gap: 8px;
    z-index: 100;
    min-width: 120px;
  }
  .header-nav.open .header-docs .header-sep,
  .header-docs.open .header-sep,
  .overflow-btn[aria-expanded="true"] + .header-docs .header-sep {
    display: none;
  }
  .header-nav.open .header-docs .docs-link,
  .header-docs.open .docs-link,
  .overflow-btn[aria-expanded="true"] + .header-docs .docs-link {
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.4;
    color: var(--yak-ink);
    text-decoration: none;
    padding: 2px 0;
    white-space: nowrap;
  }
  .header-nav.open .header-docs .docs-link:hover,
  .header-docs.open .docs-link:hover,
  .overflow-btn[aria-expanded="true"] + .header-docs .docs-link:hover {
    text-decoration: underline;
  }
  .header-nav.open .header-docs .soon-long,
  .header-docs.open .soon-long,
  .overflow-btn[aria-expanded="true"] + .header-docs .soon-long {
    display: inline;
  }
  .header-nav.open .header-docs .soon-short,
  .header-docs.open .soon-short,
  .overflow-btn[aria-expanded="true"] + .header-docs .soon-short {
    display: none;
  }
}

@media (max-width: 400px) {
  .brand-left {
    gap: 8px;
  }
  .brand-host {
    font-size: 12px;
  }
  .header-flags {
    gap: 6px;
  }
}

/* Phone widths: drop the host label so the language slots and the menu fit on one row */
@media (max-width: 600px) {
  .brand-host {
    display: none;
  }
  /* Phone readability: monospace meta text at least 13px */
  .panel-footer,
  .btn-action,
  #lang-picker .lang-english {
    font-size: 13px;
  }
}

/* Motion preference */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* Discard button for waiting recordings */
.btn-discard {
  background: none;
  border: none;
  padding: 0 4px;
  margin-left: 6px;
  font-family: inherit;
  font-size: inherit;
  color: var(--yak-vermilion, #b83a22);
  text-decoration: underline;
  cursor: pointer;
  display: inline-block;
  white-space: nowrap;
}

.btn-discard:hover {
  opacity: 0.8;
}

.btn-discard:focus-visible {
  outline: 2px solid var(--yak-ink, #1a1917);
  outline-offset: 2px;
}

.status-waiting-text {
  font-family: var(--font-serif);
  font-style: italic;
}

body[data-state="idle"] .status-row:has(#status[data-has-waiting="true"]),
body[data-state="idle"]:has(#status[data-has-waiting="true"]) .status-row {
  min-height: 48px;
  height: 48px;
}

@media (max-width: 700px) {
  body[data-state="idle"] .status-row:has(#status[data-has-waiting="true"]),
  body[data-state="idle"]:has(#status[data-has-waiting="true"]) .status-row {
    min-height: 40px;
    height: 40px;
  }
}

/* Language chip (2-3 letter code chip) */
.flag-btn.lang-chip {
  background: rgba(58, 55, 51, 0.08);
}

.flag-btn .chip-text {
  font-family: var(--yak-font-mono, ui-monospace, monospace);
  font-weight: 700;
  font-size: 10px;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: -0.02em;
  color: var(--yak-ink, #211f1d);
  user-select: none;
}

.flag-btn .chip-text[data-len="3"] {
  font-size: 7.5px;
  letter-spacing: -0.04em;
}

/* Add Language Button */
.lang-add-btn {
  position: relative;
  width: 24px;
  height: 20px;
  padding: 0;
  margin: 0;
  border: 1px solid var(--yak-grey);
  border-radius: 2px;
  background: transparent;
  color: var(--yak-ink, #211f1d);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.lang-add-btn:hover:not(:disabled) {
  border-color: var(--yak-ink, #211f1d);
  background: rgba(58, 55, 51, 0.06);
}

.lang-add-btn:focus-visible {
  outline: 2px solid var(--yak-ink, #211f1d);
  outline-offset: 2px;
}

.lang-add-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.lang-add-btn .globe-icon {
  width: 14px;
  height: 14px;
  display: block;
}

/* Language Picker Modal */
.lang-picker {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  box-sizing: border-box;
}

.lang-picker[hidden] {
  display: none !important;
}

.lang-picker-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
}

.lang-picker-panel:focus {
  outline: none;
}

.lang-picker-panel {
  position: relative;
  width: 100%;
  max-width: 320px;
  max-height: 80vh;
  background: var(--yak-paper-panel, #fdfbf7);
  border: 1px solid rgba(58, 55, 51, 0.2);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: var(--yak-ink, #211f1d);
  box-sizing: border-box;
}

.lang-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(58, 55, 51, 0.12);
}

.lang-picker-title {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  line-height: 1.2;
}

.lang-picker-close {
  background: none;
  border: none;
  font-size: 20px;
  line-height: 1;
  padding: 2px 6px;
  cursor: pointer;
  color: var(--yak-ink, #211f1d);
  border-radius: 4px;
}

.lang-picker-close:hover {
  background: rgba(58, 55, 51, 0.08);
}

.lang-picker-msg {
  padding: 8px 14px;
  background: rgba(184, 58, 34, 0.1);
  color: var(--yak-vermilion, #b83a22);
  font-size: 12px;
  font-weight: 500;
  border-bottom: 1px solid rgba(184, 58, 34, 0.2);
}

.lang-picker-msg[hidden] {
  display: none !important;
}

.lang-search-container {
  padding: 8px 14px;
  border-bottom: 1px solid rgba(58, 55, 51, 0.12);
}

.lang-search-container[hidden] {
  display: none !important;
}

.lang-search-input {
  width: 100%;
  padding: 6px 10px;
  font-size: 13px;
  border: 1px solid rgba(58, 55, 51, 0.25);
  border-radius: 4px;
  background: var(--yak-paper, #ffffff);
  color: var(--yak-ink, #211f1d);
  font-family: inherit;
  box-sizing: border-box;
}

.lang-search-input:focus {
  outline: 2px solid var(--yak-ink, #211f1d);
  outline-offset: 1px;
}

.lang-picker-list-wrapper {
  overflow-y: auto;
  flex: 1 1 auto;
  max-height: 50vh;
}

.lang-picker-list {
  list-style: none;
  margin: 0;
  padding: 4px 0;
}

.lang-picker-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 14px;
  cursor: pointer;
  transition: background 0.1s ease;
  gap: 10px;
  user-select: none;
}

.lang-picker-row:hover {
  background: rgba(58, 55, 51, 0.06);
}

.lang-picker-row-main {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 auto;
  min-width: 0;
}

.lang-picker-flag {
  width: 24px;
  height: 17px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(58, 55, 51, 0.2);
  border-radius: 2px;
  overflow: hidden;
  background: rgba(58, 55, 51, 0.08);
}

.lang-picker-flag img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.lang-picker-flag .chip-text {
  font-family: var(--yak-font-mono, ui-monospace, monospace);
  font-weight: 700;
  font-size: 9.5px;
  line-height: 1;
  text-transform: uppercase;
}

.lang-picker-flag .chip-text[data-len="3"] {
  font-size: 7px;
}

.lang-names {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

.lang-native {
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lang-english {
  font-size: 12.5px;
  color: var(--yak-grey);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lang-picker-row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.lang-check {
  color: var(--yak-ink, #211f1d);
  font-size: 13px;
  font-weight: bold;
}

.lang-remove {
  background: none;
  border: none;
  font-size: 16px;
  line-height: 1;
  color: var(--yak-grey);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 3px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.lang-remove:hover {
  color: var(--yak-vermilion, #b83a22);
  background: rgba(184, 58, 34, 0.1);
}

.lang-no-match {
  padding: 20px 14px;
  text-align: center;
  font-size: 13px;
  color: var(--yak-grey);
}

.lang-no-match[hidden] {
  display: none !important;
}

