:root {
  color-scheme: light;
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  color: #20252b;
  background: #f4f6f7;
  font-synthesis: none;
  --border: #d7dde1;
  --muted: #66717b;
  --surface: #ffffff;
  --ink: #20252b;
  --green: #16835f;
  --green-soft: #e8f5f0;
  --red: #c33d42;
  --red-soft: #fff0f0;
  --amber: #a76500;
  --amber-soft: #fff5dc;
  --blue: #286b9d;
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: #f4f6f7;
}

button,
select,
input {
  font: inherit;
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
pre:focus-visible {
  outline: 2px solid #2878ae;
  outline-offset: 2px;
}

.app-header {
  min-height: 76px;
  padding: 14px max(20px, calc((100vw - 1320px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  color: #f8fafb;
  background: #252b30;
  border-bottom: 3px solid #16835f;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 21px;
  line-height: 1.25;
  font-weight: 650;
}

.app-header p {
  margin-top: 5px;
  font-size: 12px;
  color: #bfc8ce;
}

.status-badge {
  height: 34px;
  min-width: 94px;
  padding: 0 12px;
  border: 1px solid #59636b;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 13px;
  background: #333a40;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #87939c;
}

.status-badge.recording .status-dot {
  background: #fa565c;
  box-shadow: 0 0 0 4px rgba(250, 86, 92, 0.18);
}

.status-badge.paused .status-dot {
  background: #f0ae30;
}

.status-badge.done .status-dot {
  background: #55c49a;
}

main {
  width: min(1320px, calc(100% - 32px));
  margin: 16px auto 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.config-band,
.command-band,
.metrics-band,
.waveform-section,
.result-section,
.log-section {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.config-band {
  display: grid;
  grid-template-columns: minmax(130px, 0.7fr) minmax(260px, 1.5fr) minmax(180px, 1fr) repeat(3, minmax(160px, 0.9fr));
  gap: 12px 20px;
  align-items: end;
  background: #fafbfb;
}

.field label,
.toggle-field strong {
  display: block;
  margin-bottom: 7px;
  font-size: 13px;
  font-weight: 600;
}

.field input[type="text"] {
  width: 100%;
  min-width: 0;
  height: 38px;
  padding: 0 10px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #bcc6cc;
  border-radius: 5px;
}

.field-row {
  display: flex;
  gap: 6px;
}

.field-row select {
  width: auto;
  min-width: 0;
  flex: 1 1 auto;
}

select {
  width: 100%;
  min-width: 0;
  height: 38px;
  padding: 0 10px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #bcc6cc;
  border-radius: 5px;
}

.toggle-field {
  min-width: 0;
  height: 54px;
  padding-left: 12px;
  border-left: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  cursor: pointer;
}

.toggle-field strong {
  margin: 0;
}

.toggle-field small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.toggle-field input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle {
  position: relative;
  width: 40px;
  height: 22px;
  border-radius: 11px;
  background: #aab4bb;
  transition: background 120ms ease;
}

.toggle::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.22);
  transition: transform 120ms ease;
}

.toggle-field input:checked + .toggle {
  background: var(--green);
}

.toggle-field input:checked + .toggle::after {
  transform: translateX(18px);
}

.toggle-field input:focus-visible + .toggle {
  outline: 2px solid #2878ae;
  outline-offset: 2px;
}

.command-band,
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.command-group,
.log-actions,
.result-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.button,
.icon-button {
  height: 38px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: #273038;
  background: #fff;
  border: 1px solid #b8c2c9;
  border-radius: 5px;
  cursor: pointer;
}

.button:hover:not(:disabled),
.icon-button:hover:not(:disabled) {
  background: #f0f3f5;
  border-color: #8f9ca5;
}

.button:disabled,
.icon-button:disabled,
select:disabled,
.toggle-field:has(input:disabled) {
  opacity: 0.5;
  cursor: not-allowed;
}

.button.primary {
  color: #fff;
  background: var(--green);
  border-color: var(--green);
}

.button.primary:hover:not(:disabled) {
  background: #126d50;
}

.button.danger:not(:disabled) {
  color: var(--red);
  border-color: #dca5a8;
  background: var(--red-soft);
}

.button.marker:not(:disabled) {
  color: #79500a;
  border-color: #ddbe75;
  background: var(--amber-soft);
}

.button.small {
  height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

.icon-button {
  width: 38px;
  padding: 0;
  font-size: 20px;
}

.record-icon {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: currentColor;
}

.session-note {
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.metrics-band {
  padding-top: 0;
  padding-bottom: 0;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  background: #fbfcfc;
}

.metric {
  min-width: 0;
  height: 72px;
  padding: 13px 14px;
  border-right: 1px solid var(--border);
}

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

.metric span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.metric strong {
  display: block;
  margin-top: 7px;
  overflow: hidden;
  color: #252d33;
  font-family: Consolas, "Courier New", monospace;
  font-size: 16px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric.warning {
  background: var(--amber-soft);
}

.metric.danger {
  background: var(--red-soft);
}

.section-heading h2 {
  font-size: 15px;
  font-weight: 650;
}

.section-heading p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.level-meter {
  width: 180px;
  height: 8px;
  overflow: hidden;
  background: #e1e6e9;
  border-radius: 4px;
}

.level-meter span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--green);
  transition: width 80ms linear, background 80ms linear;
}

.canvas-wrap {
  position: relative;
  width: 100%;
  height: 260px;
  margin-top: 12px;
  overflow: hidden;
  background: #151a1e;
  border: 1px solid #313a40;
  border-radius: 4px;
}

#waveformCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.empty-waveform {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #82909a;
  font-size: 13px;
  pointer-events: none;
}

.empty-waveform[hidden] {
  display: none;
}

.recording-results {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-top: 1px solid var(--border);
}

.recording-result {
  min-width: 0;
  padding: 14px 16px 0 0;
}

.recording-result + .recording-result {
  padding-right: 0;
  padding-left: 16px;
  border-left: 1px solid var(--border);
}

.recording-result-heading {
  min-height: 54px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.recording-result-heading h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 650;
}

.recording-result-heading p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
}

.recording-result-actions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.recording-result audio {
  width: 100%;
  height: 42px;
  margin-top: 8px;
}

.diagnosis-box {
  margin-top: 12px;
  padding: 10px 12px;
  display: flex;
  align-items: baseline;
  gap: 10px;
  color: #273038;
  background: #f0f6f3;
  border-left: 3px solid var(--green);
  font-size: 12px;
}

.diagnosis-box.warning {
  background: var(--amber-soft);
  border-left-color: var(--amber);
}

.diagnosis-box.danger {
  background: var(--red-soft);
  border-left-color: var(--red);
}

.diagnosis-box strong {
  flex: 0 0 auto;
}

.log-section {
  border-bottom: 0;
}

#logOutput {
  width: 100%;
  height: 260px;
  margin: 12px 0 0;
  padding: 12px;
  overflow: auto;
  color: #d7e1e7;
  background: #20262b;
  border: 1px solid #374149;
  border-radius: 4px;
  font: 12px/1.55 Consolas, "Courier New", monospace;
  white-space: pre-wrap;
  word-break: break-word;
}

.log-info {
  color: #d7e1e7;
}

.log-warn {
  color: #ffd27c;
}

.log-error {
  color: #ff9da1;
}

footer {
  width: min(1320px, calc(100% - 32px));
  margin: -12px auto 20px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  color: #76818a;
  font-size: 11px;
}

@media (max-width: 980px) {
  .config-band {
    grid-template-columns: 1fr 1fr;
  }

  .device-field {
    grid-column: 1 / -1;
  }

  .recording-results {
    grid-template-columns: 1fr;
  }

  .recording-result,
  .recording-result + .recording-result {
    padding: 14px 0 0;
    border-left: 0;
  }

  .recording-result + .recording-result {
    margin-top: 14px;
    border-top: 1px solid var(--border);
  }

  .toggle-field {
    border-left: 0;
    border-top: 1px solid var(--border);
    padding: 10px 0 0;
  }

  .metrics-band {
    grid-template-columns: repeat(4, 1fr);
  }

  .metric:nth-child(4) {
    border-right: 0;
  }

  .metric:nth-child(-n + 4) {
    border-bottom: 1px solid var(--border);
  }
}

@media (max-width: 640px) {
  .app-header {
    padding-right: 12px;
    padding-left: 12px;
    align-items: center;
    gap: 8px;
  }

  .app-header > div:first-child {
    min-width: 0;
    flex: 1 1 auto;
  }

  .app-header p {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .status-badge {
    min-width: 76px;
    padding: 0 8px;
    flex: 0 0 auto;
  }

  h1 {
    font-size: 17px;
  }

  main,
  footer {
    width: calc(100% - 16px);
  }

  .config-band {
    grid-template-columns: 1fr;
  }

  .device-field {
    grid-column: auto;
  }

  .command-band,
  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .command-group,
  .log-actions,
  .result-actions {
    width: 100%;
  }

  .result-actions .button {
    flex: 1 1 auto;
    min-width: 0;
  }

  .command-group .button {
    flex: 1 1 calc(50% - 8px);
    min-width: 0;
  }

  .session-note {
    width: 100%;
    text-align: left;
  }

  .metrics-band {
    grid-template-columns: repeat(2, 1fr);
  }

  .metric,
  .metric:nth-child(4) {
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
  }

  .metric:nth-child(even) {
    border-right: 0;
  }

  .canvas-wrap {
    height: 210px;
  }

  .level-meter {
    width: 100%;
  }

  .diagnosis-box {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .recording-result-heading {
    flex-direction: column;
  }

  .recording-result-actions {
    width: 100%;
    justify-content: flex-start;
  }
}
