:root {
  color-scheme: light;
  --bg: #eef7f3;
  --bar: #82d2c2;
  --ink: #1f2c2a;
  --muted: #60706c;
  --line: #9aaca7;
  --primary: #087966;
  --soft: #d6e5df;
  --ready-bg: #eff8f2;
  --talk-ready: #c9e6d2;
  --talk-ready-ink: #123d24;
  --log-height: clamp(190px, 26vh, 260px);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  transition: background 160ms ease;
}

body.ready-to-talk {
  background: var(--ready-bg);
}

body.local-speech-active {
  --ready-bg: #fdeceb;
  --bar: #e9aca6;
  --soft: #efd4cf;
  background: #fdeceb;
}

.app {
  min-height: 100vh;
  padding-bottom: 24px;
}

body.ready-to-talk .app {
  padding-bottom: calc(var(--log-height) + 24px);
}

.topbar {
  position: relative;
  background: var(--bar);
  padding: 14px 16px 15px;
  text-align: center;
}

.version {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 500;
}

h2 {
  margin: 0 0 12px;
  font-size: 16px;
  font-weight: 600;
}

h3 {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 600;
}

.panel {
  padding: 16px;
  border-bottom: 1px solid #c4d3ce;
  transition: background 160ms ease;
}

body.ready-to-talk .panel {
  background: var(--ready-bg);
}

body.local-speech-active .panel,
body.local-speech-active .log-wrap {
  background: #fdeceb;
}

label {
  display: block;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 12px;
}

input,
select {
  display: block;
  width: 100%;
  margin-top: 4px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  min-height: 48px;
  padding: 10px 14px;
}

.hint {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.speaker-voice {
  margin: 0 0 14px;
  color: var(--ink);
  font-size: 15px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: min(260px, 100%);
  margin: 2px auto 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}

.segmented button {
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  min-height: 32px;
}

.segmented .selected {
  background: var(--soft);
}

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

.actions > button {
  flex: 1;
}

.interpreter-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 12px;
}

.interpreter-langs {
  display: flex;
  gap: 12px;
}

.interpreter-langs label {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  font-weight: 600;
}

.interpreter-langs select {
  min-height: 40px;
  border-radius: 12px;
  border: 1px solid var(--soft);
  padding: 0 10px;
  font: inherit;
}

#listenToggleButton.listening {
  background: var(--accent, #2f80ed);
  color: #fff;
}

.delay-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.delay-track {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--soft);
  overflow: hidden;
}

.delay-bar {
  height: 100%;
  width: 0;
  border-radius: 2px;
  background: var(--primary);
  transition: width 300ms ease;
}

.delay-value {
  min-width: 38px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.wrap-actions {
  flex-wrap: wrap;
  margin-top: 8px;
}

.wrap-actions > button {
  flex: 1 1 130px;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 999px;
  padding: 0 18px;
  background: var(--soft);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
}

[hidden] {
  display: none !important;
}

.icon-button {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  font-size: 24px;
  line-height: 1;
}

.icon-button:disabled {
  opacity: 0.5;
}

.options-dialog {
  width: min(420px, calc(100vw - 32px));
  border: 0;
  border-radius: 16px;
  padding: 20px;
  background: var(--bg);
  color: var(--ink);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.22);
}

.options-dialog:focus {
  outline: none;
}

.options-dialog::backdrop {
  background: rgba(0, 0, 0, 0.28);
}

.options-dialog h2 {
  margin-bottom: 16px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}

.debug-audio {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid #c4d3ce;
}

button.primary {
  background: var(--primary);
  color: white;
}

body.ready-to-talk #talkButton {
  display: block;
  width: min(240px, 80vw);
  min-height: min(240px, 80vw);
  margin: 16px auto 0;
  border-radius: 24px;
  background: var(--talk-ready);
  color: var(--talk-ready-ink);
  font-size: 30px;
  touch-action: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
}

body.ready-to-talk .actions {
  display: block;
}

body.ready-to-talk #connectButton {
  display: block;
  width: 100%;
}

body.ready-to-talk #listenToggleButton {
  display: block;
  width: 100%;
  margin-top: 10px;
}

/* Listen mode mirrors the app client: listen toggle and hold button share
   the same 240x120 size, stacked and centered, ear icon on the toggle. */
body.interpreter-mode.ready-to-talk #listenToggleButton {
  width: min(240px, 80vw);
  min-height: 120px;
  margin: 16px auto 0;
  border-radius: 24px;
  font-size: 22px;
}

body.interpreter-mode.ready-to-talk #talkButton {
  min-height: 120px;
  font-size: 22px;
}

button:disabled {
  opacity: 0.48;
}

.status {
  margin: 14px 0 0;
}

.log-wrap {
  display: none;
  flex-direction: column;
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  height: var(--log-height);
  padding: 8px 16px 12px;
  border-top: 1px solid #c4d3ce;
  background: var(--bg);
}

body.ready-to-talk .log-wrap {
  display: flex;
  background: var(--ready-bg);
}

.log-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 8px;
}

.transcript-grid {
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: 8px;
  flex: 1;
  min-height: 0;
}

.transcript-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 1px solid #c4d3ce;
  border-radius: 10px;
  padding: 2px 10px 6px;
}

.transcript-heading {
  display: flex;
  align-items: center;
  gap: 8px;
}

.transcript-pane h2 {
  flex: 1;
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

#clearButton {
  min-height: 24px;
  padding: 0 10px;
  font-size: 11px;
}

.events {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  white-space: pre-wrap;
  font-size: 12px;
  line-height: 1.25;
}

.event {
  line-height: 1.35;
}

.portrait-only {
  display: none;
}

@media (max-width: 767px) and (orientation: landscape) {
  body {
    overflow: hidden;
  }

  .app {
    filter: blur(2px);
    pointer-events: none;
  }

  .portrait-only {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    place-items: center;
    padding: 24px;
    background: rgba(238, 247, 243, 0.96);
    color: var(--ink);
    text-align: center;
    font-size: 20px;
    font-weight: 600;
  }
}

@media (min-width: 768px) {
  :root {
    --log-height: clamp(240px, 32vh, 340px);
  }

  .app {
    max-width: 960px;
    margin: 0 auto;
  }

  .log-wrap {
    left: 50%;
    width: min(960px, 100vw);
    transform: translateX(-50%);
  }
}
