:root {
  --paper: #F4F1EB;
  --paper-tint: #EBE7DF;
  --ink: #1C1A17;
  --ink-muted: #61594F;
  --ink-faint: #8C8578;
  --hairline: #BDB5A8;
  --grid-minor: #C7BDAD;
  --grid-major: #A89E8F;
  --wall: #25221E;
  --wall-fill: #D6CEC2;
  --dimension: #1F4E79;
  --leader: #405445;
  --accent: #B85C24;
  --selection: #BF611F;
  --danger: #A82E24;
  --toolbar: rgba(255, 255, 255, 0.94);
  --shadow: 0 4px 18px rgba(28, 26, 23, 0.08);
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  --mono: "SF Mono", ui-monospace, "Menlo", "Courier New", monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  overscroll-behavior: none;
  overflow: hidden;
}
body { min-height: 100dvh; }
button, input, textarea { font-family: inherit; color: inherit; }
button { cursor: pointer; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.sr-file { position: absolute; width: 0; height: 0; opacity: 0; pointer-events: none; }
.hidden { display: none !important; }

#app, .view { position: fixed; inset: 0; }
.view-list {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(var(--safe-top) + 16px) calc(16px + var(--safe-right)) calc(28px + var(--safe-bottom)) calc(16px + var(--safe-left));
  background:
    linear-gradient(180deg, var(--paper) 0%, var(--paper-tint) 100%);
}
.list-header { margin-bottom: 16px; }
.list-title-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.brand {
  margin: 0;
  font-family: "Songti SC", "STSong", "Noto Serif SC", "Source Han Serif SC", serif;
  font-size: 32px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.tagline { margin: 4px 0 0; font-size: 13px; color: var(--ink-muted); }
.search-box input {
  width: 100%;
  border: 1px solid var(--hairline);
  background: rgba(255,255,255,0.72);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 16px; /* iOS 不会强制放大 */
  outline: none;
}
.search-box input:focus { border-color: var(--ink-muted); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 14px;
  border: 0;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
}
.btn-ink { background: var(--ink); color: var(--paper); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-ghost {
  background: var(--paper-tint);
  color: var(--ink);
  border: 1px solid var(--hairline);
}
.btn-danger { background: transparent; color: var(--danger); }
.btn:disabled { opacity: 0.4; }
.btn-row { display: flex; flex-direction: column; gap: 10px; }

.board-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr));
  gap: 14px;
  padding-bottom: 24px;
}
.board-card {
  background: rgba(255,255,255,0.86);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  overflow: hidden;
  text-align: left;
  padding: 0;
  width: 100%;
  min-height: 0;
  display: block;
}
.board-thumb {
  height: 140px;
  background: var(--paper-tint);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}
.board-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.board-thumb .count {
  position: absolute;
  right: 8px; bottom: 8px;
  background: rgba(244,241,235,0.92);
  color: var(--ink-muted);
  font: 500 11px/1 var(--mono);
  padding: 4px 8px;
  border-radius: 6px;
}
.board-meta { padding: 11px 12px 12px; }
.board-meta h2 { margin: 0; font-size: 16px; font-weight: 600; }
.board-meta time { display: block; margin-top: 4px; font-size: 12px; color: var(--ink-faint); }
.board-card-actions {
  display: flex;
  border-top: 1px solid var(--hairline);
}
.board-card-actions button {
  flex: 1;
  min-height: 44px;
  background: transparent;
  border: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-muted);
}
.board-card-actions button.delete { color: var(--danger); }

.empty-state {
  text-align: center;
  padding: 48px 24px 24px;
}
.empty-mark {
  width: 140px; height: 96px; margin: 0 auto 16px;
  border: 2px solid var(--wall);
  border-bottom: 0;
  border-radius: 2px 2px 0 0;
  position: relative;
}
.empty-mark::after {
  content: "";
  position: absolute; left: 0; right: 0; top: -14px; height: 0;
  border-top: 1.5px solid var(--dimension);
}
.empty-title { margin: 0 0 8px; font-size: 18px; font-weight: 600; }
.empty-copy { margin: 0 0 18px; font-size: 14px; color: var(--ink-muted); }

/* Editor */
.view-editor { background: var(--paper); }
#board-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  display: block;
}
.editor-chrome {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  pointer-events: none;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}
.editor-chrome > * { pointer-events: auto; }
.editor-chrome .spacer { pointer-events: none; flex: 1; }

.top-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 0;
}
.top-actions { display: flex; gap: 6px; margin-left: auto; }
.icon-btn, .chip-btn {
  min-height: 40px;
  min-width: 40px;
  padding: 0 10px;
  border: 1px solid var(--hairline);
  background: var(--toolbar);
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  box-shadow: var(--shadow);
}
.icon-btn:disabled { opacity: 0.35; }
.icon-btn.small { min-height: 36px; font-size: 12px; }
.board-name {
  border: 0;
  background: transparent;
  font-size: 16px;
  font-weight: 600;
  max-width: 36vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 8px 4px;
  min-height: 40px;
}

