/* BeadMap — app shell styles (no external assets, offline safe) */

:root {
  --bg: #ded9cf;
  --surface: #f7f6f2;
  --surface-2: #efece5;
  --line: #d9d3c7;
  --line-strong: #b9b1a2;
  --ink: #23201b;
  --ink-2: #5d574d;
  --ink-3: #8b8478;
  --accent: #2f6f5e;
  --accent-ink: #ffffff;
  --danger: #b4432f;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(35, 32, 27, .08), 0 8px 24px rgba(35, 32, 27, .06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  --mono: "SF Mono", "Cascadia Mono", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow-x: hidden;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

.app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-columns: minmax(0, 1fr);
  height: 100dvh;
  min-height: 100%;
  overflow: hidden;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .6) inset;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  white-space: nowrap;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: conic-gradient(from 45deg, #2f6f5e, #c9a227, #b4432f, #34618c, #2f6f5e);
  align-self: center;
}

.brand-name {
  font-weight: 700;
  letter-spacing: .01em;
  font-size: 15px;
}

.brand-sub {
  font-size: 12px;
  color: var(--ink-3);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  flex: 1;
  min-width: 0;
}

.spacer { flex: 1; }

.btn {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, transform .06s ease;
  white-space: nowrap;
}

.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn-primary:hover:not(:disabled) { background: #275c4e; }

.seg {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.seg-btn {
  appearance: none;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 13px;
  padding: 7px 11px;
  cursor: pointer;
  color: var(--ink-2);
}

.seg-btn + .seg-btn { border-left: 1px solid var(--line); }
.seg-btn.is-active { background: var(--ink); color: #fff; }

.field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 10px;
  background: #fff;
}

.field input[type="range"] { width: 96px; accent-color: var(--accent); }
.field output { font-family: var(--mono); font-size: 12px; min-width: 2ch; }

/* ---------- workspace ---------- */

.workspace {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr) 300px;
  min-height: 0;
  background: var(--bg);
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.panel-right { border-right: 0; border-left: 1px solid var(--line); }

.panel-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--ink-3);
}

.badge {
  font-family: var(--mono);
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink-2);
  border: 1px solid var(--line);
}

.panel-body {
  overflow: auto;
  padding: 10px;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}

.empty-hint {
  margin: 8px 4px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink-3);
}

/* ---------- stage ---------- */

.stage {
  position: relative;
  min-height: 0;
  min-width: 0;
  background:
    radial-gradient(circle at 30% 20%, #e8e4da 0%, transparent 60%),
    var(--bg);
  overflow: hidden;
  touch-action: none;
}

#board {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

#board:active { cursor: grabbing; }

.stage-hud {
  position: absolute;
  left: 12px;
  bottom: 12px;
  display: flex;
  gap: 8px;
  pointer-events: none;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-2);
  background: rgba(247, 246, 242, .82);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 8px;
  backdrop-filter: blur(6px);
}

.stage-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  pointer-events: none;
}

.stage-empty[hidden] { display: none; }

.empty-card {
  pointer-events: auto;
  max-width: 380px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 26px 24px;
  box-shadow: var(--shadow);
}

.empty-card h3 { margin: 0 0 8px; font-size: 16px; }
.empty-card p { margin: 0 0 18px; font-size: 13px; line-height: 1.6; color: var(--ink-2); }

/* ---------- status bar ---------- */

.statusbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 14px;
  font-size: 12px;
  color: var(--ink-2);
  background: var(--surface);
  border-top: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}

#status-pos { font-family: var(--mono); color: var(--ink-3); }

/* ---------- mobile bottom tabs (hidden on desktop) ---------- */

.mobile-tabs {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 52px;
  z-index: 30;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}

.mobile-tab {
  flex: 1;
  appearance: none;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 12px;
  color: var(--ink-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
}

.mobile-tab[aria-expanded="true"] { color: var(--ink); background: var(--surface-2); }

.tab-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--line-strong);
}

