:root {
  color-scheme: light dark;
  --bg: #f4f6f8;
  --bg-gradient:
    radial-gradient(120% 85% at 12% 0%, rgba(96, 165, 250, 0.42) 0%, rgba(96, 165, 250, 0) 58%),
    linear-gradient(180deg, #edf4ff 0%, #d5e5ff 52%, #bfd6ff 100%);
  --surface: #ffffff;
  --surface-elevated: #fafbfc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-muted: #dbeafe;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --radius: 10px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas, monospace;
  --app-gutter: clamp(0.5rem, 2.5vw + 0.35rem, 3rem);
  --app-max-w: min(96rem, calc(100vw - 2 * var(--app-gutter)));
  --touch-min: 44px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419;
    --bg-gradient: radial-gradient(circle at top, #263851 0%, #141c26 42%, #070b12 100%);
    --surface: #151b23;
    --surface-elevated: #1a222d;
    --border: #2d3a4d;
    --text: #e8eef4;
    --text-muted: #94a3b8;
    --accent: #60a5fa;
    --accent-hover: #93c5fd;
    --accent-muted: #1e3a5f;
    --danger: #f87171;
    --danger-hover: #fca5a5;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  }
}

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

html {
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: clamp(14px, 0.35vw + 13px, 16px);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg-gradient);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.app {
  width: min(100%, var(--app-max-w));
  max-width: var(--app-max-w);
  margin-inline: auto;
  padding-inline-start: max(var(--app-gutter), env(safe-area-inset-left, 0px));
  padding-inline-end: max(var(--app-gutter), env(safe-area-inset-right, 0px));
  padding-block-start: max(clamp(0.65rem, 2.2vw, 2rem), env(safe-area-inset-top, 0px));
  padding-block-end: max(clamp(0.65rem, 2.2vw, 2rem), env(safe-area-inset-bottom, 0px));
}

.app-header {
  margin-bottom: 1.75rem;
}

.app-header h1 {
  margin: 0 0 0.35rem;
  font-size: clamp(1.35rem, 4vw, 1.65rem);
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

noscript {
  display: block;
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;
  text-align: center;
  color: var(--danger);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(0.75rem, 2.2vw, 1.15rem) clamp(0.85rem, 2.5vw, 1.35rem);
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.panel:last-of-type {
  margin-bottom: 0;
}

.panel-title {
  margin: 0 0 0.75rem;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.field-row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

@media (min-width: 520px) {
  .field-row.field-row--inline {
    flex-direction: row;
    align-items: center;
    gap: 0.75rem;
  }

  .field-row.field-row--inline label {
    flex-shrink: 0;
    min-width: 3.5rem;
  }

  .field-row.field-row--inline select {
    flex: 1;
    min-width: 0;
  }
}

label[for="model"] {
  font-weight: 500;
  color: var(--text);
}

select#model {
  width: 100%;
  max-width: 100%;
  min-height: var(--touch-min);
  padding: 0.55rem 0.75rem;
  font: inherit;
  color: var(--text);
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

select#model:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

select#model:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.download-panel-container {
  display: grid;
  grid-template-rows: 0fr;
  margin-bottom: 0;
  opacity: 0;
  pointer-events: none;
  transition:
    grid-template-rows 0.45s cubic-bezier(0.4, 0, 0.2, 1),
    opacity 0.35s ease,
    margin-bottom 0.35s ease;
}

.download-panel-container.download-panel--visible {
  grid-template-rows: 1fr;
  margin-bottom: 1rem;
  opacity: 1;
  pointer-events: auto;
}

.download-panel-inner {
  min-height: 0;
  overflow: hidden;
}

.download-panel-inner .panel {
  margin-bottom: 0;
}

@media (prefers-reduced-motion: reduce) {
  .download-panel-container {
    transition-duration: 0.01ms;
  }
}

.download-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.75rem;
}

.download-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.download-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

#progress-label {
  display: inline-block;
  min-width: 3.5rem;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  color: var(--text);
}

.download-meta .progress-caption {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.progress-wrap {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
}

.progress-wrap progress {
  width: 100%;
}

.controls-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.75rem;
}

.btn-group {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
  width: 100%;
}

button {
  font: inherit;
  font-weight: 500;
  padding: 0.55rem 0.75rem;
  min-height: var(--touch-min);
  min-width: 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-elevated);
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

button:hover:not(:disabled) {
  background: var(--accent-muted);
  border-color: var(--accent);
}

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

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

#button-abort {
  border-color: var(--border);
  color: var(--danger);
}

#button-abort:hover:not(:disabled) {
  background: var(--surface);
  border-color: var(--danger);
}

