/* Theme tokens: every colour the UI draws comes from here, so a theme is
   just a different set of these values. */
:root {
  --bg: #000000;
  --bg-fade: rgba(0, 0, 0, 0);
  --ink: #e8e6e1;
  --muted: #8d887c;
  --surface: #16161a;
  --surface-border: #2b2b31;
  --root-border: #6b5c33;
  --edge: #5a5a64;
  --shadow: rgba(0, 0, 0, 0.55);
  --shadow-tight: rgba(0, 0, 0, 0.35);
  --shadow-lift: rgba(0, 0, 0, 0.70);
  --shadow-tight-lift: rgba(0, 0, 0, 0.45);
  --accent-soft: #7a6a3c;
  --accent-soft-ring: rgba(201, 169, 80, 0.24);
  --accent-strong: #b9a97a;
  --accent-strong-ring: rgba(201, 169, 80, 0.42);
  --placeholder: #4b463f;
  --panel-bg: rgba(16, 16, 18, 0.94);
  --dbg-anchor: #d8b23a;
  --dbg-vel: #6aa9e0;
}

/* The original paper theme, kept as an opt-in (Cmd/Ctrl+Shift+L). */
[data-theme="light"] {
  --bg: #f7f5f0;
  --bg-fade: rgba(247, 245, 240, 0);
  --ink: #3d3a34;
  --muted: #8a8577;
  --surface: #ffffff;
  --surface-border: #e8e4da;
  --root-border: #d8cfae;
  --edge: #c9c2b3;
  --shadow: rgba(61, 58, 52, 0.08);
  --shadow-tight: rgba(61, 58, 52, 0.05);
  --shadow-lift: rgba(61, 58, 52, 0.10);
  --shadow-tight-lift: rgba(61, 58, 52, 0.10);
  --accent-soft: #c9b98a;
  --accent-soft-ring: rgba(201, 185, 138, 0.30);
  --accent-strong: #b9a97a;
  --accent-strong-ring: rgba(185, 169, 122, 0.45);
  --placeholder: #b9b2a4;
  --panel-bg: rgba(255, 255, 255, 0.93);
  --dbg-anchor: #c9a227;
  --dbg-vel: #3d7fb8;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "PingFang SC", "Helvetica Neue", sans-serif;
  /* Stop iOS from inflating text in landscape / on rotate. */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

#app {
  width: 100%;
  height: 100%;
  /* Mobile browser chrome shows/hides as you scroll; dvh tracks the truly
     visible viewport so the canvas never ends up half under the URL bar. */
  height: 100dvh;
}

/* ---- toolbar ---------------------------------------------------------- */
#toolbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 44px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  z-index: 10;
  pointer-events: none;
  background: linear-gradient(var(--bg) 60%, var(--bg-fade));
}

#toolbar .brand {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

#toolbar .hint {
  font-size: 12px;
  color: var(--muted);
}

/* ---- viewport & world container --------------------------------------- */
#viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  /* The canvas owns every gesture: no page scroll, no pull-to-bounce, no
     browser pinch-zoom — all of that is handled in interaction.js. */
  touch-action: none;
  -webkit-touch-callout: none;
}

#viewport.panning {
  cursor: grabbing;
}

#world {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
}

#edges {
  position: absolute;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  overflow: visible;
  pointer-events: none;
}

.edge {
  fill: none;
  stroke: var(--edge);
  stroke-width: 1.5;
}

/* ---- cards ------------------------------------------------------------- */
.card {
  position: absolute;
  left: 0;
  top: 0;
  width: 250px;
  min-height: 56px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 10px;
  box-shadow: 0 1px 2px var(--shadow-tight), 0 4px 12px var(--shadow);
  user-select: none;
  cursor: grab;
}

.card.dragging {
  cursor: grabbing;
  box-shadow: 0 4px 8px var(--shadow-tight-lift), 0 12px 28px var(--shadow-lift);
}

.card.selected {
  border-color: var(--accent-soft);
  box-shadow: 0 0 0 2px var(--accent-soft-ring), 0 4px 12px var(--shadow);
}

