/* 纸间 · 手账风界面。颜色只引用 tokens.css 里的变量。 */
html { -webkit-text-size-adjust: 100%; }
body { font-size: 16px; position: fixed; inset: 0; touch-action: manipulation; -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
#app { position: fixed; top: 0; left: 0; right: 0; height: var(--vvh, 100%); }
[hidden] { display: none !important; }
button { -webkit-user-select: none; user-select: none; touch-action: manipulation; }
.btn { font-size: 15px; flex: none; }
.input { font-size: 16px; width: 100%; -webkit-appearance: none; appearance: none; }
textarea.input { resize: none; }
.toast-host { top: calc(env(safe-area-inset-top) + 56px); }

/* 和纸胶带：色带 + 斜条纹 */
.tape-bg { background-image: repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.42) 0 4px, transparent 4px 10px); }

/* 页面：方格纸桌面 */
.view { position: absolute; inset: 0; display: none; flex-direction: column; padding-top: env(safe-area-inset-top);
  background-color: var(--bg); background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px); background-size: 22px 22px; }
.view.active { display: flex; animation: viewIn 0.28s var(--ease-out); }
#home.active { animation: none; }
@keyframes viewIn { from { opacity: 0; transform: translateX(24px); } }
.scroller { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }

/* 分段控件：选中的那格像贴了一块黄色便签 */
.seg { display: flex; background: var(--panel); border: 1.5px solid var(--ink); border-radius: 14px; padding: 3px; flex: 1; min-width: 0; }
.seg button { flex: 1; height: 32px; border: 0; background: transparent; border-radius: 10px; font-size: 14px; color: var(--text-2); white-space: nowrap; padding: 0 6px; transition: background 0.2s, color 0.2s; }
.seg button.on { background: var(--tape-butter); color: var(--text); font-weight: 700; }
:root[data-theme='dark'] .seg button.on { color: #fff; }

/* 首页 */
.home-head { display: flex; align-items: flex-start; justify-content: space-between; padding: 16px 12px 4px 22px; }
.home-title { position: relative; }
.home-title h1 { margin: 0; font-family: var(--font-title); font-size: 38px; font-weight: 400; line-height: 1.1; letter-spacing: 0.04em; }
.home-title .squiggle { display: block; width: 84px; height: 9px; margin-top: 2px; color: var(--primary); }
.home-title .spark { position: absolute; left: 86px; top: -2px; width: 22px; height: 22px; color: var(--tape-butter); transform: rotate(12deg); }
:root[data-theme='light'] .home-title .spark { color: #f0b84d; }
.home-sub { margin: 6px 0 0; font-size: 13px; color: var(--text-3); }
.home-tools { display: flex; flex-direction: column; gap: 10px; padding: 12px 16px 10px; }
.home-scroll { padding: 14px 18px calc(env(safe-area-inset-bottom) + 110px) 16px; }
.list { display: flex; flex-direction: column; gap: 20px; }
.list.card { display: grid; grid-template-columns: 1fr 1fr; gap: 20px 16px; align-items: start; }
.item { position: relative; background: var(--panel); border: 1.5px solid var(--ink); border-radius: var(--r-lg); box-shadow: 3px 4px 0 var(--tape-pink); transition: transform 0.2s var(--ease-out); cursor: pointer; }
.item:nth-child(4n + 2) { box-shadow: 3px 4px 0 var(--tape-sage); }
.item:nth-child(4n + 3) { box-shadow: 3px 4px 0 var(--tape-butter); }
.item:nth-child(4n) { box-shadow: 3px 4px 0 var(--tape-blue); }
.item:nth-child(odd) { transform: rotate(-0.5deg); }
.item:nth-child(even) { transform: rotate(0.4deg); }
.item:active { transform: scale(0.98); }
/* 每张卡片顶上贴一小段胶带 */
.item::before { content: ''; position: absolute; top: -9px; left: 24px; width: 60px; height: 17px; background-color: var(--tape-pink); opacity: 0.9; transform: rotate(-4deg); z-index: 1;
  background-image: repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.42) 0 4px, transparent 4px 10px); }
