:root {
  --bg: #FAF6F0;
  --bg-elevated: #FFFFFF;
  --bg-soft: #F1E9DD;
  --text: #2D241E;
  --text-muted: #7C6E63;
  --border: rgba(90, 70, 54, 0.12);
  --accent: #8B5CF6;
  --accent-soft: rgba(139, 92, 246, 0.13);
  --warm-pill: rgba(255, 246, 206, 0.94);
  --warm-pill-border: rgba(226, 193, 98, 0.55);
  --glass: rgba(255, 255, 255, 0.86);
  --shadow: 0 8px 26px rgba(45, 36, 30, 0.08);
  --danger: #DC2626;
  --success: #16A34A;
}

html[data-theme="dark"] {
  --bg: #121117;
  --bg-elevated: #1D1B24;
  --bg-soft: #272432;
  --text: #F4EFE6;
  --text-muted: #A99FB4;
  --border: rgba(255, 255, 255, 0.11);
  --accent: #A78BFA;
  --accent-soft: rgba(167, 139, 250, 0.18);
  --warm-pill: rgba(62, 52, 28, 0.94);
  --warm-pill-border: rgba(246, 200, 95, 0.4);
  --glass: rgba(30, 28, 38, 0.86);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  overscroll-behavior: none;
}

.hidden {
  display: none !important;
}

/* 主框架 */
.home-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding-top: env(safe-area-inset-top);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
}

.brand-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.brand-sub {
  margin: 0;
  font-size: 11px;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sync-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9CA3AF;
  display: inline-block;
}
.sync-dot.synced { background: var(--success); }
.sync-dot.syncing { background: #F59E0B; }
.sync-dot.offline { background: #F97316; }
.sync-dot.error { background: var(--danger); }

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.tab-content-area {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px 24px;
}

.tab-pane {
  display: none;
  max-width: 960px;
  margin: 0 auto;
}
.tab-pane.active {
  display: block;
}

.pane-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
  align-items: center;
}

.primary-btn, .secondary-btn, .danger-btn {
  border: none;
  border-radius: 12px;
  padding: 10px 15px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.primary-btn {
  background: var(--accent);
  color: #FFFFFF;
}
.secondary-btn {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
}
.danger-btn {
  background: rgba(220, 38, 38, 0.12);
  color: var(--danger);
}

.search-input, .filter-select {
  padding: 9px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 14px;
}
.search-input {
  flex: 1;
  min-width: 170px;
}

/* 统计条 */
.stats-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(95px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.stat-box {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-num {
  font-size: 18px;
  font-weight: 700;
}
.stat-label {
  font-size: 12px;
  color: var(--text-muted);
}

/* 空状态 */
.empty-card {
  background: var(--bg-elevated);
  border: 1px dashed var(--border);
  border-radius: 18px;
  padding: 28px 18px;
  text-align: center;
}
.empty-emoji {
  font-size: 36px;
  margin-bottom: 6px;
}
.empty-card h3 {
  margin: 4px 0 6px;
  font-size: 16px;
}
.empty-card p {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* 图解网格 */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}

.chart-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

.chart-thumb {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: var(--bg-soft);
  cursor: pointer;
}
.chart-thumb-wrap {
  position: relative;
}
.chart-page-badge {
  position: absolute;
  right: 8px;
  bottom: 8px;
  background: rgba(34, 28, 42, 0.78);
  color: #FFFFFF;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  pointer-events: none;
}

.page-switcher {
  position: fixed;
  top: calc(108px + env(safe-area-inset-top));
  left: 12px;
  z-index: 19;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: calc(100vw - 24px);
  overflow-x: auto;
  padding: 4px 6px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.page-pill {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
  cursor: pointer;
}
.page-pill.active {
  background: var(--accent);
  color: #FFFFFF;
}

.chart-card-body {
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.chart-card-title {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.chart-card-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
}
.chart-card-actions {
  display: flex;
  gap: 4px;
  margin-top: 2px;
}
.mini-btn {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  border-radius: 8px;
  padding: 5px 2px;
  font-size: 11px;
  white-space: nowrap;
  cursor: pointer;
}

/* 线材库存列表 */
.yarns-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 12px;
}

.yarn-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow);
}

.yarn-top {
  display: flex;
  gap: 10px;
  align-items: center;
}

.yarn-swatch {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  flex-shrink: 0;
  border: 1px solid var(--border);
  object-fit: cover;
}

.yarn-head {
  flex: 1;
  min-width: 0;
}
.yarn-name {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 2px;
}
.yarn-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.yarn-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.tag-chip {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--text);
}

.yarn-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}
.yarn-weight {
  font-size: 14px;
  font-weight: 700;
}
.yarn-weight small {
  font-weight: 400;
  color: var(--text-muted);
}
.yarn-quick-btns {
  display: flex;
  gap: 4px;
}
.yarn-quick-btns button {
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
}

/* 作品集网格 */
.works-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
  gap: 12px;
}

