:root {
  color-scheme: light;
  --canvas: #eff4f1;
  --surface: #ffffff;
  --surface-muted: #f7faf8;
  --ink: #17211e;
  --ink-soft: #52605a;
  --line: #d8e2dc;
  --line-strong: #b8c9c0;
  --green: #08745d;
  --green-dark: #045443;
  --green-pale: #dff4e9;
  --amber: #a66809;
  --amber-pale: #fff1d4;
  --red: #ae3c43;
  --red-pale: #fde8e9;
  --shadow: 0 18px 38px rgb(31 60 48 / 8%);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--canvas);
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px),
    var(--canvas);
  background-size: 44px 44px;
  font-family: Inter, "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

button,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.app-shell {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 30px 0 34px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 2px 24px;
}

.brand-lockup,
.header-actions,
.section-heading,
.status-message-wrap {
  display: flex;
  align-items: center;
}

.brand-lockup {
  gap: 14px;
}

.brand-mark {
  display: flex;
  align-items: stretch;
  gap: 3px;
  width: 34px;
  height: 34px;
  padding: 6px 7px;
  border: 1px solid var(--ink);
  background: var(--green-pale);
}

.brand-mark span {
  width: 4px;
  background: var(--ink);
}

.brand-mark span:nth-child(2) {
  width: 7px;
}

.brand-mark span:nth-child(3) {
  width: 3px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--ink-soft);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

h1,
h2,
p {
  margin-top: 0;
}

h1,
h2 {
  font-weight: 760;
  letter-spacing: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 23px;
  line-height: 1.1;
}

h2 {
  margin-bottom: 0;
  font-size: 18px;
  line-height: 1.2;
}

.header-actions {
  justify-content: flex-end;
  gap: 14px;
}

.api-status,
.connection-message,
.compatibility-note,
.input-preview {
  color: var(--ink-soft);
}

.api-status {
  max-width: 260px;
  margin: 0;
  text-align: right;
  font-size: 13px;
}

.button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 5px;
  padding: 7px 13px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0;
  transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease,
    transform 140ms ease;
}

.button:not(:disabled):hover {
  transform: translateY(-1px);
}

.button:focus-visible,
select:focus-visible {
  outline: 3px solid rgb(8 116 93 / 25%);
  outline-offset: 2px;
}

.button-primary {
  color: #ffffff;
  background: var(--green-dark);
  box-shadow: 0 4px 0 #03382d;
}

.button-primary:not(:disabled):hover {
  background: var(--green);
}

.button-secondary {
  color: var(--red);
  border-color: #e7b7ba;
  background: #ffffff;
}

.button-secondary:not(:disabled):hover {
  border-color: var(--red);
  background: var(--red-pale);
}

.button-tertiary {
  color: var(--green-dark);
  border-color: var(--line-strong);
  background: var(--surface);
}

.button-tertiary:not(:disabled):hover {
  border-color: var(--green);
  background: var(--green-pale);
}

