html, body { height: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  background: #f6f7f9;
  color: #162033;
  display: flex;
  flex-direction: column;
}

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

button,
select {
  min-height: 34px;
  border-radius: 8px;
}

button {
  border: 1px solid #cfd6e4;
  background: #fff;
  color: #162033;
  padding: 6px 12px;
}

button:hover:enabled {
  background: #f8fafc;
}

button:disabled,
select:disabled {
  opacity: 0.65;
}

select {
  border: 1px solid #cfd6e4;
  background: #fff;
  padding: 4px 10px;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid #d9deea;
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}

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

.appBrand img {
  width: 58px;
  height: auto;
  flex: 0 0 auto;
}

.brandText {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brandTitle {
  font-size: 20px;
  font-weight: 750;
  letter-spacing: 0.02em;
}

.brandSubtitle {
  color: #667085;
  font-size: 12px;
}

.statusArea {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

#transcribeProgress {
  width: 180px;
  height: 14px;
}

#micSelect {
  max-width: 260px;
  min-width: 150px;
}

#status {
  display: none;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 14px;
  white-space: nowrap;
}

#status.info    { background: #e5e7eb; color: #1f2937; }
#status.working { background: #dbeafe; color: #1e40af; }
#status.error   { background: #fee2e2; color: #991b1b; }
#status.success { background: #dcfce7; color: #166534; }

main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
}

.wavePane,
.textPane {
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.wavePane {
  padding: 14px;
  border-right: 1px solid #d9deea;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
}

.textPane {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.controlGroup {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border: 1px solid #d9deea;
  border-radius: 12px;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}

.controlGroupTitle {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #475467;
}

.controlRow {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.controlRow label {
  font-size: 13px;
  font-weight: 600;
  color: #344054;
}

.waveBlock {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border: 1px solid #d9deea;
  border-radius: 12px;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}

#waveform,
#waveDetail,
#waveformImported,
#waveformRecorded {
  height: 80px;
  border: 1px solid #d9deea;
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff 0%, #fbfcfe 100%);
}

#waveDetailPane {
  --word-region-color: rgba(0, 200, 0, 0.35);
}

.transport {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  column-gap: 12px;
  align-items: center;
}

.transportGroup {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  white-space: nowrap;
}

.transportGroup.left { justify-self: start; }
.transportGroup.center { justify-self: center; }
.transportGroup.right { justify-self: end; }

.numericReadout {
  font-variant-numeric: tabular-nums;
}

.wavePane hr {
  width: 100%;
  border: 0;
  border-top: 1px solid #d9deea;
  margin: 6px 0;
}

.paneTitle {
  margin: 0;
  font-weight: 650;
}

.paneHeaderRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.transcriptSubTitleRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.paneHeaderActions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.modeToggleGroup {
  display: inline-flex;
  align-items: center;
  gap: 0;
  border: 1px solid #d9deea;
  border-radius: 10px;
  overflow: hidden;
  background: #ffffff;
}

.modeToggle {
  border: 0;
  border-right: 1px solid #d9deea;
  border-radius: 0;
  background: transparent;
  padding: 7px 11px;
  font-size: 12px;
  font-weight: 600;
  color: #344054;
}

.modeToggle:last-child {
  border-right: 0;
}

.modeToggle:hover:not(.isActive) {
  background: #f8fafc;
}

.modeToggle.isActive {
  background: #fff4e3;
  color: #8f4a00;
}

.transcriptPane {
  flex: 0 0 auto;
  min-height: 120px;
  padding: 12px;
  border: 1px solid #d9deea;
  border-radius: 12px;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
  line-height: 1.8;
  font-size: 16px;
  user-select: none;
  overflow-wrap: anywhere;
}

.transcriptPane.isActive {
  outline: 2px solid #f4a949;
  outline-offset: 6px;
  border-radius: 8px;
}

.transcriptPane.moveMode .word {
  cursor: grab;
}

.word {
  cursor: pointer;
  padding: 1px 2px;
  border-radius: 4px;
}

.word:hover { background: #f1f1f1; }
.word.selected { background: #ffe08a; }

.word.playhead {
  outline: 2px solid #f4a949;
  outline-offset: 1px;
}

.transcriptPane.dragging-words .word {
  cursor: grabbing;
}

.word.drop-before {
  box-shadow: inset 3px 0 0 #f4a949;
}

.word.drop-after {
  box-shadow: inset -3px 0 0 #f4a949;
}

#searchBar {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
  padding: 6px;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
  z-index: 10;
}

#searchBar[hidden] {
  display: none !important;
}

#searchInput {
  width: 160px;
}