.work-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.work-cover {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: var(--bg-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
}
.work-body {
  padding: 10px 12px;
}
.work-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 4px;
}
.work-meta {
  font-size: 12px;
  color: var(--text-muted);
}

/* 底部三 Tab 导航栏 */
.bottom-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-tab {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 8px 0 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
}
.bottom-tab.active {
  color: var(--accent);
  font-weight: 600;
}
.tab-ico { font-size: 19px; }
.tab-txt { font-size: 11px; }

/* 全屏图解阅读器 */
.editor-view {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.editor-topbar {
  position: relative;
  z-index: 12;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.editor-title-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 48%;
}
.editor-title {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.editor-top-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.editor-top-btn {
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 11px;
  font-size: 13px;
  cursor: pointer;
}
.editor-top-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.canvas-stage {
  position: relative;
  flex: 1;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#chart-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.sticky-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.chart-sticky-note {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: auto;
  max-width: 150px;
  padding: 5px 8px;
  border-radius: 10px;
  border: 1px solid rgba(90, 70, 54, 0.25);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.14);
  font-size: 12px;
  color: #2D241E;
  display: flex;
  align-items: flex-start;
  gap: 4px;
  cursor: grab;
  touch-action: none;
}
.sticky-text {
  word-break: break-word;
  line-height: 1.3;
}

/* 悬浮暖黄主计数器胶囊 */
.counter-capsule {
  position: fixed;
  top: calc(62px + env(safe-area-inset-top));
  right: 16px;
  z-index: 20;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--warm-pill);
  border: 1px solid var(--warm-pill-border);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  touch-action: none;
}

.capsule-drag {
  font-size: 12px;
  color: var(--text-muted);
  padding: 4px 2px;
  cursor: grab;
  user-select: none;
}

.counter-step-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.65);
  color: #2D241E;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
}
html[data-theme="dark"] .counter-step-btn {
  background: rgba(255, 255, 255, 0.16);
  color: #F4EFE6;
}

.counter-val-btn {
  min-width: 52px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 19px;
  font-weight: 700;
  cursor: pointer;
  padding: 2px 6px;
  display: inline-flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
}
.counter-side-tag {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}

/* 副计数器小条 */
.sub-counter-bar {
  position: fixed;
  top: calc(62px + env(safe-area-inset-top));
  left: 12px;
  z-index: 18;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sub-chip {
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px 8px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  backdrop-filter: blur(8px);
}
.sub-chip button {
  border: none;
  background: var(--bg-soft);
  color: var(--text);
  border-radius: 6px;
  padding: 2px 6px;
  cursor: pointer;
}

/* 底部毛玻璃 6 键胶囊工具栏 */
.editor-dock {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(14px + env(safe-area-inset-bottom));
  z-index: 25;
  width: min(94vw, 440px);
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  padding: 6px 8px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--border);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.14);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.dock-btn {
  position: relative;
  border: none;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 4px 2px;
  border-radius: 14px;
  cursor: pointer;
  min-height: 44px;
}
.dock-btn.active,
.dock-btn[aria-pressed="true"] {
  color: var(--accent);
  background: var(--accent-soft);
}
@media (pointer: coarse) {
  .dock-btn {
    min-block-size: 48px;
    min-inline-size: 44px;
  }
}
#dock-ruler.has-indicator::after {
  content: '';
  position: absolute;
  top: 5px;
  right: 12px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ruler-dot-color, #F59E0B);
}
.dock-btn:disabled {
  opacity: 0.35;
  cursor: default;
}
.dock-ico { font-size: 17px; }
.dock-txt { font-size: 11px; }

