:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #667085;
  --line: #d8dde6;
  --accent: #1677c8;
  --accent-dark: #0f5f9f;
  --ok: #138a43;
  --warn: #9f5b00;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

body.locked .app {
  display: none;
}

body:not(.setupComplete) .app > :not(.entryGate) {
  display: none;
}

.loginGate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  place-items: center;
  padding: 20px;
  background: var(--bg);
}

body.authChecked.locked .loginGate {
  display: grid;
}

body:not(.locked) .loginGate {
  display: none;
}

.entryGate {
  min-height: calc(100vh - 48px);
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
}

.entryGate h1 {
  font-size: 34px;
}

.enterButton {
  width: min(82vw, 360px);
  min-height: 96px;
  position: relative;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-size: 34px;
  font-weight: 800;
}

.enterSpinner {
  position: absolute;
  top: 50%;
  right: clamp(22px, 11vw, 52px);
  width: 30px;
  height: 30px;
  border: 3px solid rgb(255 255 255 / 0.38);
  border-top-color: #fff;
  border-radius: 50%;
  opacity: 0;
  transform: translateY(-50%);
}

.enterButton.isLoading .enterSpinner {
  opacity: 1;
  animation: enterSpin 0.75s linear infinite;
}

.enterButton.isLoading:disabled {
  cursor: progress;
  opacity: 1;
}

