:root {
  color-scheme: light;
  --bg: #f6f3ed;
  --ink: #161616;
  --muted: #6b665d;
  --line: #d8d0c2;
  --panel: #fffaf1;
  --panel-strong: #ffffff;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --amber: #b65f19;
  --danger: #a43a3a;
  --shadow: 0 18px 60px rgba(35, 28, 18, 0.1);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100svh;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(246, 243, 237, 0.96), rgba(246, 243, 237, 1)),
    repeating-linear-gradient(90deg, rgba(22, 22, 22, 0.035) 0 1px, transparent 1px 72px);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  transition:
    transform 160ms ease,
    background 160ms ease,
    border-color 160ms ease,
    color 160ms ease;
}

button:active {
  transform: translateY(1px);
}

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

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 26px clamp(18px, 4vw, 42px) 18px;
  border-bottom: 1px solid var(--line);
}

.kicker {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(28px, 5vw, 48px);
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  font-size: 20px;
  line-height: 1.15;
  letter-spacing: 0;
}

.subtle {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.status-stack {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.status-chip,
.counter {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  padding: 0 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.58);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.status-chip.online {
  border-color: rgba(15, 118, 110, 0.32);
  background: rgba(15, 118, 110, 0.11);
  color: var(--accent-strong);
}

.status-chip.offline {
  border-color: rgba(164, 58, 58, 0.28);
  background: rgba(164, 58, 58, 0.08);
  color: var(--danger);
}

.status-chip.muted {
  color: var(--muted);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 0.92fr) minmax(320px, 1.08fr);
  grid-template-areas:
    "connection log"
    "commands log";
  gap: 18px;
  padding: 18px clamp(18px, 4vw, 42px) 42px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.86);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.connection-panel {
  grid-area: connection;
}

.command-panel {
  grid-area: commands;
}

.log-panel {
  grid-area: log;
  min-height: min(700px, calc(100svh - 132px));
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.primary-button,
.secondary-button,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  font-weight: 800;
  white-space: nowrap;
}

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

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

.primary-button:hover {
  background: var(--accent-strong);
}

.secondary-button {
  border: 1px solid rgba(15, 118, 110, 0.28);
  background: #ffffff;
  color: var(--accent-strong);
}

.secondary-button:hover {
  border-color: rgba(15, 118, 110, 0.52);
}

.ghost-button {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
}

.ghost-button:hover {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.62);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 0 18px 18px;
}

.button-row.compact {
  padding: 0;
  justify-content: flex-end;
}

.spec-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  margin: 0;
  border-bottom: 1px solid var(--line);
  background: var(--line);
}

.spec-grid div {
  min-width: 0;
  padding: 14px 18px;
  background: rgba(255, 255, 255, 0.45);
}

.spec-grid dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.spec-grid dd {
  margin: 6px 0 0;
  overflow-wrap: anywhere;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 14px;
  font-weight: 800;
}

.toggle-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.toggle-line input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.command-list {
  display: grid;
  gap: 1px;
  background: var(--line);
  border-bottom: 1px solid var(--line);
}

.scan-config {
  padding: 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.38);
}

.scan-config h2 {
  margin-bottom: 14px;
}

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

.scan-grid label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.scan-grid select {
  min-width: 0;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: rgba(255, 255, 255, 0.84);
  color: var(--ink);
  font: inherit;
  font-weight: 800;
}

.command-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 14px 18px;
  background: rgba(255, 255, 255, 0.52);
}

.command-name {
  margin: 0;
  font-size: 15px;
  font-weight: 850;
}

.command-hex {
  margin-top: 5px;
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.raw-send {
  padding: 18px;
}

.raw-send label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.raw-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.raw-input-row input {
  min-width: 0;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: rgba(255, 255, 255, 0.8);
  color: var(--ink);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.raw-input-row input:focus {
  outline: 2px solid rgba(15, 118, 110, 0.22);
  border-color: rgba(15, 118, 110, 0.56);
}

.log-list {
  display: flex;
  flex-direction: column-reverse;
  gap: 1px;
  max-height: calc(100svh - 238px);
  min-height: 520px;
  margin: 0;
  padding: 0;
  overflow: auto;
  background: var(--line);
  list-style: none;
}

.log-row {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 12px;
  padding: 12px 18px;
  background: rgba(255, 255, 255, 0.58);
}

.log-row.tx {
  border-left: 4px solid var(--accent);
}

.log-row.rx {
  border-left: 4px solid var(--amber);
}

.log-row.heartbeat {
  background: rgba(255, 255, 255, 0.44);
}

.log-meta {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.log-hex {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.log-note {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.dump-panel {
  border-top: 1px solid var(--line);
  background: rgba(255, 250, 241, 0.9);
}

.dump-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.dump-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  margin: 0;
  background: var(--line);
}

.dump-stats div {
  padding: 12px 18px;
  background: rgba(255, 255, 255, 0.52);
}

.dump-stats dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
}

.dump-stats dd {
  margin: 5px 0 0;
  font-size: 18px;
  font-weight: 850;
}

#dumpHex,
#decodedJson {
  display: block;
  width: 100%;
  min-height: 180px;
  border: 0;
  border-top: 1px solid var(--line);
  padding: 14px 18px;
  resize: vertical;
  background: rgba(255, 255, 255, 0.66);
  color: var(--ink);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.5;
}

.decoded-panel {
  border-top: 1px solid var(--line);
}

@media (max-width: 900px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .status-stack {
    justify-content: flex-start;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-areas:
      "connection"
      "commands"
      "log";
  }

  .log-panel {
    min-height: 520px;
  }
}

@media (max-width: 560px) {
  .section-head,
  .command-item,
  .raw-send {
    padding-left: 14px;
    padding-right: 14px;
  }

  .section-head {
    flex-direction: column;
  }

  .primary-button,
  .secondary-button,
  .ghost-button {
    width: 100%;
  }

  .connect-actions {
    width: 100%;
  }

  .button-row,
  .raw-input-row,
  .command-item,
  .scan-grid {
    grid-template-columns: 1fr;
  }

  .button-row {
    display: grid;
    padding-left: 14px;
    padding-right: 14px;
  }

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

  .log-list {
    max-height: none;
    min-height: 420px;
  }

  .log-row {
    grid-template-columns: 48px minmax(0, 1fr);
    padding-left: 14px;
    padding-right: 14px;
  }

  .dump-head {
    flex-direction: column;
    padding-left: 14px;
    padding-right: 14px;
  }
}