.dock-expand-fab {
  position: fixed;
  right: 18px;
  bottom: calc(22px + env(safe-area-inset-bottom));
  z-index: 25;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--glass);
  color: var(--text);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.dock-expand-fab span { font-size: 15px; line-height: 1; }
.dock-expand-fab small { font-size: 10px; color: var(--text-muted); }

/* 工具上方微调浮条 */
.tool-subbar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(82px + env(safe-area-inset-bottom));
  z-index: 24;
  width: min(94vw, 420px);
  padding: 12px 14px;
  border-radius: 20px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.12);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.subbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.subbar-row.switches-row {
  justify-content: space-around;
  padding-bottom: 2px;
  border-bottom: 1px solid var(--border-soft, rgba(140, 120, 100, 0.1));
}
.subbar-row.dual-seg-row {
  justify-content: space-between;
}
.subbar-row.sliders-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.slider-num {
  color: var(--accent);
  font-weight: 600;
  margin-left: 4px;
  font-variant-numeric: tabular-nums;
}

.slider-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}
.slider-input-wrap input[type="range"] {
  flex: 1;
  min-width: 0;
  accent-color: var(--accent);
}
.nudge-btn {
  width: 30px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 16px;
  line-height: 1;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.1s ease, background-color 0.12s ease;
}
.nudge-btn:active {
  transform: scale(0.92);
  background: var(--accent-soft);
  color: var(--accent);
}

.subbar-hint {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.35;
  background: var(--bg-soft);
  padding: 5px 8px;
  border-radius: 8px;
}

.subbar-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

/* 现代开关 Switch 适配 (依据 modern-web-guidance: switch 规范) */
.toggle-switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}
.toggle-switch input[type="checkbox"][switch] {
  appearance: auto;
  accent-color: var(--accent);
  cursor: pointer;
  width: 18px;
  height: 18px;
  margin: 0;
}
.toggle-switch input[type="checkbox"][switch]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.switch-label {
  font-size: 12px;
  color: var(--text);
  font-weight: 500;
}

