:root {
  color-scheme: light;
  --device-panel-width: 620px;
  --text: #14213d;
  --heading: #111c34;
  --page: #fff;
  --surface: #fff;
  --inset: #f7f9fc;
  --inset-hover: #f5f9ff;
  --border: #e0e5ec;
  --control-border: #d9e0ea;
  --soft-border: #edf0f4;
  --secondary-text: #43516a;
  --muted: #65738a;
  --subtle: #64728a;
  --accent: #1769e0;
  --accent-hover: #125cc7;
  --accent-tint: #edf4ff;
  --primary: #1769e0;
  --primary-hover: #125cc7;
  --neutral-tint: #f0f3f7;
  --success: #167861;
  --success-tint: #f0faf7;
  --success-border: #cdeee5;
  --error: #b43b4b;
  --error-tint: #fff5f6;
  --error-border: #f3cbd0;
  font-family: Inter, "SF Pro Display", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--text);
  background: var(--page);
  font-synthesis: none;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --text: #e3edf7;
  --heading: #f2f7fc;
  --page: #1a1a1a;
  --surface: #19232e;
  --inset: #111c27;
  --inset-hover: #213244;
  --border: #303e4d;
  --control-border: #425266;
  --soft-border: #324152;
  --secondary-text: #c4d2e2;
  --muted: #aabbd0;
  --subtle: #a2b2c6;
  --accent: #90bdff;
  --accent-hover: #b5d3ff;
  --accent-tint: #223951;
  --primary: #2568ce;
  --primary-hover: #2059b2;
  --neutral-tint: #283749;
  --success: #69d9b7;
  --success-tint: #16362f;
  --success-border: #285548;
  --error: #ff9ba8;
  --error-tint: #3b242d;
  --error-border: #68404b;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--page);
}

button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.page-shell {
  width: min(1080px, calc(100% - 40px));
  min-height: 100vh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

.site-header {
  height: 88px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

.brand {
  color: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 11px;
}

.brand-name { font-size: 19px; font-weight: 750; letter-spacing: -.02em; }
.brand .logo-dark,
:root[data-theme="dark"] .brand .logo-light { display: none; }
:root[data-theme="dark"] .brand .logo-dark { display: block; }

.header-actions { display: flex; align-items: center; gap: 8px; }
.header-actions > a { color: var(--accent); }
button:is(.language-toggle, .theme-toggle) {
  min-width: 44px;
  min-height: 44px;
  padding: 0 9px;
  border: 1px solid var(--control-border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--secondary-text);
  font-size: 14px;
  font-weight: 650;
}
button:is(.language-toggle, .theme-toggle):hover { background: var(--accent-tint); color: var(--accent-hover); }
.theme-toggle { display: inline-grid; place-items: center; }
.theme-toggle svg, .usb-icon svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.theme-toggle .sun-icon, .theme-toggle[aria-pressed="true"] .moon-icon { display: none; }
.theme-toggle[aria-pressed="true"] .sun-icon { display: block; }

.more-menu { position: relative; }

.more-menu summary {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 44px;
  padding: 0 13px;
  border: 1px solid var(--control-border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--secondary-text);
  font-size: 14px;
  font-weight: 650;
  list-style: none;
  cursor: pointer;
}

.more-menu summary::-webkit-details-marker { display: none; }
.more-menu summary::after {
  content: "";
  width: 6px;
  height: 6px;
  border: solid currentColor;
  border-width: 0 1.5px 1.5px 0;
  transform: translateY(-2px) rotate(45deg);
}
.more-menu[open] summary::after { transform: translateY(2px) rotate(225deg); }

.more-menu-options {
  position: absolute;
  inset-inline-end: 0;
  top: calc(100% + 8px);
  z-index: 1;
  width: max-content;
  min-width: 160px;
  padding: 5px;
  border: 1px solid var(--control-border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(31, 48, 78, .12);
}

.more-menu-options :is(button, a) {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--secondary-text);
  font-size: 14px;
  text-decoration: none;
}
.more-menu-options :is(button, a):not(:disabled):is(:hover, :focus-visible) { background: var(--accent-tint); color: var(--accent-hover); }

.local-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--secondary-text);
  font-size: 13px;
  font-weight: 600;
}

