/* ───────── 基础 ───────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--txt); font-family: var(--font);
  font-size: 14.5px; line-height: 1.6; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
h1, h2, h3, h4, p { margin: 0; }
h1, h2, h3 { text-wrap: balance; letter-spacing: -.01em; }
a { color: inherit; text-decoration: none; }
img, svg { max-width: 100%; }
button { font: inherit; color: inherit; }
input, textarea, select { font: inherit; color: var(--txt); }
[hidden] { display: none !important; }
::selection { background: var(--acc-soft); }
:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; border-radius: 6px; }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); }
.mute { color: var(--mute); }
.dim { color: var(--txt-2); }
.grow { flex: 1; }
.row { display: flex; align-items: center; gap: var(--sp-3); }
.row.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: var(--sp-3); }
.skip { position: absolute; left: -999px; top: 8px; z-index: 99; background: var(--acc); color: var(--on-acc); padding: 6px 12px; border-radius: 8px; }
.skip:focus { left: 8px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ───────── 外壳 ───────── */
.app { display: grid; grid-template-columns: var(--side-w) 1fr; min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: var(--sp-4);
  padding: var(--sp-5) var(--sp-4); background: var(--bg-2); border-right: 1px solid var(--line-soft); z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 8px; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; }
.brand-mark svg { width: 38px; height: 38px; }
.brand-txt { display: flex; flex-direction: column; line-height: 1.15; }
.brand-txt b { font-family: var(--display); font-weight: 700; font-size: 17px; letter-spacing: .02em; }
.brand-txt small { font-size: 11.5px; color: var(--mute); }
.nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav-sec { font: 600 11px/1 var(--display); letter-spacing: .14em; text-transform: uppercase; color: var(--mute); padding: 14px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: 11px; color: var(--txt-2);
  font-size: 14px; position: relative; transition: background .18s, color .18s;
}
.nav a svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.nav a:hover { background: var(--raised); color: var(--txt); }
.nav a.on { background: var(--acc-soft); color: var(--txt); }
.nav a.on::before { content: ""; position: absolute; left: -16px; top: 9px; bottom: 9px; width: 3px; border-radius: 0 3px 3px 0; background: var(--grad); }
.nav a.on svg { color: var(--acc); opacity: 1; }
.nav .tag { margin-left: auto; font-size: 10.5px; padding: 1px 7px; border-radius: 99px; background: var(--raised-2); color: var(--mute); }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.main { min-width: 0; display: flex; flex-direction: column; }
.top {
  position: sticky; top: 0; z-index: 15; display: flex; align-items: center; gap: var(--sp-3);
  padding: 12px var(--sp-8); background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px) saturate(140%); border-bottom: 1px solid var(--line-soft);
}
.crumb { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--mute); min-width: 0; flex: 1 1 auto; }
.crumb > * { white-space: nowrap; flex: none; }
/* 首页标题「工作台」曾被挤成一个「工」字：b 允许收缩但至少留出 4 个字宽 */
.crumb b { color: var(--txt); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 0 1 auto; min-width: 4em; }
.top-status { display: flex; gap: 8px; align-items: center; }
.view { padding: var(--sp-6) var(--sp-8) 80px; max-width: 1440px; width: 100%; margin: 0 auto; outline: none; }
.only-mobile { display: none; }