.slider-box {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.slider-title-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.micro-link-btn {
  border: none;
  background: var(--bg-soft);
  color: var(--text-muted);
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 6px;
  cursor: pointer;
}
.micro-link-btn:hover {
  color: var(--accent);
}

.color-dots {
  display: flex;
  align-items: center;
  gap: 8px;
}
.color-dot {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.color-dot:hover {
  transform: scale(1.08);
}
.color-dot.active {
  border-color: var(--text);
  transform: scale(1.15);
  box-shadow: 0 0 0 2px var(--bg-elevated);
}
.color-picker-input {
  width: 28px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
}

.seg-group {
  display: inline-flex;
  background: var(--bg-soft);
  border-radius: 12px;
  padding: 3px;
  gap: 2px;
}
.seg-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 5px 11px;
  font-size: 12px;
  border-radius: 9px;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.seg-btn.active {
  background: var(--bg-elevated);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.popover-menu {
  position: fixed;
  top: calc(54px + env(safe-area-inset-top));
  right: 12px;
  z-index: 30;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 6px;
  display: flex;
  flex-direction: column;
  min-width: 190px;
}
.popover-menu button {
  border: none;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
}
.popover-menu button:hover {
  background: var(--bg-soft);
}

/* 弹窗 */
dialog.app-dialog {
  width: min(calc(100% - 32px), 480px);
  margin: auto;
  padding: 0;
  max-height: 86vh;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  overflow: hidden;
  flex-direction: column;
}
dialog[open] { display: flex; }
dialog:modal, dialog::backdrop { overscroll-behavior: contain; }
dialog::backdrop { background: rgb(18 16 24 / 50%); }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 {
  margin: 0;
  font-size: 16px;
}
.modal-body {
  padding: 14px 16px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
}
.form-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.form-field.full {
  grid-column: 1 / -1;
}
.form-field label {
  font-size: 12px;
  color: var(--text-muted);
}
.form-field input, .form-field textarea, .form-field select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.gallery-preview {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  gap: 8px;
}
.gallery-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.toast {
  position: fixed;
  bottom: calc(96px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  background: rgba(34, 28, 42, 0.92);
  color: #FFFFFF;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}


:root { color-scheme: light dark; }
:root:has(> head > meta[name="color-scheme"][content="light"]) { color-scheme: light; }
:root:has(> head > meta[name="color-scheme"][content="dark"]) { color-scheme: dark; }
@media (prefers-color-scheme: dark) {
  :root:has(> head > meta[name="color-scheme"][content="light dark"]) { color-scheme: dark; }
}
body { accent-color: var(--accent); }
@supports not (accent-color: auto) { input:focus-visible { outline: 2px solid var(--accent); } }
h1,h2,h3 { text-wrap: balance; }
p,li { text-wrap: pretty; }
.tab-content-area { scroll-padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
.modal-body { container: modal / inline-size; }
@container modal (min-width: 400px) { .form-grid { grid-template-columns: repeat(2,minmax(0,1fr)); } }
.form-field, .form-field input { min-width: 0; }
.form-field input[type=checkbox] { width: auto; }
.form-field input[type=color] { height: 40px; }
#sync-gen { white-space: nowrap; flex-shrink: 0; }
.line-icon { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }
.photo-tile,.photo-cover { position: relative; }
.photo-cover { padding: 0; background: transparent; border: 0; }
.photo-tile button,.photo-cover small { position: absolute; top: 0; right: 0; border: 0; border-radius: 50%; background: #302739; color: white; }
.photo-detail { width: 100%; display: block; }
.photo-detail.zoomed { width: auto; max-width: none; }
.photo-scroll { overflow: auto; max-height: 58vh; }
.yarn-card progress { width: 100%; height: 6px; }
@media (pointer: coarse) {
  .primary-btn, .secondary-btn, .danger-btn, .file-btn, .icon-btn, .dock-btn, .counter-step-btn {
    min-width: 44px;
    min-height: 44px;
  }
  .form-field input:not([type=checkbox]):not([type=color]), select, textarea { min-height: 44px; font-size: 16px; }
}

.editor-title-wrap { min-width: 0; flex: 1; }
#focus-timer { font-variant-numeric: tabular-nums; white-space: nowrap; }
.modal-body table { border-collapse: collapse; text-align: center; }
.modal-body td, .modal-body th { padding: .3em; border-bottom: 1px solid var(--border); }
.modal-body h3, .modal-body p { margin: 0; }
.photo-cover small { padding: 2px 5px; }
#app-dialog .form-grid label input[type=number] { max-width: 100%; }
#app-dialog:has(.photo-detail) { width: min(calc(100% - 20px), 900px); }

/* 图解文件夹面包屑与卡片 */
.folder-breadcrumb {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  margin-bottom: 12px;
  border-radius: 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
}
.folder-back-btn {
  border: none;
  background: var(--bg-soft);
  color: var(--text);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.folder-crumb-title {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.folder-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}
.folder-collage {
  width: 100%;
  aspect-ratio: 4 / 3;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 2px;
  padding: 6px;
  background: var(--bg-soft);
  cursor: pointer;
}
.folder-mini-img, .folder-mini-empty {
  width: 100%;
  height: 100%;
  border-radius: 6px;
  object-fit: cover;
  background: var(--bg-elevated);
}
.folder-pick-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.folder-pick-chip {
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  border-radius: 10px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}
.folder-pick-chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.collect-check-list {
  max-height: 200px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-soft);
}
.collect-check-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 4px 6px;
  cursor: pointer;
}
.collect-check-item small {
  color: var(--text-muted);
}

/* 线材成分快速点选面板 */
.field-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.comp-picker {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
  padding: 8px;
  border-radius: 12px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
}
.comp-chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.comp-chip {
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
  transition: transform 0.1s ease, background-color 0.12s ease;
}
.comp-chip.pct-chip {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.comp-chip.pct-chip.active {
  background: var(--accent);
  color: #FFFFFF;
  border-color: var(--accent);
  font-weight: 600;
}
.comp-chip.mat-chip:active {
  transform: scale(0.94);
  background: var(--accent-soft);
  color: var(--accent);
}