.card.editing {
  border-color: var(--accent-strong);
  box-shadow: 0 0 0 2px var(--accent-strong-ring), 0 4px 12px var(--shadow);
  cursor: text;
}

.card.editing .card-title,
.card.editing .card-note {
  outline: none;
  cursor: text;
}

.card.editing .card-title:empty::before,
.card.editing .card-note:empty::before {
  content: attr(data-placeholder);
  color: var(--placeholder);
}

/* ---- preset card colours -------------------------------------------------
   A whitelist of six tints (see CARD_COLORS in app.js; main.js sanitises to
   the same list, so a hand-edited file can never inject an arbitrary value).
   Each preset defines two hooks — a soft wash for the panel and a stronger
   border/left-bar — tuned per theme so text contrast never breaks. A card
   without data-color keeps the default surface above. */
.card[data-color] {
  background: var(--card-wash);
  border-color: var(--card-tint);
  border-left: 3px solid var(--card-tint);
}

/* Dark theme pigments (the default canvas is black). */
[data-color="amber"]  { --card-wash: rgba(201, 169, 80, 0.10);  --card-tint: #c9a950; }
[data-color="rose"]   { --card-wash: rgba(224, 122, 138, 0.10); --card-tint: #e07a8a; }
[data-color="sky"]    { --card-wash: rgba(106, 169, 224, 0.10); --card-tint: #6aa9e0; }
[data-color="mint"]   { --card-wash: rgba(110, 200, 170, 0.10); --card-tint: #6ec8aa; }
[data-color="violet"] { --card-wash: rgba(167, 139, 250, 0.10); --card-tint: #a78bfa; }
[data-color="lime"]   { --card-wash: rgba(163, 214, 108, 0.10); --card-tint: #a3d66c; }

/* Light theme pigments: the paper canvas is near-white, so washes go a touch
   deeper and tints darker to stay legible on #ffffff. */
[data-theme="light"] [data-color="amber"]  { --card-wash: rgba(201, 169, 80, 0.16);  --card-tint: #9a7d2a; }
[data-theme="light"] [data-color="rose"]   { --card-wash: rgba(224, 122, 138, 0.14); --card-tint: #b04a5c; }
[data-theme="light"] [data-color="sky"]    { --card-wash: rgba(106, 169, 224, 0.16); --card-tint: #2f6ea8; }
[data-theme="light"] [data-color="mint"]   { --card-wash: rgba(110, 200, 170, 0.16); --card-tint: #2e8a6e; }
[data-theme="light"] [data-color="violet"] { --card-wash: rgba(167, 139, 250, 0.14); --card-tint: #6d4fc4; }
[data-theme="light"] [data-color="lime"]   { --card-wash: rgba(163, 214, 108, 0.18); --card-tint: #5d8a2e; }

/* The colour swatch button mirrors the current tint so the bar reads as a
   colour control even before the palette opens. */
.card-color-btn::after {
  content: "";
  display: block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--card-tint, var(--muted));
  border: 1px solid rgba(128, 128, 128, 0.45);
}

.card-color-wrap {
  position: relative;
  display: flex;
}

/* The palette: a small popover above the action bar. Kept in the DOM (hidden)
   so the delegated click handler can toggle it without rebuilding markup. */
.card-palette {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  display: flex;
  gap: 4px;
  padding: 5px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  box-shadow: 0 4px 16px var(--shadow);
  z-index: 7;
}

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

.card-swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid rgba(128, 128, 128, 0.45);
  padding: 0;
  cursor: pointer;
  transition: transform 0.1s;
}

.card-swatch:hover { transform: scale(1.15); }

.card-swatch[data-swatch="amber"]  { background: #c9a950; }
.card-swatch[data-swatch="rose"]   { background: #e07a8a; }
.card-swatch[data-swatch="sky"]    { background: #6aa9e0; }
.card-swatch[data-swatch="mint"]   { background: #6ec8aa; }
.card-swatch[data-swatch="violet"] { background: #a78bfa; }
.card-swatch[data-swatch="lime"]   { background: #a3d66c; }

/* "No colour": a hollow dot with a slash. */
.card-swatch-none {
  background:
    linear-gradient(45deg, transparent 44%, var(--muted) 44%, var(--muted) 56%, transparent 56%),
    var(--surface);
}

/* ---- hover action bar (edit / add child / delete) --------------------- */
.card-toolbar {
  position: absolute;
  top: 6px;
  right: 6px;
  display: none;
  gap: 3px;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  box-shadow: 0 2px 8px var(--shadow);
  z-index: 6;
}

/* Show on hover or when the card is selected; never while editing (the bar
   would overlap the text the user is typing). */
.card:hover > .card-toolbar,
.card.selected > .card-toolbar {
  display: flex;
}

.card-toolbar button {
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.12s, color 0.12s;
}

.card-toolbar button:hover {
  background: var(--accent-soft);
  color: var(--ink);
}

.card-toolbar button[data-act="del"]:hover {
  background: rgba(255, 90, 90, 0.18);
  color: #ff8585;
}

/* ---- debug overlay (C7, F3) -------------------------------------------- */
#debug-panel {
  position: absolute;
  right: 14px;
  bottom: 14px;
  min-width: 200px;
  padding: 10px 12px;
  background: var(--panel-bg);
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  box-shadow: 0 4px 16px var(--shadow);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  line-height: 1.55;
  color: var(--ink);
  white-space: pre;
  display: none;
  z-index: 20;
  pointer-events: none;
}

#debug-panel.visible {
  display: block;
}

.dbg-anchor {
  fill: none;
  stroke: var(--dbg-anchor);
  stroke-width: 1.6;
}

.dbg-anchor-line {
  stroke: var(--dbg-anchor);
  stroke-width: 1;
  stroke-dasharray: 4 4;
  opacity: 0.65;
}

.dbg-vel {
  stroke: var(--dbg-vel);
  stroke-width: 1.6;
}

.card-root {
  border-color: var(--root-border);
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
  padding-right: 28px; /* clear the hover action bar */
}

.card-note {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---- toolbar actions: 一键整洁 + 返回首页 + 导出 PDF + Guidance -------- */
/* #toolbar is pointer-events:none so the canvas stays draggable under it;
   the controls opt back in. */
#tidy-btn {
  pointer-events: auto;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-strong);
  background: var(--surface);
  border: 1px solid var(--accent-soft-ring);
  border-radius: 8px;
  padding: 6px 14px;
  cursor: pointer;
  transition: transform 90ms ease, background 120ms ease, box-shadow 120ms ease, color 120ms ease;
}

#tidy-btn:hover {
  background: var(--accent-soft-ring);
  color: var(--ink);
}

/* Press feedback: the button dips under the finger, then a short pulse when
   the tidy fires. This is what makes the press read as "it did something". */
#tidy-btn:active {
  transform: scale(0.93);
}

#tidy-btn.tidying {
  animation: tidy-pulse 750ms ease;
}

@keyframes tidy-pulse {
  0%   { transform: scale(0.93); box-shadow: 0 0 0 0 var(--accent-strong-ring); }
  40%  { transform: scale(1.03); box-shadow: 0 0 0 7px rgba(201, 169, 80, 0); }
  100% { transform: scale(1);    box-shadow: 0 0 0 0 rgba(201, 169, 80, 0); }
}

/* Quick "back to the library" right next to the main action; quiet by
   default so 一键整洁 stays the visually dominant button. */
#home-top-btn {
  pointer-events: auto;
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 6px 11px;
  cursor: pointer;
  transition: transform 90ms ease, background 120ms ease, color 120ms ease, border-color 120ms ease;
}

#home-top-btn:hover {
  color: var(--ink);
  border-color: var(--surface-border);
  background: var(--surface);
}

#home-top-btn:active { transform: scale(0.93); }

#guidance-btn {
  pointer-events: auto;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.3px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  transition: transform 90ms ease, background 120ms ease, color 120ms ease, border-color 120ms ease;
}

#guidance-btn:hover {
  color: var(--ink);
  border-color: var(--accent-soft-ring);
  background: var(--surface);
}

#guidance-btn:active {
  transform: scale(0.93);
}

/* Export PDF: a quiet, bordered tool sitting just LEFT of Guidance. The
   toolbar itself is pointer-events:none (so the canvas under it stays
   draggable), so every real control — including this one — must opt back in
   with pointer-events:auto, or clicks fall through and "do nothing". */
#export-pdf-btn {
  pointer-events: auto;
  margin-left: auto; /* push the export + Guidance pair to the far right */
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.3px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  transition: transform 90ms ease, background 120ms ease, color 120ms ease, border-color 120ms ease;
}

#export-pdf-btn:hover {
  color: var(--ink);
  border-color: var(--accent-soft-ring);
  background: var(--surface);
}

#export-pdf-btn:active {
  transform: scale(0.93);
}

/* ---- guidance: floating, blurred, modal help panel --------------------- */
/* z-index 25 = above the home library (20), below the name dialog (30). */
#guidance {
  position: absolute;
  inset: 0;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
}

#guidance[hidden] { display: none; }

/* The blur + dim that "虚化后面的图" and lock the board behind the panel. */
.guidance-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.42);
  -webkit-backdrop-filter: blur(8px) saturate(0.9);
  backdrop-filter: blur(8px) saturate(0.9);
}