.devPanel {
  margin-top: auto;
  padding-top: 8px;
}

.devPanel summary {
  cursor: pointer;
  user-select: none;
  padding: 8px 10px;
  border: 1px solid #d9deea;
  border-radius: 8px;
  background: #ffffff;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.devTitle { font-weight: 650; }
.devHint  { color: #666; font-size: 12px; }

.devBody {
  margin-top: 10px;
  border: 1px solid #d9deea;
  border-radius: 8px;
  padding: 10px;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.devSectionTitle { font-weight: 650; margin-bottom: 6px; }

.devRow {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.devRow label { font-size: 13px; color: #333; }

.word.deleted {
  color: #999;
  text-decoration: line-through;
}

/* ============================================================================
   Mobile web support
   ========================================================================== */

@media (max-width: 760px) {
  html,
  body {
    width: 100%;
    overflow: hidden;
    -webkit-text-size-adjust: 100%;
  }

  header {
    flex-wrap: wrap;
    gap: 8px;
    padding: 6px 8px;
    overflow-x: auto;
  }

  header img {
    width: 48px;
    height: auto;
  }

  header button,
  header select {
    min-height: 36px;
  }

  .headerDivider {
    display: none;
  }

  .statusArea {
    flex: 1 0 100%;
    margin-left: 0;
    min-width: 0;
  }

  #status {
    white-space: normal;
  }

  #transcribeProgress {
    flex: 1;
    min-width: 120px;
    width: auto;
  }

  main {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(40vh, 1fr);
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  .wavePane {
    border-right: 0;
    border-bottom: 1px solid #ddd;
    gap: 8px;
  }

  .devPanel {
    display: none;
  }

  .textPane {
    overflow: visible;
  }

  .transport {
    grid-template-columns: auto 1fr;
    row-gap: 6px;
  }

  .transportGroup.center {
    justify-self: end;
  }

  .transportGroup.right {
    grid-column: 1 / -1;
    justify-self: start;
    max-width: 100%;
    overflow: hidden;
  }

  #loadedFile {
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #transcript {
    line-height: 2;
    touch-action: pan-y;
    -webkit-user-select: none;
  }

  .word {
    display: inline-block;
    padding: 3px 3px;
    touch-action: manipulation;
  }

  #searchBar {
    position: fixed;
    left: 8px;
    right: 8px;
  }

  #searchInput {
    width: auto;
    min-width: 0;
    flex: 1;
  }
}

.word.added {
  color: #22863a;
  font-style: italic;
}

.word.moved {
  color: #b08800;
  font-style: italic;
}

#specJson {
  width: 100%;
  height: 160px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.35;
  padding: 8px;
  border: 1px solid #ddd;
  border-radius: 8px;
  resize: vertical;
  background: #fcfcfd;
}

#log {
  max-height: 180px;
  overflow: auto;
  margin: 0;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: #0b0b0b;
  color: #e8e8e8;
  font-size: 12px;
  line-height: 1.35;
}

.highlight {
  background: #f4a949;
}

@media (max-width: 1100px) {
  main {
    grid-template-columns: 1fr;
  }

  .wavePane {
    border-right: 0;
    border-bottom: 1px solid #d9deea;
  }

  .controlBoard,
  .transcriptToolbar {
    grid-template-columns: 1fr;
  }

  .paneHeaderRow,
  .transcriptSubTitleRow {
    align-items: flex-start;
    flex-direction: column;
  }

  .paneHeaderActions {
    justify-content: flex-start;
  }
}