/* ───────── 按钮 ───────── */
.btn {
  --b-bg: var(--raised); --b-fg: var(--txt); --b-bd: var(--line);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 16px;
  border-radius: 12px; border: 1px solid var(--b-bd); background: var(--b-bg); color: var(--b-fg);
  font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap; user-select: none;
  transition: background .18s, border-color .18s, box-shadow .2s, filter .2s; will-change: transform;
}
.btn svg { width: 17px; height: 17px; flex: none; }
.btn:hover { border-color: color-mix(in srgb, var(--acc) 45%, var(--line)); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn.primary { --b-bg: var(--grad); --b-fg: var(--on-acc); --b-bd: transparent; background: var(--grad); box-shadow: var(--glow); }
.btn.primary:hover { filter: brightness(1.07) saturate(1.05); }
.btn.soft { --b-bg: var(--acc-soft); --b-bd: transparent; --b-fg: var(--acc); }
.btn.ghost { --b-bg: transparent; --b-bd: transparent; --b-fg: var(--txt-2); }
.btn.ghost:hover { background: var(--raised); }
.btn.danger { --b-bg: var(--err-soft); --b-bd: transparent; --b-fg: var(--err); }
.btn.lg { height: 50px; padding: 0 22px; font-size: 15.5px; border-radius: 15px; }
.btn.xl { height: 58px; padding: 0 26px; font-size: 16.5px; border-radius: 17px; }
.btn.sm { height: 30px; padding: 0 11px; font-size: 12.5px; border-radius: 9px; }
.btn.block { width: 100%; }
.icon-btn {
  width: 38px; height: 38px; display: grid; place-items: center; border-radius: 12px; border: 1px solid var(--line);
  background: var(--raised); cursor: pointer; color: var(--txt-2);
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { color: var(--txt); border-color: color-mix(in srgb, var(--acc) 40%, var(--line)); }

/* ───────── 卡片 ───────── */
.card {
  position: relative; background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--r-lg);
  box-shadow: var(--shadow); padding: var(--sp-5);
}
:root[data-theme="day"] .card { border-color: var(--line); }
.card.hover { transition: border-color .2s, box-shadow .25s, transform .25s var(--ease); cursor: pointer; }
.card.hover:hover { border-color: color-mix(in srgb, var(--acc) 38%, transparent); box-shadow: var(--glow); transform: translateY(-2px); }
.card.flat { box-shadow: none; }
.card.hero { overflow: hidden; background: radial-gradient(120% 140% at 0% 0%, var(--acc-soft), transparent 55%), radial-gradient(90% 120% at 100% 100%, var(--acc-2-soft), transparent 60%), var(--surface); }
.card.glass { background: color-mix(in srgb, var(--surface) 72%, transparent); backdrop-filter: blur(16px); }
.card-h { display: flex; align-items: center; gap: 10px; margin-bottom: var(--sp-4); }
.card-h h3 { font-size: 15px; font-weight: 600; }
.card-h .sub { font-size: 12.5px; color: var(--mute); }
.chip-ic { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; background: var(--acc-soft); color: var(--acc); flex: none; }
.chip-ic svg { width: 18px; height: 18px; }
.eyebrow { font: 600 11px/1 var(--display); letter-spacing: .16em; text-transform: uppercase; color: var(--mute); }
.big-num { font-family: var(--display); font-weight: 700; font-size: 34px; line-height: 1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.section-h { display: flex; align-items: baseline; gap: var(--sp-3); margin: var(--sp-8) 0 var(--sp-4); }
.section-h h2 { font-size: 19px; font-weight: 600; }
.section-h .sub { color: var(--mute); font-size: 13px; }
.section-h a.more { margin-left: auto; font-size: 13px; color: var(--acc); }
.page-h { display: flex; align-items: flex-end; gap: var(--sp-4); flex-wrap: wrap; margin-bottom: var(--sp-6); }
.page-h h1 { font-size: clamp(24px, 3vw, 32px); font-weight: 700; font-family: var(--font); }
.page-h p { color: var(--mute); margin-top: 6px; max-width: 60ch; }
.grid { display: grid; gap: var(--sp-4); }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.auto { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }

/* ───────── 胶囊 / 徽章 ───────── */
.pill { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--raised-2); color: var(--txt-2); white-space: nowrap; }
.pill svg { width: 13px; height: 13px; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.err { background: var(--err-soft); color: var(--err); }
.pill.acc { background: var(--acc-soft); color: var(--acc); }
.pill.demo { background: var(--warn-soft); color: var(--warn); border: 1px dashed color-mix(in srgb, var(--warn) 55%, transparent); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--mute); display: inline-block; flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 4px var(--ok-soft); }
.dot.warn { background: var(--warn); }
.dot.err { background: var(--err); }
.fam { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 9px; border-radius: 7px; font: 600 11.5px/1 var(--display); letter-spacing: .02em; }
.fam::before { content: ""; width: 6px; height: 6px; border-radius: 2px; background: currentColor; }
.fam.esp32 { color: var(--fam-esp32); background: color-mix(in srgb, var(--fam-esp32) 14%, transparent); }
.fam.avr { color: var(--fam-avr); background: color-mix(in srgb, var(--fam-avr) 14%, transparent); }
.fam.stm32 { color: var(--fam-stm32); background: color-mix(in srgb, var(--fam-stm32) 16%, transparent); }
.fam.ros { color: var(--fam-ros); background: color-mix(in srgb, var(--fam-ros) 14%, transparent); }
.fam.custom { color: var(--fam-custom); background: color-mix(in srgb, var(--fam-custom) 14%, transparent); }
.stars { display: inline-flex; gap: 2px; color: var(--amber); }
.stars i { width: 12px; height: 12px; display: inline-block; background: currentColor; clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); }
.stars i.off { color: var(--line); }