[data-theme="light"] .guidance-backdrop {
  background: rgba(247, 245, 240, 0.42);
}

.guidance-inner {
  position: relative;
  width: min(560px, 100%);
  max-height: calc(100vh - 96px);
  overflow: auto;
  padding: 20px 22px 18px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 14px;
  box-shadow: 0 24px 70px var(--shadow-lift);
  animation: guidance-in 160ms ease;
}

@keyframes guidance-in {
  from { opacity: 0; transform: translateY(8px) scale(0.985); }
  to   { opacity: 1; transform: none; }
}

.guidance-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.guidance-head h2 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

#guidance-close {
  width: 26px;
  height: 26px;
  font: inherit;
  font-size: 13px;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  cursor: pointer;
  transition: transform 90ms ease, color 120ms ease, background 120ms ease;
}

#guidance-close:hover {
  color: var(--ink);
  background: var(--bg);
  border-color: var(--surface-border);
}

#guidance-close:active { transform: scale(0.9); }

.guidance-section { margin-bottom: 16px; }

.guidance-section h3 {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

/* Buttons inside the guidance panel share one quiet, tactile style. */
#guidance #home-btn,
#guidance #board-name,
.guidance-actions button {
  pointer-events: auto;
  width: auto;
  height: auto;
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  padding: 7px 13px;
  cursor: pointer;
  transition: transform 90ms ease, border-color 120ms ease, background 120ms ease, color 120ms ease;
}

#guidance #home-btn:hover,
#guidance #board-name:hover,
.guidance-actions button:hover {
  border-color: var(--accent-soft-ring);
  color: var(--accent-strong);
}

#guidance #home-btn:active,
#guidance #board-name:active,
.guidance-actions button:active {
  transform: scale(0.95);
}

#guidance #board-name {
  font-weight: 600;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.guide-list {
  list-style: none;
  display: grid;
  gap: 7px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted);
}

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

