:root {
  --bg: #f1f5f1;
  --card: #fff;
  --ink: #183f45;
  --muted: #6f8582;
  --line: #dbe5df;
  --teal: #16877f;
  --dark: #153b42;
  --mint: #94e2c2;
  --radius: 12px;
  --gap: 12px;
  color-scheme: light;
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
p {
  font-size: 12px;
  line-height: 1.7;
  color: var(--muted);
  margin: 0;
}
button,
select {
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  border: 1px solid #ccdad5;
  border-radius: 7px;
  background: white;
  color: var(--ink);
  padding: 7px 13px;
  transition:
    background 0.15s,
    box-shadow 0.15s;
}
button:hover:not(:disabled) {
  background: #e7f1eb;
}
button:disabled {
  opacity: 0.45;
  cursor: default;
}
button:focus-visible,
select:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 3px solid #7acbbb;
  outline-offset: 2px;
}
.primary {
  color: white;
  background: var(--teal);
  border-color: var(--teal);
  font-weight: 600;
}
.primary:hover:not(:disabled) {
  background: #116b65;
}
.text-button {
  background: none;
  border: none;
  color: #4f716b;
  padding: 7px 8px;
}
.small-button {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
}
.mini {
  padding: 3px 6px;
  font-size: 12px;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

/* ---- 顶栏 ---- */
.topbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 22px;
  padding: 10px 18px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.brand h1 {
  font-size: 18px;
  margin: 0;
  letter-spacing: -0.3px;
}
.brand span {
  font-size: 11px;
  color: var(--teal);
  letter-spacing: 1px;
  font-weight: 600;
}
.controls,
.run-settings,
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.run-settings {
  font-size: 12px;
  color: var(--muted);
  margin-left: auto;
}
.run-settings select {
  padding: 5px 8px;
}
.rate {
  font: 12px Consolas, monospace;
  min-width: 82px;
}
.status {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--teal);
  min-width: 72px;
}
.status:before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 100%;
  background: #a6b6ac;
}
.status.running:before {
  background: #1fa589;
  box-shadow: 0 0 0 4px #def2e9;
}
.alert {
  position: fixed;
  z-index: 5;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  width: min(760px, calc(100vw - 40px));
  border: 1px solid #dfc5b6;
  background: #fff3e8;
  color: #925a35;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 13px;
  line-height: 1.7;
  box-shadow: 0 8px 24px #5a3a2420;
  cursor: pointer;
  overflow-wrap: anywhere;
}
.alert[hidden] {
  display: none;
}

.author {
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f6faf6;
  font-size: 12px;
}
.author > * {
  border: none;
  background: none;
  border-radius: 0;
  padding: 5px 10px;
  font-size: 12px;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}
.author > * + * {
  border-left: 1px solid var(--line);
}
.author a {
  color: var(--teal);
}
.author a:hover,
.author > button:hover:not(:disabled) {
  background: #e7f1eb;
}
.author-name {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}
.author-name i {
  font-style: normal;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background: var(--dark);
  color: var(--mint);
  display: grid;
  place-items: center;
  font-size: 11px;
}