/* ───────── 表单 ───────── */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; color: var(--txt-2); font-weight: 600; }
.input, .select, .textarea {
  width: 100%; background: var(--raised); border: 1px solid var(--line); border-radius: 12px; padding: 10px 13px; outline: none;
  transition: border-color .18s, box-shadow .18s;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--acc); box-shadow: 0 0 0 4px var(--acc-soft); }
.textarea { resize: vertical; min-height: 90px; line-height: 1.6; }
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 12px; background: var(--raised); border: 1px solid var(--line); }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 9px; font-size: 13px; color: var(--txt-2); cursor: pointer; white-space: nowrap; }
.seg button.on { background: var(--surface); color: var(--txt); box-shadow: var(--shadow); }
:root:not([data-theme="day"]) .seg button.on { background: var(--raised-2); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 13px; border-radius: 99px; border: 1px solid var(--line);
  background: var(--raised); color: var(--txt-2); font-size: 13px; cursor: pointer; white-space: nowrap; transition: all .18s;
}
.chip:hover { color: var(--txt); border-color: color-mix(in srgb, var(--acc) 40%, var(--line)); }
.chip.on { background: var(--acc-soft); border-color: color-mix(in srgb, var(--acc) 55%, transparent); color: var(--txt); }
.chip svg { width: 15px; height: 15px; }

/* ───────── 热品角标（StackChan 等本周热品） ───────── */
.hot-tag {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px; border-radius: 7px; flex: none;
  font: 600 11.5px/1 var(--display); letter-spacing: .02em; color: #FFF7ED; white-space: nowrap;
  background: linear-gradient(135deg, var(--coral) 0%, var(--amber) 100%);
  box-shadow: 0 6px 16px -9px var(--coral);
}
.hot-tag svg { width: 13px; height: 13px; }
.hot-tag.sm { height: 19px; padding: 0 7px; font-size: 10.5px; }
.hot-tag.sm svg { width: 11px; height: 11px; }
.chip.hot { border-color: color-mix(in srgb, var(--coral) 42%, var(--line)); }
.chip.hot > svg { color: var(--coral); }
.chip.hot:hover { border-color: color-mix(in srgb, var(--coral) 62%, var(--line)); }
.chip.hot.on { background: color-mix(in srgb, var(--coral) 13%, transparent); border-color: color-mix(in srgb, var(--coral) 62%, transparent); }