.guide-list kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  padding: 1px 5px;
  border: 1px solid var(--surface-border);
  border-radius: 5px;
  background: var(--bg);
  color: var(--ink);
}

.guidance-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--surface-border);
}

/* ---- home: the board library ------------------------------------------- */
#home {
  position: absolute;
  inset: 44px 0 0 0; /* below the toolbar, so the back arrow stays reachable */
  z-index: 20;
  background: var(--bg);
  overflow: auto;
  padding: 28px 32px 48px;
}
#home:not([hidden]) { display: block; }

.home-inner {
  max-width: 900px;
  margin: 0 auto;
}

.home-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.home-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}

#home-back {
  font: inherit;
  font-size: 13px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  padding: 7px 13px;
  cursor: pointer;
  transition: transform 90ms ease, border-color 120ms ease, color 120ms ease, background 120ms ease;
}

#home-back:hover {
  color: var(--ink);
  border-color: var(--accent-soft-ring);
}

#home-back:active { transform: scale(0.95); }

.home-head h1 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.home-sub {
  margin-top: 5px;
  font-size: 12px;
  color: var(--muted);
}

#new-board {
  flex: none;
  font: inherit;
  font-size: 13px;
  color: var(--accent-strong);
  background: transparent;
  border: 1px solid var(--accent-soft-ring);
  border-radius: 8px;
  padding: 7px 13px;
  cursor: pointer;
}