.item:nth-child(4n + 2)::before { background-color: var(--tape-sage); left: auto; right: 54px; transform: rotate(3deg); }
.item:nth-child(4n + 3)::before { background-color: var(--tape-butter); left: 44%; transform: rotate(-2deg); }
.item:nth-child(4n)::before { background-color: var(--tape-blue); left: 18px; transform: rotate(5deg); }
.item-article { display: flex; gap: 12px; padding: 18px 44px 14px 18px; min-height: 96px; }
.item-main { flex: 1; min-width: 0; }
.item-title { font-size: 18px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-text { margin-top: 4px; font-size: 14px; line-height: 1.55; color: var(--text-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.item-date { display: inline-block; margin-top: 9px; padding: 1px 9px; font-size: 11px; color: var(--primary); border: 1px dashed var(--primary); border-radius: 99px; font-variant-numeric: tabular-nums; }
.item-thumb { width: 66px; height: 66px; object-fit: cover; flex: none; align-self: center; padding: 4px; background: #fffdf9; box-shadow: 0 2px 6px rgba(74, 61, 51, 0.22); transform: rotate(3deg); }
.item-card { padding: 6px; }
.item-card img { display: block; width: 100%; height: auto; border-radius: 10px; }
.list.card .item::before { left: 50%; right: auto; margin-left: -26px; width: 52px; }
.item-more { position: absolute; top: 6px; right: 4px; width: 36px; height: 36px; border: 0; background: transparent; border-radius: 50%; color: var(--text-3); display: flex; align-items: center; justify-content: center; z-index: 2; }
.item-card .item-more { background: rgba(74, 61, 51, 0.5); color: #fff; width: 30px; height: 30px; top: 12px; right: 12px; }
.empty { text-align: center; padding: 56px 20px 0; }
.empty svg { width: 132px; height: 112px; color: var(--ink); }
.empty-title { margin: 10px 0 0; font-family: var(--font-title); font-size: 22px; }
.empty-sub { margin: 8px 0 0; font-size: 14px; color: var(--text-3); }
.tip { position: relative; display: flex; align-items: center; gap: 12px; background: var(--panel); border: 1.5px dashed var(--primary); border-radius: var(--r-lg); padding: 14px 14px 14px 16px; margin-bottom: 22px; }
.tip strong { font-size: 15px; }
.tip p { margin: 4px 0 0; font-size: 13px; line-height: 1.55; color: var(--text-2); }
.fab { position: absolute; right: 22px; bottom: calc(env(safe-area-inset-bottom) + 26px); width: 60px; height: 60px; border: 2px solid var(--ink); border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 0 var(--ink); transition: transform 0.12s, box-shadow 0.12s; }
.fab:active { transform: translateY(4px) rotate(90deg); box-shadow: 0 0 0 var(--ink); }

/* 顶栏 */
.bar { display: flex; align-items: center; gap: 10px; height: 54px; padding: 0 14px 3px 6px; flex: none; }
.bar-status { flex: 1; font-size: 13px; color: var(--text-3); text-align: right; padding-right: 4px; }
.bar-title { flex: 1; font-family: var(--font-title); font-size: 20px; }
.bar .back { color: var(--text); }

/* 稿纸：以下数值与 js/templates.js 的 BLOCK、js/render.js 的绘制保持一致 */
.paper-wrap { background: var(--canvas); display: flex; flex-direction: column; }
.paper { --fs: 16px; --p-bg: #fff; --p-text: #1d1d1f; --p-sub: #86868b; --p-accent: #1d1d1f; --p-line: #d2d2d7; --p-top: 40px; --p-padl: 28px;
  position: relative; flex: 1 0 auto; width: 100%; max-width: 480px; margin: 0 auto; padding: var(--p-top) 28px 48px var(--p-padl); background-color: var(--p-bg); color: var(--p-text);
  font-family: var(--p-font); font-size: var(--fs); letter-spacing: 0; }
.paper[data-dots] { background-image: radial-gradient(circle at center, var(--p-dot) 0.9px, transparent 1.1px); background-size: 18px 18px; }
.paper[data-grid] { background-image: linear-gradient(var(--p-grid) 1px, transparent 1px), linear-gradient(90deg, var(--p-grid) 1px, transparent 1px); background-size: 20px 20px; }
.paper[data-holes] { background-image: radial-gradient(circle at 18px 16px, var(--p-holes) 6px, transparent 6.5px), linear-gradient(90deg, transparent 36px, var(--p-margin) 36px, var(--p-margin) 37px, transparent 37px); background-size: 100% 32px, 100% 100%; }
.tape-top { display: none; position: absolute; top: 17px; left: 50%; width: 128px; height: 26px; margin-left: -64px; transform: rotate(-3deg); opacity: 0.88; background-color: var(--p-tape); pointer-events: none; }
.paper[data-tape] .tape-top { display: block; }
.sticker { position: absolute; top: 30px; right: 28px; width: 34px; height: 28px; pointer-events: none; }
.sticker svg { display: block; width: 34px; height: 28px; }
.head { margin-bottom: 28px; text-align: var(--p-align, left); }
.rule-top { display: none; height: 6px; border-top: 3px solid var(--p-accent); border-bottom: 1px solid var(--p-accent); margin-bottom: 18px; box-sizing: border-box; }
.paper[data-top-rule] .rule-top { display: block; }
#edTitle { display: block; width: 100%; border: 0; outline: 0; background: transparent; resize: none; overflow: hidden; padding: 0; margin: 0;
  font-family: inherit; font-size: calc(var(--fs) * 1.6); font-weight: 700; line-height: 1.35; color: inherit; text-align: inherit; letter-spacing: 0; border-radius: 0; }
#edTitle::placeholder { color: var(--p-sub); opacity: 0.6; }
.bar-deco { display: none; margin-top: 14px; background: var(--p-accent); }
.paper[data-bar] .bar-deco { display: block; }
.paper[data-align='center'] .bar-deco { margin-left: auto; margin-right: auto; }
.date { margin-top: 12px; font-size: 12px; line-height: 1.5; color: var(--p-sub); }
.date:empty { display: none; }
.paper[data-date='stamp'] .date { display: inline-block; padding: 3px 10px; border: 1px dashed var(--p-accent); border-radius: 99px; font-size: 11px; color: var(--p-accent); }
.paper[data-date='stamp'] .date:empty { display: none; }
.rule-bottom { display: none; margin-top: 18px; height: 1px; background: var(--p-line); }
.paper[data-bottom-rule] .rule-bottom { display: block; }
.paper[data-bottom-rule='short'] .rule-bottom { width: 48px; margin-left: auto; margin-right: auto; }

.body { position: relative; outline: 0; min-height: 40vh; line-height: 1.8; word-break: break-word; overflow-wrap: anywhere; -webkit-user-select: text; user-select: text; caret-color: var(--primary); }
.body.is-empty::before { content: attr(data-placeholder); position: absolute; left: 0; top: 0; color: var(--p-sub); opacity: 0.6; pointer-events: none; }
.body > * { margin: 0 0 calc(var(--fs) * 0.8); }
.body > :first-child { margin-top: 0 !important; }
.body h2 { font-size: 1.35em; line-height: 1.4; font-weight: 700; margin: calc(var(--fs) * 1.2) 0 calc(var(--fs) * 0.6); }
.body h3 { font-size: 1.15em; line-height: 1.5; font-weight: 700; margin: var(--fs) 0 calc(var(--fs) * 0.5); }
.body blockquote { font-size: 0.95em; line-height: 1.75; color: var(--p-sub); margin: 0 0 calc(var(--fs) * 0.85); padding-left: 14px; border-left: 3px solid var(--p-accent); }
.body ul, .body ol { padding-left: 1.4em; margin: 0 0 calc(var(--fs) * 0.55); }
.body li { margin: 0 0 calc(var(--fs) * 0.25); }
.body ul li::marker { color: var(--p-accent); }
.body hr { border: 0; height: 1px; width: 30%; background: var(--p-line); margin: calc(var(--fs) * 1.4) auto; }
.body figure { margin: 0 0 calc(var(--fs) * 0.9); -webkit-user-select: none; user-select: none; }
.body img { display: block; width: 100%; border-radius: 6px; }
.body b, .body strong { font-weight: 700; }
/* 手账版式的段落样式 */
.paper[data-h2='marker'] .body h2 { width: fit-content; max-width: 100%; background-image: linear-gradient(transparent 58%, var(--p-hl) 58%, var(--p-hl) 92%, transparent 92%); background-size: 100% 1.4em; }
.paper[data-h2='marker'] .body h2[style*='center'] { margin-left: auto; margin-right: auto; }
.paper[data-h2='marker'] .body h2[style*='right'] { margin-left: auto; }
.paper[data-quote='bubble'] .body blockquote { border-left: 0; color: var(--p-text); background: var(--p-quote); border-radius: 12px; padding: calc(var(--fs) * 0.6) calc(var(--fs) * 0.9); }
.paper[data-hr='dash'] .body hr { width: 100%; height: 0; background: none; border-top: 1.5px dashed var(--p-line); }
.paper[data-photo='polaroid'] .body figure { position: relative; margin: calc(var(--fs) * 0.5) 6px calc(var(--fs) * 1.2); padding: 8px; background: #fffdf9; box-shadow: 0 3px 12px rgba(74, 61, 51, 0.24); transform: rotate(-1.2deg); }
.paper[data-photo='polaroid'] .body figure:nth-of-type(even) { transform: rotate(1.2deg); }
.paper[data-photo='polaroid'] .body figure::before { content: ''; position: absolute; top: -8px; left: 50%; width: 56px; height: 16px; margin-left: -28px; transform: rotate(5deg); opacity: 0.88; background-color: var(--p-tape2);
  background-image: repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.42) 0 4px, transparent 4px 10px); }
.paper[data-photo='polaroid'] .body figure:nth-of-type(even)::before { transform: rotate(-4deg); }
.paper[data-photo='polaroid'] .body img { border-radius: 0; }

/* 工具栏：始终贴在键盘上方 */
.toolbar { flex: none; display: flex; align-items: center; justify-content: space-between; height: 50px; padding: 0 8px; background: var(--panel); border-top: 1.5px solid var(--ink); }
.toolbar button { flex: 1; max-width: 52px; height: 38px; border: 0; background: transparent; border-radius: 12px; color: var(--text-2); display: flex; align-items: center; justify-content: center; font-size: 18px; transition: background 0.15s, color 0.15s; }
.toolbar button:active { background: var(--hover); }
.toolbar button.on { background: var(--tape-butter); color: var(--text); }
:root[data-theme='dark'] .toolbar button.on { color: #fff; }
#editor:not(.typing) .toolbar { height: calc(50px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); }

/* 卡片编辑 */
.card-stage { flex: 1; min-height: 80px; display: flex; align-items: center; justify-content: center; padding: 12px 20px; overflow: hidden; }
#cdCanvas { border-radius: 3px; box-shadow: var(--shadow-lift); flex: none; }
.card-panel { flex: none; background: var(--panel); border-top: 1.5px solid var(--ink); border-radius: var(--r-xl) var(--r-xl) 0 0; padding: 14px 16px calc(env(safe-area-inset-bottom) + 14px); }
.pane { display: flex; flex-direction: column; gap: 12px; margin-top: 14px; min-height: 208px; }
.row { display: flex; align-items: center; gap: 12px; min-height: 36px; }
.row-label { width: 34px; flex: none; font-size: 14px; color: var(--text-2); }
.row-text { flex: 1; font-size: 15px; }
.row input[type='range'] { flex: 1; min-width: 0; height: 28px; }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; flex: 1; min-width: 0; padding: 1px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; white-space: nowrap; }
.swatches { display: flex; gap: 10px; overflow-x: auto; scrollbar-width: none; flex: 1; min-width: 0; padding: 5px 4px; }
.swatches::-webkit-scrollbar { display: none; }
.swatches button { flex: none; width: 28px; height: 28px; padding: 0; border: 1.5px solid var(--line-strong); border-radius: 50%; }
.swatches button.on { border-color: var(--ink); box-shadow: 0 0 0 2px var(--panel), 0 0 0 3.5px var(--ink); }

/* 导出预览 */
.export-scroll { background: var(--canvas); padding: 16px 24px 24px; }
#exImg { display: block; width: 100%; max-width: 420px; margin: 0 auto; border-radius: 3px; box-shadow: var(--shadow-lift); -webkit-touch-callout: default; }
.export-foot { flex: none; background: var(--panel); padding: 10px 16px calc(env(safe-area-inset-bottom) + 14px); border-top: 1.5px solid var(--ink); }
.export-foot p { margin: 0 0 10px; font-size: 12px; text-align: center; }
.export-actions { display: flex; gap: 10px; }
.export-actions .btn { flex: 1; height: 46px; font-size: 16px; }
.export-actions .btn-primary { flex: 1.6; }

/* 底部面板 */
.sheet-overlay { position: fixed; inset: 0; z-index: 2500; background: rgba(60, 45, 30, 0.32); display: flex; align-items: flex-end; justify-content: center; animation: fadeIn 0.18s ease-out; }
.sheet { width: 100%; max-width: 520px; max-height: 86%; overflow-y: auto; background: var(--panel); border: 1.5px solid var(--ink); border-bottom: 0; border-radius: var(--r-xl) var(--r-xl) 0 0; padding: 8px 18px calc(env(safe-area-inset-bottom) + 20px); display: flex; flex-direction: column; gap: 12px; animation: sheetUp 0.32s var(--ease-out); }
/* 样式面板不遮挡稿纸，改动能立刻看到 */
#styleSheet { background: transparent; }
#styleSheet .sheet { box-shadow: var(--shadow); }
@keyframes sheetUp { from { transform: translateY(100%); } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 0 2px 2px; font-family: var(--font-title); font-size: 22px; }
.sheet-label { width: fit-content; font-size: 13px; color: var(--text); margin-top: 6px; padding: 0 6px; background: linear-gradient(transparent 55%, var(--tape-butter) 55%); }
.sheet-note { margin: 0; font-size: 13px; line-height: 1.6; color: var(--text-2); }
.acct { display: flex; flex-direction: column; gap: 10px; }
.tpl-row { display: flex; gap: 12px; overflow-x: auto; scrollbar-width: none; margin: 0 -18px; padding: 10px 18px 8px; }
.tpl-row::-webkit-scrollbar { display: none; }
.tpl { flex: none; border: 0; background: transparent; padding: 0; display: flex; flex-direction: column; align-items: center; gap: 7px; font-size: 13px; color: var(--text-2); }
.tpl-thumb { position: relative; width: 74px; height: 96px; border-radius: 8px; padding: 18px 10px 10px; display: flex; flex-direction: column; gap: 6px; border: 1.5px solid var(--line-strong); }
.tpl-thumb i { display: block; height: 3px; border-radius: 2px; background: currentColor; opacity: 0.28; }
.tpl-thumb i:first-of-type { height: 6px; width: 60%; opacity: 0.9; margin-bottom: 2px; }
.tpl-thumb i.accent { height: 4px; width: 34%; opacity: 1; }
.tpl-thumb u { position: absolute; top: -6px; left: 50%; width: 34px; height: 11px; margin-left: -17px; transform: rotate(-4deg); opacity: 0.9; background-image: repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.42) 0 3px, transparent 3px 7px); }
.tpl-thumb[data-align='center'] { align-items: center; }
.tpl-thumb[data-align='center'] i:not(:first-of-type):not(.accent) { width: 100%; }
.tpl-thumb[data-align='left'] i:last-child { width: 70%; }
.tpl.on { color: var(--text); font-weight: 700; }
.tpl.on .tpl-thumb { border-color: var(--ink); box-shadow: 3px 3px 0 var(--primary); }
.switch { -webkit-appearance: none; appearance: none; width: 52px; height: 30px; border: 1.5px solid var(--ink); border-radius: 99px; background: var(--fill); position: relative; flex: none; margin: 0; transition: background 0.2s; }
.switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 23px; height: 23px; border-radius: 50%; background: var(--panel); border: 1.5px solid var(--ink); box-sizing: border-box; transition: transform 0.3s var(--spring); }
.switch:checked { background: var(--tape-sage); }
.switch:checked::after { transform: translateX(22px); }
.sheet.action { gap: 10px; padding-top: 18px; }
.action-title { text-align: center; font-size: 13px; color: var(--text-3); padding: 0 12px 4px; }
.action-title:empty { display: none; }
#actionItems { display: flex; flex-direction: column; gap: 10px; }
.sheet.action .btn { height: 48px; width: 100%; font-size: 16px; border-radius: 14px; }
.sheet.action .btn.danger { color: var(--danger); }
.action-cancel { background: var(--fill); margin-top: 2px; }

@media (min-width: 620px) {
  .paper { margin: 20px auto; min-height: 0; box-shadow: var(--shadow-card); }
  .home-scroll, .home-head, .home-tools { max-width: 620px; width: 100%; margin-left: auto; margin-right: auto; }
  .fab { right: calc(50% - 290px); }
  .sheet-overlay { align-items: center; }
  .sheet { border-radius: var(--r-xl); border-bottom: 1.5px solid var(--ink); }
  .card-panel { width: 100%; max-width: 520px; margin: 0 auto 20px; border: 1.5px solid var(--ink); border-radius: var(--r-xl); }
}