.status-band {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 2fr;
  min-height: 79px;
  border: 1px solid var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.status-item,
.status-message-wrap {
  min-width: 0;
  padding: 14px 18px;
  border-right: 1px solid var(--line);
}

.status-label {
  display: block;
  margin-bottom: 4px;
  color: var(--ink-soft);
  font-size: 12px;
}

.status-item strong {
  display: block;
  overflow: hidden;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 15px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.connection-state.is-idle {
  color: var(--ink-soft);
}

.connection-state.is-connecting {
  color: var(--amber);
}

.connection-state.is-connected {
  color: var(--green-dark);
}

.connection-state.is-error {
  color: var(--red);
}

.status-message-wrap {
  gap: 9px;
  border-right: 0;
}

.status-dot {
  display: block;
  width: 9px;
  height: 9px;
  flex: 0 0 9px;
  border-radius: 50%;
  background: var(--ink-soft);
}

.status-dot.is-connecting {
  background: var(--amber);
  animation: pulse 1.2s ease-in-out infinite;
}

.status-dot.is-connected {
  background: var(--green);
}

.status-dot.is-error {
  background: var(--red);
}

.connection-message {
  margin: 0;
  font-size: 13px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(310px, 0.85fr);
  gap: 18px;
  margin-top: 18px;
}

.scan-panel,
.settings-panel,
.devices-section,
.history-section,
.debug-section {
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.scan-panel {
  display: flex;
  min-height: 278px;
  flex-direction: column;
  padding: 23px 25px;
}

.section-heading {
  justify-content: space-between;
  gap: 18px;
}

.muted-time {
  flex: 0 0 auto;
  color: var(--ink-soft);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12px;
}

.scan-value {
  display: flex;
  min-width: 0;
  min-height: 118px;
  flex: 1;
  align-items: center;
  overflow-wrap: anywhere;
  color: var(--green-dark);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: clamp(26px, 4vw, 50px);
  font-weight: 800;
  line-height: 1.13;
}

.input-preview {
  min-height: 24px;
  margin: 8px 0 0;
  overflow-wrap: anywhere;
  border-top: 1px solid var(--line);
  padding-top: 12px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12px;
}

.settings-panel {
  padding: 20px;
}

.compact-heading {
  align-items: flex-start;
}

.usb-details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  margin-top: 25px;
  border: 1px solid var(--line);
  background: var(--line);
}

.usb-details > div {
  min-width: 0;
  padding: 12px;
  background: var(--surface-muted);
}

.usb-details dt {
  margin-bottom: 5px;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 700;
}

.usb-details dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 13px;
  font-weight: 700;
}

.devices-section,
.history-section {
  margin-top: 18px;
  padding: 20px;
}

.devices-heading,
.history-heading,
.debug-heading {
  margin-bottom: 16px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 5px;
}

table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  text-align: left;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

th {
  color: var(--ink-soft);
  background: var(--surface-muted);
  font-size: 12px;
  font-weight: 700;
}

td {
  font-size: 14px;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.device-name,
.device-id,
.scan-content,
.scan-time {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.device-id,
.scan-time {
  color: var(--ink-soft);
  font-size: 13px;
}

.device-state {
  display: inline-block;
  border-radius: 4px;
  padding: 2px 7px;
  color: var(--ink-soft);
  background: #edf1ef;
  font-size: 12px;
  font-weight: 700;
}

.device-state.is-connected {
  color: var(--green-dark);
  background: var(--green-pale);
}

.empty-row td {
  padding: 25px 14px;
  color: var(--ink-soft);
  text-align: center;
}

.scan-index {
  width: 78px;
  color: var(--ink-soft);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 13px;
}

.scan-content {
  overflow-wrap: anywhere;
  color: var(--green-dark);
  font-weight: 700;
}

.compatibility-note {
  margin: 14px 2px 0;
  font-size: 12px;
}

.debug-section {
  margin-top: 18px;
  padding: 20px;
}

.debug-environment {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  margin: 0 0 14px;
  border: 1px solid var(--line);
  background: var(--line);
}

.debug-environment > div {
  min-width: 0;
  padding: 10px 12px;
  background: var(--surface-muted);
}

.debug-environment .debug-origin {
  grid-column: span 2;
}

.debug-environment .debug-browser {
  grid-column: 1 / -1;
}

.debug-environment dt {
  margin-bottom: 3px;
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 700;
}

.debug-environment dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12px;
}

.debug-log-wrap {
  max-height: 294px;
  overflow: auto;
  border: 1px solid #2e3e38;
  border-radius: 5px;
  background: #17211e;
}

.debug-log {
  display: flex;
  min-width: 640px;
  flex-direction: column;
  gap: 1px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.debug-log li {
  display: grid;
  grid-template-columns: 70px 68px minmax(0, 1fr);
  gap: 10px;
  padding: 9px 12px;
  border-bottom: 1px solid rgb(255 255 255 / 8%);
  color: #e7f0eb;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
}

.debug-log li:last-child {
  border-bottom: 0;
}

.debug-log .debug-time {
  color: #a6b8af;
}

.debug-log .debug-level {
  font-weight: 700;
}

.debug-log .debug-level.is-info {
  color: #84d8b1;
}

.debug-log .debug-level.is-warn {
  color: #f2c56b;
}

.debug-log .debug-level.is-error {
  color: #ff9ea4;
}

.debug-log .debug-message {
  min-width: 0;
  overflow-wrap: anywhere;
}

.debug-log .debug-empty {
  display: block;
  min-width: 0;
  color: #a6b8af;
  text-align: center;
}

@keyframes pulse {
  50% {
    opacity: 0.42;
  }
}

@media (max-width: 800px) {
  .app-shell {
    width: min(100% - 28px, 640px);
    padding-top: 20px;
  }

  .app-header,
  .header-actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .app-header {
    gap: 17px;
  }

  .header-actions {
    width: 100%;
    gap: 10px;
  }

  .header-actions .button {
    width: 100%;
  }

  .api-status {
    max-width: none;
    text-align: left;
  }

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

  .status-message-wrap {
    grid-column: 1 / -1;
    border-top: 1px solid var(--line);
  }

  .status-item:nth-child(2) {
    border-right: 0;
  }

  .status-item:nth-child(3) {
    border-top: 1px solid var(--line);
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .scan-panel {
    min-height: 236px;
    padding: 20px;
  }

  .scan-value {
    min-height: 100px;
  }
}

@media (max-width: 440px) {
  .status-item,
  .status-message-wrap,
  .settings-panel,
  .devices-section,
  .history-section,
  .debug-section {
    padding: 14px;
  }

  .section-heading {
    align-items: flex-start;
  }

  .usb-details {
    grid-template-columns: 1fr;
    margin-top: 20px;
  }

  .muted-time {
    padding-top: 3px;
    font-size: 11px;
    text-align: right;
  }

  .debug-environment {
    grid-template-columns: 1fr 1fr;
  }

  .debug-environment .debug-origin,
  .debug-environment .debug-browser {
    grid-column: 1 / -1;
  }

  .debug-log {
    min-width: 0;
  }

  .debug-log li {
    grid-template-columns: 54px 48px minmax(0, 1fr);
    gap: 6px;
    padding: 8px 9px;
    font-size: 11px;
  }
}