#new-board:hover {
  background: var(--accent-soft-ring);
  color: var(--ink);
}

#board-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}

.home-card {
  position: relative;
  padding: 14px 14px 40px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 120ms ease, transform 120ms ease;
}

.home-card:hover {
  border-color: var(--accent-soft-ring);
  transform: translateY(-1px);
}

.home-card.current {
  border-color: var(--accent-strong-ring);
  box-shadow: 0 0 0 1px var(--accent-soft-ring);
}

/* Pinned (favourites float to the top of the library): a warm left bar so the
   shortlist reads at a glance, without shouting over the "current" ring. */
.home-card.pinned {
  border-left: 3px solid var(--accent-soft);
  padding-left: 12px;
}

/* The favourite star: always visible (a starred board must read as starred
   without a hover), filled and gold when it is one, hollow and faint when it
   is not. It sits in the card's top-right corner, clear of the name. */
.home-star {
  position: absolute;
  top: 9px;
  right: 10px;
  padding: 2px 4px;
  font-size: 15px;
  line-height: 1;
  color: var(--muted);
  opacity: 0.45;
  background: none;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: color 120ms ease, opacity 120ms ease, transform 120ms ease;
}

.home-star:hover {
  opacity: 1;
  color: var(--accent-strong);
  transform: scale(1.15);
}

.home-card.pinned .home-star {
  opacity: 1;
  color: var(--accent-strong);
}

.home-card-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-right: 26px; /* keep the name clear of the favourite star */
}

.home-card-meta {
  margin-top: 5px;
  font-size: 11px;
  color: var(--muted);
}

.home-card-actions {
  position: absolute;
  left: 14px;
  bottom: 10px;
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity 120ms ease;
}

.home-card:hover .home-card-actions,
.home-card.current .home-card-actions {
  opacity: 1;
}

.home-card-actions button {
  font: inherit;
  font-size: 11px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--surface-border);
  border-radius: 6px;
  padding: 2px 8px;
  cursor: pointer;
}

.home-card-actions button:hover {
  color: var(--ink);
  border-color: var(--accent-soft-ring);
}

.home-empty {
  margin-top: 28px;
  font-size: 12px;
  color: var(--muted);
}

/* ---- dialog ------------------------------------------------------------ */
#dialog {
  position: absolute;
  inset: 0;
  z-index: 30;
  background: rgba(0, 0, 0, 0.45);
  align-items: center;
  justify-content: center;
}
#dialog:not([hidden]) { display: flex; }

.dialog-inner {
  width: 330px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 12px;
  box-shadow: 0 18px 50px var(--shadow-lift);
}

#dialog-label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}

#dialog-input {
  width: 100%;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
}

#dialog-input:focus {
  border-color: var(--accent-strong-ring);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.dialog-actions button {
  font: inherit;
  font-size: 13px;
  padding: 6px 14px;
  border-radius: 7px;
  cursor: pointer;
  border: 1px solid var(--surface-border);
  background: transparent;
  color: var(--muted);
}

.dialog-actions button:hover { color: var(--ink); }

#dialog-ok {
  border-color: var(--accent-soft-ring);
  color: var(--accent-strong);
}

#dialog-ok:hover {
  background: var(--accent-soft-ring);
  color: var(--ink);
}

/* ---- touch devices (phones / tablets) ---------------------------------- */
/* Hover does not exist here: the action bar appears on TAP (the card gets
   .selected), so its buttons must be finger-sized, not mouse-sized. */
@media (pointer: coarse) {
  .card-toolbar {
    gap: 4px;
    padding: 4px;
  }

  .card-toolbar button {
    width: 34px;
    height: 34px;
    font-size: 15px;
    border-radius: 8px;
  }

  /* Clear the (now bigger) action bar. */
  .card-title {
    padding-right: 46px;
  }

  /* Comfortable tap targets on the top bar. */
  #tidy-btn,
  #home-top-btn,
  #guidance-btn,
  #export-pdf-btn {
    padding: 9px 14px;
  }

  /* The favourite star must be a real tap target, not a 15px glyph. */
  .home-star {
    top: 4px;
    right: 6px;
    width: 34px;
    height: 34px;
    font-size: 19px;
    padding: 0;
    opacity: 0.7;
  }

  .home-card-name {
    padding-right: 38px;
  }
}

