:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #667085;
  --line: #d8dde6;
  --accent: #1677c8;
  --accent-dark: #0f5f9f;
  --ok: #138a43;
  --warn: #9f5b00;
  --danger: #b42318;
  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);
}

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

.offlineTopbar {
  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,
.onlineLink {
  font-size: 14px;
}

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

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

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

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

.onlineLink {
  display: inline-grid;
  place-items: center;
  text-decoration: none;
}

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

#offlineDeviceHint,
.meterLabel,
.statusLine,
#packSummary {
  color: var(--muted);
}

.offlineControls {
  padding: 16px;
}

.downloadPanel {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

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

.downloadHeader {
  justify-content: space-between;
  align-items: flex-start;
}

.stateBadge {
  min-height: 28px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ok);
  font-size: 12px;
  font-weight: 700;
}

.stateBadge.isOffline {
  color: var(--danger);
}

.setupGrid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}

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

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

.downloadActions {
  flex-wrap: wrap;
}

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

#downloadProgress {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #1677c8, #138a43);
  transition: width 120ms linear;
}

.statusLine {
  min-height: 20px;
}

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

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

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

.speakButton.isRecording,
#startButton.isRecording {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.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;
}

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

#offlineStatus {
  margin-top: 8px;
}

.debugPanel {
  margin-top: 8px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.debugPanel summary {
  cursor: pointer;
  width: max-content;
}

#debugLog {
  max-height: 160px;
  overflow: auto;
  margin: 8px 0 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f9fafb;
  color: var(--ink);
  white-space: pre-wrap;
  font: 11px/1.35 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

.transcripts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  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 {
    overflow: hidden;
  }

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

  .offlineTopbar {
    display: none;
  }

  .offlineControls {
    position: relative;
    padding: 8px;
  }

  .downloadPanel {
    gap: 8px;
    margin-bottom: 8px;
  }

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

  #packSummary,
  .statusLine {
    font-size: 12px;
  }

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

  .setupGrid label:last-child {
    grid-column: 1 / -1;
  }

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

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

  .downloadActions {
    gap: 6px;
  }

  .downloadActions button {
    min-height: 34px;
    font-size: 12px;
  }

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

  #startButton,
  .speakButton {
    min-height: 76px;
    font-size: 30px;
  }

  .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;
  }

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

  .transcripts {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) 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;
  }
}