/* ---- 三列布局：1080p 下 100% 缩放一屏看全 ---- */
.layout {
  display: grid;
  grid-template-columns: minmax(480px, 1.45fr) minmax(330px, 0.95fr) minmax(370px, 1.05fr);
  gap: var(--gap);
  padding: var(--gap) 18px;
  flex: 1;
  width: 100%;
  max-width: 2200px;
  margin: 0 auto;
}
.col {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  min-width: 0;
}
.card {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px 16px;
}
.card-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
h2 {
  font-size: 14px;
  font-weight: 650;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.hint {
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
}
.hint.warn {
  color: #b2552a;
  font-weight: 600;
  cursor: help;
}
.caption {
  font-size: 11px;
  margin-top: 6px;
}

/* ---- LCD ---- */
.lcd-card {
  background: var(--dark);
  border-radius: var(--radius);
  padding: 12px 16px 14px;
}
.lcd-card .card-title {
  color: #e1f3e9;
}
.lcd-card .card-title > span {
  font-size: 11px;
  color: #8db0aa;
}
.screen-frame {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  column-gap: 8px;
  row-gap: 4px;
  background: #102c31;
  border: 1px solid #36565c;
  border-radius: 8px;
  padding: 10px 14px 14px 8px;
  /* 屏幕高度不超过视口剩余空间，宽屏矮窗口时不溢出 */
  max-width: calc((100vh - 330px) * 4 / 3 + 70px);
  margin: 0 auto;
}
.line-gutter {
  display: grid;
  grid-template-rows: repeat(10, 1fr);
  color: #96b8ad;
  font: 11px Consolas, monospace;
  user-select: none;
}
.line-gutter span {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
}
.line-gutter span::after {
  content: "";
  width: 4px;
  height: 1px;
  background: #51776d;
}
.ruler-corner {
  color: #7c9d93;
  text-align: right;
  font: 10px/16px Consolas, monospace;
  user-select: none;
}
.column-gutter {
  display: grid;
  grid-template-columns: repeat(20, minmax(0, 1fr));
  text-align: center;
  color: #96b8ad;
  font: 10px/16px Consolas, monospace;
  user-select: none;
}
.screen {
  aspect-ratio: 4/3;
  position: relative;
  background: #000;
  overflow: hidden;
  border-radius: 2px;
}
.screen canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
}
#screen-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: #112d32;
  text-align: center;
  color: #c3dad0;
}
#screen-empty[hidden] {
  display: none;
}
#screen-empty strong {
  font-size: 18px;
  font-weight: 500;
}
#screen-empty p {
  color: #7fa7a0;
}
.chip-icon {
  font-family: Consolas, monospace;
  border: 1px solid #47746b;
  border-radius: 9px;
  padding: 12px;
  color: #84baaa;
  letter-spacing: 3px;
  box-shadow: 0 0 0 6px #14373a;
  margin-bottom: 8px;
}

/* ---- 串口 ---- */
.serial-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 170px;
}
.baud {
  font: 12px Consolas, monospace;
  font-weight: 400;
  color: var(--muted);
}
.baud.warn {
  color: #b2552a;
  font-weight: 600;
}
pre {
  flex: 1;
  background: #f4f7f2;
  border: 1px solid #e6ece3;
  border-radius: 7px;
  padding: 10px 12px;
  font: 13px/1.6 Consolas, "Microsoft YaHei", monospace;
  min-height: 70px;
  max-height: 40vh;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: #44665b;
  margin: 0 0 8px;
}
form {
  display: flex;
  align-items: center;
  gap: 8px;
}
input:not([type]) {
  font: 13px inherit;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 10px;
  background: #fff;
  color: var(--ink);
  min-width: 0;
}
#serial-input {
  flex: 1;
}
.newline {
  display: flex;
  align-items: center;
  font-size: 12px;
  white-space: nowrap;
  color: var(--muted);
  gap: 4px;
  accent-color: var(--teal);
}

/* ---- 程序信息 ---- */
.file-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.file-icon {
  font: 11px Consolas, monospace;
  border: 1px solid var(--line);
  background: #f2f6ef;
  border-radius: 8px;
  padding: 10px 8px;
  color: var(--teal);
}
.file-text {
  min-width: 0;
}
h3 {
  font-size: 14px;
  margin: 0 0 2px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#file-info {
  font-size: 11px;
  line-height: 1.5;
}
.metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 10px 0 0;
}
.metrics > div + div {
  border-left: 1px solid var(--line);
  padding-left: 14px;
}
dt {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 2px;
}
dd {
  margin: 0;
  font: 20px Consolas, monospace;
}
dd small {
  font-size: 12px;
  color: var(--muted);
}
#pc {
  font-size: 16px;
  line-height: 26px;
}