.hint-bar {
  align-self: center;
  margin-top: 8px;
  max-width: calc(100% - 24px);
  background: rgba(244,241,235,0.94);
  color: var(--dimension);
  font: 500 12px/1.4 var(--mono);
  padding: 6px 12px;
  border-radius: 8px;
}
.chip-btn {
  align-self: center;
  margin-top: 8px;
  color: var(--accent);
  border-radius: 999px;
}
.annotate-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 16px 8px;
  padding: 10px 14px;
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
}
.annotate-banner button {
  border: 0;
  background: transparent;
  color: #fff;
  font-weight: 700;
  min-height: 36px;
  padding: 0 6px;
}

.inspector {
  margin: 0 12px 8px;
  padding: 8px 12px;
  background: var(--toolbar);
  border: 1px solid var(--hairline);
  border-radius: 12px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 13px;
}
.inspector .label { font-size: 11px; font-weight: 600; color: var(--ink-muted); }
.inspector .value { font: 600 14px/1 var(--mono); }
.inspector .link {
  border: 0; background: transparent;
  font-size: 13px; font-weight: 600; color: var(--accent);
  min-height: 36px; padding: 0 4px;
}
.inspector .del {
  margin-left: auto; border: 0; background: transparent;
  color: var(--danger); font-weight: 600; min-height: 36px; min-width: 36px;
}
.stepper { display: flex; align-items: center; gap: 4px; color: var(--ink-muted); }
.stepper button {
  width: 32px; height: 32px; border: 1px solid var(--hairline);
  background: #fff; border-radius: 8px; font-weight: 700;
}

.bottom-chrome {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 0 10px 10px;
}
.tool-rail {
  display: flex;
  gap: 2px;
  padding: 4px;
  background: var(--toolbar);
  border: 1px solid var(--hairline);
  border-radius: 14px;
  box-shadow: var(--shadow);
  flex: 1;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.tool-btn {
  flex: 1 0 auto;
  min-width: 48px;
  height: 52px;
  border: 0;
  background: transparent;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 10px;
  font-weight: 500;
  color: var(--ink);
}
.tool-btn .tool-icon { font-size: 16px; line-height: 1.2; }
.tool-btn.is-active { background: var(--ink); color: var(--paper); }
.zoom-cluster {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.zoom-label { font: 500 11px/1 var(--mono); color: var(--ink-muted); }

/* Sheets */
.sheet-root {
  position: fixed; inset: 0; z-index: 40;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-backdrop { position: absolute; inset: 0; background: rgba(28,26,23,0.35); }
.sheet {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: min(88dvh, 720px);
  background: var(--paper);
  border-radius: 18px 18px 0 0;
  padding: 8px 16px calc(16px + var(--safe-bottom));
  overflow: auto;
  box-shadow: 0 -8px 32px rgba(28,26,23,0.16);
}
.sheet-handle {
  width: 36px; height: 4px; border-radius: 2px;
  background: var(--hairline); margin: 4px auto 12px;
}
.sheet h3 { margin: 0 0 12px; font-size: 17px; text-align: center; }
.sheet p.help { margin: 0 0 14px; font-size: 13px; color: var(--ink-muted); text-align: center; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--ink-muted); margin-bottom: 6px; }
.field input, .field textarea, .field select {
  width: 100%;
  border: 1px solid var(--hairline);
  background: #fff;
  border-radius: 10px;
  padding: 12px;
  font-size: 16px;
  outline: none;
}
.field input.mono { font-family: var(--mono); font-size: 20px; }
.unit-row { display: flex; align-items: center; gap: 8px; }
.unit-row input { flex: 1; }
.seg {
  display: flex; background: var(--paper-tint); border-radius: 10px; padding: 3px; gap: 2px;
}
.seg button {
  flex: 1; min-height: 36px; border: 0; background: transparent;
  border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--ink-muted);
}
.seg button.is-on { background: #fff; color: var(--ink); box-shadow: var(--shadow); }
.toggle {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 0; font-size: 15px;
}
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); }
.sheet-actions { display: flex; gap: 10px; margin-top: 8px; }
.sheet-actions .btn { flex: 1; }

.toast {
  position: fixed;
  left: 50%; top: calc(var(--safe-top) + 72px);
  transform: translateX(-50%);
  z-index: 50;
  background: rgba(255,255,255,0.94);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow);
  max-width: 80vw;
}

@media (min-width: 700px) {
  .view-list { padding-left: 28px; padding-right: 28px; }
  .board-name { max-width: 240px; }
}