/* ---- narrow screens (phones in portrait) ------------------------------- */
@media (max-width: 720px) {
  #toolbar {
    height: 52px;
    padding: 0 10px;
    gap: 8px;
  }

  #tidy-btn { font-size: 12.5px; padding: 8px 12px; }
  #home-top-btn { font-size: 12px; padding: 8px 10px; }
  #guidance-btn { font-size: 12px; padding: 8px 10px; letter-spacing: 0; }
  #export-pdf-btn { font-size: 12px; padding: 8px 10px; letter-spacing: 0; }

  /* Cards must never be wider than the phone. */
  .card {
    width: min(250px, calc(100vw - 40px));
  }

  /* Guidance becomes a bottom sheet: thumb-reachable, safe-area aware. */
  #guidance {
    align-items: flex-end;
    padding: 10px;
  }

  .guidance-inner {
    width: 100%;
    max-height: 86dvh;
    border-radius: 16px 16px 0 0;
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
  }

  /* The library: one column, tighter gutters, stacked header. */
  #home {
    inset: 52px 0 0 0;
    padding: 18px 14px 40px;
  }

  .home-head {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .home-head-actions {
    justify-content: flex-end;
  }

  #board-list {
    grid-template-columns: 1fr;
  }

  .dialog-inner {
    width: calc(100vw - 28px);
  }

  #debug-panel {
    font-size: 10px;
    min-width: 160px;
  }
}

/* ==== brand, save status, web banner, canvas hint, toast ================= */
/* The toolbar keeps a `.brand` slot for the product name; it is non-interactive
   (the toolbar is pointer-events:none) so it never steals a canvas gesture. */
#toolbar .brand {
  margin-right: 2px;
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
}

/* Desktop only: a quiet "已保存" pulse after an auto-save lands. Empty by
   default (zero width) so it does not shift the toolbar. */
#save-status {
  font-size: 12px;
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.25s ease;
  white-space: nowrap;
}
#save-status.show {
  opacity: 1;
}

/* Web only: the browser keeps nothing, and this strip makes that impossible
   to miss. Fixed to the bottom so it never covers the top toolbar. */
#web-banner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 22;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px 14px;
  font-size: 12.5px;
  line-height: 1.35;
  color: var(--ink);
  background: var(--panel-bg);
  border-top: 1px solid var(--surface-border);
  box-shadow: 0 -4px 16px var(--shadow);
}
#web-banner[hidden] { display: none; }
.web-banner-text { flex: 0 1 auto; max-width: 720px; }
#web-banner-close {
  pointer-events: auto;
  font: inherit;
  line-height: 1;
  padding: 4px 9px;
  border-radius: 7px;
  border: 1px solid var(--surface-border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
#web-banner-close:hover { color: var(--ink); }

/* First-run / near-empty board hint: a faint pill above the web banner. */
#canvas-hint {
  position: fixed;
  left: 50%;
  bottom: 60px;
  transform: translateX(-50%);
  z-index: 15;
  max-width: calc(100vw - 32px);
  padding: 8px 14px;
  font-size: 12.5px;
  color: var(--muted);
  background: var(--panel-bg);
  border: 1px solid var(--surface-border);
  border-radius: 999px;
  box-shadow: 0 4px 16px var(--shadow);
  pointer-events: none;
  text-align: center;
  opacity: 0;
  transition: opacity 0.4s ease;
}
#canvas-hint.show { opacity: 1; }
#canvas-hint[hidden] { display: none; }

/* Ephemeral toast (web export confirmation, etc.). */
#toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%);
  z-index: 26;
  max-width: calc(100vw - 32px);
  padding: 9px 16px;
  font-size: 13px;
  color: var(--ink);
  background: var(--panel-bg);
  border: 1px solid var(--surface-border);
  border-radius: 10px;
  box-shadow: 0 6px 22px var(--shadow);
  pointer-events: none;
  text-align: center;
  opacity: 0;
  transition: opacity 0.25s ease;
}
#toast.show { opacity: 1; }
#toast[hidden] { display: none; }