.mobile-tab[aria-expanded="true"] .tab-dot { background: var(--accent); }

/* ---------- mobile ---------- */

@media (max-width: 1080px) {
  .workspace { grid-template-columns: 220px minmax(0, 1fr) 260px; }
  .brand-sub { display: none; }
}

@media (max-width: 820px) {
  body { padding-bottom: 0; }

  .statusbar { display: none; }

  .workspace { margin-bottom: calc(52px + env(safe-area-inset-bottom)); }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 8px 10px;
  }

  .brand { gap: 6px; }

  .toolbar {
    flex-wrap: nowrap;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    padding-bottom: 2px;
    scrollbar-width: none;
    gap: 6px;
  }

  .toolbar::-webkit-scrollbar { display: none; }

  .btn { padding: 8px 10px; flex: 0 0 auto; }
  .seg, .field { flex: 0 0 auto; }

  .workspace {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
  }

  /* both side panels become bottom sheets, opened from the tab bar */
  .panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 52px;
    top: auto;
    width: auto;
    max-height: 68dvh;
    display: flex;
    border: 0;
    border-top: 1px solid var(--line);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -10px 30px rgba(35, 32, 27, .18);
    transform: translateY(calc(100% + 64px));
    transition: transform .24s cubic-bezier(.2, .8, .2, 1);
    z-index: 25;
  }

  .panel.is-open { transform: translateY(0); }
  .panel-left { display: flex; }
  .mobile-tabs { display: flex; }
  .statusbar { font-size: 11px; }
  .stage-empty { padding: 16px; }
  .empty-card { padding: 20px 18px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- inspector ---------- */

.fieldset {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  margin-bottom: 10px;
}

.fieldset h3 {
  margin: 0 0 8px;
  font-size: 11px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 600;
}

.kv {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  padding: 3px 0;
  color: var(--ink-2);
}

.kv b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }

.note {
  font-size: 11px;
  color: var(--ink-3);
  font-family: var(--mono);
  padding-top: 2px;
}

.hint {
  margin: 8px 0 0;
  font-size: 11px;
  line-height: 1.5;
  color: var(--ink-3);
}

.fields { display: grid; gap: 6px; }

.row {
  display: grid;
  grid-template-columns: 1fr 116px;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--ink-2);
}

.row input {
  width: 100%;
  font: inherit;
  font-family: var(--mono);
  font-size: 12px;
  padding: 5px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  text-align: right;
}

.row input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--ink-2);
  padding: 4px 0;
  cursor: pointer;
}

.check input { accent-color: var(--accent); }

.actions { display: flex; gap: 8px; }
.actions .btn { flex: 1; justify-content: center; }

.stage.is-dragover::after {
  content: "松开导入图纸";
  position: absolute;
  inset: 12px;
  border: 2px dashed var(--accent);
  border-radius: 12px;
  background: rgba(47, 111, 94, .06);
  display: grid;
  place-items: center;
  font-size: 14px;
  color: var(--accent);
  pointer-events: none;
}

/* ---------- colour list ---------- */

.list-summary {
  font-size: 11px;
  color: var(--ink-3);
  padding: 2px 4px 8px;
  font-variant-numeric: tabular-nums;
}

.swatch-row {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 4px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
}

.swatch-pick {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 4px;
  border: 0;
  background: transparent;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.row-check {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink-3);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}