.local-badge > span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #18a985;
  box-shadow: 0 0 0 4px rgba(24, 169, 133, .12);
}

main { flex: 1; padding: 72px 0 56px; }

.hero { max-width: 640px; margin-bottom: 36px; }
.eyebrow { margin: 0 0 13px; color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: .18em; }
h1 { margin: 0; color: var(--heading); font-size: clamp(42px, 7vw, 68px); line-height: 1.04; letter-spacing: -.055em; }
.lead { margin: 18px 0 0; color: var(--muted); font-size: 17px; line-height: 1.7; }

.connect-card { max-width: 620px; }
body:not(.device-connected) .hero,
body:not(.device-connected) .connect-card { margin-left: auto; margin-right: auto; }
body:not(.device-connected) .hero { text-align: center; }
body:not(.device-connected) .connect-card { padding: 32px; }
body.device-connected .hero { margin-bottom: 22px; }
body.device-connected .hero h1 { font-size: clamp(34px, 5vw, 52px); }
body.device-connected .connect-card { max-width: none; padding: 20px 24px; }
body.device-connected .connect-card .card-header { align-items: center; }
body.device-connected .connect-card .actions { margin-top: 16px; }
.connected-content { margin-top: 20px; }
.business-panel { margin-bottom: 20px; }
.business-content { margin-top: 16px; }

.card {
  min-width: 0;
  padding: 26px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: 0 18px 50px rgba(31, 48, 78, .07);
}

.card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.step-title { min-width: 0; display: flex; align-items: center; gap: 13px; }
.step-number {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: var(--accent);
  background: var(--accent-tint);
  font-size: 14px;
  font-weight: 800;
}
.step-label { margin: 0 0 2px; color: var(--subtle); font-size: 11px; font-weight: 700; letter-spacing: .08em; }
h2 { margin: 0; color: var(--heading); font-size: 20px; letter-spacing: -.025em; }
h3 { margin: 0; color: var(--heading); font-size: 17px; letter-spacing: -.02em; }