/* ───────── 进度 ───────── */
.bar { height: 8px; border-radius: 99px; background: var(--raised-2); overflow: hidden; }
.bar > i { display: block; height: 100%; width: 100%; background: var(--grad); border-radius: inherit; transform-origin: left center; transform: scaleX(var(--p, 0)); transition: transform .5s var(--ease); }
.ring { position: relative; display: grid; place-items: center; }
.ring svg { transform: rotate(-90deg); }
.ring .ring-bg { stroke: var(--raised-2); }
.ring .ring-fg { stroke: url(#ringGrad); stroke-linecap: round; transition: stroke-dashoffset .5s var(--ease); }
.ring .ring-c { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }
.skel { background: linear-gradient(90deg, var(--raised) 0%, var(--raised-2) 50%, var(--raised) 100%); background-size: 200% 100%; animation: shimmer 1.4s infinite linear; border-radius: 10px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ───────── 空状态 ───────── */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; padding: 36px 20px; color: var(--mute); }
.empty .art { width: 120px; height: 90px; opacity: .9; }
.empty h4 { color: var(--txt); font-size: 15px; font-weight: 600; }
.empty p { max-width: 44ch; font-size: 13.5px; }

/* ───────── 层 · toast / sheet / modal ───────── */
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 90; pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 10px; min-width: 240px; max-width: 380px; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-lg); font-size: 13.5px;
}
.toast .chip-ic { width: 30px; height: 30px; border-radius: 9px; }
.toast.ok .chip-ic { background: var(--ok-soft); color: var(--ok); }
.toast.err .chip-ic { background: var(--err-soft); color: var(--err); }
.toast.warn .chip-ic { background: var(--warn-soft); color: var(--warn); }
.scrim { position: fixed; inset: 0; background: var(--scrim); backdrop-filter: blur(3px); z-index: 60; }
.sheet {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(480px, 100vw); z-index: 61; background: var(--surface);
  border-left: 1px solid var(--line); box-shadow: var(--shadow-lg); display: flex; flex-direction: column;
}
.sheet-h { display: flex; align-items: center; gap: 10px; padding: 18px 20px; border-bottom: 1px solid var(--line-soft); }
.sheet-h h3 { font-size: 17px; font-weight: 600; }
.sheet-b { padding: 20px; overflow-y: auto; flex: 1; }
.sheet-f { padding: 14px 20px; border-top: 1px solid var(--line-soft); display: flex; gap: 10px; }
.modal-wrap { position: fixed; inset: 0; z-index: 62; display: grid; place-items: center; padding: 16px; }
.modal { width: min(520px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl); box-shadow: var(--shadow-lg); }
.modal.wide { width: min(760px, 100%); }
.modal-h { display: flex; align-items: center; gap: 10px; padding: 20px 22px 0; }
.modal-h h3 { font-size: 18px; font-weight: 600; }
.modal-b { padding: 16px 22px 22px; }

