:root {
  color-scheme: light;
  --canvas: #f3f5fb;
  --surface: #fff;
  --ink: #19233d;
  --muted: #53617b;
  --quiet: #60708a;
  --border: #e0e6f1;
  --blue: #3d55cc;
  --blue-hover: #3048b9;
  --blue-soft: #eef2ff;
  --green: #13755d;
  --red: #9c383e;
  --mono: ui-monospace, "SFMono-Regular", Consolas, "Noto Sans Mono CJK SC", monospace;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  background: var(--canvas);
  color: var(--ink);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { min-width: 0; margin: 0; }
h1, h2, p { margin: 0; }
button, input { font: inherit; }
code { font-family: var(--mono); }
:focus-visible { outline: 2px solid #5671ed; outline-offset: 3px; }

.visually-hidden, .icon-library {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.icon {
  width: 1.25rem;
  height: 1.25rem;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.shell { width: min(1180px, calc(100% - 64px)); margin-inline: auto; }
.topbar { border-bottom: 1px solid var(--border); background: var(--surface); }
.topbar-inner {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand, .topbar-actions { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.brand-mark, .section-icon, .banner-icon, .file-icon {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}
.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  color: white;
  background: var(--blue);
  box-shadow: inset 0 0 0 1px #ffffff24, 0 3px 8px #22377222;
}
.brand strong { display: block; font-size: 1.06rem; line-height: 1.1; letter-spacing: -.025em; }
.brand small { display: block; margin-top: 4px; color: var(--quiet); font-size: .72rem; }
.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 4px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  background: #f6f8fc;
  font-size: .76rem;
  font-weight: 650;
  line-height: 1.35;
}
.connection-pill { padding: 6px 10px; border-radius: 999px; }
.status-dot { width: 7px; height: 7px; flex: none; border-radius: 50%; background: #8795ab; }
.connection-pill[data-state="connected"],
#boot-status[data-state="ok"] { color: var(--green); border-color: #cde9de; background: #eef9f3; }
.connection-pill[data-state="connected"] .status-dot { background: #21a47f; }
.connection-pill[data-state="flashing"] { color: var(--blue); border-color: #d9e1ff; background: var(--blue-soft); }
.connection-pill[data-state="flashing"] .status-dot { background: var(--blue); }

.button {
  min-height: 41px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 13px;
  border: 1px solid transparent;
  border-radius: 9px;
  font-size: .86rem;
  font-weight: 650;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color .15s, border-color .15s, box-shadow .15s;
}
.button .icon { width: 17px; height: 17px; }
.button.primary { color: white; background: var(--blue); }
.button.primary:hover:not(:disabled) { background: var(--blue-hover); box-shadow: 0 3px 10px #3d55cc28; }
.button.secondary { color: var(--ink); background: var(--surface); border-color: #dce3f0; }
.button.secondary:hover:not(:disabled) { color: var(--blue-hover); border-color: #bac7f1; background: #f7f9ff; }
.button:disabled { color: #566582; background: #f0f3f9; border-color: #e4e9f3; cursor: default; }
.button.primary:disabled { color: #475985; background: #e8edfa; border-color: #e4e9f8; }

main.shell { padding-block: 20px 0; }

.status-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 16px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface);
}
.banner-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--blue-soft);
  color: var(--blue);
}
.banner-icon .icon { width: 17px; height: 17px; }
.banner-copy { flex: 1; display: flex; align-items: baseline; gap: 12px; }
.banner-copy p { color: var(--muted); font-size: .86rem; overflow-wrap: anywhere; }
.status-banner[data-tone="success"] .banner-icon { color: var(--green); background: #eef9f3; }
.status-banner[data-tone="error"] .banner-icon { color: var(--red); background: #faeded; }
.status-banner[data-tone="error"] p, .flash-progress[data-tone="error"] p { color: var(--red); }
.status-banner[data-tone="success"] p, .flash-progress[data-tone="success"] p { color: var(--green); }
.noscript { margin-bottom: 16px; color: var(--red); }

.workspace { display: grid; grid-template-columns: minmax(0, 1.48fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.card {
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 3px 10px #25395c08;
}
.card-heading { display: flex; align-items: center; gap: 11px; min-width: 0; }
.card-heading > div { flex: 1; min-width: 0; }
.section-icon {
  width: 42px;
  height: 42px;
  border-radius: 11px;
  color: var(--blue);
  background: var(--blue-soft);
}
.card h2 { font-size: 1.3rem; letter-spacing: -.025em; line-height: 1.35; }
.target-pill { margin-left: auto; color: #374eae; background: var(--blue-soft); border-color: #e2e8ff; white-space: nowrap; }
#boot-status { max-width: 100%; overflow-wrap: anywhere; }
#boot-status[data-state="error"] { color: var(--red); border-color: #f2d7da; background: #fff4f4; }

.mode-switch {
  display: flex;
  gap: 4px;
  margin: 16px 0;
  padding: 4px;
  border: 0;
  border-radius: 9px;
  background: #f0f3f9;
}
.mode-switch label {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px;
  border-radius: 6px;
  color: var(--muted);
  font-size: .85rem;
  cursor: pointer;
}
.mode-switch label:has(input:checked) { color: var(--blue); background: #fff; box-shadow: 0 1px 4px #25395c12; }
.mode-switch input { margin: 0; accent-color: var(--blue); }
.mode-switch:disabled label { cursor: default; }

#config-form, #flash-form { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.form-grid, .flash-options {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px 14px;
}
.form-grid { margin: 0; padding: 0; border: 0; }
#advanced-fields { margin-top: 12px; }
.field { min-width: 0; }
.field.full-width { grid-column: 1 / -1; }
.field label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
  font-size: .85rem;
  font-weight: 650;
}
.counter, .field-size {
  margin-left: auto;
  color: var(--quiet);
  font: .72rem var(--mono);
  white-space: nowrap;
}
.counter[data-invalid="true"] { color: var(--red); font-weight: 700; }
.field input, .command-form input {
  display: block;
  width: 100%;
  min-width: 0;
  height: 40px;
  padding: 0 10px;
  border: 1px solid #dce3ef;
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  font: .87rem var(--mono);
}
.field input::placeholder { color: #61708a; opacity: 1; }
.field input:disabled, .field input[readonly] {
  color: #596781;
  background: #f7f9fd;
  border-color: #e5eaf3;
  opacity: 1;
}
.field small { display: block; margin-top: 5px; color: var(--quiet); font-size: .75rem; line-height: 1.5; }

.workflow {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  margin-top: auto;
  padding-top: 16px;
}
.workflow .button { padding-inline: 5px; gap: 5px; font-size: .8rem; }
.workflow[data-mode="advanced"] { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.firmware-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  min-height: 65px;
  margin-top: 16px;
  border: 1px dashed #a7b7ec;
  border-radius: 10px;
  background: #f7f9ff;
}
.file-icon { width: 34px; height: 34px; border-radius: 8px; background: #e9eeff; color: var(--blue); }
.file-icon .icon { width: 17px; height: 17px; }
.file-copy { min-width: 0; flex: 1; }
.file-copy strong {
  display: block;
  color: var(--blue-hover);
  font-size: .9rem;
  overflow-wrap: anywhere;
}
.file-copy small { display: block; margin-top: 2px; font-size: .74rem; color: var(--quiet); }
.flash-options { margin-top: 13px; }
.flash-help { margin-top: 5px; color: var(--quiet); font-size: .75rem; }
.flash-details {
  margin: 11px 0;
  padding-block: 8px;
  border-top: 1px solid #edf0f7;
  border-bottom: 1px solid #edf0f7;
  color: var(--muted);
  font-size: .8rem;
}
.flash-details summary { width: fit-content; color: #48598a; cursor: pointer; }
.check { display: flex; align-items: center; gap: 7px; margin-top: 7px; cursor: pointer; }
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--blue); }
.flash-progress { margin-top: auto; padding: 0 0 11px; }
.progress-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 9px;
  margin-bottom: 6px;
  font-size: .79rem;
  font-weight: 650;
  color: var(--muted);
}
.progress-label p { overflow-wrap: anywhere; }
.progress-label span { font-family: var(--mono); }
progress {
  display: block;
  width: 100%;
  height: 7px;
  appearance: none;
  border: 0;
  border-radius: 999px;
  background: #eaf0fa;
  overflow: hidden;
}
progress::-webkit-progress-bar { background: #eaf0fa; }
progress::-webkit-progress-value { background: var(--blue); border-radius: 999px; }
progress::-moz-progress-bar { background: var(--blue); }
.flash-progress[data-tone="success"] progress::-webkit-progress-value { background: #21a47f; }
.flash-button { width: 100%; }

.terminal {
  margin-top: 18px;
  padding: 14px 17px 15px;
  border: 1px solid #273454;
  border-radius: 15px;
  background: #17213b;
  color: #f0f4ff;
}
.terminal-header, .command-form { display: flex; align-items: center; gap: 9px; }
.terminal-header { justify-content: flex-end; margin-top: 8px; }
.terminal-title { display: inline-flex; align-items: center; gap: 8px; vertical-align: middle; }
.terminal > summary { cursor: pointer; font-weight: 650; }
.terminal-title .icon { color: #9cb3ff; }
.button.terminal-clear, .button.terminal-send {
  min-height: 34px;
  color: #e0e7ff;
  background: #283656;
  border-color: #3b4a6e;
  font-size: .78rem;
}
.button.terminal-clear:hover, .button.terminal-send:hover:not(:disabled) { background: #334569; }
.button.terminal-send:disabled { color: #a3b0cf; background: #25314e; }
#log {
  height: 158px;
  margin: 10px 0;
  padding: 11px 12px;
  overflow: auto;
  border: 1px solid #2a3654;
  border-radius: 8px;
  background: #101930;
  color: #d6e3ff;
  font: .8rem / 1.55 var(--mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
#log:empty::before { content: "暂无日志"; color: #9babce; }
.command-form label { flex: 0 0 auto; color: #cbd6f2; font-size: .78rem; }
.command-form input { height: 34px; color: #e6edff; background: #101930; border-color: #3b4a6e; }
.command-form input:disabled { color: #a2b0d0; opacity: 1; }

.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 0 21px;
  color: var(--quiet);
  font-size: .76rem;
}
.footer .separator { padding-inline: 4px; }

@media (max-width: 1020px) {
  .workspace { grid-template-columns: minmax(0, 1.26fr) minmax(0, 1fr); }
  .card { padding: 18px; }
  .workflow[data-mode="advanced"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .shell { width: calc(100% - 32px); }
  main.shell { padding-top: 16px; }
  .workspace { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .terminal { margin-top: 14px; }
}
@media (max-width: 440px) {
  .brand, .topbar-actions { gap: 7px; }
  .brand-mark { width: 33px; height: 33px; }
  .brand strong { font-size: .92rem; }
  .brand small { font-size: .65rem; }
  .connect-button { gap: 4px; padding-inline: 7px; font-size: .77rem; }
  .connection-pill { padding-inline: 6px; gap: 4px; font-size: .66rem; }
  .status-dot { width: 6px; height: 6px; }
  .banner-copy { display: block; }
  .banner-copy p { font-size: .78rem; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .footer { align-items: flex-start; flex-direction: column; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