.state-pill {
  flex: 0 0 auto;
  padding: 6px 9px;
  border-radius: 999px;
  color: var(--muted);
  background: var(--neutral-tint);
  font-size: 11px;
  font-weight: 700;
}
.state-pill.ready { color: var(--success); background: var(--success-tint); }
.card-copy { min-height: 48px; margin: 22px 0 17px; color: var(--muted); font-size: 14px; line-height: 1.7; }
code { padding: 2px 6px; border-radius: 5px; color: var(--accent); background: var(--accent-tint); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.actions { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.actions.link-actions { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.link-actions button { padding-inline: 6px; }
.link-upgrade-card { max-width: 620px; margin: 16px auto 0; }
.connection-options { display: grid; gap: 12px; }
.connect-button { width: 100%; }
.connected-actions { margin-top: 0; }
button {
  min-height: 46px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 12px;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
button:not(:disabled):active { transform: translateY(1px); }
button.primary { color: #fff; background: var(--primary); font-weight: 750; box-shadow: 0 8px 20px rgba(23, 105, 224, .18); }
button.primary:not(:disabled):hover { background: var(--primary-hover); box-shadow: 0 10px 26px rgba(23, 105, 224, .24); }
button.secondary { color: var(--secondary-text); border-color: var(--control-border); background: var(--surface); font-weight: 650; }
button:disabled { opacity: .42; cursor: not-allowed; box-shadow: none; }
button.primary.firmware-current {
  color: var(--muted);
  background: var(--neutral-tint);
  border-color: var(--control-border);
  box-shadow: none;
  opacity: 1;
}
.reflash-trigger {
  min-height: 32px;
  padding: 0;
  border: 0;
  color: inherit;
  font: inherit;
  background: transparent;
  touch-action: manipulation;
}
.reflash-trigger:disabled { opacity: 1; cursor: default; }

.file-picker {
  min-height: 72px;
  padding: 13px 15px;
  border: 1px dashed var(--control-border);
  border-radius: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--secondary-text);
  background: var(--inset);
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
.file-picker:hover { border-color: var(--accent); background: var(--inset-hover); }
.file-picker:has(input:disabled) { opacity: .5; cursor: not-allowed; }
.file-icon { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; color: var(--accent); background: var(--accent-tint); font-size: 21px; font-weight: 700; }
.file-picker strong, .file-picker small { display: block; }
.file-picker strong { font-size: 14px; }
.file-picker small { margin-top: 4px; color: var(--subtle); font-size: 12px; }
.file-picker input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.info-box {
  min-height: 84px;
  margin: 14px 0 0;
  padding: 14px 15px;
  overflow: auto;
  border: 1px solid var(--soft-border);
  border-radius: 12px;
  color: var(--secondary-text);
  background: var(--inset);
  font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.device-details { margin-top: 13px; }
.device-details summary {
  width: fit-content;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 650;
}
.device-details[open] summary { color: var(--accent); }
.device-details .info-box { min-height: 0; }

.flash-button { width: 100%; margin-top: 14px; }
progress { width: 100%; height: 7px; margin-top: 15px; border: 0; border-radius: 99px; overflow: hidden; background: var(--neutral-tint); accent-color: #18a985; }
progress::-webkit-progress-bar { background: var(--neutral-tint); }
progress::-webkit-progress-value { border-radius: 99px; background: #18a985; transition: width .2s ease; }
progress::-moz-progress-bar { border-radius: 99px; background: #18a985; }

.status {
  min-height: 42px;
  margin-top: 13px;
  padding: 10px 13px;
  border: 1px solid var(--success-border);
  border-radius: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--success);
  background: var(--success-tint);
  font-size: 14px;
  font-weight: 650;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #18a985; box-shadow: 0 0 0 4px rgba(24, 169, 133, .11); }
.status.error { color: var(--error); border-color: var(--error-border); background: var(--error-tint); }
.status.error .status-dot { background: #d84c5e; box-shadow: 0 0 0 4px rgba(216, 76, 94, .1); }

.state-pill.error { color: var(--error); background: var(--error-tint); }
.business-panel {
  margin-top: 0;
  padding: 26px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: 0 18px 50px rgba(31, 48, 78, .07);
}
.business-panel[hidden] { display: none; }
.business-header { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.business-content { margin-top: 22px; }

.firmware-dialog {
  width: calc(100% - 28px);
  max-width: var(--device-panel-width);
  max-height: calc(100vh - 32px);
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 22px;
  color: inherit;
  background: var(--surface);
  box-shadow: 0 28px 90px rgba(17, 28, 52, .28);
}
.firmware-dialog::backdrop { background: rgba(17, 28, 52, .5); backdrop-filter: blur(3px); }
.firmware-dialog-shell { max-height: calc(100vh - 32px); padding: 26px; overflow: auto; }
.embedded-device-panel { display: block; width: 100%; min-height: min(600px, 75dvh); border: 0; }
.dialog-actions { display: flex; align-items: center; gap: 10px; }
.dialog-close {
  width: 38px;
  min-height: 38px;
  padding: 0;
  border-color: var(--control-border);
  color: var(--secondary-text);
  background: var(--surface);
  font-size: 24px;
  line-height: 1;
}
.dialog-copy { margin: 22px 0 17px; color: var(--muted); font-size: 14px; line-height: 1.7; }
.online-firmware {
  margin-top: 22px;
  padding: 18px;
  border: 1px solid var(--soft-border);
  border-radius: 16px;
  background: var(--inset);
}
.online-firmware-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.online-description { margin: 14px 0 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.online-notes { margin: 10px 0 0; color: var(--subtle); font-size: 12px; line-height: 1.6; white-space: pre-wrap; }
.manual-upgrade { margin-top: 15px; border-top: 1px solid var(--soft-border); }
.manual-upgrade summary { padding: 16px 2px 2px; color: var(--muted); cursor: pointer; font-size: 13px; font-weight: 650; }
.manual-upgrade summary .state-pill { margin-left: 7px; }
.manual-upgrade[open] summary { color: var(--accent); }
.manual-upgrade-content .dialog-copy { margin-top: 14px; }
.upgrade-status {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--success);
  background: var(--success-tint);
  font-size: 12px;
  font-weight: 650;
}
.upgrade-status.error { color: var(--error); background: var(--error-tint); }
body:has(.firmware-dialog[open]) { overflow: hidden; }

.notice { margin-top: 20px; padding: 4px 8px; display: flex; align-items: flex-start; gap: 12px; color: var(--muted); }
.notice-icon { flex: 0 0 auto; width: 22px; height: 22px; border: 1px solid #bdc7d5; border-radius: 50%; display: grid; place-items: center; font: 700 12px Georgia, serif; }
.notice p { margin: 0; font-size: 12px; line-height: 1.65; }
.notice strong { color: var(--secondary-text); }

footer {
  min-height: 74px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--subtle);
  font-size: 12px;
  letter-spacing: .02em;
}
footer strong { color: var(--secondary-text); }

.product-page .site-header { height: 68px; }
.product-page main { padding: 24px 0 20px; }
.product-page #device-card, .product-page .connected-content {
  max-width: var(--product-content-width, var(--device-panel-width));
  margin-inline: auto;
}
.product-page #device-card {
  padding: clamp(20px, 5vw, 28px);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 6px 24px rgba(31, 48, 78, .04);
}
.product-page .connection-options { grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.product-page .connection-options > button { min-width: 0; padding-inline: 10px; }
.product-page .more-menu > summary { min-height: 46px; }
.product-page .more-menu-options { z-index: 5; }
.product-page .connected-content { margin-top: 0; }
.product-page .connected-content:has([data-vector-workbench]) { max-width: var(--product-content-width, 900px); }
.business-panel:has([data-vector-workbench]) { padding: clamp(8px, 2vw, 16px); border-radius: 14px; box-shadow: none; }
.business-panel:has([data-vector-workbench]) > .card-header { align-items: center; padding: 0 4px; }
.business-panel > [data-vector-workbench] { margin-top: 10px; }
.business-panel:has([data-vector-workbench][data-plugin-tabs]) > .card-header { display: none; }
.business-panel > [data-vector-workbench][data-plugin-tabs] { margin-top: 0; }
#demo-options { display: grid; gap: 8px; margin: 18px 0; }
.device-tabs {
  order: 1;
  position: sticky;
  bottom: 0;
  z-index: 2;
  display: flex;
  width: 100%;
  max-width: var(--device-panel-width);
  margin-inline: auto;
  gap: 8px;
  padding: 8px 12px max(8px, env(safe-area-inset-bottom));
  border: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  background: var(--surface);
}
.device-tabs button { flex: 1; min-width: 0; min-height: 52px; display: grid; justify-items: center; align-content: center; gap: 2px; padding: 4px; background: transparent; color: var(--secondary-text); font-size: .78rem; font-weight: 650; line-height: 1.15; }
.device-tabs svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.device-tabs button[aria-selected="true"] { background: var(--accent-tint); color: var(--accent-hover); }
.device-tabs:has([data-plugin-tab]) { overflow-x: auto; }
.device-tabs:has([data-plugin-tab]) button { min-width: 52px; white-space: nowrap; }
@media (max-width: 540px) {
  .device-tabs:has([data-plugin-tab]) { gap: 2px; padding-inline: 4px; }
  .device-tabs:has([data-plugin-tab]) button { flex: 1 0 auto; min-height: 48px; font-size: .72rem; }
}
.esc-tab-label { display: none; }
body:has([data-plugin-android-style]) {
  --esc-toolbar-bottom: calc(65px + env(safe-area-inset-bottom, 0px));
  background: light-dark(#f1f5f9, #0f172a);
}
body:has([data-plugin-android-style]) .device-tabs {
  gap: 2px;
  padding: 4px 4px calc(4px + env(safe-area-inset-bottom, 0px));
  border-radius: 0;
  background: light-dark(#fff, #1e293b);
}
body:has([data-plugin-android-style]) .device-tabs button { min-height: 55px; color: inherit; background: transparent; }
body:has([data-plugin-android-style]) .device-tabs svg { box-sizing: content-box; padding: 3px 14px; border-radius: 999px; }
body:has([data-plugin-android-style]) .device-tabs button[aria-selected="true"] svg { background: #34d399; color: #052e24; }
body:has([data-plugin-android-style]) .esc-tab-label { display: inline; }
body:has([data-plugin-android-style]) .portal-tab-label { display: none; }
.product-page .business-panel:has([data-plugin-android-style][data-plugin-view="parameters"]) {
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}
.business-panel:has([data-plugin-android-style][data-plugin-view="parameters"]) > .card-header { padding: 0 12px; }
.business-panel > [data-plugin-android-style][data-plugin-view="parameters"] { margin-top: 12px; }
.connection-state {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  color: var(--success);
  font-size: 14px;
  font-weight: 650;
  overflow-wrap: anywhere;
}
.usb-icon {
  display: grid;
  place-items: center;
  flex: 0 0 40px;
  height: 40px;
  border-radius: 11px;
  background: var(--success-tint);
}
.connection-state.pending { color: var(--secondary-text); }
.connection-state.pending .usb-icon { color: var(--accent); background: var(--accent-tint); }
.connection-state.error { color: var(--error); }
.connection-state.error .usb-icon { background: var(--error-tint); }
.product-page .portal-footer { min-height: 48px; border: 0; justify-content: flex-end; }
.product-page .portal-footer > span { display: inline; }
.product-page.device-connected .portal-footer { display: none; }

@media (min-width: 900px) {
  .product-page { --product-content-width: none; }
  .product-page .page-shell { width: min(1200px, calc(100% - 64px)); }
  .product-page #device-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 16px 24px;
  }
  .product-page #device-card .connection-state { margin-bottom: 0; }
  .product-page #device-details { grid-column: 1 / -1; margin-top: 0; }
  .product-page .connection-options > button { min-width: 128px; padding-inline: 18px; }
  .product-page .device-tabs {
    order: 0;
    position: static;
    max-width: none;
    margin-top: 16px;
    padding: 6px;
    border-radius: 14px;
  }
  .product-page .device-tabs button {
    flex: 0 1 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding-inline: 14px;
    font-size: .9rem;
  }
  .product-page .device-tabs svg { width: 20px; height: 20px; }
  .product-page:has([data-plugin-android-style]) { --esc-toolbar-bottom: 0px; }
  .product-page:has([data-plugin-android-style]) .device-tabs button { min-height: 44px; }
  .product-page:has([data-plugin-android-style]) .device-tabs svg { padding-inline: 8px; }
}

@media (max-width: 760px) {
  .page-shell { width: min(100% - 28px, 560px); }
  .product-page .page-shell { width: min(100% - 28px, var(--device-panel-width)); }
  .site-header { height: 72px; }
  .local-badge { display: none; }
  main { padding: 48px 0 38px; }
  .hero { margin-bottom: 28px; }
  .workflow { grid-template-columns: 1fr; }
  .card { padding: 21px; border-radius: 18px; }
  .business-panel { padding: 21px; border-radius: 18px; }
  .firmware-dialog { border-radius: 18px; }
  .firmware-dialog-shell { padding: 21px; }
  .card-copy { min-height: auto; }
  footer { min-height: 68px; }
  footer > :last-child { display: none; }
  .product-page .site-header { height: 64px; }
  .product-page main { padding-top: 20px; }
}

@media (max-width: 420px) {
  .actions { grid-template-columns: 1fr; }
  body.link-page .connect-card, .link-upgrade-card { padding: 20px; }
  .link-actions { gap: 6px; }
  .link-actions button { padding-inline: 4px; font-size: 13px; }
  .card-header { gap: 10px; }
  .state-pill { padding: 5px 8px; }
  .brand { gap: 7px; }
  .brand-name { font-size: 18px; }
  .header-actions { gap: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