/* ───────── 代码 ───────── */
.code {
  font: 13px/1.7 var(--mono); background: var(--code-bg); color: #D6DEEB; border-radius: var(--r); border: 1px solid var(--line-soft);
  overflow: auto; tab-size: 2; counter-reset: ln;
}
.code pre { margin: 0; padding: 14px 0; }
.code .ln { display: block; padding: 0 16px 0 0; white-space: pre; }
.code .ln::before { counter-increment: ln; content: counter(ln); display: inline-block; width: 44px; padding-right: 14px; text-align: right; color: #475569; user-select: none; }
.tk-kw { color: var(--kw); } .tk-str { color: var(--str); } .tk-num { color: var(--num); } .tk-fn { color: var(--fn); } .tk-cm { color: var(--cm); font-style: italic; } .tk-pp { color: var(--pp); }
.editor { position: relative; display: grid; grid-template-columns: 52px 1fr; background: var(--code-bg); border: 1px solid var(--line-soft); border-radius: var(--r); overflow: hidden; min-height: 360px; }
.editor .gutter { font: 13px/1.7 var(--mono); color: #475569; text-align: right; padding: 14px 12px 14px 0; user-select: none; overflow: hidden; white-space: pre; }
.editor .ed-area { position: relative; overflow: auto; }
.editor pre, .editor textarea {
  margin: 0; padding: 14px 16px; font: 13px/1.7 var(--mono); white-space: pre; tab-size: 2; min-height: 100%; border: 0;
}
.editor pre { position: absolute; left: 0; top: 0; width: max-content; min-width: 100%; pointer-events: none; color: #D6DEEB; overflow: visible; }
.editor textarea { position: relative; display: block; width: 100%; min-height: 360px; resize: none; background: transparent; color: transparent; caret-color: #fff; outline: none; overflow: hidden; }
.editor textarea::selection { background: rgba(34,211,238,.25); color: transparent; }

/* ───────── 日志 / 串口 ───────── */
.log { font: 12.5px/1.65 var(--mono); background: var(--code-bg); color: #C8D3E6; border-radius: var(--r-sm); padding: 12px 14px; overflow: auto; white-space: pre-wrap; word-break: break-word; }
.log .s-err { color: #FCA5A5; } .log .s-ok { color: #86EFAC; } .log .s-tx { color: #67E8F9; } .log .s-mute { color: #64748B; }

/* ───────── 表格 ───────── */
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; font: 600 11px/1 var(--display); letter-spacing: .12em; text-transform: uppercase; color: var(--mute); padding: 0 12px 10px 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 12px 12px 12px 0; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }

/* 演示数据标记 */
.demo-flag { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--warn); background: var(--warn-soft); border: 1px dashed color-mix(in srgb, var(--warn) 55%, transparent); padding: 3px 10px; border-radius: 99px; }

/* 头像 */
.avatar { width: 40px; height: 40px; border-radius: 13px; overflow: hidden; flex: none; background: var(--raised-2); display: grid; place-items: center; }
.avatar svg, .avatar img { width: 100%; height: 100%; display: block; object-fit: cover; }
.avatar.sm { width: 30px; height: 30px; border-radius: 10px; }
.avatar.lg { width: 88px; height: 88px; border-radius: 26px; }
.avatar.xl { width: 128px; height: 128px; border-radius: 36px; }

/* 侧栏底部：余额 + 我 */
.bal-chip { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 14px; background: var(--raised); border: 1px solid var(--line-soft); cursor: pointer; }
.bal-chip:hover { border-color: color-mix(in srgb, var(--acc) 40%, transparent); }
.bal-chip .v { font-family: var(--display); font-weight: 700; font-size: 16px; }
.bal-chip.low { border-color: color-mix(in srgb, var(--warn) 55%, transparent); background: var(--warn-soft); }
.me-chip { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 14px; }
.me-chip:hover { background: var(--raised); }
.me-chip .nm { font-weight: 600; font-size: 13.5px; line-height: 1.2; }
.me-chip .lv { font-size: 11.5px; color: var(--mute); }
.xp-mini { height: 4px; border-radius: 99px; background: var(--raised-2); overflow: hidden; margin-top: 4px; }
.xp-mini > i { display: block; height: 100%; background: var(--grad); transform-origin: left; transform: scaleX(var(--p, 0)); }

/* 引导聚光灯 */
.spot-ring { position: fixed; z-index: 80; border-radius: 16px; box-shadow: 0 0 0 9999px var(--scrim), 0 0 0 2px var(--acc), 0 0 30px 4px color-mix(in srgb, var(--acc) 40%, transparent); pointer-events: none; transition: all .35s var(--ease); }
.spot-card { position: fixed; z-index: 81; width: min(320px, calc(100vw - 32px)); background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow-lg); padding: 16px; }
.spot-card h4 { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.spot-card p { font-size: 13.5px; color: var(--txt-2); }

/* 按下回弹由 motion.js 驱动；无 GSAP 时的兜底 */
.pressable:active { transform: scale(.97); }

@media (max-width: 1100px) {
  .grid.c4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.c3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; width: 280px; transform: translateX(-102%); transition: transform .3s var(--ease); box-shadow: var(--shadow-lg); }
  .app.menu-open .side { transform: none; }
  .only-mobile { display: grid; }
  .top { padding: 10px 16px; }
  .view { padding: 18px 16px 72px; }
  .grid.c2, .grid.c3, .grid.c4 { grid-template-columns: 1fr; }
  .top-status .pill span { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