/* ---- 按键与 LED ---- */
.keys {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.key {
  padding: 8px 2px 6px;
  background: linear-gradient(180deg, #fff, #f0f5ec);
  box-shadow: 0 2px 0 #d4dfcf;
  touch-action: none;
  user-select: none;
}
.key b {
  font-size: 17px;
  font-weight: 650;
  display: block;
}
.key small {
  display: block;
  font-size: 10px;
  color: #8a9b93;
  margin-top: 2px;
}
.key.pressed {
  background: #c4e5d1 !important;
  box-shadow: inset 0 2px 4px #18423426;
  transform: translateY(2px);
}
.key.latched {
  background: #a9d8bf !important;
  box-shadow: inset 0 2px 4px #18423440;
  transform: translateY(2px);
}
.holds {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 4px;
  min-height: 16px;
  font: 11px Consolas, monospace;
  color: var(--muted);
  text-align: center;
}
.holds .active {
  color: var(--teal);
  font-weight: 600;
}
.leds {
  display: flex;
  justify-content: space-between;
  gap: 4px;
}
.led-item {
  display: flex;
  align-items: center;
  flex-direction: column;
  gap: 5px;
}
.led {
  width: 22px;
  height: 22px;
  border-radius: 100%;
  background: radial-gradient(circle at 35% 30%, #e2eadd, #acbba6 60%, #90a48d);
  border: 1px solid #bcc9b7;
}
.led.on {
  background: radial-gradient(circle at 35% 30%, #fff9ce, #f0ce64 60%, #c69c29);
  border-color: #e0b944;
  box-shadow: 0 0 12px #efd05d99;
}
.led-item span {
  font: 10px Consolas, monospace;
  color: #7f8f84;
}

/* ---- 滑块 ---- */
.slider-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
  gap: 8px;
  margin-top: 4px;
}
.slider-label small {
  font-size: 11px;
  color: var(--muted);
  margin-left: 4px;
}
.route {
  color: var(--teal);
}
output {
  font: 19px Consolas, monospace;
  white-space: nowrap;
}
.num {
  display: flex;
  align-items: baseline;
  gap: 4px;
}
.num small {
  font-size: 11px;
  color: var(--muted);
}
.num-input {
  width: 92px;
  font: 18px Consolas, monospace;
  text-align: right;
  color: var(--ink);
  border: 1px solid transparent;
  border-bottom: 1px dashed #b9cbc3;
  border-radius: 4px;
  background: transparent;
  padding: 1px 4px;
}
.num-input:hover,
.num-input:focus {
  border-color: #b9cbc3;
  background: #fff;
}
output small {
  font: 11px "Segoe UI", sans-serif;
}
input[type="range"] {
  width: 100%;
  height: 4px;
  accent-color: #509e86;
  cursor: pointer;
  margin: 6px 0 8px;
}
.row {
  display: flex;
  align-items: center;
  gap: 10px;
  border-top: 1px solid #edf1ec;
  padding-top: 8px;
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
}
.row strong {
  flex: 1;
  text-align: right;
  font: 12px Consolas, monospace;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row label {
  white-space: nowrap;
}

/* ---- PWM ---- */
.pwm-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.pwm-table th {
  text-align: left;
  font-weight: 500;
  color: var(--muted);
  font-size: 11px;
  padding: 0 0 4px;
}
.pwm-table td {
  border-top: 1px solid #edf1ec;
  padding: 5px 0;
  font-family: Consolas, monospace;
}
.pwm-table td:first-child {
  font-weight: 600;
  color: var(--teal);
  width: 46px;
}
.trend-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--muted);
  margin: 8px 0 4px;
}
.legend {
  display: inline-block;
  width: 14px;
  height: 0;
  margin: 0 4px 3px 10px;
  border-top: 2px solid #16877f;
}
.legend.freq {
  border-top: 2px dashed #c69c29;
}
#trend {
  width: 100%;
  height: 96px;
  display: block;
  background: #f7faf6;
  border: 1px solid #e6ece3;
  border-radius: 7px;
}

/* ---- EEPROM ---- */
.eeprom {
  display: grid;
  grid-template-columns: 24px repeat(16, 1fr);
  gap: 0 2px;
  font: 11px/16px Consolas, monospace;
  text-align: center;
  color: var(--ink);
}
.eeprom-head {
  color: #9db1a9;
  text-align: left;
}
.eeprom .blank {
  color: #c2d0c9;
}
.eeprom .new {
  animation: written 1.5s ease-out;
}
@keyframes written {
  from {
    background: #f0ce64;
    color: #183f45;
  }
  to {
    background: transparent;
  }
}

/* ---- RTC ---- */
.rtc-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.clock {
  font: 26px Consolas, monospace;
  letter-spacing: 2px;
  background: #edf4eb;
  border-radius: 7px;
  padding: 6px 14px;
  color: #3b746a;
}
.date {
  font: 12px Consolas, monospace;
  color: #3b746a;
  text-align: right;
  margin-top: 4px;
}

/* ---- 弹窗 ---- */
dialog.sheet {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 26px 30px 24px;
  color: var(--ink);
  box-shadow: 0 18px 50px #163d3d2e;
  width: min(420px, calc(100vw - 32px));
}
dialog#help {
  width: min(760px, calc(100vw - 32px));
}
dialog.sheet::backdrop {
  background: #102c3155;
}
dialog.sheet h2:focus {
  outline: none;
}
dialog.sheet h2 {
  font-size: 19px;
  margin: 10px 0 8px;
}
.sheet-close {
  position: absolute;
  top: 8px;
  right: 8px;
}
.sheet-close button {
  border: none;
  background: none;
  font-size: 22px;
  line-height: 1;
  padding: 6px 10px;
  color: var(--muted);
}
.help-body p {
  font-size: 13px;
  margin-bottom: 10px;
}
.help-body select {
  margin-left: 10px;
}
.help-body a,
.about-list a {
  color: var(--teal);
  text-decoration: none;
}
.help-body a:hover,
.about-list a:hover {
  text-decoration: underline;
}
.about-avatar {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--dark);
  color: var(--mint);
  display: grid;
  place-items: center;
  font-size: 22px;
  font-weight: 600;
}
.about-list {
  margin: 18px 0 0;
  display: grid;
  gap: 14px;
}
.about-list dd {
  font: 14px "Segoe UI", "Microsoft YaHei", sans-serif;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ---- 笔记本宽度：顶栏保持一行 ---- */
@media (max-width: 1500px) {
  .topbar {
    gap: 8px 12px;
  }
  .lbl {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }
  .rate {
    min-width: 0;
  }
  .controls button {
    padding: 7px 10px;
  }
}

/* ---- 较矮窗口（笔记本、投影）：压缩间距，尽量一屏放下 ---- */
@media (max-height: 860px) and (min-width: 1201px) {
  :root {
    --gap: 8px;
  }
  .topbar {
    padding: 6px 14px;
  }
  .layout {
    padding: 8px 14px;
  }
  .card,
  .lcd-card {
    padding: 8px 12px;
  }
  .card-title {
    margin-bottom: 4px;
  }
  .metrics {
    margin-top: 4px;
  }
  dd {
    font-size: 17px;
  }
  .file-icon {
    padding: 6px;
  }
  .key {
    padding: 5px 2px 4px;
  }
  .led {
    width: 18px;
    height: 18px;
  }
  output,
  .num-input {
    font-size: 16px;
  }
  input[type="range"] {
    margin: 4px 0 4px;
  }
  .pwm-table td {
    padding: 3px 0;
  }
  #trend {
    height: 64px;
  }
  .eeprom {
    font-size: 10.5px;
    line-height: 13.5px;
  }
  .clock {
    font-size: 21px;
    padding: 3px 10px;
  }
  .caption,
  #rtc-note {
    margin-top: 3px;
  }
  .screen-frame {
    max-width: calc((100vh - 250px) * 4 / 3 + 70px);
  }
}

/* ---- 较窄窗口：两列，输出区移到下方 ---- */
@media (max-width: 1200px) {
  .layout {
    grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
  }
  .col-output {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1.2fr 1fr 0.8fr;
    align-items: start;
  }
  .screen-frame {
    max-width: none;
  }
}
@media (max-width: 860px) {
  .layout,
  .col-output {
    grid-template-columns: 1fr;
  }
  .run-settings {
    margin-left: 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}