.row-check:hover { border-color: var(--accent); color: var(--accent); }
.row-check.is-done { background: var(--accent); border-color: var(--accent); color: #fff; }

.swatch-row:hover { background: var(--surface-2); }
.swatch-row.is-active { border-color: var(--accent); background: #fff; }

.swatch {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid rgba(0, 0, 0, .18);
  flex: 0 0 auto;
}

.swatch-meta { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.swatch-meta b { font-family: var(--mono); font-size: 12px; font-weight: 600; }
.swatch-meta small { font-size: 11px; color: var(--ink-3); }


/* ---------- glyph classes ---------- */

.panel-body-split {
  border-top: 1px solid var(--line);
  max-height: 46%;
  flex: 0 0 auto;
}

.glyph-list { display: grid; gap: 4px; }

.glyph-row {
  display: grid;
  grid-template-columns: 18px auto 1fr 64px;
  align-items: center;
  gap: 8px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.glyph-row canvas {
  max-width: 100%;
  height: auto;
  border-radius: 3px;
  border: 1px solid var(--line);
  background: #fff;
  image-rendering: pixelated;
}

.glyph-meta { font-size: 11px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

.glyph-row input {
  width: 100%;
  font: inherit;
  font-size: 12px;
  padding: 3px 6px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  text-align: center;
}


.swatch-sm {
  width: 18px;
  height: 18px;
  border-radius: 4px;
}


/* ---------- progress + step navigation ---------- */

#progress-text {
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
  white-space: nowrap;
}

.mini-btn {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
}

.mini-btn:hover { background: var(--surface-2); }

@media (max-width: 820px) {
  #progress-text { display: none; }
}


.mini-select {
  font: inherit;
  font-size: 12px;
  padding: 2px 6px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

@media (max-width: 820px) {
  #section-jump { max-width: 92px; }
}


.row-done {
  flex: 0 0 auto;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
  min-width: 0;
}

.swatch-row.is-complete { background: rgba(47, 111, 94, .08); }
.swatch-row.is-complete .row-done { color: var(--accent); font-weight: 600; }
.swatch-row.is-complete .row-done::after { content: " ✓"; }


/* ---------- export menu + conflicts ---------- */

.export-menu {
  position: fixed;
  z-index: 60;
  min-width: 200px;
  padding: 6px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 12px 32px rgba(35, 32, 27, .18);
  display: grid;
  gap: 2px;
}

.export-menu button {
  appearance: none;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 13px;
  text-align: left;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--ink);
}

.export-menu button:hover { background: var(--surface-2); }

.warn-chip {
  margin: 0 4px 8px;
  padding: 5px 8px;
  border-radius: 6px;
  background: rgba(180, 67, 47, .1);
  color: var(--danger);
  font-size: 11px;
}

.swatch-row.is-conflict { box-shadow: inset 3px 0 0 var(--danger); }


.suggest-row {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 2px 0 0;
}

.suggest-chip {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink-2);
  font: inherit;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 999px;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}

.suggest-chip:hover { border-color: var(--accent); color: var(--accent); }


.suggest-label {
  font-size: 10px;
  color: var(--ink-3);
  align-self: center;
  padding-right: 2px;
}


/* ---------- colour-system prompt ---------- */

.palette-prompt {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  background: rgba(35, 32, 27, .45);
  padding: 20px;
}

.palette-prompt[hidden] { display: none; }

.pp-card {
  background: var(--surface);
  border-radius: 14px;
  padding: 24px 26px;
  max-width: 480px;
  box-shadow: 0 24px 60px rgba(35, 32, 27, .3);
}

.pp-card h3 { margin: 0 0 8px; font-size: 17px; }
.pp-card p { margin: 0; font-size: 13px; line-height: 1.6; color: var(--ink-2); }

.pp-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.pp-actions .btn { flex: 1 1 auto; justify-content: center; }

.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink-2); }


.match-badge {
  font-size: 11px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}


/* candidate picker */

.match-badge {
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: 0 2px;
  border-bottom: 1px dotted currentColor;
}

.candidate-menu {
  position: fixed;
  z-index: 70;
  min-width: 280px;
  padding: 6px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 14px 36px rgba(35, 32, 27, .2);
  display: grid;
  gap: 2px;
}

.candidate-head {
  font-size: 11px;
  color: var(--ink-3);
  padding: 6px 8px 4px;
}

.candidate-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  font: inherit;
  font-size: 12px;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.candidate-row:hover { background: var(--surface-2); }
.cand-name { color: var(--ink-3); font-size: 11px; }
.cand-de { margin-left: auto; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.candidate-row.is-ghost { color: var(--ink-3); }


.brand-tag {
  margin-left: 7px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(47, 111, 94, .35);
  background: rgba(47, 111, 94, .1);
  color: var(--accent);
  font: inherit;
  font-size: 10px;
  line-height: 1.5;
  letter-spacing: .06em;
  text-transform: uppercase;
  cursor: pointer;
}

.brand-tag:hover { background: rgba(47, 111, 94, .18); }

/* ---------- busy overlay ---------- */

.busy {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  background: rgba(35, 32, 27, .38);
  padding: 20px;
}

.busy[hidden] { display: none; }

.busy-card {
  display: grid;
  justify-items: center;
  gap: 10px;
  min-width: 250px;
  padding: 24px 28px;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 24px 60px rgba(35, 32, 27, .3);
  text-align: center;
}

.busy-card p { margin: 0; font-size: 14px; }
.busy-card small { color: var(--ink-3); font-size: 11px; }

.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(47, 111, 94, .18);
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}


/* ---------- gesture guide ---------- */

.guide {
  position: fixed;
  inset: 0;
  z-index: 95;
  display: grid;
  place-items: center;
  background: rgba(35, 32, 27, .45);
  padding: 20px;
}

.guide[hidden] { display: none; }

.guide-card {
  width: min(470px, 100%);
  padding: 22px 24px;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 24px 60px rgba(35, 32, 27, .3);
}

.guide-card h3 { margin: 0 0 12px; font-size: 17px; }

.guide-list {
  margin: 0 0 14px;
  padding-left: 18px;
  display: grid;
  gap: 8px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--ink-2);
}

