:root {
  --ink: #24231f;
  --ink-soft: #66645d;
  --paper: #f7f2e8;
  --paper-deep: #eee6d8;
  --panel: #fffdf8;
  --line: #d8d0c2;
  --line-soft: #e8e1d5;
  --accent: #7e302e;
  --accent-dark: #642321;
  --good: #287b5e;
  --good-soft: #e8f3ed;
  --bad: #a84643;
  --bad-soft: #f8eae8;
  --blue: #41647d;
  --blue-soft: #eaf0f4;
  --gold: #9d722d;
  --gold-soft: #f7efd9;
  --shadow: 0 12px 36px rgba(47, 41, 31, 0.1);
  --topbar-h: 78px;
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

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

html, body { margin: 0; min-height: 100%; background: var(--paper); }
body { overflow: hidden; }
button, input, textarea, select { font: inherit; }
button { color: inherit; }

.app-shell { height: 100vh; display: grid; grid-template-rows: var(--topbar-h) 1fr; }

.topbar {
  position: relative;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(250px, 1fr) auto minmax(250px, 1fr);
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 248, .95);
  box-shadow: 0 2px 16px rgba(61, 52, 39, .05);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 42px; height: 42px; display: grid; place-items: center;
  border-radius: 50%; color: var(--panel); background: var(--accent);
  font-family: "Noto Serif TC", "PMingLiU", serif; font-size: 22px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.28);
}
.brand h1 { margin: 0; font-family: "Noto Serif TC", "PMingLiU", serif; font-size: 19px; letter-spacing: .08em; }
.brand p { margin: 3px 0 0; color: var(--ink-soft); font-size: 11px; letter-spacing: .12em; }