#button-start {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

#button-start:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

#button-push {
  min-width: 0;
  width: 100%;
}

.meter-wrap {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
}

.meter-wrap progress {
  width: 100%;
}

.transcript {
  margin: 0;
  font-size: clamp(1rem, 2.8vw, 1.1rem);
  font-weight: 500;
  min-height: 1.5em;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.panel .transcript {
  margin-top: 0.15rem;
}

.panel .hint {
  margin-top: 0.65rem;
}

#partial {
  color: var(--text);
}

#partial.hypothesis-partial {
  color: var(--text-muted);
}

#partial.hypothesis-final {
  color: var(--text);
}

.hint {
  margin: 0;
  font-size: clamp(0.78rem, 1.75vw, 0.8125rem);
  font-weight: 400;
  font-style: italic;
  color: var(--text-muted);
  min-height: 1.45em;
  overflow-wrap: anywhere;
}

.push-row {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
}

.push-hint {
  font-size: clamp(0.78rem, 2vw, 0.8125rem);
  color: var(--text-muted);
  font-style: italic;
  max-width: none;
  line-height: 1.45;
}

h2 {
  margin: 1.35rem 0 0.5rem;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.panel + h2 {
  margin-top: 1.5rem;
}

.results-layout {
  margin-top: 0.25rem;
  display: flex;
  flex-direction: column;
  gap: 0;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.results-layout__results,
.results-layout__profile {
  min-width: 0;
}

.results-layout__profile .panel {
  margin-bottom: 0;
  min-width: 0;
}

.results-layout__results #output {
  min-width: 0;
}

@media (min-width: 520px) {
  .download-row {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }

  .progress-wrap {
    flex: 1 1 12rem;
    width: auto;
  }

  .controls-row {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }

  .btn-group {
    display: flex;
    flex-wrap: wrap;
    width: auto;
    flex: 0 1 auto;
  }

  .btn-group button {
    min-width: 4.25rem;
  }

  .meter-wrap {
    flex: 1 1 12rem;
    width: auto;
  }

  .push-row {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }

  #button-push {
    width: auto;
    min-width: 10rem;
  }
}

@media (min-width: 900px) {
  #profile {
    max-height: min(22rem, 45vh);
  }
}

@media (min-width: 1400px) {
  :root {
    --app-max-w: min(112rem, calc(100vw - 2 * var(--app-gutter)));
  }
}

#output {
  min-height: 2rem;
}

#output details {
  margin-bottom: 0.5rem;
  padding: 0.5rem 0.65rem;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

#output summary {
  cursor: pointer;
  font-weight: 500;
}

#output pre {
  margin: 0.5rem 0 0;
  padding: 0.65rem 0.75rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  line-height: 1.45;
  overflow-x: auto;
  border-radius: 6px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
}

#profile {
  margin: 0;
  padding: 0.75rem 1rem;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  font-family: var(--mono);
  font-size: 0.75rem;
  line-height: 1.5;
  white-space: pre;
  overflow-wrap: normal;
  word-break: normal;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 16rem;
  overflow-x: auto;
  overflow-y: auto;
}

progress[value] {
  --track: var(--border);
  --fill: var(--accent);

  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  height: 0.55rem;
  border: none;
  border-radius: 999px;
  background: var(--track);
}

progress[value]::-webkit-progress-bar {
  border-radius: 999px;
  background: var(--track);
}

progress[value]::-webkit-progress-value {
  border-radius: 999px;
  background: var(--fill);
}

progress[value]::-moz-progress-bar {
  border-radius: 999px;
  background: var(--fill);
}

#volume-meter[value] {
  --fill: #2ea36c;
}

@media (prefers-color-scheme: dark) {
  #volume-meter[value] {
    --fill: #4ade80;
  }
}

a.audio {
  color: var(--accent);
  text-underline-offset: 2px;
}