.guide-list b { color: var(--ink); }

.guide-check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  font-size: 12px;
  color: var(--ink-3);
}

.guide-card .btn { width: 100%; justify-content: center; }

.mini-btn.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}


/* ---------- manual calibration ---------- */

.calib {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.calib > .btn { width: 100%; justify-content: center; }

.nudge {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.nudge .mini-btn {
  padding: 6px 0;
  text-align: center;
}

.calib-rect {
  position: absolute;
  z-index: 20;
  border: 2px dashed var(--accent);
  background: rgba(47, 111, 94, .1);
  pointer-events: none;
}


.calib-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.calib-row .btn {
  width: 100%;
  justify-content: center;
  padding: 8px 6px;
}


/* active tool / help / row actions */

.btn.is-active,
.btn.is-active:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.help-dot {
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink-3);
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  align-self: center;
}

.help-dot:hover { border-color: var(--accent); color: var(--accent); }

.help-pop[hidden] { display: none; }

.help-pop {
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 12px;
  line-height: 1.6;
  color: var(--ink-2);
  display: grid;
  gap: 6px;
}

.help-pop b { color: var(--ink); }

.calib-row {
  grid-template-columns: 1fr 1fr auto;
  display: grid;
  gap: 6px;
}

.glyph-actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
  justify-content: flex-end;
  margin-top: 2px;
}

.glyph-actions .mini-btn {
  padding: 4px 8px;
  font-size: 11px;
}