@keyframes enterSpin {
  from {
    transform: translateY(-50%) rotate(0deg);
  }

  to {
    transform: translateY(-50%) rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .enterButton.isLoading .enterSpinner {
    animation: none;
    transform: translateY(-50%);
  }
}

body.setupComplete .entryGate {
  display: none;
}

.loginPanel {
  width: min(100%, 360px);
  display: grid;
  gap: 14px;
  padding: 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  font: inherit;
}

.errorText {
  min-height: 20px;
  color: #b42318;
}

.app {
  width: min(1040px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 20px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.1;
}

h2 {
  font-size: 16px;
}

p,
label,
select,
button,
.offlineModeButton {
  font-size: 14px;
}

.controls,
.transcripts article {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.topStats {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

#deviceHint,
#modeHelp,
.meterLabel,
.muted {
  color: var(--muted);
}

.controls {
  padding: 16px;
}

.modeHeader,
.meterLabel,
.actions,
.setupGrid,
.modeButtons {
  display: flex;
  gap: 10px;
  align-items: center;
}

.modeHeader {
  justify-content: space-between;
  margin-bottom: 12px;
}

#translationState {
  color: var(--ok);
  font-size: 13px;
}

.modeButtons {
  flex-wrap: wrap;
}

button,
select,
.offlineModeButton {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 6px;
  min-height: 38px;
  padding: 0 12px;
}

button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.offlineModeButton {
  position: fixed;
  right: max(10px, env(safe-area-inset-right));
  bottom: max(10px, env(safe-area-inset-bottom));
  z-index: 10;
  display: inline-grid;
  place-items: center;
  text-decoration: none;
  white-space: nowrap;
}

.mobileOnly {
  display: none;
}

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

button.selected {
  border-color: var(--accent);
  color: var(--accent-dark);
  background: #eef7ff;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

button.primary.isBlocked {
  background: #b42318;
  border-color: #b42318;
  color: #fff;
  box-shadow: 0 0 0 3px rgba(180, 35, 24, 0.22);
}

body.translationBlocked #startButton {
  background: #b42318;
  border-color: #b42318;
  color: #fff;
  box-shadow: 0 0 0 3px rgba(180, 35, 24, 0.22);
}

.setupGrid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) 44px;
  margin-top: 16px;
}

.setupGrid label {
  min-width: 0;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

[hidden] {
  display: none !important;
}

select {
  width: 100%;
  min-width: 0;
}

input[type="range"] {
  min-height: 24px;
  padding: 0;
  accent-color: var(--accent);
}

.meterWrap {
  margin-top: 16px;
}

.meterLabel {
  justify-content: space-between;
  margin-bottom: 6px;
}

.meter {
  width: 100%;
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5e9f0;
}

#meterBar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #15803d, #f5a524);
  transition: width 80ms linear;
}

.volumeControl {
  margin-top: 12px;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
}

.startVoiceControl {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  width: max-content;
}

.startVoiceControl input {
  width: 18px;
  min-height: 18px;
}

.actions {
  margin-top: 0;
  display: grid;
  grid-template-columns: minmax(132px, 1fr);
  align-items: end;
}

#startButton,
.speakButton {
  width: 100%;
  min-height: 76px;
  font-size: 30px;
  font-weight: 800;
  touch-action: manipulation;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.speakButton {
  border-color: #0f766e;
  background: #0f766e;
  color: #fff;
  touch-action: none;
}

.speakButton.isRecording {
  background: #b42318;
  border-color: #b42318;
}

.speakStatus {
  min-height: 20px;
  color: var(--muted);
  font-size: 14px;
  margin-top: 8px;
}

.targetLanguageControl {
  min-width: 132px;
}

.transcriptLanguageControl {
  display: grid;
  grid-template-columns: auto minmax(132px, 180px);
  align-items: center;
  justify-content: start;
  gap: 8px;
  max-width: none;
}

.iconButton {
  width: 44px;
  min-width: 44px;
  min-height: 38px;
  padding: 0;
  display: grid;
  place-items: center;
  align-self: end;
}

.iconButton svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.elapsedTime {
  position: fixed;
  top: max(6px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #b42318;
  font-size: 12px;
  line-height: 1;
  margin: 0;
  pointer-events: none;
}

#elapsedTime {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.creditBalance {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.transcripts {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(120px, 160px) minmax(0, 1fr);
  align-items: stretch;
  gap: 16px;
  margin-top: 16px;
}

.transcripts article {
  padding: 16px;
  min-height: 260px;
  overflow: hidden;
}

.textBox {
  margin-top: 12px;
  white-space: pre-wrap;
  line-height: 1.45;
  font-size: 18px;
  overflow: auto;
}

.transcriptGroup + .transcriptGroup {
  margin-top: 14px;
}

.timestamp {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  margin-bottom: 3px;
}

.transcriptText {
  display: block;
}

@media (max-width: 760px) {
  html,
  body {
    min-height: 100%;
  }

  body:not(.locked) {
    overflow: hidden;
  }

  .app {
    width: 100%;
    height: 100dvh;
    min-height: 0;
    padding: 0;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 8px;
  }

  .topbar {
    display: none;
  }

  .desktopOnly {
    display: none;
  }

  .offlineModeButton {
    display: inline-grid;
    min-height: 26px;
    padding: 0 8px;
    font-size: 11px;
  }

  .controls {
    position: relative;
    padding: 0 0 8px;
    border-left: 0;
    border-right: 0;
    border-radius: 0;
  }

  .modePanel {
    display: none;
  }

  .actions {
    grid-template-columns: minmax(0, 1fr);
  }

  #startButton,
  .speakButton {
    min-height: 92px;
    font-size: 30px;
    border-radius: 0;
  }

  .setupGrid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 34px;
    gap: 6px;
    margin-top: 8px;
  }

  .setupGrid label:last-of-type {
    grid-column: 1 / span 2;
  }

  label {
    gap: 3px;
    font-size: 11px;
  }

  select {
    min-height: 34px;
    padding: 0 6px;
    font-size: 12px;
  }

  .targetLanguageControl {
    min-width: 0;
  }

  .iconButton {
    width: 34px;
    min-width: 34px;
    min-height: 34px;
  }

  .iconButton svg {
    width: 18px;
    height: 18px;
  }

  .meterWrap {
    margin-top: 8px;
  }

  .meterLabel {
    margin-bottom: 4px;
    font-size: 12px;
  }

  .meter {
    height: 8px;
  }

  .volumeControl {
    margin-top: 6px;
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 8px;
    font-size: 12px;
  }

  .startVoiceControl {
    margin-top: 4px;
    font-size: 12px;
  }

  input[type="range"] {
    min-height: 20px;
  }

  .speakStatus {
    min-height: 16px;
    margin-top: 4px;
    padding-right: 112px;
    font-size: 12px;
  }

  .elapsedTime {
    top: max(6px, env(safe-area-inset-top));
    right: max(10px, env(safe-area-inset-right));
    font-size: 11px;
  }

  .transcripts {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto minmax(0, 1fr);
    gap: 8px;
    margin-top: 0;
    min-height: 0;
  }

  .transcripts article {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    min-height: 0;
    padding: 10px;
  }

  .transcripts h2 {
    font-size: 14px;
  }

  .textBox {
    min-height: 0;
    margin-top: 6px;
    font-size: 15px;
    line-height: 1.35;
    -webkit-overflow-scrolling: touch;
  }
}
