:root {
  --ink: #1d1914;
  --muted: #6f675c;
  --paper: #f3efe6;
  --paper-2: #fffdf8;
  --line: #ddd4c6;
  --side: #14211e;
  --side-2: #1d2e29;
  --side-text: #e7f0ea;
  --teal: #0e6b60;
  --teal-2: #149485;
  --copper: #c4622d;
  --good: #1c7a45;
  --bad: #a33b32;
  --shadow: 0 12px 28px rgba(48, 34, 12, 0.08);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  font-size: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--paper); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.55; }

.app {
  height: 100vh;
  display: grid;
  grid-template-columns: 268px minmax(0, 1fr) 360px;
  grid-template-rows: auto auto minmax(0, 1fr) 30px;
  grid-template-areas:
    "top top top"
    "palette palette palette"
    "nav stage panel"
    "status status status";
}
body.nav-collapsed .app { grid-template-columns: 36px minmax(0, 1fr) 360px; }
body.panel-collapsed .app { grid-template-columns: 268px minmax(0, 1fr) 36px; }
body.nav-collapsed.panel-collapsed .app { grid-template-columns: 36px minmax(0, 1fr) 36px; }
body.wide .app { grid-template-columns: 268px minmax(0, 1fr) 0px; }
body.wide.nav-collapsed .app { grid-template-columns: 36px minmax(0, 1fr) 0px; }
body.wide #panel { display: none; }
body.wide #palette { display: none; }

#palette {
  grid-area: palette;
  background: var(--paper-2);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}
#palette:empty { display: none; }
.palette-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  min-width: 0;
}
#palette .toolbar {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0;
}
#palette .ribbon {
  flex: 0 0 auto;
  margin-left: auto;
  padding: 0;
  flex-wrap: nowrap;
  justify-content: flex-end;
}

#top {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--paper-2);
  border-bottom: 1px solid var(--line);
}
.top-title { min-width: 0; flex: 1; display: flex; align-items: baseline; gap: 10px; }
.top-title h1 { margin: 0; font-size: 16px; font-weight: 650; white-space: nowrap; }
.top-title p { margin: 0; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; margin-left: auto; }

#nav {
  grid-area: nav;
  background: var(--side);
  color: var(--side-text);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
#nav-scroll { flex: 1; min-height: 0; overflow: auto; padding: 14px 12px 24px; }
body.nav-collapsed #nav-scroll { display: none; }
#nav-toggle {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: 36px;
  padding: 0 12px;
  border: 0;
  border-bottom: 1px solid #2c403a;
  background: transparent;
  color: var(--side-text);
  font-size: 13px;
}
#nav-toggle:hover { background: var(--side-2); }
body.nav-collapsed #nav-toggle {
  flex: 1;
  height: auto;
  writing-mode: vertical-rl;
  justify-content: center;
  gap: 10px;
  padding: 14px 0;
  border-bottom: 0;
  letter-spacing: 0.18em;
}
body.nav-collapsed #nav-toggle .chev { writing-mode: horizontal-tb; letter-spacing: 0; }
#stage {
  grid-area: stage;
  overflow: auto;
  min-width: 0;
  background:
    linear-gradient(transparent 31px, rgba(90, 70, 40, 0.05) 32px),
    linear-gradient(90deg, transparent 31px, rgba(90, 70, 40, 0.05) 32px),
    var(--paper);
  background-size: 32px 32px, 32px 32px, auto;
}
#panel {
  grid-area: panel;
  background: var(--paper-2);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
#panel-scroll { flex: 1; min-height: 0; overflow: auto; }
body.panel-collapsed #panel-scroll { display: none; }
#panel-toggle {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: 36px;
  padding: 0 12px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #f7f1e6;
  color: var(--ink);
  font-size: 13px;
}
#panel-toggle:hover { background: #efe6d6; }
body.panel-collapsed #panel-toggle {
  flex: 1;
  height: auto;
  writing-mode: vertical-rl;
  justify-content: center;
  gap: 10px;
  padding: 14px 0;
  border-bottom: 0;
  letter-spacing: 0.18em;
}
body.panel-collapsed #panel-toggle .chev { writing-mode: horizontal-tb; letter-spacing: 0; }
#status {
  grid-area: status;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 0 12px;
  background: #efeae0;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}
#status b { color: var(--ink); font-weight: 600; }

