@font-face {
  font-family: "SBC";
  src: url("fonts/sbc.woff2") format("woff2"), url("fonts/sbc.otf") format("opentype");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;
  --bg: #f3f4f5;
  --surface: #ffffff;
  --surface-2: #f7f8f9;
  --line: #e1e4e7;
  --line-strong: #c9ced3;
  --text: #15191c;
  --muted: #646c73;
  --faint: #8d949a;
  --accent: #0079c1;
  --accent-ink: #ffffff;
  --accent-soft: #e3f3fc;
  --warn: #9a6400;
  --warn-soft: #fbf1dc;
  --danger: #b3261e;
  --danger-soft: #fbe7e5;
  --heard: #b8743a;
  --focus: #0079c1;
  /* SBC covers Latin, Arabic and Persian; the Noto faces after it pick up the
     scripts it does not have (CJK, Devanagari, Hebrew). */
  --font: "SBC", "Noto Sans", "Noto Sans JP", "Noto Sans SC", "Noto Sans KR",
    "Noto Sans Devanagari", "Noto Sans Hebrew", -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --gutter: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0e1113;
    --surface: #15191c;
    --surface-2: #1b2024;
    --line: #262c31;
    --line-strong: #353d43;
    --text: #e7eaec;
    --muted: #9aa2a8;
    --faint: #6f777d;
    --accent: #2fb0f2;
    --accent-ink: #04131c;
    --accent-soft: #0e2330;
    --warn: #e0a642;
    --warn-soft: #2a2213;
    --danger: #ef6b61;
    --danger-soft: #2c1715;
    --heard: #d69a62;
    --focus: #2fb0f2;
  }
}

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

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

[hidden] {
  display: none !important;
}

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

/* ---------- Layout ---------- */

.app {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-areas:
    "top"
    "setup"
    "feed"
    "dock";
  height: 100vh;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  background: var(--surface);
  border-inline: 1px solid var(--line);
}

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: env(safe-area-inset-top) var(--gutter) 0;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.setup {
  grid-area: setup;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px var(--gutter) 16px;
  border-bottom: 1px solid var(--line);
}

.feed {
  grid-area: feed;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface-2);
}

.dock {
  grid-area: dock;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px var(--gutter) calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--surface);
}

/* ---------- Top bar ---------- */

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  display: block;
  flex: none;
  width: 28px;
  height: 28px;
}

