@font-face {
    font-family: "Work Sans";
    src: url("fonts/work-sans-regular.ttf") format("truetype");
    font-style: normal;
    font-weight: 400;
    font-display: swap;
  }
  @font-face {
    font-family: "Barlow Condensed";
    src: url("fonts/barlow-condensed-regular.ttf") format("truetype");
    font-style: normal;
    font-weight: 400;
    font-display: swap;
  }
  @font-face {
    font-family: "Barlow Condensed";
    src: url("fonts/barlow-condensed-medium.ttf") format("truetype");
    font-style: normal;
    font-weight: 500;
    font-display: swap;
  }
  @font-face {
    font-family: "Share Tech Mono";
    src: url("fonts/share-tech-mono.ttf") format("truetype");
    font-style: normal;
    font-weight: 400;
    font-display: swap;
  }
  :root {
    --bg: #e8e8e8;
    --surface: #f5f5f5;
    --surface2: #dedede;
    --border: #c8c8c8;
    --text: #3a3a3a;
    --text2: #61656b;
    --accent: #3a3a3a;
    --accent2: #242424;
    --green: #268052;
    --yellow: #8b641c;
    --red: #b33e3e;
    --body-font: "Work Sans", "Microsoft YaHei", "PingFang SC", sans-serif;
    --mono-font: "Share Tech Mono", "Microsoft YaHei", "PingFang SC", monospace;
  }
  * { box-sizing: border-box; margin: 0; padding: 0; letter-spacing: 0; }
  body {
    font-family: var(--body-font);
    font-size: 14px;
    line-height: 1.65;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
  }
  ::selection { background: #dbdbdb; color: #000; }
  a { color: inherit; }
  button, input { font: inherit; }
  button:focus-visible, a:focus-visible, .file-input-wrapper:focus-within {
    outline: 2px solid var(--text);
    outline-offset: 4px;
  }
  .site-topbar {
    min-height: 104px;
    padding: 12px 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
  }
  .brand { display: block; flex-shrink: 0; width: 80px; height: 80px; }
  .brand img { display: block; width: 80px; height: 80px; object-fit: contain; }
  .site-nav { display: flex; gap: 20px; font: 14px var(--mono-font); }
  .site-nav a { padding: 8px 0; text-decoration: none; }
  .site-nav a:hover { color: #000; }
  .site-nav a[aria-current="page"] { border-bottom: 1px solid var(--text); }
  .container {
    width: 100%;
    max-width: 800px;
    margin: 24px auto 0;
    padding: 0 32px 40px;
  }
  .page-heading { padding: 0 0 28px; border-bottom: 1px solid var(--border); }
  h1 {
    font-family: "Barlow Condensed", sans-serif;
    font-size: 42px;
    font-weight: 500;
    font-style: italic;
    line-height: 1.15;
    overflow-wrap: anywhere;
  }
  .subtitle {
    font-family: var(--mono-font);
    font-size: 13px;
    color: var(--text2);
    margin-top: 12px;
  }
  .tool-section {
    padding: 24px 0;
    border-bottom: 1px solid var(--border);
  }
  .section-heading {
    font-family: var(--mono-font);
    font-size: 14px;
    font-weight: 400;
    color: var(--text);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
  }
  .dot {
    width: 6px;
    height: 6px;
    border-radius: 0;
    display: inline-block;
    flex-shrink: 0;
    background: var(--text2);
  }
  .dot-ok { background: var(--green); }
  .dot-warn { background: var(--yellow); }
  .dot-err { background: var(--red); }
  .driver-note { color: var(--text2); font-size: 13px; margin-top: 4px; }
  .driver-info { display: none; }
  .driver-info.show { display: block; }
  .driver-info .steps {
    margin: 10px 0;
    font-size: 14px;
    line-height: 1.7;
  }
  code { font-family: var(--mono-font); font-size: 13px; overflow-wrap: anywhere; }
  .driver-info .steps code { background: var(--surface2); padding: 2px 6px; }
  .icon {
    display: inline-block;
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
    background: var(--icon) center / contain no-repeat;
    filter: brightness(0);
  }
  .icon-usb { --icon: url("icons/usb.svg"); }
  .icon-upload { --icon: url("icons/upload.svg"); }
  .icon-download { --icon: url("icons/download.svg"); }
  .icon-package { --icon: url("icons/package.svg"); }
  .icon-file { --icon: url("icons/file-code-2.svg"); }
  .icon-loading { --icon: url("icons/loader-circle.svg"); animation: spin 1s linear infinite; }
  @keyframes spin { to { transform: rotate(360deg); } }
  .btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    min-height: 46px;
    padding: 10px 22px;
    border: 1px solid var(--text);
    border-radius: 0;
    font-family: var(--mono-font);
    font-size: 14px;
    font-weight: 400;
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s;
    color: #fff;
    background: var(--text);
  }
  .btn:disabled, .flash-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
  }
  .btn:hover:not(:disabled) { background: var(--accent2); border-color: var(--accent2); }
  #btnConnect { min-width: 142px; }
  .btn-outline {
    background: transparent;
    color: var(--text);
  }
  .btn-outline:hover:not(:disabled) { color: #fff; }
  .btn:not(.btn-outline) .icon, .flash-btn .icon,
  .btn-outline:hover:not(:disabled) .icon { filter: brightness(0) invert(1); }
  .btn-sm { padding: 10px 16px; font-size: 13px; }
  .btn-group { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 16px; }
  .connection-row { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
  #deviceInfo { font-size: 13px; color: var(--text2); overflow-wrap: anywhere; }
  .flash-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 142px;
    gap: 14px;
  }
  .file-input-wrapper {
    display: flex;
    align-items: center;
    min-height: 46px;
    gap: 12px;
    padding: 10px 16px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text2);
    position: relative;
    min-width: 0;
  }
  .file-input-wrapper:hover { border-color: var(--text); }
  .file-input-wrapper:has(input:disabled) { opacity: .45; }
  #fileLabel { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .file-input-wrapper input[type=file] {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
  }
  .flash-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 46px;
    padding: 10px 24px;
    font-family: var(--mono-font);
    font-size: 14px;
    background: var(--text);
    border: 1px solid var(--text);
    border-radius: 0;
    color: #fff;
    cursor: pointer;
    transition: background .15s, border-color .15s;
  }
  .flash-btn:hover:not(:disabled) {
    background: var(--accent2);
    border-color: var(--accent2);
  }
  .firmware-meta { display: flex; gap: 8px 24px; flex-wrap: wrap; font-size: 12px; color: var(--text2); margin-top: 12px; }
  .progress-wrap { display: none; margin-top: 20px; }
  .progress-wrap.show { display: block; }
  .progress-bar-outer {
    width: 100%;
    height: 4px;
    background: var(--surface2);
    overflow: hidden;
    margin-bottom: 10px;
  }
  .progress-bar-inner {
    height: 100%;
    background: var(--green);
    transition: width .2s;
    width: 0%;
  }
  .progress-text {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
    font-family: var(--mono-font);
    font-size: 12px;
    color: var(--text2);
  }
  .log-area {
    padding: 0;
    max-height: 180px;
    overflow-y: auto;
    overflow-wrap: anywhere;
    font-family: var(--mono-font);
    font-size: 13px;
    line-height: 1.8;
    display: none;
  }
  .log-area.show { display: block; }
  .log-area .log-line { margin: 3px 0; }
  .log-debug { color: var(--text2); }
  .log-info  { color: var(--text2); }
  .log-ok    { color: var(--green); }
  .log-warn  { color: var(--yellow); }
  .log-err   { color: var(--red); }
  footer {
    font-family: var(--mono-font);
    text-align: center;
    font-size: 12px;
    color: var(--text2);
    padding: 28px 0 0;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 12px;
  }
  footer a { text-decoration: none; }
  footer a:hover { color: #000; }
  .unsupported { padding: 40px 0; }
  .unsupported h2 { font-size: 20px; font-weight: 400; }
  .unsupported p { margin-top: 16px; color: var(--text2); }
  @media (max-width: 600px) {
    .site-topbar { min-height: 88px; padding: 4px 20px; gap: 16px; }
    .site-nav { gap: 14px; font-size: 12px; }
    .container { margin-top: 20px; padding: 0 24px 32px; }
    h1 { font-size: 34px; }
    .subtitle { font-size: 12px; }
    .tool-section { padding: 22px 0; }
    .flash-row { grid-template-columns: minmax(0, 1fr); gap: 12px; }
    .flash-btn { width: 142px; }
    footer { justify-content: center; }
  }
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; }
  }

  [hidden] { display: none !important; }
  .icon-refresh { --icon: url("icons/refresh-cw.svg"); }
  .icon-trash { --icon: url("icons/trash-2.svg"); }
  .icon-logout { --icon: url("icons/log-out.svg"); }
  .icon-login { --icon: url("icons/log-in.svg"); }
  .icon-lock { --icon: url("icons/lock-keyhole.svg"); }
  .icon-button {
    width: 46px; height: 46px; flex: 0 0 46px;
    display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--border); border-radius: 0;
    background: transparent; color: var(--text); cursor: pointer;
  }
  .icon-button:hover:not(:disabled) { background: var(--surface); border-color: var(--text); }
  .icon-button:disabled { opacity: .45; cursor: not-allowed; }
  .source-tabs { display: flex; gap: 0; margin-bottom: 16px; }
  .source-tabs button {
    min-height: 36px; min-width: 112px; border: 1px solid var(--border);
    padding: 6px 18px; border-radius: 0; background: transparent; color: var(--text2); cursor: pointer;
  }
  .source-tabs button + button { border-left: 0; }
  .source-tabs button[aria-selected="true"] { background: var(--text); color: #fff; border-color: var(--text); }
  .source-tabs button:disabled { opacity: .45; cursor: not-allowed; }
  .official-selector { display: flex; align-items: center; gap: 10px; min-width: 0; }
  .official-selector select { min-width: 0; flex: 1; width: 100%; height: 46px; padding: 8px 12px; }
  .official-details { margin-top: 12px; font-size: 13px; }
  #officialNotes { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--text2); margin-top: 4px; }
  select, .admin-form input:not([type="checkbox"]), .admin-form textarea {
    border: 1px solid var(--border); border-radius: 0; background: var(--surface); color: var(--text);
    font: inherit; width: 100%; min-width: 0; padding: 10px 12px; min-height: 46px;
  }
  select:focus, .admin-form input:focus, .admin-form textarea:focus { outline: 1px solid var(--text); }
  .admin-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
  .admin-heading h1 { font-size: 38px; }
  .admin-heading .btn { flex-shrink: 0; }
  .admin-form { display: grid; gap: 16px; }
  .admin-form fieldset { border: 0; display: grid; gap: 16px; min-width: 0; }
  .admin-form label:not(.checkbox-label) { display: grid; gap: 6px; min-width: 0; }
  .admin-form textarea { resize: vertical; min-height: 100px; }
  .form-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
  .form-actions { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
  .checkbox-label { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
  input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--text); }
  .notice { min-height: 24px; font-size: 13px; overflow-wrap: anywhere; }
  .section-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
  .section-toolbar .section-heading { margin: 0; }
  .firmware-list { list-style: none; }
  .firmware-item { border-top: 1px solid var(--border); padding: 18px 0; overflow-wrap: anywhere; }
  .firmware-item-heading { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
  .firmware-item-version { font-family: var(--mono-font); color: var(--text2); }
  .firmware-item-meta, .firmware-item-notes { color: var(--text2); font-size: 13px; margin-top: 6px; white-space: pre-wrap; }
  .firmware-item-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
  .firmware-item-actions .checkbox-label { margin-right: auto; }
  .danger { color: var(--red); }
  .edit-dialog {
    width: min(560px, calc(100% - 48px)); max-height: calc(100% - 48px);
    margin: auto; padding: 24px; overflow: auto;
    border: 1px solid var(--border); border-radius: 0;
    background: var(--bg); color: var(--text);
  }
  .edit-dialog::backdrop { background: rgb(0 0 0 / .35); }
  details summary { cursor: pointer; }
  details .admin-form { margin-top: 18px; }
  @media (max-width: 600px) {
    .form-grid { grid-template-columns: minmax(0, 1fr); }
    .admin-heading { flex-wrap: wrap; }
    .admin-heading h1 { font-size: 32px; }
  }