.mini-btn.is-danger { color: #a4453b; border-color: rgba(164, 69, 59, .35); }
.mini-btn.is-danger:hover { background: rgba(164, 69, 59, .08); border-color: #a4453b; }


/* image saver (mobile-friendly export) */

.image-saver {
  position: fixed;
  inset: 0;
  z-index: 96;
  display: grid;
  place-items: center;
  background: rgba(35, 32, 27, .55);
  padding: 16px;
}

.image-saver-card {
  width: min(560px, 100%);
  max-height: 92vh;
  overflow: auto;
  display: grid;
  gap: 12px;
  padding: 16px;
  border-radius: 14px;
  background: var(--surface);
}

.image-saver-card h3 { margin: 0; font-size: 15px; }
.image-saver-card img { width: 100%; border-radius: 8px; display: block; }

.image-saver-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.image-saver-actions .btn { justify-content: center; text-decoration: none; }


/* cross-check between printed code and swatch match */

.swatch-row.is-pending {
  background: rgba(196, 148, 42, .1);
  box-shadow: inset 2px 0 0 #c4942a;
}

.mini-btn.is-warn {
  color: #8a6416;
  border-color: rgba(196, 148, 42, .55);
  background: rgba(196, 148, 42, .12);
}

.mini-btn.is-warn:hover { background: rgba(196, 148, 42, .22); }


/* flashing hint for the calibration tools */

@keyframes calibFlash {
  0%, 100% { box-shadow: 0 0 0 0 rgba(47, 111, 94, 0); }
  50% { box-shadow: 0 0 0 4px rgba(47, 111, 94, .35); }
}

.btn.is-flashing {
  animation: calibFlash 1.1s ease-in-out infinite;
  border-color: var(--accent);
  color: var(--accent);
}


/* ---------- mobile: scrollable toolbar, no overlapping panels ---------- */

@media (max-width: 820px) {
  .topbar {
    overflow: hidden;
  }

  .toolbar {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }

  .toolbar::-webkit-scrollbar { display: none; }
  .toolbar .spacer { display: none; }
  .toolbar > * { flex: 0 0 auto; }

  .panel { z-index: 5; }
  .panel-body { -webkit-overflow-scrolling: touch; }
}

/* flashing hint also works on collapsed sections and panel tabs */

.fieldset h3.is-flashing,
.mobile-tab.is-flashing {
  animation: calibFlash 1.1s ease-in-out infinite;
  border-radius: 6px;
}

.panel.needs-attention {
  box-shadow: inset 0 0 0 2px rgba(47, 111, 94, .45);
}


/* dialogs must fit a 390px phone */

.pp-card,
.image-saver-card {
  width: min(480px, 100%);
  max-height: 90vh;
  overflow: auto;
}

.pp-actions {
  flex-wrap: wrap;
}

.pp-actions .btn {
  flex: 1 1 140px;
  min-width: 0;
  justify-content: center;
}


@media (max-width: 520px) {
  .pp-card,
  .image-saver-card {
    width: calc(100vw - 32px);
    max-width: calc(100vw - 32px);
    padding: 18px 16px;
  }

  .pp-actions {
    flex-direction: column;
  }

  .pp-actions .btn {
    flex: 1 1 auto;
    width: 100%;
  }

  .palette-prompt { padding: 16px; }
}


/* the old auto-grid shortcut is gone: manual locating uses 选起点 + 量格距 */
#btn-manual { display: none !important; }


/* ---------- mobile layout, take 2 ---------- */

@media (max-width: 820px) {
  .topbar {
    flex-wrap: nowrap;
    align-items: center;
    overflow: hidden;
  }

  .brand { flex: 0 0 auto; }

  .toolbar {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 6px 8px 6px 0;
  }

  .toolbar::-webkit-scrollbar { display: none; }
  .toolbar > * { flex: 0 0 auto; }
  .toolbar .spacer { display: none; }

  /* the sheet must never sit on top of the toolbar, and its body must scroll */
  .panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
    max-height: calc(100dvh - 132px);
    z-index: 30;
  }

  .panel-head { flex: 0 0 auto; }

  .panel-body,
  .panel-body-split,
  #glyph-panel,
  #inspector {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
}


/* ---------- mobile: one scroll container for the whole top bar ---------- */

@media (max-width: 820px) {
  .topbar {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-right: 10px;
  }

  .topbar::-webkit-scrollbar { display: none; }

  .topbar > * { flex: 0 0 auto; }

  .toolbar {
    flex: 0 0 auto;
    overflow: visible;
    min-width: max-content;
    padding: 6px 0;
  }

  .toolbar .spacer { display: none; }
}

/* ---------- draggable panel height ---------- */

.panel-head {
  touch-action: none;
  cursor: grab;
}

.panel-head::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 4px;
  width: 44px;
  height: 4px;
  margin-left: -22px;
  border-radius: 2px;
  background: rgba(35, 32, 27, .18);
}