.nav-block { margin-bottom: 16px; }
.nav-label {
  margin: 0 4px 6px;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #9eb0a8;
}
.nav-item, .ghost, .solid, .copper, .tiny {
  border: 1px solid transparent;
  background: transparent;
  border-radius: 8px;
}
.nav-item {
  width: 100%;
  text-align: left;
  color: var(--side-text);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-item small { color: #9eb0a8; }
.nav-item.active, .nav-item:hover { background: var(--side-2); }
.nav-item.active { box-shadow: inset 3px 0 0 var(--copper); }
.nav-actions { display: flex; gap: 6px; margin: 4px; flex-wrap: wrap; }
.ctx-menu {
  position: fixed;
  z-index: 30;
  min-width: 132px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 4px;
}
.ctx-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 8px;
  padding: 7px 10px;
}
.ctx-menu button:hover { background: #f3efe6; }
.ctx-menu button.danger { color: var(--bad); }
.steps { display: flex; flex-direction: column; gap: 6px; margin: 0 4px; }
.steps button { color: var(--side-text); background: #243833; border-radius: 8px; padding: 8px 10px; text-align: left; line-height: 1.35; }
.steps button em { font-style: normal; color: #f0c7a8; margin-right: 6px; }
#nav .ghost { background: transparent; color: var(--side-text); border-color: #3e564f; }
#nav .ghost:hover { background: var(--side-2); }

.solid, .copper, .ghost, .tiny {
  padding: 7px 10px;
  border-radius: 8px;
}
.solid { background: var(--teal); color: white; }
.copper { background: var(--copper); color: white; }
.ghost { background: white; border-color: var(--line); }
.tiny { padding: 4px 8px; background: white; border-color: var(--line); font-size: 12px; }
.danger { color: var(--bad); border-color: #e7c4c0; background: #fff6f5; }

.ribbon, .banner, .toolbar, .page-head { padding: 12px 16px 0; }
.ribbon {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.stat {
  background: rgba(255, 253, 248, 0.92);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 10px;
  min-width: 88px;
  box-shadow: var(--shadow);
}
.stat span { display: block; color: var(--muted); font-size: 11px; }
.stat b { font-variant-numeric: tabular-nums; font-size: 15px; }
.banner {
  color: #7a4b24;
}
.banner button { margin-left: 8px; }
.toolbar { display: flex; gap: 6px; overflow: auto; padding-bottom: 8px; }
.tool {
  flex: 0 0 auto;
  width: 78px;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 4px 7px;
  text-align: center;
}
.tool svg { width: 42px; height: 32px; display: block; margin: 0 auto 2px; }
.tool span { display: block; font-size: 12px; }
.tool:hover { border-color: var(--teal); }

.crumbs { display: flex; gap: 6px; align-items: center; padding: 0 16px; color: var(--muted); }
.crumbs button { background: transparent; border: 0; color: var(--teal); padding: 0; }

.flow {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 36px;
  padding: 18px 22px 64px;
  min-height: calc(100% - 150px);
  width: max-content;
}
.flow-lane {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: flex-start;
  gap: 22px;
  min-height: 64px;
}
.flow-lane > .col { position: relative; z-index: 1; }
.col.is-dragging { z-index: 4; }
.flow-links {
  position: absolute;
  left: 0;
  top: 0;
  overflow: visible;
  pointer-events: none;
  z-index: 0;
}
.flow-links path {
  fill: none;
  stroke: #8d8376;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sym {
  width: 124px;
  position: relative;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 8px 10px;
  text-align: center;
  box-shadow: var(--shadow);
  user-select: none;
  cursor: grab;
  touch-action: none;
}
.col.is-dragging .sym { cursor: grabbing; }
.sym strong { display: block; margin-top: 4px; font-size: 13px; line-height: 1.25; }
.sym em { display: block; margin-top: 3px; color: var(--muted); font-style: normal; font-size: 11px; line-height: 1.3; }
.sym .glyph { width: 64px; height: 48px; }
.sym .score {
  position: absolute;
  top: 6px;
  right: 6px;
  min-width: 18px;
  height: 18px;
  border-radius: 99px;
  background: var(--ink);
  color: white;
  font-size: 11px;
  line-height: 18px;
  padding: 0 4px;
}
.sym .tag {
  display: inline-block;
  margin-top: 4px;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.sym.is-selected { border-color: var(--teal); box-shadow: 0 0 0 2px rgba(14, 107, 96, 0.25); }
.look-inherited { filter: grayscale(0.9); opacity: 0.78; }
.look-added { outline: 2px solid var(--copper); }
.look-removed { opacity: 0.62; }
.look-removed strong { text-decoration: line-through; }
.look-removed::before {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  top: 34px;
  height: 2px;
  background: var(--bad);
  transform: rotate(-12deg);
}
.thumb {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 6px;
  display: block;
  margin: 0 auto 2px;
}
.emoji-thumb { font-size: 22px; line-height: 1; }

.type-part, .type-subassembly, .type-preprocessed { color: #1f6f8b; }
.type-tool { color: #2f7d4a; }
.type-fasten { color: #c46b2c; }
.type-operation { color: #5c6b7a; }
.type-multitouch { color: #a33b3b; }
.type-material { color: #6d4c9a; }
.type-repeat { color: #0f6e6b; }
.type-inspect { color: #9a6b12; }
.type-note { color: #b0892e; }
.type-option { color: #3d4c8a; }
.type-fixture { color: #6b6258; }
.fill { fill: currentColor; }
.stroke { fill: none; stroke: currentColor; stroke-width: 2.4; }
.paperfill { fill: #fffdf8; }

.branches { margin-top: 8px; display: flex; flex-direction: column; gap: 8px; }
.branch {
  border: 1px dashed #b7ad9e;
  border-radius: 12px;
  padding: 6px;
  background: rgba(255, 253, 248, 0.7);
  min-width: 140px;
}
.branch.is-on { border-color: var(--teal); background: rgba(20, 148, 133, 0.08); }
.branch header { display: flex; gap: 4px; justify-content: space-between; margin-bottom: 6px; }
.branch-row {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 28px;
}
.empty-branch { color: var(--muted); font-size: 12px; padding: 8px; }
.quality {
  margin-top: 8px;
  border: 1.5px dashed #3d6f9a;
  border-radius: 12px;
  padding: 6px;
  background: rgba(61, 111, 154, 0.06);
}
.quality .q-label { color: #3d6f9a; font-size: 12px; margin-bottom: 6px; }

.panel-body, .page { padding: 14px 14px 28px; }
.panel-body h2, .page h2 { margin: 0 0 8px; font-size: 18px; }
.hint { color: var(--muted); font-size: 12px; line-height: 1.5; }
.group { margin: 12px 0; padding-top: 8px; border-top: 1px solid var(--line); }
.group h3 { margin: 0 0 8px; font-size: 13px; letter-spacing: 0.04em; }
label.row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; font-size: 12px; color: var(--muted); }
label.row.inline { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); }
label.row input, label.row select, label.row textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: white;
  border-radius: 8px;
  padding: 7px 8px;
}
label.row textarea { min-height: 68px; resize: vertical; }
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 8px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 10px 0; }
.filters label { display: flex; align-items: center; gap: 6px; }
.munro {
  background: #f7f1e4;
  border-radius: 8px;
  padding: 8px;
}
.munro b { font-size: 20px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; }

.page-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-end; }
.page-head h2 { margin: 0; }
.cards { display: grid; gap: 10px; }
.card, .table-wrap, .sheet-step {
  background: rgba(255, 253, 248, 0.94);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}
.card h3 { margin: 0 0 6px; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 7px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
.better { color: var(--good); }
.worse { color: var(--bad); }
.bars { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.bar-row { display: grid; grid-template-columns: 168px 1fr 120px; gap: 8px; align-items: center; }
.bar { height: 12px; background: #e7e0d4; border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--teal); }
.bar.alt i { background: var(--copper); }

.sheet { display: grid; gap: 12px; }
.sheet-step { display: grid; grid-template-columns: 72px 1fr; gap: 12px; }
.sheet-step .no {
  width: 56px; height: 56px; border-radius: 12px;
  background: var(--side); color: white;
  display: flex; align-items: center; justify-content: center;
  font-family: "Palatino Linotype", serif; font-size: 22px;
}
.warning-box { margin-top: 6px; color: var(--bad); background: #fff4f2; border-radius: 8px; padding: 6px 8px; }
.callout { background: #fff8e8; }

.modal {
  position: fixed; inset: 0;
  background: rgba(20, 16, 12, 0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  z-index: 20;
}
.modal.hidden, .toast.hidden { display: none; }
.dialog {
  width: min(560px, 100%);
  background: var(--paper-2);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.dialog h2 { margin: 0 0 10px; text-align: center; font-size: 18px; }
.dialog footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
[hidden] { display: none !important; }
.dialog.symbol-editor {
  width: min(980px, 100%);
  max-height: calc(100vh - 28px);
  overflow: auto;
  border-radius: 10px;
  padding: 12px 14px 10px;
}
.dialog.lib-editor { width: min(760px, 100%); }
.symbol-editor h2 { font-weight: 650; }
.ed-host { margin: 0 0 10px; font-size: 14px; }
.ed-top { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(200px, 0.7fr); gap: 12px; align-items: start; }
.ed-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
.ed-fields .wide { grid-column: 1 / -1; }
.ed-field { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); min-width: 0; }
.ed-field.wide { grid-column: 1 / -1; }
.ed-field input, .ed-field select, .ed-field textarea, .lib-create input, .branch-table input {
  width: 100%;
  border: 1px solid #c5bfb4;
  border-radius: 4px;
  padding: 4px 6px;
  background: white;
  color: var(--ink);
}
.ed-inline { display: flex; gap: 6px; align-items: center; }
.ed-inline input, .ed-inline select { flex: 1; }
.ed-affix { display: flex; align-items: center; gap: 4px; }
.ed-affix i { font-style: normal; color: var(--muted); }
.must-box {
  grid-column: 1 / -1;
  border: 2px solid var(--bad);
  border-radius: 4px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--ink);
}
.must-box label, .ed-checks label { display: flex; align-items: center; gap: 6px; color: var(--ink); font-size: 13px; }
.ed-media { border: 1px solid #c5bfb4; min-height: 210px; background: #fbfaf7; display: flex; flex-direction: column; }
.ed-media-bar { display: flex; gap: 6px; padding: 6px; border-bottom: 1px solid var(--line); background: #f3f0ea; }
.ed-media-view { flex: 1; min-height: 140px; display: flex; align-items: center; justify-content: center; padding: 8px; }
.ed-media-view img { max-width: 100%; max-height: 220px; }
.ed-tabs { display: flex; gap: 2px; margin-top: 12px; border-bottom: 1px solid #b7b1a6; }
.ed-tabs button {
  border: 1px solid transparent;
  border-bottom: 0;
  background: #e7e2d8;
  padding: 6px 12px;
  border-radius: 6px 6px 0 0;
}
.ed-tabs button.is-on { background: white; border-color: #b7b1a6; font-weight: 650; }
.ed-panel { border: 1px solid #b7b1a6; border-top: 0; background: white; padding: 10px; min-height: 180px; }
.munro-layout { display: grid; grid-template-columns: 148px 1fr 1fr 150px; gap: 8px; }
.ed-checks { border: 1px solid #c5bfb4; margin: 0; padding: 8px; min-width: 0; }
.ed-checks legend { padding: 0 4px; font-size: 12px; color: var(--muted); }
.ed-checks label span { margin-left: auto; color: var(--muted); font-size: 11px; }
.munro-score-box { border: 1px solid #c5bfb4; padding: 8px; text-align: center; }
.munro-score-box b { display: block; font-size: 36px; line-height: 1.1; }
.munro-score-box small, .editor-error { color: var(--bad); }
.editor-error { margin: 0; font-size: 13px; }
.ed-footer { align-items: center; }
.ed-footer .editor-error { margin-right: auto; }
.lib-editor table { width: 100%; }
.lib-editor th, .lib-editor td, .branch-table th, .branch-table td { text-align: left; }
.lib-wrap { max-height: 280px; overflow: auto; border: 1px solid #c5bfb4; background: white; }
.lib-editor tbody tr { cursor: pointer; }
.lib-editor tbody tr.is-on { background: #d6e8f6; }
.lib-bar { display: flex; gap: 10px; align-items: end; justify-content: space-between; margin-top: 10px; flex-wrap: wrap; }
.lib-create { display: flex; gap: 6px; align-items: center; margin-top: 8px; }
.lib-create input { width: auto; flex: 1; }
.branch-table { width: 100%; }
.ed-simple { display: grid; gap: 8px; }
.legend-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.legend-grid article { border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.toast {
  position: fixed; bottom: 42px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: white; padding: 10px 14px; border-radius: 999px;
  z-index: 30;
}

@media print {
  body { background: white; }
  #top, #palette, #nav, #panel, #status, .no-print { display: none !important; }
  .app { display: block; height: auto; }
  #stage { overflow: visible; background: white; }
  .sheet-step { break-inside: avoid; }
}