.section-tabs { display: flex; align-self: stretch; gap: 4px; }
.section-tab {
  position: relative; min-width: 128px; padding: 0 18px; border: 0;
  background: transparent; color: var(--ink-soft); cursor: pointer; font-weight: 650;
}
.section-tab span { margin-right: 7px; color: #aaa397; font-size: 10px; letter-spacing: .08em; }
.section-tab::after { content: ""; position: absolute; left: 18px; right: 18px; bottom: 0; height: 3px; border-radius: 3px 3px 0 0; background: transparent; }
.section-tab:hover { color: var(--ink); background: #faf7f0; }
.section-tab.active { color: var(--accent); }
.section-tab.active::after { background: var(--accent); }

.top-actions { justify-self: end; display: flex; align-items: center; gap: 8px; }
.ghost-btn, .primary-btn, .complete-btn, .wide-btn, .text-btn {
  border-radius: 9px; border: 1px solid var(--line); padding: 9px 13px;
  background: var(--panel); cursor: pointer; font-weight: 650;
}
.ghost-btn:hover, .wide-btn:hover { border-color: #aaa194; background: #fff; }
.primary-btn { border-color: var(--accent); background: var(--accent); color: white; }
.primary-btn:hover { background: var(--accent-dark); }
.complete-btn { border-color: #bed8c9; background: var(--good-soft); color: var(--good); }
.complete-btn.done { border-color: var(--good); background: var(--good); color: #fff; }
.text-btn { border-color: transparent; background: transparent; color: var(--ink-soft); }
.text-btn:hover { color: var(--accent); background: #f5efe5; }
.count-badge { display: inline-grid; min-width: 20px; height: 20px; place-items: center; margin-left: 4px; padding: 0 5px; border-radius: 999px; background: var(--paper-deep); font-size: 11px; }

.workspace-layout { min-height: 0; display: grid; grid-template-columns: 300px minmax(0, 1fr); }
.workspace-layout.palette-collapsed { grid-template-columns: 54px minmax(0, 1fr); }

.palette-panel {
  position: relative; z-index: 10; min-height: 0; display: flex; flex-direction: column;
  padding: 19px 15px 14px; border-right: 1px solid var(--line); background: var(--panel);
  box-shadow: 4px 0 16px rgba(61, 52, 39, .04); transition: width .2s ease;
}
.palette-head { display: flex; justify-content: space-between; align-items: flex-start; padding: 0 5px 12px; }
.eyebrow { color: var(--accent); font-size: 9px; font-weight: 800; letter-spacing: .2em; }
.palette-head h2, .dialog-head h2 { margin: 4px 0 0; font-family: "Noto Serif TC", "PMingLiU", serif; font-size: 19px; }
.icon-btn { width: 32px; height: 32px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); cursor: pointer; font-size: 21px; }
.icon-btn:hover { border-color: #aaa194; background: #fff; }
.workspace-layout.palette-collapsed .palette-panel { padding: 16px 10px; overflow: hidden; }
.workspace-layout.palette-collapsed .palette-head > div,
.workspace-layout.palette-collapsed .search-box,
.workspace-layout.palette-collapsed .palette-tip,
.workspace-layout.palette-collapsed .palette-groups,
.workspace-layout.palette-collapsed .palette-footer { display: none; }
.workspace-layout.palette-collapsed .palette-head { padding: 0; }
.workspace-layout.palette-collapsed #collapsePalette { transform: rotate(180deg); }

.search-box { display: flex; align-items: center; gap: 7px; margin: 0 4px 10px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 9px; background: #fff; }
.search-box:focus-within { border-color: #a88668; box-shadow: 0 0 0 3px rgba(168,134,104,.12); }
.search-box span { color: #928b80; font-size: 20px; }
.search-box input { width: 100%; border: 0; outline: 0; background: transparent; font-size: 13px; }
.palette-tip { margin: 0 4px 10px; padding: 9px 10px; border-radius: 8px; background: var(--paper); color: var(--ink-soft); font-size: 11px; line-height: 1.55; }
.palette-groups { min-height: 0; overflow: auto; padding: 0 3px 12px; scrollbar-width: thin; }
.palette-group { padding: 7px 1px 8px; border-bottom: 1px solid var(--line-soft); }
.palette-group:last-child { border-bottom: 0; }
.palette-group h3 { margin: 0 0 5px 2px; color: var(--ink-soft); font-size: 11px; letter-spacing: .06em; }
.element-grid { display: flex; flex-wrap: wrap; gap: 3px; }
.row-break { flex-basis: 100%; height: 0; }
.palette-item {
  min-height: 28px; padding: 3px 7px; overflow: hidden; border: 1px solid var(--line);
  border-radius: 6px; background: #fff; cursor: grab; font-size: 12px; text-overflow: ellipsis; white-space: nowrap;
}
.palette-item:hover { border-color: #9e9181; box-shadow: 0 3px 8px rgba(46,40,31,.08); }
.palette-item:active { cursor: grabbing; }
.palette-item[data-type="palace"] { border-color: #9eb4c3; background: var(--blue-soft); color: #294e68; }
.palette-item[data-type="good"] { border-color: #99c6b2; background: var(--good-soft); color: #1f684e; }
.palette-item[data-type="bad"] { border-color: #d9a3a0; background: var(--bad-soft); color: #8e3432; }
.palette-item[data-type="marker"] { border-color: #d7be83; background: var(--gold-soft); color: #805c1f; }
.palette-item[data-type="chart-palace"] { border-color: #9eb4c3; background: var(--blue-soft); color: #294e68; }
.palette-item[data-type="change-blue"] { border-color: #1f3f8a; background: #eef2fb; color: #1f3f8a; }
.palette-item[data-type="change"], .palette-item[data-type="chain-palace-red"], .palette-item[data-type="chain-step"], .palette-item[data-type="chain-result"] { border-color: #ef9a9a; background: #fff5f5; color: #dc3434; }
.palette-item[data-type="chain-palace-green"] { border-color: #91d6ad; background: #f2fff7; color: #16884a; }
.palette-item[data-type="chain-palace"] { border-color: #999; background: #fff; color: #333; }
.palette-item[data-type="change"],
.palette-item[data-type="change-blue"],
.palette-item[data-type="chain-palace"],
.palette-item[data-type="chain-palace-red"],
.palette-item[data-type="chain-palace-green"] {
  width: 32px; height: 32px; min-height: 32px; padding: 0; border-radius: 50%; overflow: visible;
}
.palette-item[data-type="self-change-red"] { border-color: #ef9a9a; color: #dc3434; }
.palette-item[data-type="self-change-green"] { border-color: #91d6ad; color: #16884a; }
.palette-item[data-type^="free-arrow-"] { font-size: 13px; font-weight: 700; }
.palette-item[data-type^="free-arrow-red-"] { border-color: #ef9a9a; color: #dc3434; }
.palette-item[data-type="chart-star"] { min-height: 0; padding: 3px 4px; white-space: pre-line; line-height: 1.2; font-size: 13px; }
.palette-item[data-type="change-arrow"] { color: #2563aa; border-color: #a9c2e0; }
.palette-item[data-type="dayun-oval"] { color: #ef4444; border: 1.5px solid #ef4444; border-radius: 999px; padding: 3px 10px; }
.palette-item[data-type="chain-star"], .palette-item[data-type="chart-text"], .palette-item[data-type="chain-step"] { min-width: 28px; padding: 3px 0; }
.palette-item[data-type^="highlight-"].active { outline: 2px solid var(--accent); outline-offset: 1px; font-weight: 700; }
.palette-item[data-type="highlight-yellow"] { background: #fff8a6; }
.palette-item[data-type="highlight-purple"] { background: #eadcff; }
.palette-item[data-type="highlight-orange"] { background: #ffe0bd; }
.palette-item[data-type="highlight-red"] { background: #ffd0d0; }
.palette-footer { margin-top: auto; padding: 11px 4px 0; border-top: 1px solid var(--line-soft); }
.wide-btn { width: 100%; }
.palette-footer p { margin: 9px 0 0; color: var(--ink-soft); font-size: 10px; text-align: center; }
.autosave-dot { display: inline-block; width: 6px; height: 6px; margin-right: 5px; border-radius: 50%; background: var(--good); }

.board-panel { position: relative; min-width: 0; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) 28px; background: var(--paper); }
.top-bars { position: relative; z-index: 30; display: flex; flex-wrap: wrap; align-items: center; border-bottom: 1px solid var(--line); background: var(--panel); }
.top-bars > .document-bar { flex: 1 1 400px; padding: 3px 10px; border-bottom: 0; background: transparent; }
.top-bars > .tool-bar { flex: 1 1 auto; min-height: 0; padding: 3px 10px; border-bottom: 0; background: transparent; }
.top-bars .document-fields label { display: flex; align-items: center; gap: 6px; }
.top-bars .document-fields label span { white-space: nowrap; }
.top-bars #homeworkName { min-width: 140px; }
.top-bars .document-fields { min-width: 210px; }
.top-bars .document-fields input { height: 28px; }
.top-bars .tool-btn { height: 28px; }
.top-bars button { white-space: nowrap; }
.top-bars .primary-btn, .top-bars .text-btn { padding-top: 5px; padding-bottom: 5px; }
.bars-toggle { position: absolute; top: 100%; right: 22px; z-index: 31; width: 38px; height: 16px; padding: 0; border: 1px solid var(--line); border-top: 0; border-radius: 0 0 7px 7px; background: var(--panel); color: var(--ink-soft); font-size: 11px; line-height: 14px; cursor: pointer; }
.bars-toggle:hover { color: var(--accent); background: #f2e9dc; }
.board-panel.bars-collapsed .top-bars > .document-bar, .board-panel.bars-collapsed .top-bars > .tool-bar { display: none; }
.board-panel.bars-collapsed .top-bars { border-bottom: 0; }
.palette-item.armed { outline: 2px solid var(--accent); outline-offset: 1px; box-shadow: 0 0 0 4px rgba(168,134,104,.18); }
.board-canvas.placing, .board-canvas.placing * { cursor: copy !important; }
.document-bar { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 10px 18px; border-bottom: 1px solid var(--line); background: #faf7f0; }
.document-fields, .document-actions { display: flex; align-items: flex-end; gap: 10px; }
.document-fields label { display: grid; gap: 3px; }
.document-fields label span { color: var(--ink-soft); font-size: 10px; }
.document-fields input { height: 34px; border: 1px solid var(--line); border-radius: 7px; padding: 0 9px; background: var(--panel); outline: none; font-size: 13px; }
.document-fields { flex: 1; min-width: 0; }
.name-field { flex: 1; max-width: 720px; }
#homeworkName { width: 100%; }
.document-fields input:focus { border-color: #a88668; box-shadow: 0 0 0 3px rgba(168,134,104,.1); }

.tool-bar { display: flex; align-items: center; min-height: 48px; gap: 6px; padding: 6px 14px; border-bottom: 1px solid var(--line); background: var(--panel); }
.tool-group { display: flex; gap: 4px; }
.tool-btn { min-width: 36px; height: 34px; padding: 0 9px; border: 1px solid transparent; border-radius: 7px; background: transparent; cursor: pointer; font-size: 16px; }
.tool-btn span { margin-left: 3px; font-size: 12px; }
.tool-btn:hover { border-color: var(--line); background: var(--paper); }
.tool-btn.active { border-color: #c6b39b; background: #f2e9dc; color: var(--accent); }
.tool-btn.danger:hover { border-color: #e3b0ae; background: var(--bad-soft); color: var(--bad); }
.tool-btn:disabled { opacity: .35; pointer-events: none; }
.tool-separator { width: 1px; height: 22px; margin: 0 3px; background: var(--line); }
.tool-spacer { flex: 1; }
.line-color-control { display: flex; align-items: center; gap: 3px; margin-left: 2px; padding: 3px; border: 1px solid var(--line); border-radius: 8px; background: #faf7f0; }
.line-color-control button { height: 26px; padding: 0 7px; border: 1px solid transparent; border-radius: 5px; background: transparent; color: var(--ink-soft); cursor: pointer; font-size: 10px; }
.line-color-control button:hover, .line-color-control button.active { border-color: var(--line); background: #fff; color: var(--ink); }
.line-color-control i { display: inline-block; width: 14px; height: 2px; margin-right: 4px; vertical-align: middle; background: #333; }
.line-color-control [data-line-kind="red"] i { background: #ef4444; }
.line-color-control [data-line-kind="green"] i { background: #22a35a; }
.line-color-control [data-line-kind="blue"] i { background: #2863b5; }
.line-style-control { display: flex; align-items: center; gap: 3px; padding: 3px; border: 1px solid var(--line); border-radius: 8px; background: #faf7f0; }
.line-style-control button { height: 26px; padding: 0 7px; border: 1px solid transparent; border-radius: 5px; background: transparent; color: var(--ink-soft); cursor: pointer; font-size: 10px; }
.line-style-control button:hover, .line-style-control button.active { border-color: var(--line); background: #fff; color: var(--ink); }
.toggle-control { display: flex; align-items: center; gap: 7px; color: var(--ink-soft); cursor: pointer; font-size: 11px; }
.toggle-control input { position: absolute; opacity: 0; }
.toggle-control span { position: relative; width: 30px; height: 17px; border-radius: 99px; background: #d6d0c6; }
.toggle-control span::after { content: ""; position: absolute; width: 13px; height: 13px; top: 2px; left: 2px; border-radius: 50%; background: #fff; transition: .15s; }
.toggle-control input:checked + span { background: var(--accent); }
.toggle-control input:checked + span::after { transform: translateX(13px); }
.zoom-control { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.zoom-control button { height: 31px; min-width: 32px; border: 0; border-right: 1px solid var(--line-soft); background: #fff; cursor: pointer; }
.zoom-control button:last-child { border-right: 0; }
#zoomLabel { min-width: 53px; color: var(--ink-soft); font-size: 11px; }

.canvas-viewport { position: relative; min-height: 0; overflow: auto; background-color: var(--paper-deep); background-image: linear-gradient(45deg, rgba(106,91,70,.025) 25%, transparent 25%), linear-gradient(-45deg, rgba(106,91,70,.025) 25%, transparent 25%); background-size: 24px 24px; }
.canvas-sizer { position: relative; width: 1000px; height: 1400px; margin: 28px auto; transition: width .15s, height .15s; }
.board-canvas {
  position: absolute; left: 0; top: 0; width: 1000px; height: 1400px;
  transform-origin: 0 0; overflow: hidden; outline: none; border: 1px solid #cfc5b5;
  border-radius: 4px; background-color: #fff;
  box-shadow: var(--shadow); touch-action: none;
}
.board-canvas.connecting { cursor: crosshair; }
.board-canvas.highlighting, .board-canvas.highlighting * { cursor: crosshair !important; }
.board-canvas.texting, .board-canvas.texting * { cursor: text !important; }
.marquee { position: absolute; z-index: 7; border: 1px dashed var(--accent); background: rgba(126,48,46,.06); pointer-events: none; }
.text-tool b { font-family: Georgia, "Times New Roman", serif; font-size: 16px; }
.hl-stroke { fill: none; stroke-linecap: round; stroke-linejoin: round; opacity: .42; mix-blend-mode: multiply; pointer-events: none; }
.hl-stroke.selected { opacity: .7; filter: drop-shadow(0 0 2px #7e302e); }
.edge-layer, .node-layer { position: absolute; inset: 0; }
.edge-layer { z-index: 1; overflow: visible; pointer-events: none; }
.stroke-layer { position: absolute; inset: 0; z-index: 6; overflow: visible; pointer-events: none; }
.node-layer { z-index: 2; pointer-events: none; }
.edge-path { fill: none; stroke: #333; stroke-width: 1.8; pointer-events: stroke; cursor: pointer; }
.edge-path.red { stroke: #ef4444; }
.edge-path.green { stroke: #22a35a; }
.edge-path.blue { stroke: #2863b5; }
.edge-hit { fill: none; stroke: transparent; stroke-width: 14; pointer-events: stroke; cursor: pointer; }
.edge-selected { fill: none; stroke: var(--accent); stroke-width: 5; opacity: .26; pointer-events: none; }
.draft-edge { fill: none; stroke: var(--accent); stroke-width: 2; stroke-dasharray: 6 5; pointer-events: none; }

.board-node {
  position: absolute; display: grid; place-items: center; min-width: 62px; min-height: 40px;
  padding: 7px 10px; border: 1px solid #cfc8bc; border-radius: 8px; background: #fff;
  box-shadow: 0 2px 8px rgba(46,40,31,.08); cursor: grab; user-select: none; pointer-events: auto;
  font-weight: 650; line-height: 1.25; text-align: center; white-space: pre-wrap;
}
.board-node:hover { border-color: #918779; }
.board-node.selected { outline: 2px solid var(--accent); outline-offset: 2px; z-index: 4; }
.board-node[class*="type-free-arrow-"].selected, .board-node.type-change-arrow.selected { outline-style: dashed; outline-width: 1px; }
.board-node.connect-source { outline: 3px solid var(--accent); outline-offset: 3px; }
.board-node.type-palace { border: 2px solid #84a4b8; border-radius: 999px; background: var(--blue-soft); color: #274f69; font-size: 15px; font-weight: 700; }
.board-node.type-star { background: #fff; color: #292824; font-family: "Noto Serif TC", "PMingLiU", serif; font-size: 16px; }
.board-node.type-good { border-color: #87bea5; background: var(--good-soft); color: #1c694e; }
.board-node.type-bad { border-color: #d3918e; background: var(--bad-soft); color: #913633; }
.board-node.type-marker { border-color: #d0b16f; background: var(--gold-soft); color: #78571f; }
.board-node.type-stem, .board-node.type-branch { min-width: 42px; min-height: 42px; padding: 4px; border-radius: 6px; font-family: "Noto Serif TC", "PMingLiU", serif; font-size: 18px; }
.board-node.type-note { min-width: 130px; min-height: 56px; align-content: start; justify-items: start; border-color: #d5c79e; background: #fff9d9; color: #5f5331; font-weight: 500; text-align: left; }
.board-node.type-chart-palace,
.board-node.type-chart-text,
.board-node.type-chart-mark,
.board-node.type-chain-star,
.board-node.type-chain-label,
.board-node.type-chain-step,
.board-node.type-chain-result {
  min-width: 0; min-height: 0; padding: 2px; border: 0; border-radius: 0; background: transparent; box-shadow: none;
}
.board-node.type-chart-palace { font-size: 16px; font-weight: 700; }
.board-node.type-chart-star {
  min-width: 28px; min-height: 30px; padding: 3px 0; border: 0; background: transparent; box-shadow: none;
  font-size: 19px; font-weight: 700; line-height: 24px; white-space: pre-line;
}
.board-node.type-chart-text { font-size: 15px; }
.board-node.type-chart-mark { color: #2563aa; font-size: 15px; font-weight: 700; }
.board-node.type-change, .board-node.type-change-blue {
  min-width: 26px; min-height: 26px; padding: 0; border: 1.5px solid #e23e3e; border-radius: 50%;
  background: #fff; color: #e23e3e; box-shadow: none; font-size: 13px;
}
.board-node.type-change-blue { border-color: #1f3f8a; color: #1f3f8a; }
.board-node.type-chain-palace,
.board-node.type-chain-palace-red,
.board-node.type-chain-palace-green {
  min-width: 22px; min-height: 22px; padding: 0; border: 2.5px solid #333; border-radius: 50%;
  background: #fff; box-shadow: none; color: #333; font-size: 16px;
}
.board-node.type-chain-palace-red { border-color: #ef4444; color: #ef4444; }
.board-node.type-chain-palace-green { border-color: #22a35a; color: #22a35a; }
.board-node.type-chain-star { padding: 0; font-size: 18px; font-weight: 500; line-height: 1; }
.board-node.type-chain-label { color: #333; font-size: 15px; font-weight: 500; }
.board-node.type-chain-step, .board-node.type-chain-result { color: #ef4444; font-size: 15px; font-weight: 500; }
.board-node.type-self-change-red,
.board-node.type-self-change-green { min-width: 0; min-height: 0; padding: 0; border: 0; border-radius: 0; background: transparent; box-shadow: none; }
.board-node.type-self-change-red { color: #ef4444; }
.board-node.type-self-change-green { color: #22a35a; }
.board-node.type-self-change-red .node-label,
.board-node.type-self-change-green .node-label { position: absolute; width: 16px; height: 16px; line-height: 16px; font-size: 15px; font-weight: 700; text-align: center; }
.board-node[class*="type-free-arrow-"] { min-width: 20px; min-height: 20px; padding: 0; border: 0; border-radius: 0; background: transparent; box-shadow: none; color: #333; }
.board-node[class*="type-free-arrow-red-"] { color: #ef4444; }
.board-node.type-separator { min-height: 12px; padding: 0; border: 0; border-top: 1.5px solid #555; border-radius: 0; background: transparent; box-shadow: none; }
.board-node[class*="type-highlight-"] { min-height: 20px; padding: 0; border: 0; border-radius: 999px; box-shadow: none; opacity: .46; mix-blend-mode: multiply; }
.board-node.type-highlight-yellow { background: #fff000; }
.board-node.type-highlight-purple { background: #c4a1ff; }
.board-node.type-highlight-orange { background: #ffbd7a; }
.board-node.type-highlight-red { background: #ff7777; }
.resize-handle { position: absolute; width: 11px; height: 11px; border: 2px solid #fff; border-radius: 3px; background: var(--accent); cursor: nwse-resize; display: none; z-index: 2; }
.resize-handle.br { right: -6px; bottom: -6px; }
.resize-handle.tl { left: -6px; top: -6px; }
.resize-handle.ml { left: -6px; top: calc(50% - 5px); cursor: ew-resize; border-radius: 50%; }
.resize-handle.mr { right: -6px; top: calc(50% - 5px); cursor: ew-resize; border-radius: 50%; }
.rotate-handle { position: absolute; left: calc(50% - 6px); top: -24px; width: 12px; height: 12px; border: 2px solid var(--accent); border-radius: 50%; background: #fff; cursor: grab; display: none; z-index: 2; }
.rotate-handle::after { content: ""; position: absolute; left: 3px; top: 10px; height: 10px; border-left: 1.5px solid var(--accent); }
.board-node.single .resize-handle, .board-node.single .rotate-handle, .board-node.single .loop-handle { display: block; }
.loop-handle { position: absolute; width: 12px; height: 12px; border: 2px solid #fff; border-radius: 50%; background: var(--accent); display: none; z-index: 2; cursor: ew-resize; }
.loop-handle.hgt { cursor: ns-resize; border-radius: 3px; }
.board-node[class*="-loop"] .resize-handle { display: none !important; }
.node-svg { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
.drag-ghost { position: fixed; left: -2000px; top: -2000px; pointer-events: none; }
.drag-ghost .board-node { box-shadow: none; }
.board-node.type-change-arrow { min-width: 0; min-height: 0; padding: 0; border: 0; border-radius: 0; background: transparent; box-shadow: none; color: #2563aa; }
.board-node.type-change-arrow .node-label { position: absolute; width: 16px; height: 16px; line-height: 16px; font-size: 15px; font-weight: 700; text-align: center; }
.node-label[data-dir="ne"] { right: -2px; top: -4px; }
.node-label[data-dir="nw"] { left: -2px; top: -2px; }
.node-label[data-dir="se"] { right: -2px; bottom: -2px; }
.node-label[data-dir="sw"] { left: -2px; bottom: -2px; }
.board-node.type-dayun-oval { min-width: 0; min-height: 0; padding: 0 6px; border: 2px solid #ef4444; border-radius: 50%; background: transparent; box-shadow: none; color: #ef4444; font-size: 15px; font-weight: 700; white-space: nowrap; }
.board-node.type-textbox { min-width: 0; min-height: 0; padding: 2px 4px; border: 1px solid transparent; border-radius: 3px; background: transparent; box-shadow: none; color: #111; font-size: 16px; font-weight: 500; text-align: left; place-items: start; }
.board-node.type-textbox .node-label { width: 100%; outline: none; white-space: pre-wrap; word-break: break-word; min-height: 1.3em; cursor: inherit; }
.board-node.type-textbox.selected, .board-node.type-textbox.editing { border-color: #b9ae9d; border-style: dashed; }
.board-node.type-textbox.editing .node-label { cursor: text; }
.connection-dot { position: absolute; width: 8px; height: 8px; border: 2px solid #fff; border-radius: 50%; background: var(--accent); opacity: 0; }
.board-canvas.connecting .board-node:hover .connection-dot, .board-node.connect-source .connection-dot { opacity: 1; }
.connection-dot.left { left: -5px; top: calc(50% - 4px); }
.connection-dot.right { right: -5px; top: calc(50% - 4px); }

.ziwei-frame {
  position: absolute; z-index: 0; left: 130px; top: 110px; width: 740px; height: 896px;
  display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 1fr);
  border: 2px solid #333; background-color: #fff;
  background-image:
    linear-gradient(to right, transparent calc(25% - 1px), #333 calc(25% - 1px), #333 calc(25% + 1px), transparent calc(25% + 1px)),
    linear-gradient(to right, transparent calc(50% - 1px), #333 calc(50% - 1px), #333 calc(50% + 1px), transparent calc(50% + 1px)),
    linear-gradient(to right, transparent calc(75% - 1px), #333 calc(75% - 1px), #333 calc(75% + 1px), transparent calc(75% + 1px)),
    linear-gradient(to bottom, transparent calc(25% - 1px), #333 calc(25% - 1px), #333 calc(25% + 1px), transparent calc(25% + 1px)),
    linear-gradient(to bottom, transparent calc(50% - 1px), #333 calc(50% - 1px), #333 calc(50% + 1px), transparent calc(50% + 1px)),
    linear-gradient(to bottom, transparent calc(75% - 1px), #333 calc(75% - 1px), #333 calc(75% + 1px), transparent calc(75% + 1px));
  pointer-events: auto;
}
.ziwei-frame[hidden] { display: none; }
.ziwei-cell { position: relative; }
.cell-footer { position: absolute; left: 0; right: 0; bottom: 8px; height: 38px; pointer-events: none; }
.cell-footer b { position: absolute; left: 42px; bottom: 2px; font-family: "Noto Serif TC", "PMingLiU", serif; font-size: 24px; line-height: 1; }
.stem-slot { position: absolute; left: 7px; bottom: 1px; width: 32px; height: 30px; display: grid; place-items: center; pointer-events: auto; border-bottom: 1px solid #b8b2a9; color: #2f2d29; font-family: "Noto Serif TC", "PMingLiU", serif; font-size: 24px; font-weight: 700; line-height: 1; cursor: default; }
.stem-slot.empty { color: #b4aea4; font-family: inherit; font-size: 13px; font-weight: 400; }
.ziwei-cell.stem-drop .stem-slot { background: #fff1d6; border-bottom-color: var(--accent); }
.cell-footer input { position: absolute; bottom: 1px; height: 28px; pointer-events: auto; border: 0; border-bottom: 1px solid #b8b2a9; border-radius: 0; background: transparent; outline: none; color: #2f2d29; font-family: inherit; font-size: 13px; text-align: center; }
.cell-footer input:focus { border-bottom-color: var(--accent); background: #fffaf2; }
.cell-footer input::placeholder { color: #b4aea4; }
.cell-footer [data-cell-field="stem"] { left: 7px; width: 30px; font-size: 17px; }
.cell-footer [data-cell-field="range"] { right: 7px; width: 82px; font-size: 16px; font-weight: 600; }
.cell-footer [data-cell-field="range"]::placeholder { font-size: 11px; font-weight: 400; }
.cell-si { grid-area: 1 / 1; } .cell-wu { grid-area: 1 / 2; } .cell-wei { grid-area: 1 / 3; } .cell-shen { grid-area: 1 / 4; }
.cell-chen { grid-area: 2 / 1; } .cell-you { grid-area: 2 / 4; }
.cell-mao { grid-area: 3 / 1; } .cell-xu { grid-area: 3 / 4; }
.cell-yin { grid-area: 4 / 1; } .cell-chou { grid-area: 4 / 2; } .cell-zi { grid-area: 4 / 3; } .cell-hai { grid-area: 4 / 4; }
.ziwei-center {
  grid-area: 2 / 2 / 4 / 4; z-index: 1; display: grid; grid-template-rows: auto 1fr auto;
  margin: -1px; border: 2px solid #333; background: #fff;
  font-family: "Noto Serif TC", "PMingLiU", serif;
}
.center-choices { display: flex; justify-content: center; gap: 12px; padding: 30px 22px 0; pointer-events: auto; }
.center-choices select { height: 34px; padding: 0 10px; border: 1px solid #cfc8bc; border-radius: 999px; background: #faf7f0; color: #2f2d29; font-family: inherit; font-size: 15px; cursor: pointer; outline: none; }
.center-choices select:focus { border-color: var(--accent); }
.choice-group { display: flex; padding: 2px; border: 1px solid #cfc8bc; border-radius: 999px; background: #faf7f0; }
.choice-group button { width: 34px; height: 30px; border: 0; border-radius: 999px; background: transparent; color: #81796f; cursor: pointer; font-family: inherit; font-size: 14px; }
.choice-group button.active { background: var(--accent); color: #fff; }
.center-fields { display: grid; grid-template-columns: repeat(4, 1fr); align-items: center; gap: 12px; padding: 22px 34px 8px; pointer-events: auto; }
.center-fields label { display: grid; justify-items: center; gap: 8px; font-size: 20px; font-weight: 700; }
.center-fields select { width: 72px; height: 34px; border: 0; border-bottom: 1px solid #9f988e; outline: none; background: transparent; font-family: inherit; font-size: 16px; text-align: center; text-align-last: center; cursor: pointer; }
.center-fields select:focus { border-bottom-color: var(--accent); background: #fffaf2; }
.center-fields input { width: 64px; height: 34px; border: 0; border-bottom: 1px solid #9f988e; outline: none; background: transparent; font-family: inherit; font-size: 16px; text-align: center; }
.center-fields input:focus { border-bottom-color: var(--accent); background: #fffaf2; }
.bureau-field { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 0 0 46px; pointer-events: auto; font-size: 22px; font-weight: 700; }
.bureau-field input { width: 92px; height: 34px; border: 0; border-bottom: 1px solid #9f988e; outline: none; background: transparent; font-family: inherit; font-size: 16px; text-align: center; }
.bureau-field input:focus { border-bottom-color: var(--accent); background: #fffaf2; }

.empty-hint { position: fixed; z-index: 4; left: calc(50% + 110px); top: 53%; width: 310px; transform: translate(-50%, -50%); padding: 28px; border: 1px dashed #b9ae9d; border-radius: 14px; background: rgba(255,253,248,.92); text-align: center; pointer-events: none; }
.empty-hint.hidden { display: none; }
.empty-symbol { width: 44px; height: 44px; display: grid; place-items: center; margin: 0 auto 10px; border-radius: 50%; background: #efe5d7; color: var(--accent); font-size: 24px; }
.empty-hint h3 { margin: 0 0 5px; font-family: "Noto Serif TC", "PMingLiU", serif; }
.empty-hint p { margin: 0; color: var(--ink-soft); font-size: 12px; line-height: 1.65; }

.status-bar { display: flex; align-items: center; gap: 9px; padding: 0 14px; border-top: 1px solid var(--line); background: var(--panel); color: var(--ink-soft); font-size: 10px; }
.status-divider { width: 1px; height: 11px; background: var(--line); }
.status-spacer { flex: 1; }

.toast { position: fixed; z-index: 100; left: 50%; bottom: 34px; transform: translate(-50%, 20px); padding: 10px 16px; border-radius: 9px; background: #292722; color: #fff; opacity: 0; pointer-events: none; box-shadow: var(--shadow); transition: .2s; font-size: 13px; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.app-dialog { width: min(760px, calc(100vw - 36px)); max-height: min(760px, calc(100vh - 40px)); padding: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); color: var(--ink); box-shadow: 0 30px 90px rgba(35,31,25,.25); }
.app-dialog::backdrop { background: rgba(40,36,30,.48); backdrop-filter: blur(3px); }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; padding: 20px 22px 16px; border-bottom: 1px solid var(--line-soft); }
.dialog-tools { display: flex; align-items: center; gap: 8px; padding: 10px 22px; border-bottom: 1px solid var(--line-soft); background: #faf7f0; }
.dialog-tools p { flex: 1; margin: 0; color: var(--ink-soft); font-size: 12px; }
.file-label { display: inline-block; }
.file-label input { display: none; }
.record-list { max-height: 540px; overflow: auto; padding: 10px 22px 22px; }
.record-card { display: grid; grid-template-columns: 1fr auto; gap: 4px 14px; align-items: center; padding: 14px 0; border-bottom: 1px solid var(--line-soft); }
.record-card h3 { margin: 0; font-size: 14px; }
.record-card p { margin: 4px 0 0; color: var(--ink-soft); font-size: 11px; }
.record-actions { grid-row: span 2; display: flex; gap: 6px; }
.record-actions button { padding: 7px 10px; border: 1px solid var(--line); border-radius: 7px; background: #fff; cursor: pointer; font-size: 11px; }
.record-actions button:hover { border-color: #a89b8a; }
.record-actions .remove:hover { border-color: #d49b99; background: var(--bad-soft); color: var(--bad); }
.record-empty { padding: 55px 0; color: var(--ink-soft); text-align: center; }
.small-dialog { width: min(460px, calc(100vw - 36px)); }
.dialog-field { display: grid; gap: 6px; padding: 18px 22px 0; color: var(--ink-soft); font-size: 12px; }
.dialog-field textarea { resize: vertical; min-height: 90px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; outline: none; color: var(--ink); }
.dialog-field textarea:focus { border-color: #a88668; box-shadow: 0 0 0 3px rgba(168,134,104,.1); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 18px 22px 22px; }
.help-dialog { width: min(800px, calc(100vw - 36px)); }
.help-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; max-height: 620px; overflow: auto; background: var(--line-soft); }
.help-grid article { position: relative; min-height: 145px; padding: 24px 24px 22px 62px; background: var(--panel); }
.help-grid b { position: absolute; left: 22px; top: 24px; width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%; background: var(--paper-deep); color: var(--accent); font-size: 11px; }
.help-grid h3 { margin: 0 0 7px; font-size: 14px; }
.help-grid p { margin: 0; color: var(--ink-soft); font-size: 12px; line-height: 1.7; }

@media (max-width: 1050px) {
  .topbar { grid-template-columns: auto 1fr auto; gap: 10px; padding: 0 14px; }
  .brand p { display: none; }
  .section-tab { min-width: 104px; padding: 0 9px; }
  .section-tab::after { left: 9px; right: 9px; }
  .top-actions .ghost-btn { display: none; }
  .workspace-layout { grid-template-columns: 260px minmax(0, 1fr); }
  .element-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  :root { --topbar-h: 118px; }
  body { overflow: hidden; }
  .topbar { grid-template-columns: 1fr auto; grid-template-rows: 62px 56px; }
  .brand-mark { width: 36px; height: 36px; }
  .brand h1 { font-size: 16px; }
  .section-tabs { grid-column: 1 / -1; grid-row: 2; width: 100%; }
  .section-tab { flex: 1; min-width: 0; font-size: 12px; }
  .section-tab span { display: none; }
  .top-actions { grid-column: 2; grid-row: 1; }
  .workspace-layout { grid-template-columns: 54px minmax(0, 1fr); }
  .palette-panel { padding: 16px 10px; overflow: hidden; }
  .palette-head > div, .search-box, .palette-tip, .palette-groups, .palette-footer { display: none; }
  .palette-head { padding: 0; }
  #collapsePalette { transform: rotate(180deg); }
  .workspace-layout.mobile-open { grid-template-columns: min(82vw, 300px) minmax(0, 1fr); }
  .workspace-layout.mobile-open .palette-panel { padding: 19px 15px 14px; overflow: visible; }
  .workspace-layout.mobile-open .palette-head > div,
  .workspace-layout.mobile-open .search-box,
  .workspace-layout.mobile-open .palette-tip,
  .workspace-layout.mobile-open .palette-groups,
  .workspace-layout.mobile-open .palette-footer { display: flex; }
  .workspace-layout.mobile-open .palette-head > div { display: block; }
  .workspace-layout.mobile-open .palette-groups { display: block; }
  .workspace-layout.mobile-open .palette-footer { display: block; }
  .workspace-layout.mobile-open #collapsePalette { transform: none; }
  .document-bar { align-items: flex-end; padding: 8px; }
  .document-fields, .top-bars .document-fields { min-width: 0; }
  .top-bars #homeworkName { min-width: 0; }
  #homeworkName { width: 100%; }
  #newBoardBtn { display: none; }
  .primary-btn { padding: 8px 9px; font-size: 11px; }
  .tool-bar { padding: 5px 7px; }
  .tool-btn span, .toggle-control, .tool-separator:nth-of-type(2), #duplicateBtn { display: none; }
  .empty-hint { left: 57%; width: min(280px, 62vw); }
  .help-grid { grid-template-columns: 1fr; }
}


.board-canvas.arrow-drawing, .board-canvas.arrow-drawing * { cursor: crosshair !important; }
.board-node.place-ghost { opacity: .45; z-index: 40; pointer-events: none !important; outline: 1px dashed rgba(126,47,40,.5); outline-offset: 2px; }
.board-node.place-ghost * { pointer-events: none !important; }
.board-node.place-ghost .resize-handle, .board-node.place-ghost .rotate-handle, .board-node.place-ghost .loop-handle, .board-node.place-ghost .connection-dot { display: none !important; }
.auto-arrow-toggle { display: flex; align-items: center; gap: 8px; margin: 0 4px 10px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); font-size: 12px; cursor: pointer; user-select: none; }
.auto-arrow-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.auto-arrow-toggle .switch { position: relative; flex: none; width: 30px; height: 17px; border-radius: 9px; background: #cfc5b5; transition: background .15s; }
.auto-arrow-toggle .switch::after { content: ""; position: absolute; left: 2px; top: 2px; width: 13px; height: 13px; border-radius: 50%; background: #fff; transition: transform .15s; }
.auto-arrow-toggle input:checked + .switch { background: var(--accent); }
.auto-arrow-toggle input:checked + .switch::after { transform: translateX(13px); }
.workspace-layout.palette-collapsed .auto-arrow-toggle { display: none; }
.ziwei-cell .cell-corner { position: absolute; left: 7px; top: 7px; z-index: 1; width: 58px; height: 32px; padding: 0 6px; border: 1.5px solid #a99f90; border-radius: 5px; background: #faf6ee; outline: none; color: #1f1d1a; font-family: inherit; font-size: 20px; font-weight: 700; text-align: left; }
.ziwei-cell .cell-corner:focus { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px rgba(126,48,46,.12); }
/* screenshot (clean) view */
.clean-view .ziwei-frame input, .clean-view .ziwei-frame select { border-color: transparent !important; background: transparent !important; box-shadow: none !important; -webkit-appearance: none; appearance: none; pointer-events: none; }
.clean-view .ziwei-frame input::placeholder { color: transparent !important; }
.clean-view .ziwei-frame select.is-empty { color: transparent !important; }
.clean-view .stem-slot { border-bottom-color: transparent !important; }
.clean-view .stem-slot.empty { color: transparent !important; }
.clean-view .resize-handle, .clean-view .rotate-handle, .clean-view .loop-handle, .clean-view .connection-dot, .clean-view .empty-hint, .clean-view .marquee { display: none !important; }
.clean-view .board-node.selected { outline: none !important; }
.clean-view .edge-selected { display: none; }
.clean-view .board-node.type-textbox { border-color: transparent !important; }
.clean-btn.active { border-color: #c6b39b; background: #f2e9dc; color: var(--accent); }
.palette-item.arrow-icon { min-width: 48px; min-height: 34px; display: inline-grid; place-items: center; padding: 3px 4px; }
.palette-item.arrow-icon svg { display: block; pointer-events: none; }
.palette-item.arrow-icon .node-svg { position: static; overflow: visible; }

/* ===== Brand backgrounds (鄭淨陽品牌指引: 紙白 #FFFFFF, 淺米色 #FBF8F2) — page chrome only; palette items and board untouched ===== */
:root, html, body, .board-panel { background: #FBF8F2; }
.topbar { background: rgba(255, 255, 255, .96); }
.palette-panel, .top-bars, .status-bar, .bars-toggle { background: #FFFFFF; }
.palette-tip { background: #FBF8F2; }
.canvas-viewport { background-color: #FBF8F2; background-image: none; }
.newboard-pop { position: fixed; z-index: 200; width: 250px; padding: 12px 12px 10px; border: 1px solid #E8E2D6; border-radius: 10px; background: #FFFFFF; box-shadow: 0 10px 28px rgba(29, 49, 71, .16); font-size: 13px; color: #1D3147; }
.newboard-pop::before { content: ""; position: absolute; top: -6px; left: calc(var(--arrow-x, 50%) - 6px); width: 10px; height: 10px; border-left: 1px solid #E8E2D6; border-top: 1px solid #E8E2D6; background: #FFFFFF; transform: rotate(45deg); }
.newboard-pop p { margin: 0 0 10px; line-height: 1.6; }
.newboard-pop-actions { display: grid; gap: 6px; }
.newboard-pop-actions button { width: 100%; padding: 7px 10px; font-size: 12px; }

/* ===== Brand: logo seal, buttons and tool buttons (palette list items and board untouched) ===== */
.brand-mark {
  position: relative; width: 40px; height: 40px; border-radius: 5px; background: #B23A2B; color: #FFFAF3;
  font-family: "Noto Serif TC", "Songti TC", serif; font-weight: 900; font-size: 22px; line-height: 1;
  box-shadow: none;
}
.brand-mark::after { content: ""; position: absolute; inset: 2.5px; border: 1px solid rgba(255, 250, 243, .6); border-radius: 3px; pointer-events: none; }
.brand h1 { font-family: "Noto Serif TC", "Songti TC", serif; font-weight: 700; font-size: 18px; color: #1D3147; }
.brand p { color: #5F6B78; }

.topbar, .top-bars, .tool-bar, .newboard-pop { color: #1D3147; }
.section-tab { color: #4D5A68; }
.section-tab:hover { color: #1D3147; background: #E8EFF6; }
.section-tab span { color: #5F6B78; }
.section-tab.active { color: #1D3147; }
.section-tab.active::after { background: #315D86; }

.primary-btn { border-color: #315D86; background: #315D86; color: #FFFFFF; }
.primary-btn:hover { border-color: #244969; background: #244969; }
.ghost-btn { border-color: #CFD6DE; background: #FFFFFF; color: #1D3147; }
.ghost-btn:hover { border-color: #AAB6C3; background: #FFFFFF; }
.text-btn { color: #315D86; }
.text-btn:hover { color: #244969; background: #E8EFF6; }
.top-bars #newBoardBtn { border-color: #CFD6DE; background: #FFFFFF; color: #1D3147; }
.top-bars #newBoardBtn:hover { border-color: #AAB6C3; background: #FFFFFF; }
.count-badge { background: #E8EFF6; color: #315D86; }
.icon-btn { border-color: #CFD6DE; background: #FFFFFF; color: #1D3147; }
.icon-btn:hover { border-color: #AAB6C3; background: #FFFFFF; }

.tool-btn { color: #1D3147; }
.tool-btn:hover { border-color: #CFD6DE; background: #E8EFF6; }
.tool-btn.active, .tool-btn[aria-pressed="true"] { border-color: #315D86; background: #E8EFF6; color: #315D86; }
.tool-btn.danger:hover { border-color: #F3DCD6; background: #FBF1EE; color: #B23A2B; }
.tool-separator { background: #E4E7EB; }
.toggle-control { color: #4D5A68; }
.toggle-control span { background: #CFD6DE; }
.toggle-control input:checked + span { background: #315D86; }
.bars-toggle { color: #5F6B78; border-color: #E4E7EB; }
.bars-toggle:hover { color: #315D86; background: #E8EFF6; }
.document-fields label span { color: #5F6B78; }
.document-fields input:focus { border-color: #315D86; box-shadow: 0 0 0 3px #E8EFF6; }

.newboard-pop small { color: #5F6B78; font-size: 11px; }
.danger-btn { width: 100%; padding: 7px 10px; border: 1px solid #B23A2B; border-radius: 9px; background: #B23A2B; color: #FFFAF3; font-size: 12px; font-weight: 650; cursor: pointer; }
.danger-btn:hover { background: #9A3124; border-color: #9A3124; }
#clearBoardBtn svg { display: block; }

/* board area white on every page */
.board-panel, .canvas-viewport { background-color: #FFFFFF; background-image: none; }
.newboard-pop-actions { grid-template-columns: 1fr 1fr; }

/* logo back to the round mark, no inner frame */
.brand-mark { width: 42px; height: 42px; border-radius: 50%; }
.brand-mark::after { content: none; display: none; }

/* pale white chrome, no cream (Yannis). Palette list items and the board untouched. */
:root, html, body { background: #FFFFFF; }
.palette-tip { background: #F7F8FA; }
.document-fields input, #homeworkName { background: #FFFFFF; border-color: #E4E7EB; }
#addTextBtn { background: #FFFFFF; border-color: #CFD6DE; color: #1D3147; }
#addTextBtn:hover { border-color: #AAB6C3; }
.app-dialog, .help-grid article { background: #FFFFFF; }
.dialog-tools { background: #F7F8FA; }
.app-dialog::backdrop { background: rgba(29, 49, 71, .4); }
.status-divider { background: #E4E7EB; }
.topbar, .palette-panel, .top-bars, .status-bar, .bars-toggle { border-color: #E4E7EB; }

/* palace top-left box: 20% shorter, paler (Yannis) */
.ziwei-cell .cell-corner { width: 46px; padding: 0 4px; border-color: #cdc6ba; background: #fdfbf8; }

/* slimmer top bar (Yannis: too tall) */
@media (min-width: 761px) {
  :root { --topbar-h: 52px; }
  .topbar { height: var(--topbar-h); min-height: 0; gap: 16px; padding: 0 18px; }
  .brand { gap: 9px; }
  .brand-mark { width: 32px; height: 32px; font-size: 17px; }
  .brand h1 { font-size: 16px; line-height: 1.2; }
  .brand p { margin-top: 1px; font-size: 10px; line-height: 1.2; }
  .section-tab { padding: 0 14px; font-size: 14px; }
  .top-actions .ghost-btn { padding: 5px 11px; font-size: 13px; }
}

/* top area another 15% slimmer so the chart gets the room (Yannis) */
@media (min-width: 761px) {
  :root { --topbar-h: 44px; }
  .brand-mark { width: 28px; height: 28px; font-size: 15px; }
  .brand h1 { font-size: 15px; }
  .brand p { font-size: 9.5px; }
  .section-tab { font-size: 13.5px; }
  .top-actions .ghost-btn { padding: 3px 10px; font-size: 12.5px; }
  .top-bars > .document-bar { padding-top: 3px; padding-bottom: 3px; }
  .top-bars > .tool-bar { padding-top: 2px; padding-bottom: 2px; min-height: 0; }
  .top-bars .primary-btn, .top-bars .text-btn, .top-bars #newBoardBtn { padding: 3px 12px; font-size: 13px; line-height: 1.5; }
  .top-bars .tool-btn, .top-bars .document-fields input { height: 26px; }
}
@media (min-width: 761px) { .top-bars .zoom-control button { height: 26px; } }

/* search box and placement tip removed from the palette (Yannis) */
.palette-panel .search-box, .palette-panel .palette-tip { display: none !important; }

/* palette title 40% smaller (Yannis) */
.palette-head h2 { font-size: 11.5px; margin-top: 2px; }
/* palette head +20% (Yannis) */
.palette-head h2 { font-size: 13.8px; }
.palette-head .eyebrow { font-size: 10.8px; }

/* status bar removed; the sheet area takes its space (Yannis) */
.status-bar { display: none !important; }
.board-panel { grid-template-rows: auto minmax(0, 1fr); }

/* folded header (double-click the top header) */
.app-shell.header-folded { --topbar-h: 12px; }
.app-shell.header-folded .topbar { height: 12px; min-height: 0; padding: 0; cursor: pointer; overflow: hidden; display: flex; justify-content: center; align-items: center; background: #F7F8FA; }
.app-shell.header-folded .topbar > * { display: none !important; }
.app-shell.header-folded .topbar::after { content: "▾ 展開頂部"; font-size: 9px; line-height: 1; color: #5F6B78; letter-spacing: .1em; }
.app-shell.header-folded .topbar:hover { background: #E8EFF6; }

/* palette: every text 2px smaller, panel narrower (Yannis) */
@media (min-width: 761px) {
  .workspace-layout { grid-template-columns: 260px minmax(0, 1fr); }
  .workspace-layout.palette-collapsed { grid-template-columns: 54px minmax(0, 1fr); }
}
.palette-groups { zoom: .84; }
.palette-head .eyebrow { font-size: 8.8px; }
.palette-head h2 { font-size: 11.8px; }
.palette-panel .auto-arrow-toggle { font-size: 10px; }
.palette-panel #addTextBtn { font-size: 12px; padding: 6px 10px; }
.palette-footer p, .palette-footer span { font-size: 8.5px; }