.panel-head { position: relative; }

@media (min-width: 821px) {
  .panel-head::after { display: none; }
  .panel-head { cursor: default; touch-action: auto; }
}


/* ---------- mobile: brand row + full-width scrollable toolbar row ---------- */

@media (max-width: 820px) {
  .topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 8px;
    overflow: visible;
    padding-bottom: 4px;
  }

  .brand {
    flex: 0 0 100%;
    justify-content: center;
    padding-bottom: 2px;
  }

  .toolbar {
    flex: 0 0 100%;
    width: 100%;
    min-width: 0;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 2px 10px;
  }

  .toolbar::-webkit-scrollbar { display: none; }
  .toolbar > * { flex: 0 0 auto; }

  /* independent section heights: divider between the two right-hand blocks */
  #inspector,
  #glyph-panel {
    flex: 0 0 auto;
    max-height: 60%;
    overflow-y: auto;
  }

  .panel-splitter {
    display: block;
  }
}

.panel-splitter {
  display: none;
  flex: 0 0 auto;
  height: 14px;
  margin: 2px 10px;
  border-radius: 7px;
  background: rgba(35, 32, 27, .08);
  touch-action: none;
  cursor: row-resize;
  position: relative;
}

.panel-splitter::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 40px;
  height: 3px;
  margin: -1.5px 0 0 -20px;
  border-radius: 2px;
  background: rgba(35, 32, 27, .3);
}


/* ---------- right panel: two sections ---------- */

.panel-tabs {
  display: none;
  gap: 6px;
  padding: 8px 10px 6px;
  flex: 0 0 auto;
}

.panel-tabs button {
  flex: 1;
  padding: 7px 0;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: #fff;
  font: inherit;
  font-size: 12px;
  color: var(--ink-2);
  cursor: pointer;
}

.panel-tabs button.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

@media (max-width: 820px) {
  .panel-tabs { display: flex; }

  .panel-right[data-section='locate'] .sec-color,
  .panel-right[data-section='color'] .sec-locate {
    display: none;
  }

  /* the visible section owns the remaining height and scrolls itself */
  .panels-right .sec,
  .panel-right .sec {
    flex: 1 1 auto;
    max-height: none;
    overflow-y: auto;
  }
}


/* ---------- mobile, third pass: everything visible, everything scrolls ---------- */

@media (max-width: 820px) {
  .topbar {
    display: block;
    overflow: visible;
    padding: 6px 10px 8px;
  }

  .brand {
    display: flex;
    justify-content: center;
    margin-bottom: 6px;
  }

  /* wrap instead of scrolling: every button must be reachable */
  .toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    overflow: visible;
    width: 100%;
    min-width: 0;
    padding: 0;
  }

  .toolbar > * { flex: 0 0 auto; }
  .toolbar .spacer { display: none; }

  .seg { order: 10; }

  /* the right panel becomes a real column with a bounded height */
  .panel {
    height: calc(100dvh - 150px);
    max-height: calc(100dvh - 150px);
    min-height: 0;
  }

  .panel-tabs { flex: 0 0 auto; }

  .panel-right .sec {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
}


@media (max-width: 820px) {
  /* the header must grow with the wrapped toolbar instead of overlapping the chart */
  .app { grid-template-rows: auto 1fr auto; }
  .topbar { height: auto; min-height: 0; }
}


/* the visible section must fill the panel: an earlier rule capped it at 60%,
   which left the blank rectangle at the bottom */
@media (max-width: 820px) {
  #inspector,
  #glyph-panel {
    flex: 1 1 0 !important;
    max-height: none !important;
    min-height: 0;
  }

  .panel-splitter { display: none; }
}


/* keep the version badge lowercase, e.g. v1.0.0 */
.brand-tag {
  text-transform: none !important;
  letter-spacing: .02em;
}