/* Action button inside a toast (e.g. "撤销" after a delete). The toast itself
   is pointer-events:none so it never blocks the canvas; the button opts back in. */
.toast-action {
  pointer-events: auto;
  margin-left: 10px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 7px;
  border: 1px solid var(--accent-soft);
  background: var(--accent-soft);
  color: var(--ink);
  cursor: pointer;
}
.toast-action:hover { border-color: var(--accent-strong); }

/* ==== v0.10: fold toggle, side editor, library tools ===================== */

/* Fold badge, hanging just below the card's bottom-right corner so it never
   covers the title/note text. Only rendered when the card has children. */
.card-fold {
  position: absolute;
  right: 6px;
  bottom: -13px;
  z-index: 5;
  height: 21px;
  min-width: 34px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--surface-border);
  background: var(--surface);
  color: var(--muted);
  font: 600 11px/1 -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.card-fold:hover {
  color: var(--ink);
  border-color: var(--accent-soft);
  background: var(--accent-soft);
}
.card.collapsed > .card-fold {
  color: var(--accent-strong);
  border-color: var(--accent-strong);
}
/* A folded branch reads as "cut" at a glance. */
.card.collapsed {
  border-style: dashed;
}

/* ---- Obsidian-style side editor -------------------------------------------
   A docked right-hand panel. The canvas keeps its gestures (the panel only
   covers the right edge), and the card updates live as you type. */
#editor {
  position: fixed;
  top: 44px;
  right: 0;
  bottom: 0;
  width: 380px;
  max-width: 94vw;
  z-index: 18;
  display: flex;
  flex-direction: column;
  background: var(--panel-bg);
  border-left: 1px solid var(--surface-border);
  box-shadow: -8px 0 24px var(--shadow);
  transform: translateX(100%);
  transition: transform 0.22s ease;
  pointer-events: auto;
}
#editor.open { transform: translateX(0); }
#editor[hidden] { display: none; }

.editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--surface-border);
}
.editor-kicker {
  font-size: 11.5px;
  letter-spacing: 0.6px;
  color: var(--muted);
}
#editor-close {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  border: 1px solid var(--surface-border);
  background: transparent;
  color: var(--muted);
  font: inherit;
  line-height: 1;
  cursor: pointer;
}
#editor-close:hover { color: var(--ink); background: var(--accent-soft); }

.editor-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px;
  overflow: auto;
}
.editor-label {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}
#editor-title,
#editor-note {
  width: 100%;
  box-sizing: border-box;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 9px;
  padding: 9px 10px;
  outline: none;
}
#editor-title { font-size: 15px; font-weight: 600; }
#editor-note {
  flex: 1;
  min-height: 200px;
  resize: none;
  font-size: 14px;
  line-height: 1.65;
}
#editor-title:focus,
#editor-note:focus {
  border-color: var(--accent-soft);
  box-shadow: 0 0 0 2px var(--accent-soft-ring);
}
.editor-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 6px;
}
.editor-hint { font-size: 11.5px; color: var(--muted); }
#editor-delete {
  font: inherit;
  font-size: 12.5px;
  padding: 6px 11px;
  border-radius: 8px;
  border: 1px solid var(--surface-border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
#editor-delete:hover {
  color: #ff8585;
  border-color: rgba(255, 90, 90, 0.5);
  background: rgba(255, 90, 90, 0.12);
}

/* ---- library search + sort ------------------------------------------------ */
.home-tools {
  display: flex;
  gap: 10px;
  margin: 2px 0 18px;
}
#home-search {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 9px;
  padding: 9px 12px;
  outline: none;
}
#home-search:focus {
  border-color: var(--accent-soft);
  box-shadow: 0 0 0 2px var(--accent-soft-ring);
}
#home-sort {
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 9px;
  padding: 9px 10px;
  cursor: pointer;
  outline: none;
}

@media (max-width: 720px) {
  #editor {
    width: 100vw;
    max-width: 100vw;
  }
  .home-tools { flex-direction: column; }
  #editor-note { min-height: 150px; }
}