.brand-name {
  overflow: hidden;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.topbar-end {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.icon-button:hover,
.icon-button[aria-expanded="true"] {
  border-color: var(--line);
  background: var(--surface-2);
  color: var(--text);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

.status-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  background: currentColor;
}

.status-badge.connecting,
.status-badge.reconnecting {
  border-color: transparent;
  background: var(--warn-soft);
  color: var(--warn);
}

.status-badge.connected {
  border-color: transparent;
  background: var(--accent-soft);
  color: var(--accent);
}

.status-badge.connected::before {
  animation: pulse 1.4s ease-in-out infinite;
}

.status-badge.error,
.status-badge.failed,
.status-badge.disconnected {
  border-color: transparent;
  background: var(--danger-soft);
  color: var(--danger);
}

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

/* ---------- Fields ---------- */

fieldset {
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

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

.label {
  display: block;
  padding: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.hint,
.note {
  margin: 0;
  font-size: 12px;
  color: var(--faint);
}

.note {
  padding: 8px 10px;
  border-inline-start: 2px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--muted);
}

.hint-link {
  align-self: flex-start;
  margin-top: -6px;
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
}

.hint-link:hover {
  text-decoration: underline;
}

input[type="password"],
input[type="text"],
select {
  width: 100%;
  height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  font-size: 14px;
  appearance: none;
  -webkit-appearance: none;
}

select {
  padding-inline-end: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23888' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  text-overflow: ellipsis;
  cursor: pointer;
}

input:hover,
select:hover:not(:disabled) {
  border-color: var(--faint);
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--focus);
  box-shadow: inset 0 0 0 1px var(--focus);
}

select:disabled,
input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.input-row {
  display: flex;
}

.input-row input {
  flex: 1;
  min-width: 0;
  font-family: var(--mono);
  font-size: 13px;
}

.input-addon {
  flex: none;
  min-width: 56px;
  height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-inline-start: 0;
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}

.input-addon:hover {
  color: var(--text);
}

/* Segmented control */

.segmented {
  display: grid;
  grid-auto-columns: minmax(0, 1fr);
  grid-auto-flow: column;
  border: 1px solid var(--line-strong);
}

.segmented label {
  position: relative;
  display: block;
}

.segmented label + label {
  border-inline-start: 1px solid var(--line-strong);
}

.segmented input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}

.segmented span {
  display: grid;
  place-items: center;
  height: 36px;
  padding: 0 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
  transition: background-color 120ms ease, color 120ms ease;
}

.segmented label:hover span {
  color: var(--text);
}

.segmented input:checked + span {
  background: var(--text);
  color: var(--surface);
}

.segmented input:focus-visible + span {
  outline: 2px solid var(--focus);
  outline-offset: -4px;
}

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

.segmented input:disabled + span {
  opacity: 0.55;
}

/* Settings drawer */

.settings {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin: -14px calc(var(--gutter) * -1) 0;
  padding: 14px var(--gutter) 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.settings .segmented,
.settings .input-addon {
  background: var(--surface);
}

/* Language pair */

.lang-pair {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 28px minmax(0, 1fr);
  align-items: end;
}

.lang-cell {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.static-value {
  display: flex;
  align-items: center;
  height: 40px;
  padding: 0 10px;
  border: 1px dashed var(--line-strong);
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lang-arrow {
  display: grid;
  place-items: center;
  height: 40px;
  color: var(--faint);
}

/* ---------- Transcript ---------- */

.feed-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 40px;
  padding: 0 var(--gutter);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.text-button {
  height: 28px;
  padding: 0 8px;
  margin-inline-end: -8px;
  border: 0;
  background: transparent;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}

.text-button:hover {
  color: var(--text);
}

.transcript {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px var(--gutter);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.entry {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-inline-start: 2px solid var(--line-strong);
  background: var(--surface);
}

.entry.heard {
  border-inline-start-color: var(--heard);
}

.entry.translation {
  border-inline-start-color: var(--accent);
}

.entry-label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 4px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--faint);
}

.entry.live .entry-label::after {
  content: "";
  width: 5px;
  height: 5px;
  background: currentColor;
  animation: pulse 1s ease-in-out infinite;
}

.entry.heard .entry-label {
  color: var(--heard);
}

.entry.translation .entry-label {
  color: var(--accent);
}

.entry-text {
  margin: 0;
  font-size: 15px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

/* Arabic-script text sits taller and needs more room between lines. */
.entry[dir="rtl"] .entry-text {
  font-size: 16px;
  line-height: 1.85;
}

.entry[dir="rtl"] .entry-label {
  letter-spacing: 0;
}

.entry.heard .entry-text {
  color: var(--muted);
}

.empty-state {
  margin: auto 0;
  padding: 24px 8px;
  text-align: center;
  color: var(--faint);
}

.empty-state svg {
  display: block;
  margin: 0 auto 10px;
  color: var(--line-strong);
}

.empty-state p {
  margin: 0;
  font-size: 13px;
}

.empty-state p + p {
  margin-top: 2px;
  font-size: 12px;
}

/* ---------- Dock ---------- */

.dock-info {
  flex: 1;
  min-width: 0;
}

.status-text {
  margin: 0 0 3px;
  overflow: hidden;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.status-text.is-error {
  color: var(--danger);
  white-space: normal;
}

.meters {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 16px;
  margin: 0;
}

.meters div {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.meters dt {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--faint);
}

.meters dd {
  margin: 0;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.run-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex: none;
  min-width: 124px;
  height: 46px;
  padding: 0 18px;
  border: 0;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 120ms ease, opacity 120ms ease;
}

.run-button:hover {
  filter: brightness(1.06);
}

.run-button:active {
  filter: brightness(0.94);
}

.run-button:disabled {
  opacity: 0.6;
  cursor: progress;
}

.run-icon {
  width: 0;
  height: 0;
  border-block: 6px solid transparent;
  border-inline-start: 9px solid currentColor;
}

.run-button[data-state="running"] {
  background: var(--danger);
  color: #fff;
}

.run-button[data-state="running"] .run-icon {
  width: 10px;
  height: 10px;
  border: 0;
  background: currentColor;
}

.run-button[data-state="busy"] .run-icon {
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-inline-end-color: transparent;
  animation: spin 0.8s linear infinite;
}

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

/* ---------- Mobile ---------- */

@media (max-width: 480px) {
  .app {
    border: 0;
  }

  /* 16px stops iOS Safari from zooming the page on focus. */
  input[type="password"],
  input[type="text"],
  select {
    height: 44px;
    font-size: 16px;
  }

  .input-addon,
  .static-value,
  .lang-arrow {
    height: 44px;
  }

  .segmented span {
    height: 40px;
  }

  .run-button {
    min-width: 112px;
    height: 48px;
  }
}

/* ---------- Desktop: setup beside the feed ---------- */

@media (min-width: 900px) {
  body {
    padding: 24px;
  }

  .app {
    grid-template-columns: 340px minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "top top"
      "setup feed"
      "dock feed";
    max-width: 1080px;
    height: calc(100dvh - 48px);
    border: 1px solid var(--line);
  }

  .setup {
    overflow-y: auto;
    border-bottom: 0;
    border-inline-end: 1px solid var(--line);
  }

  .dock {
    border-inline-end: 1px solid var(--line);
  }

  .run-button {
    min-width: 128px;
  }
}

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