/* CanvasMD — paper / notebook visual language.
   Kraft desk, cream notebook page with binding, sticky-note memos with tape,
   fountain-pen ink accents. Interaction patterns follow HIG; visuals do not. */

:root {
  --ink: #3a3127;
  --ink-soft: #6b5d4c;
  --ink-faint: #9a8b76;
  --accent: #2f5d8a;          /* fountain-pen blue */
  --accent-soft: rgba(47, 93, 138, .12);
  --danger: #b4442f;          /* red ink */
  --marker: #f3d36b;          /* highlighter */
  --paper: #fbf8f0;
  --paper-2: #f5efe1;
  --paper-3: #ece3cf;
  --line: #d9ccb2;
  --line-strong: #c5b393;
  --desk: #c8b08a;
  --shadow-1: 0 1px 2px rgba(60, 40, 15, .16), 0 2px 6px rgba(60, 40, 15, .10);
  --shadow-2: 0 2px 4px rgba(60, 40, 15, .14), 0 10px 26px rgba(60, 40, 15, .20);
  --radius: 6px;
  --ui-font: "Zen Maru Gothic", "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "BIZ UDPGothic", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  --title-font: "Shippori Mincho", "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", Georgia, serif;
  --mono: "JetBrains Mono", "Cascadia Code", Consolas, "SFMono-Regular", Menlo, monospace;
  --noise: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .25 0 0 0 0 .12 0 0 0 .07 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  --fiber: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.012 .35' numOctaves='2' seed='4'/%3E%3CfeColorMatrix values='0 0 0 0 .3 0 0 0 0 .2 0 0 0 0 .08 0 0 0 .10 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23f)'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--ui-font);
  font-size: 15px;
  color: var(--ink);
  background: var(--desk);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.ic { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
kbd { font-family: var(--mono); font-size: 11.5px; background: var(--paper); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 1px 6px; white-space: nowrap; }

.app { height: 100%; display: flex; flex-direction: column; }
.boot { margin: auto; font-family: var(--title-font); font-size: 28px; color: rgba(58, 49, 39, .5); letter-spacing: .1em; }
.fatal { margin: auto; max-width: 560px; background: var(--paper); padding: 24px 28px; border-radius: var(--radius); box-shadow: var(--shadow-2); }
.fatal pre { white-space: pre-wrap; color: var(--danger); }

/* ------------------------------------------------------------- toolbar */

.toolbar {
  position: relative; z-index: 30;
  display: flex; align-items: center; gap: 8px;
  height: 58px; padding: 0 10px;
  background: var(--paper-2) var(--noise);
  border-bottom: 1px solid var(--line-strong);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .6) inset, 0 3px 8px rgba(60, 40, 15, .12);
}
.toolbar::after { /* stitching */
  content: ""; position: absolute; left: 0; right: 0; bottom: 4px; height: 0;
  border-bottom: 1.5px dashed rgba(150, 125, 90, .35);
  pointer-events: none;
}
.tb-group { display: flex; align-items: center; gap: 2px; min-width: 0; }
.tb-left { flex: 1 1 0; min-width: 0; overflow: hidden; }
.tb-right { flex: 1 0 auto; }
.tb-center { flex: none; }
.tb-right { justify-content: flex-end; }
.tb-center { justify-content: center; }
.tb-sep { width: 1px; height: 22px; background: var(--line); margin: 0 6px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  min-width: 38px; height: 38px; padding: 0 7px;
  border: 0; background: transparent; border-radius: 6px; color: var(--ink-soft);
  transition: background .12s, color .12s;
}
.icon-btn:hover:not(:disabled) { background: rgba(243, 211, 107, .45); color: var(--ink); }
.icon-btn:active:not(:disabled) { background: rgba(243, 211, 107, .8); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn.on { color: var(--accent); background: var(--accent-soft); }

.ws-btn {
  display: inline-flex; align-items: center; gap: 7px; height: 40px; padding: 0 10px; margin-left: 4px;
  border: 1px solid transparent; background: transparent; border-radius: 6px; max-width: 280px;
}
.ws-btn:hover { background: rgba(255, 255, 255, .55); border-color: var(--line); }
.ws-name { font-family: var(--title-font); font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.page-label {
  display: inline-flex; align-items: baseline; gap: 10px; height: 40px; padding: 0 16px;
  background: #fffdf7; border: 1px solid var(--line); border-radius: 4px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .8) inset, 0 1px 2px rgba(60, 40, 15, .1);
  min-width: 180px; justify-content: center; line-height: 38px; font-size: 15px;
}
.page-label:hover { border-color: var(--line-strong); }
.pl-name { font-family: var(--title-font); font-weight: 700; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl-num { font-size: 12px; color: var(--ink-faint); font-variant-numeric: tabular-nums; }
.zoom-label { border: 1px solid var(--line); background: #fffdf7; min-width: 64px; height: 30px; padding: 0 10px; border-radius: 15px; color: var(--ink); font-variant-numeric: tabular-nums; font-size: 14px; font-weight: 700; }
.zoom-label:hover { background: rgba(243, 211, 107, .45); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 16px;
  background: #fffdf7; color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: 5px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .9) inset, 0 1px 1px rgba(60, 40, 15, .12);
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: #fff8e2; }
.btn:active:not(:disabled) { transform: translateY(1px); box-shadow: none; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: #234a70; color: #fdfaf2; box-shadow: 0 1px 0 rgba(255, 255, 255, .25) inset, 0 1px 2px rgba(20, 40, 70, .3); }
.btn.primary:hover:not(:disabled) { background: #356a9c; }
.btn.destructive { color: var(--danger); border-color: rgba(180, 68, 47, .5); }
.btn.destructive:hover:not(:disabled) { background: #fbeae4; }
.btn.small { height: 30px; padding: 0 12px; font-size: 14px; }
.btn.new-memo { height: 38px; font-size: 15px; margin-right: 4px; background: var(--marker); border-color: #d6b54c; font-weight: 700; }
.btn.new-memo:hover { background: #f7dc80; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.linkish { border: 0; background: none; color: var(--accent); text-decoration: underline; padding: 0 4px; }
.linkish.dim { color: var(--ink-faint); text-decoration: none; }

/* ------------------------------------------------------------- layout */

.main { flex: 1; display: flex; min-height: 0; position: relative; }
.desk-wrap { flex: 1; position: relative; min-width: 0; }
.desk {
  position: absolute; inset: 0; overflow: auto;
  background-color: var(--desk);
  background-image: var(--noise), var(--fiber), radial-gradient(ellipse at 50% 40%, rgba(255, 245, 220, .35), rgba(90, 60, 20, .15));
  outline: none;
}
.desk.drop-target { box-shadow: inset 0 0 0 3px var(--accent); }
.stage { overflow: clip; min-width: 100%; min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 56px 72px; position: relative; width: max-content; height: max-content; }
.page-holder { position: relative; flex: none; }

/* notebook binding */
.page-holder::before {
  content: ""; position: absolute; left: -18px; top: 18px; bottom: 18px; width: 28px; z-index: 3; pointer-events: none;
  background:
    radial-gradient(circle at 14px 50%, #6f5a3e 0 4.2px, transparent 5px) 0 0 / 28px 34px repeat-y,
    radial-gradient(ellipse at 14px 50%, rgba(255, 255, 255, .0) 0 9px, transparent 10px) 0 0 / 28px 34px repeat-y;
  filter: drop-shadow(0 1px 0 rgba(255, 255, 255, .25));
}
.page-holder::after { /* stacked sheets underneath */
  content: ""; position: absolute; inset: 0; z-index: -1; border-radius: 2px 6px 6px 2px;
  background: #efe7d4;
  box-shadow: 3px 3px 0 -1px #ebe2cd, 3px 3px 0 0 #d8cbb0, 6px 6px 0 -1px #e7dcc4, 6px 6px 0 0 #d1c3a5, 0 18px 40px rgba(50, 30, 10, .35);
}

.page {
  position: absolute; left: 0; top: 0; transform-origin: 0 0;
  background-color: var(--page-bg, var(--paper));
  background-image: var(--noise);
  border-radius: 2px 5px 5px 2px;
  box-shadow: 0 0 0 1px rgba(120, 95, 60, .18), 0 1px 3px rgba(60, 40, 15, .2);
  isolation: isolate; overflow: hidden;
  user-select: none;
}
.page[data-paper="kraft"] { background-image: var(--noise), var(--fiber); filter: sepia(.05); }
.page[data-paper="graph"] { background-image: var(--noise), linear-gradient(rgba(110, 160, 190, .22) 1px, transparent 1px), linear-gradient(90deg, rgba(110, 160, 190, .22) 1px, transparent 1px); background-size: auto, 20px 20px, 20px 20px; }
.page[data-paper="notebook"] { background-image: var(--noise), linear-gradient(90deg, transparent 63px, rgba(220, 120, 110, .5) 63px 65px, transparent 65px), linear-gradient(transparent 31px, rgba(130, 170, 200, .35) 31px 32px); background-size: auto, auto, 100% 32px; }
.page.locked .lock-badge { display: flex; }
.lock-badge { display: none; position: absolute; right: 14px; top: 12px; z-index: 99998; align-items: center; gap: 5px; padding: 3px 10px; font-size: 12px; color: var(--ink-soft); background: rgba(255, 253, 247, .9); border: 1px solid var(--line); border-radius: 20px; pointer-events: none; }

.page-grid { position: absolute; inset: 0; pointer-events: none; z-index: 0; }
.page-grid[data-style="dot"] { background-image: radial-gradient(circle, rgba(110, 90, 60, .32) 1px, transparent 1.4px); background-size: var(--grid) var(--grid); background-position: calc(var(--grid) / -2) calc(var(--grid) / -2); }
.page-grid[data-style="line"] { background-image: linear-gradient(rgba(110, 90, 60, .12) 1px, transparent 1px), linear-gradient(90deg, rgba(110, 90, 60, .12) 1px, transparent 1px); background-size: var(--grid) var(--grid); }
.memo-layer { position: absolute; inset: 0; z-index: 1; }
.page-overlay { position: absolute; inset: 0; z-index: 99990; pointer-events: none; }
.page-overlay > * { pointer-events: auto; }

/* page-turn edges */
.page-edge { position: absolute; top: 0; bottom: 0; width: 26px; z-index: 5; cursor: grab; }
.edge-right { right: -12px; }
.edge-left { left: -12px; }
.page-edge::after { /* dog-ear hint */
  content: ""; position: absolute; bottom: 0; width: 0; height: 0; opacity: 0; transition: opacity .15s, border-width .15s;
}
.edge-right::after { right: 12px; border-left: 0 solid transparent; border-bottom: 0 solid transparent; background: linear-gradient(225deg, transparent 50%, #e9dfca 50%); }
.edge-right:hover::after, .edge-left:hover::after { opacity: 1; width: 26px; height: 26px; box-shadow: -2px -2px 4px rgba(0, 0, 0, .12); }
.edge-left::after { left: 12px; background: linear-gradient(135deg, transparent 50%, #e9dfca 50%); }
.page-edge:hover { background: linear-gradient(90deg, transparent, rgba(255, 250, 235, .25), transparent); }
body.turning, body.turning * { cursor: grabbing !important; user-select: none !important; }
body.dragging iframe, body.turning iframe { pointer-events: none; }
body.dragging { cursor: grabbing; }

.turn-layer { position: absolute; left: 0; top: 0; transform-origin: 0 0; z-index: 20; pointer-events: none; }
.turn-shade { position: absolute; inset: 0; pointer-events: none; }
.turn-flap-wrap { position: absolute; inset: 0; filter: drop-shadow(-4px 4px 10px rgba(40, 25, 10, .35)); }
.turn-flap { position: absolute; left: 0; top: 0; transform-origin: 0 0; background-color: #efe7d6; }
.turn-flap::before { content: ""; position: absolute; inset: 0; background-image: var(--noise), var(--fiber); opacity: .9; }
.slide-layer { position: absolute; inset: 0; pointer-events: none; z-index: 20; }
.slide-page { position: absolute; overflow: visible; }
.slide-page > .page { box-shadow: 0 0 0 1px rgba(120, 95, 60, .18), 0 12px 30px rgba(50, 30, 10, .3); }
.static-page { position: absolute; left: 0; top: 0; transform-origin: 0 0; }

/* ----------------------------------------------------------------- memo */

.memo {
  position: absolute; display: flex; flex-direction: column;
  border-radius: 2px 2px 3px 3px;
  box-shadow: 0 1px 1px rgba(60, 40, 15, .18), 0 3px 8px rgba(60, 40, 15, .14);
  color: var(--memo-fg);
  font-family: var(--memo-font);
  outline: none;
  contain: layout style;
}
.memo::after { /* paper curl shadow */
  content: ""; position: absolute; right: 6px; bottom: 4px; width: 46%; height: 18px; z-index: -1;
  box-shadow: 4px 8px 12px rgba(50, 30, 10, .28); transform: rotate(3deg); pointer-events: none;
}
.memo-bg { position: absolute; inset: 0; background-color: var(--memo-bg); background-image: var(--noise); border-radius: inherit; }
.memo-img { position: absolute; inset: 0; border-radius: inherit; pointer-events: none; }
.memo-overlay { position: absolute; inset: 0; background: var(--memo-bg); opacity: 0; pointer-events: none; border-radius: inherit; }
.memo.selected { box-shadow: 0 0 0 1.5px var(--accent), 0 0 0 4px rgba(47, 93, 138, .15), 0 6px 18px rgba(60, 40, 15, .22); }
.memo.selected .memo-head { opacity: 1; }
.memo.pulse { animation: pulse 1.1s ease; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 1.5px var(--accent); } 40% { box-shadow: 0 0 0 8px rgba(243, 211, 107, .8); } }
.memo.detaching { opacity: .55; box-shadow: 0 0 0 2px dashed var(--accent); outline: 2px dashed var(--accent); }
.memo.stack-hidden { display: none; }
.memo.stack-top::before { /* deck edges */
  content: attr(data-count) "枚"; position: absolute; right: -6px; top: -10px; z-index: 5;
  background: var(--accent); color: #fdfaf2; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 10px;
  font-family: var(--ui-font);
}
.memo.stack-top { box-shadow: 4px 4px 0 -1px #f3eddc, 4px 4px 0 0 rgba(120, 95, 60, .3), 8px 8px 0 -1px #ede5d0, 8px 8px 0 0 rgba(120, 95, 60, .25), 0 6px 16px rgba(60, 40, 15, .2); }
.memo.stack-top.selected { box-shadow: 4px 4px 0 -1px #f3eddc, 4px 4px 0 0 rgba(120, 95, 60, .3), 8px 8px 0 -1px #ede5d0, 8px 8px 0 0 rgba(120, 95, 60, .25), 0 0 0 1.5px var(--accent); }
.memo.light::after { display: none; }

.memo-head {
  position: relative; z-index: 2; flex: none;
  display: flex; align-items: center; gap: 4px; height: 30px; padding: 0 4px 0 8px;
  cursor: grab; touch-action: none;
  font-family: var(--ui-font); font-size: 13px; color: color-mix(in srgb, var(--memo-fg) 70%, transparent);
  background: color-mix(in srgb, var(--memo-bg) 80%, #8a7350 20%);
  background-image: linear-gradient(rgba(255, 255, 255, .25), rgba(255, 255, 255, 0));
  border-radius: 2px 2px 0 0;
  opacity: .9;
}
.memo-head::before { /* washi tape */
  content: ""; position: absolute; left: 50%; top: -9px; width: 64px; height: 18px; transform: translateX(-50%) rotate(-2deg);
  background: rgba(240, 220, 160, .55); background-image: repeating-linear-gradient(90deg, rgba(255, 255, 255, .25) 0 4px, transparent 4px 8px);
  box-shadow: 0 1px 1px rgba(60, 40, 15, .12); pointer-events: none;
  clip-path: polygon(3% 0, 97% 4%, 100% 50%, 96% 100%, 2% 96%, 0 50%);
}
.memo-browser .memo-head::before { background-color: rgba(170, 200, 220, .55); }
.memo-grip { width: 10px; height: 12px; flex: none; opacity: .5; background: radial-gradient(circle, currentColor 1px, transparent 1.3px) 0 0 / 4px 4px; }
.memo-title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 700; }
.memo-badges { display: flex; gap: 2px; }
.memo-head-btns { display: flex; gap: 0; opacity: 0; transition: opacity .12s; }
.memo:hover .memo-head-btns, .memo.selected .memo-head-btns, .memo-head-btns:focus-within { opacity: 1; }
.head-btn { min-width: 28px; height: 26px; padding: 0 4px; color: inherit; }
.head-btn:hover { background: rgba(255, 255, 255, .45) !important; }
body.dragging .memo-head { cursor: grabbing; }
.in-group .memo-head { border-bottom: 1.5px dashed color-mix(in srgb, var(--accent) 50%, transparent); }

.memo-body { position: relative; z-index: 1; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.memo-scroll { flex: 1; overflow: auto; min-height: 0; scrollbar-width: thin; scrollbar-color: rgba(100, 80, 50, .3) transparent; }
.mode-source .memo-scroll { display: none; }
.md-source { display: none; }
.mode-source .md-source {
  display: block; flex: 1; width: 100%; resize: none; border: 0; outline: none; padding: 6px 12px 12px;
  background: transparent; color: var(--memo-fg); font-family: var(--mono); font-size: calc(var(--memo-fs) * .88);
  line-height: calc(var(--memo-fs) * .88 * var(--lh)); user-select: text; -webkit-user-select: text;
}
.memo.ruled.mode-source .md-source {
  background-image: linear-gradient(to top, var(--rule-c) var(--rule-w), transparent var(--rule-w));
  background-size: 100% calc(var(--memo-fs) * .88 * var(--lh)); background-position: 0 6px; background-attachment: local;
}
.resize-cursor * { cursor: inherit !important; }

/* resize handles */
.rz { position: absolute; z-index: 4; }
.rz-n, .rz-s { left: 8px; right: 8px; height: 7px; cursor: ns-resize; }
.rz-n { top: -3px; } .rz-s { bottom: -3px; }
.rz-e, .rz-w { top: 8px; bottom: 8px; width: 7px; cursor: ew-resize; }
.rz-e { right: -3px; } .rz-w { left: -3px; }
.rz-ne, .rz-nw, .rz-se, .rz-sw { width: 12px; height: 12px; }
.rz-ne { right: -4px; top: -4px; cursor: nesw-resize; } .rz-sw { left: -4px; bottom: -4px; cursor: nesw-resize; }
.rz-nw { left: -4px; top: -4px; cursor: nwse-resize; } .rz-se { right: -4px; bottom: -4px; cursor: nwse-resize; }
.memo.selected .rz-se::after { content: ""; position: absolute; right: 5px; bottom: 5px; width: 8px; height: 8px; border-right: 2px solid var(--accent); border-bottom: 2px solid var(--accent); opacity: .7; }
.page.locked .rz, .static-page .rz { display: none; }
.page.locked .memo-head { cursor: default; }

/* ------------------------------------------------------- live editor */

.md-editor {
  min-height: 100%; display: flex; flex-direction: column;
  padding: 4px 12px 0; outline: none;
  font-size: var(--memo-fs); line-height: calc(1em * var(--lh));
  white-space: pre-wrap; overflow-wrap: anywhere; word-break: normal;
  user-select: text; -webkit-user-select: text; cursor: text;
  caret-color: var(--accent);
  tab-size: 4;
}
.md-editor.readonly { cursor: default; }
.contrast-aid .md-editor, .contrast-aid .md-source { text-shadow: 0 0 2px var(--memo-bg), 0 0 4px var(--memo-bg), 0 0 1px var(--memo-bg); }
.ln { position: relative; min-height: calc(1em * var(--lh)); line-height: calc(1em * var(--lh)); padding: 0; margin: 0; }
.memo.ruled .ln:not(.k-code):not(.k-fence):not(.tbl-hidden),
.memo.ruled .rule-fill {
  background-image: linear-gradient(to top, var(--rule-c) var(--rule-w), transparent var(--rule-w));
  background-size: 100% calc(1em * var(--lh));
}
.memo.ruled.rule-fixed .ln:not(.sized):not(.k-heading):not(.k-code):not(.k-fence) { line-height: var(--sp); min-height: var(--sp); background-size: 100% var(--sp); }
.memo.ruled.rule-fixed .rule-fill { background-size: 100% var(--sp); }
.rule-fill { flex: 1; min-height: calc(1em * var(--lh) * 2); user-select: none; }
.ln .mk { color: color-mix(in srgb, var(--memo-fg) 40%, transparent); font-weight: normal; font-style: normal; }
.ln:not(.active) .mk { display: none; }
.ln.k-heading { font-weight: 700; font-family: var(--title-font); }
.memo .ln.k-heading { font-family: inherit; }
.ln.h1 { letter-spacing: .01em; }
.ln.k-quote { border-left: 3px solid color-mix(in srgb, var(--memo-fg) 30%, transparent); padding-left: 10px; color: color-mix(in srgb, var(--memo-fg) 78%, transparent); font-style: italic; }
.ln.k-hr:not(.active)::after { content: ""; position: absolute; left: 0; right: 0; top: 50%; border-top: 1.5px solid color-mix(in srgb, var(--memo-fg) 35%, transparent); }
.ln.k-hr:not(.active) { color: transparent; }
.ln.k-code, .ln.k-fence { font-family: var(--mono); font-size: .86em; background: rgba(60, 45, 25, .07); padding: 0 8px; margin: 0 -4px; }
.ln.k-fence:not(.active) { color: color-mix(in srgb, var(--memo-fg) 40%, transparent); }
.ln.k-fence:not(.active) .mk { display: inline; font-size: .85em; }
.ln.k-mathblock, .math { font-family: "Cambria Math", "STIX Two Math", "Times New Roman", serif; font-style: italic; }
.ln.k-mathblock { text-align: center; }
.ln.k-mathfence:not(.active) { font-size: .7em; color: transparent; }
.ln.k-table { font-family: var(--mono); font-size: .88em; }
.ln.tbl-hidden { display: none; }
.tbl-widget { margin: 4px 0; cursor: text; overflow-x: auto; }
.tbl-widget table, .md-render table { border-collapse: collapse; font-size: .92em; }
.tbl-widget th, .tbl-widget td, .md-render th, .md-render td { border: 1px solid color-mix(in srgb, var(--memo-fg, #3a3127) 25%, transparent); padding: 2px 8px; }
.tbl-widget th, .md-render th { background: rgba(60, 45, 25, .06); }
.bullet { display: inline-block; width: 1.1em; }
.bullet::before { content: "•"; color: color-mix(in srgb, var(--memo-fg) 65%, transparent); }
.ln.active .bullet { display: none; }
.ol-num { color: color-mix(in srgb, var(--memo-fg) 70%, transparent); font-variant-numeric: tabular-nums; }
.cb {
  display: inline-block; width: .95em; height: .95em; margin: 0 .35em 0 0; vertical-align: -.12em;
  border: 1.5px solid color-mix(in srgb, var(--memo-fg) 55%, transparent); border-radius: 3px; cursor: pointer; background: rgba(255, 255, 255, .4);
}
.cb.on { background: var(--accent); border-color: var(--accent); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3.5 8.5l3 3l6-7' fill='none' stroke='%23fff' stroke-width='2.2' stroke-linecap='round'/%3E%3C/svg%3E"); }
.ln.done:not(.active) { color: color-mix(in srgb, var(--memo-fg) 50%, transparent); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--memo-fg) 35%, transparent); }

code.icode { font-size: .88em; background: rgba(60, 45, 25, .09); border-radius: 3px; padding: 0 .25em; }
.ln a.lnk, .ln a.memolink, .md-render a { color: var(--accent); text-decoration: underline; text-decoration-color: rgba(47, 93, 138, .4); text-underline-offset: 2px; cursor: pointer; }
.ln a.memolink { background: rgba(243, 211, 107, .35); border-radius: 3px; text-decoration: none; padding: 0 2px; }
.dark-paper .ln a.lnk, .dark-paper .md-render a { color: #9cc6ef; }
.inline-img { max-width: 100%; max-height: 160px; display: block; margin: 2px 0; border-radius: 2px; }
.ln:not(.active) .img-alt { display: none; }
.tk-k { color: #8a3d6b; font-weight: 600; } .tk-s { color: #3c7a3a; } .tk-c { color: #8f8574; font-style: italic; } .tk-n { color: #a35a12; }
.dark-paper .tk-k { color: #e7a0cf; } .dark-paper .tk-s { color: #a8d8a0; } .dark-paper .tk-n { color: #f0b070; }

/* -------------------------------------------------------- browser memo */

.bm-bar { display: flex; align-items: center; gap: 1px; padding: 3px 4px; background: rgba(255, 255, 255, .55); border-bottom: 1px solid rgba(120, 95, 60, .2); flex: none; font-family: var(--ui-font); }
.bm-btn { min-width: 30px; height: 30px; padding: 0 5px; }
.bm-url { flex: 1; min-width: 40px; height: 30px; border: 1px solid var(--line); border-radius: 15px; background: #fffdf7; padding: 0 10px; font-size: 13.5px; outline: none; user-select: text; }
.bm-url:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.bm-zoom-val { border: 0; background: none; font-size: 11px; color: var(--ink-soft); min-width: 38px; height: 24px; border-radius: 4px; font-variant-numeric: tabular-nums; }
.bm-zoom-val:hover { background: rgba(243, 211, 107, .45); }
.memo-browser .memo-body { background: #fff; }
.bm-view { position: relative; flex: 1; min-height: 0; overflow: hidden; background: #fff; }
.bm-frame { position: absolute; left: 0; top: 0; border: 0; transform-origin: 0 0; background: #fff; }
.bm-loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--ink-faint); background: rgba(251, 248, 240, .85); font-size: 12px; pointer-events: none; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.bm-empty, .bm-placeholder { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center; padding: 16px; color: var(--ink-soft); background: var(--paper) var(--noise); font-family: var(--ui-font); font-size: 12.5px; }
.bm-empty p { margin: 0; }
.bm-quick { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.bm-err-title { font-weight: 700; color: var(--ink); }
.bm-err-reason { font-size: 11px; color: var(--ink-faint); max-width: 90%; word-break: break-all; }
.bm-err-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.bm-placeholder { word-break: break-all; font-size: 11px; }
.bm-status { display: none; }
.bm-status.show { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; padding: 4px 8px; font-size: 11px; color: var(--ink-soft); background: #fff8e2; border-top: 1px solid var(--line); font-family: var(--ui-font); }

/* ------------------------------------------------------ page chrome UI */

.marquee { position: absolute; border: 1.5px dashed var(--accent); background: rgba(47, 93, 138, .07); pointer-events: none !important; }
.guide { position: absolute; pointer-events: none !important; }
.guide.v { top: 0; bottom: 0; width: 0; border-left: 1px dashed #d0573d; }
.guide.h { left: 0; right: 0; height: 0; border-top: 1px dashed #d0573d; }
.guides { position: absolute; inset: 0; pointer-events: none !important; }
.group-frame { position: absolute; border: 1.5px dashed var(--accent); border-radius: 6px; pointer-events: none !important; }
.group-label { position: absolute; left: 6px; top: -22px; display: flex; align-items: center; gap: 4px; padding: 1px 8px; font-size: 11px; color: var(--accent); background: rgba(255, 253, 247, .95); border: 1px solid rgba(47, 93, 138, .35); border-radius: 10px; }
.group-rz { position: absolute; right: -7px; bottom: -7px; width: 14px; height: 14px; background: #fffdf7; border: 2px solid var(--accent); border-radius: 3px; cursor: nwse-resize; pointer-events: auto; }
.stack-tab {
  position: absolute; display: flex; align-items: center; gap: 5px; height: 24px; padding: 0 4px 0 8px;
  font-size: 11.5px; color: var(--ink-soft); background: #f6efdc; border: 1px solid var(--line-strong); border-bottom: 0;
  border-radius: 7px 7px 0 0; cursor: grab; white-space: nowrap; box-shadow: 0 -1px 2px rgba(60, 40, 15, .08);
}
.stack-tab.selected { color: var(--accent); border-color: rgba(47, 93, 138, .5); }
.tab-btn { border: 0; background: transparent; border-radius: 4px; padding: 0 6px; height: 24px; font-size: 13px; color: inherit; }
.tab-btn:hover { background: rgba(243, 211, 107, .5); }
.ghost {
  position: absolute; border: 2px dashed rgba(120, 95, 60, .45); border-radius: 4px; background: rgba(255, 253, 245, .35);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 8px; text-align: center;
}
.ghost-label { display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--ink-soft); font-size: 12px; max-width: 100%; }
.ghost-label span { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.ghost-label small { color: var(--ink-faint); }
.ghost-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }

.save-state { position: absolute; left: 12px; bottom: 10px; font-size: 13px; color: rgba(58, 49, 39, .65); padding: 2px 9px; border-radius: 10px; background: rgba(255, 250, 235, .55); transition: opacity .3s; pointer-events: none; }
.save-state[data-state="idle"], .save-state:not([data-state]) { opacity: 0; }
.save-state[data-state="error"] { color: var(--danger); background: #fbeae4; opacity: 1; }
.info-flash { position: absolute; left: 50%; bottom: 18px; transform: translate(-50%, 8px); padding: 6px 14px; border-radius: 16px; background: rgba(58, 49, 39, .88); color: #fbf6e8; font-size: 14.5px; opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; white-space: nowrap; }
.info-flash.show { opacity: 1; transform: translate(-50%, 0); }

/* ------------------------------------------------------------- sidebars */

.sidebar {
  width: 200px; flex: none; display: flex; flex-direction: column; min-height: 0;
  background: #efe6d2 var(--noise); border-right: 1px solid var(--line-strong);
  box-shadow: inset -6px 0 10px -8px rgba(60, 40, 15, .3);
  transition: margin-left .22s ease;
}
.sidebar-hidden .sidebar { margin-left: -200px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 8px 8px 14px; flex: none; }
.panel-head h2 { margin: 0; font-family: var(--title-font); font-size: 14px; letter-spacing: .08em; color: var(--ink-soft); }
.page-list { list-style: none; margin: 0; padding: 4px 12px 24px; overflow: auto; flex: 1; display: flex; flex-direction: column; gap: 12px; scrollbar-width: thin; }
.page-item { display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 6px 4px; border-radius: 6px; cursor: pointer; outline: none; position: relative; }
.page-item:hover { background: rgba(255, 255, 255, .35); }
.page-item.current { background: rgba(243, 211, 107, .45); }
.page-item:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.page-item.drop-before::before, .page-item.drop-after::after { content: ""; position: absolute; left: 6px; right: 6px; height: 3px; background: var(--accent); border-radius: 2px; }
.page-item.drop-before::before { top: -8px; } .page-item.drop-after::after { bottom: -8px; }
.page-item.dragging-item { opacity: .4; }
.page-thumb { position: relative; overflow: hidden; border-radius: 1px 3px 3px 1px; box-shadow: 0 0 0 1px rgba(120, 95, 60, .25), 2px 2px 0 -1px #e9dfca, 2px 2px 0 0 rgba(120, 95, 60, .25), 0 2px 5px rgba(60, 40, 15, .15); pointer-events: none; }
.thumb-memo { position: absolute; border-radius: 1px; box-shadow: 0 .5px 1px rgba(60, 40, 15, .25); overflow: hidden; }
.thumb-memo span { display: block; font-size: 5px; line-height: 1.2; padding: 1px; color: rgba(40, 30, 20, .7); white-space: nowrap; overflow: hidden; }
.page-cap { display: flex; align-items: center; gap: 6px; font-size: 13px; max-width: 100%; color: var(--ink-soft); }
.page-num { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--ink-faint); }
.page-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.drawer {
  width: 420px; flex: none; display: flex; flex-direction: column; min-height: 0;
  background: var(--paper) var(--noise); border-left: 1px solid var(--line-strong);
  box-shadow: -6px 0 16px rgba(60, 40, 15, .14);
  user-select: none;
}
.history-tools { padding: 0 12px 8px; display: flex; flex-direction: column; gap: 8px; border-bottom: 1px solid var(--line); }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.filters .field { height: 28px; font-size: 12px; }
.history-list, .history-detail { flex: 1; overflow: auto; padding: 8px 8px 24px; scrollbar-width: thin; }
.hist-item { display: flex; gap: 10px; align-items: flex-start; padding: 9px 8px; border-radius: 6px; cursor: pointer; border-bottom: 1px dashed var(--line); outline: none; }
.hist-item:hover { background: rgba(243, 211, 107, .25); }
.hist-item:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }
.hist-chip { width: 26px; height: 30px; flex: none; display: flex; align-items: center; justify-content: center; border-radius: 2px; box-shadow: var(--shadow-1); color: var(--ink-soft); }
.hist-main { flex: 1; min-width: 0; }
.hist-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hist-snippet { font-size: 13.5px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.hist-meta { display: flex; flex-wrap: wrap; gap: 4px 8px; font-size: 11px; color: var(--ink-faint); margin-top: 4px; align-items: center; }
.state-badge { padding: 0 6px; border-radius: 8px; border: 1px solid var(--line); background: #fffdf7; }
.state-badge[data-state="detached"] { color: var(--accent); border-color: rgba(47, 93, 138, .35); }
.state-badge[data-state="trash"] { color: var(--danger); border-color: rgba(180, 68, 47, .35); }
.state-badge[data-state="archived"] { color: #7a6a2c; }
.hist-more { opacity: .6; }
.list-actions { display: flex; justify-content: flex-end; padding: 0 4px 8px; }
.empty-note { display: flex; flex-direction: column; align-items: center; color: var(--ink-faint); padding: 40px 0; }
.detail-head { display: flex; align-items: center; gap: 4px; }
.detail-head h3 { margin: 0; font-size: 14px; font-family: var(--title-font); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rev-wrap { display: flex; flex-direction: column; gap: 8px; }
.rev-list { max-height: 220px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; background: #fffdf7; }
.rev-item { padding: 6px 10px; border-bottom: 1px dashed var(--line); cursor: pointer; outline: none; }
.rev-item[aria-selected="true"] { background: rgba(243, 211, 107, .45); }
.rev-date { font-size: 12px; font-weight: 700; }
.rev-snip { font-size: 11px; color: var(--ink-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rev-preview { min-height: 120px; max-height: 320px; overflow: auto; padding: 10px 14px; background: #fbf3c8 var(--noise); border-radius: 2px; box-shadow: var(--shadow-1); user-select: text; }
.detail-actions { display: flex; justify-content: flex-end; padding-top: 10px; }
.md-render { font-size: 14px; line-height: 1.6; }
.md-render h1, .md-render h2, .md-render h3 { margin: .4em 0 .3em; font-family: var(--title-font); }
.md-render p { margin: .3em 0; }
.md-render pre { background: rgba(60, 45, 25, .07); padding: 6px 10px; overflow: auto; font-family: var(--mono); font-size: 12px; }
.md-render blockquote { margin: .4em 0; padding-left: 10px; border-left: 3px solid var(--line-strong); color: var(--ink-soft); }
.md-render ul, .md-render ol { padding-left: 1.4em; margin: .3em 0; }
.md-render li.task { list-style: none; margin-left: -1.2em; }

/* ------------------------------------------------- menus, popovers, sheets */

.menu {
  position: fixed; z-index: 10000; min-width: 210px; max-width: 360px; max-height: 80vh; overflow: auto;
  padding: 5px; background: #fffcf3 var(--noise); border: 1px solid var(--line-strong); border-radius: 6px;
  box-shadow: var(--shadow-2); font-size: 14.5px; animation: pop .1s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(-3px); } }
.mi { display: flex; align-items: center; gap: 6px; padding: 7px 12px 7px 4px; border-radius: 4px; cursor: default; outline: none; white-space: nowrap; }
.mi:focus, .mi:hover { background: rgba(243, 211, 107, .55); }
.mi[aria-disabled="true"] { opacity: .4; }
.mi[aria-disabled="true"]:hover, .mi[aria-disabled="true"]:focus { background: none; }
.mi.danger .mi-label { color: var(--danger); }
.mi-check { width: 16px; text-align: center; color: var(--accent); font-weight: 700; }
.mi-label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.mi-sc { color: var(--ink-faint); font-size: 11.5px; margin-left: 18px; }
.mi-sub { color: var(--ink-faint); margin-left: 12px; }
.mi-swatch { width: 12px; height: 12px; border-radius: 2px; box-shadow: 0 0 0 1px rgba(60, 40, 15, .2); }
.msep { height: 0; border-top: 1px dashed var(--line); margin: 5px 6px; }
.mheader { font-size: 11px; color: var(--ink-faint); padding: 4px 10px 2px 26px; letter-spacing: .05em; }

.popover {
  position: fixed; z-index: 9000; width: max-content; max-width: min(380px, 94vw); max-height: 86vh; overflow: auto;
  padding: 14px 16px; background: #fffcf3 var(--noise); border: 1px solid var(--line-strong); border-radius: 7px;
  box-shadow: var(--shadow-2); animation: pop .12s ease-out;
}
.pop-arrow { position: absolute; top: -7px; width: 14px; height: 14px; background: #fffcf3; border-left: 1px solid var(--line-strong); border-top: 1px solid var(--line-strong); transform: rotate(45deg); }
.popover.above .pop-arrow { top: auto; bottom: -7px; transform: rotate(225deg); }
.pop-title { font-family: var(--title-font); font-weight: 700; font-size: 14px; margin-bottom: 10px; }
.pop-appearance { width: 380px; }
.appearance .form-row { margin-bottom: 10px; }
.img-row { display: flex; gap: 6px; flex-wrap: wrap; }
.jump { width: 240px; }
.jump-row { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.jump-row .field { width: 70px; }
.jump-list { max-height: 240px; overflow: auto; display: flex; flex-direction: column; border-top: 1px dashed var(--line); padding-top: 6px; }
.jump-item { display: flex; gap: 8px; align-items: center; border: 0; background: none; text-align: left; padding: 4px 6px; border-radius: 4px; }
.jump-item:hover { background: rgba(243, 211, 107, .45); }

.sheet-backdrop { position: fixed; inset: 0; z-index: 8000; display: flex; align-items: flex-start; justify-content: center; padding-top: 9vh; background: rgba(50, 35, 15, .28); animation: fade .15s ease-out; }
.sheet-backdrop.out { opacity: 0; transition: opacity .15s; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: min(500px, 94vw); max-height: 82vh; display: flex; flex-direction: column;
  background: var(--paper) var(--noise); border: 1px solid var(--line-strong); border-radius: 4px 4px 8px 8px;
  box-shadow: 0 24px 60px rgba(40, 25, 10, .4); animation: drop .2s cubic-bezier(.2, .8, .3, 1);
  border-top: 4px solid var(--accent);
}
.sheet.wide { width: min(800px, 94vw); }
@keyframes drop { from { transform: translateY(-14px); opacity: 0; } }
.sheet-title { margin: 0; padding: 18px 22px 4px; font-family: var(--title-font); font-size: 20px; }
.sheet-msg { margin: 6px 22px 0; color: var(--ink-soft); line-height: 1.6; white-space: pre-line; }
.sheet-content { padding: 12px 22px 4px; overflow: auto; flex: 1; min-height: 0; user-select: text; }
.sheet-buttons { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px 18px; flex-wrap: wrap; }
.sheet-buttons .btn:first-child:not(:only-child):not(.primary) { margin-right: auto; }
.sheet-buttons .btn { min-width: 84px; }

.form { display: flex; flex-direction: column; gap: 10px; }
.form-row { display: flex; flex-direction: column; gap: 5px; }
.form-row.inline { flex-direction: row; align-items: center; flex-wrap: wrap; }
.form-row.inline .form-label { width: 100%; }
.form-label { font-size: 13.5px; font-weight: 700; color: var(--ink-soft); }
.form-hint, .form-note { font-size: 11.5px; color: var(--ink-faint); line-height: 1.55; margin: 0; }
.field { height: 36px; border: 1px solid var(--line-strong); border-radius: 5px; background: #fffdf7; padding: 0 9px; outline: none; user-select: text; min-width: 0; }
textarea.field { height: auto; padding: 6px 9px; resize: vertical; }
.field.code { font-family: var(--mono); font-size: 12.5px; }
.field.num { width: 90px; }
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field.search { height: 32px; border-radius: 16px; padding: 0 14px; }
select.field { padding-right: 4px; }

.segmented { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--line-strong); border-radius: 6px; overflow: hidden; background: #fffdf7; align-self: flex-start; }
.segmented button { border: 0; background: none; padding: 6px 13px; font-size: 14px; border-right: 1px solid var(--line); }
.segmented button:last-child { border-right: 0; }
.segmented button[aria-checked="true"] { background: var(--accent); color: #fdfaf2; }
.segmented button:hover:not([aria-checked="true"]) { background: rgba(243, 211, 107, .4); }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; align-self: flex-start; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track { width: 36px; height: 20px; border-radius: 10px; background: #d9ccb2; position: relative; transition: background .15s; box-shadow: inset 0 1px 2px rgba(60, 40, 15, .25); }
.switch-track::after { content: ""; position: absolute; left: 2px; top: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fffdf7; box-shadow: 0 1px 2px rgba(60, 40, 15, .35); transition: transform .15s; }
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch-label { font-size: 12.5px; }

.swatches { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.swatch { width: 24px; height: 24px; border-radius: 3px; border: 0; box-shadow: 0 0 0 1px rgba(60, 40, 15, .25), 1px 1px 2px rgba(60, 40, 15, .2); padding: 0; }
.swatch[aria-checked="true"] { box-shadow: 0 0 0 2px #fffdf7, 0 0 0 4px var(--accent); }
.swatch-custom { width: 28px; height: 26px; padding: 0; border: 1px dashed var(--line-strong); background: none; border-radius: 4px; cursor: pointer; }
.slider-row { display: flex; align-items: center; gap: 10px; }
.slider { flex: 1; accent-color: var(--accent); }
.slider-val { min-width: 44px; text-align: right; font-size: 12px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

.settings { display: flex; gap: 16px; min-height: 380px; }
.tabs { display: flex; flex-direction: column; gap: 2px; width: 150px; flex: none; border-right: 1px dashed var(--line); padding-right: 10px; }
.tabs button { text-align: left; border: 0; background: none; padding: 7px 10px; border-radius: 5px; }
.tabs button[aria-selected="true"] { background: rgba(243, 211, 107, .55); font-weight: 700; }
.tabs button:hover:not([aria-selected="true"]) { background: rgba(255, 255, 255, .5); }
.tab-body { flex: 1; min-width: 0; }
.shortcuts { border-collapse: collapse; width: 100%; font-size: 12.5px; }
.shortcuts td { padding: 5px 6px; border-bottom: 1px dashed var(--line); vertical-align: top; }
.shortcuts td:first-child { white-space: nowrap; width: 1%; }

.tpl-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; margin-top: 10px; }
.tpl-card { display: flex; align-items: center; gap: 10px; padding: 8px; border: 1px solid var(--line); border-radius: 6px; background: #fffdf7; }
.tpl-swatch { width: 46px; height: 46px; border-radius: 2px; display: flex; align-items: center; justify-content: center; font-size: 10px; overflow: hidden; box-shadow: var(--shadow-1); flex: none; padding: 2px; text-align: center; color: var(--ink-soft); }
.tpl-info { flex: 1; min-width: 0; }
.tpl-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tpl-meta { font-size: 11px; color: var(--ink-faint); }
.tpl-actions { display: flex; align-items: center; gap: 2px; }
.bundle-summary { display: flex; flex-direction: column; gap: 4px; padding: 10px 12px; background: #fffdf7; border: 1px solid var(--line); border-radius: 6px; font-size: 12.5px; }

.toasts { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 9500; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 12px; padding: 8px 10px 8px 16px; background: #3a3127; color: #fbf6e8; border-radius: 6px; box-shadow: var(--shadow-2); font-size: 14.5px; animation: drop .2s ease-out; max-width: 80vw; }
.toast.out { opacity: 0; transition: opacity .25s; }
.toast-action { border: 0; background: var(--marker); color: #3a3127; font-weight: 700; padding: 3px 10px; border-radius: 4px; }

/* ----------------------------------------------------- detached window */

body.detached-window { background: #efe6d2; }
body.detached-window .app { height: 100%; }
.detached-bar { display: flex; align-items: center; gap: 4px; height: 36px; padding: 0 6px 0 12px; background: var(--paper-2) var(--noise); border-bottom: 1px solid var(--line-strong); flex: none; }
.dt-title { font-family: var(--title-font); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dt-spacer { flex: 1; }
.detached-body { flex: 1; position: relative; min-height: 0; padding: 0; }
.memo.detached { position: absolute; inset: 0; border-radius: 0; box-shadow: none; }
.memo.detached::after { display: none; }
.memo.detached .memo-head::before { display: none; }
.memo.detached .rz { display: none; }
.memo.detached .memo-head { display: none; }

/* ------------------------------------------------------- accessibility */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
@media (max-width: 860px) {
  .tb-left, .tb-right { flex: 0 1 auto; }
  .tb-center { flex: 1 1 auto; min-width: 0; }
  .page-label { min-width: 0; flex: 0 1 auto; overflow: hidden; }
  .pl-name { max-width: 90px; }
  .ws-btn { max-width: 150px; }
  .tb-right .icon-btn[aria-label="縮小"], .tb-right .icon-btn[aria-label="拡大"] { display: none; }
  .btn.new-memo span, .tb-sep { display: none; }
  .drawer { position: absolute; right: 0; top: 0; bottom: 0; z-index: 25; width: min(360px, 92vw); }
}

/* --------------------------------------------- screen-sized pages (default) */

.desk.screen-mode { background: var(--page-bg-screen, #fbf8f0); }
.desk.screen-mode .stage { padding: 0; display: block; }
.desk.screen-mode .page-holder::before,
.desk.screen-mode .page-holder::after { display: none; }
.desk.screen-mode .page { border-radius: 0; box-shadow: none; }
.desk.screen-mode .edge-right { right: 0; width: 22px; }
.desk.screen-mode .edge-left { left: 0; width: 22px; }
.desk.screen-mode .edge-right::after { right: 0; }
.desk.screen-mode .edge-left::after { left: 0; }
.desk.screen-mode .page-edge:hover { background: linear-gradient(90deg, transparent, rgba(160, 130, 90, .12)); }
.desk.screen-mode .edge-left:hover { background: linear-gradient(270deg, transparent, rgba(160, 130, 90, .12)); }

/* ------------------------------------------------------------- tutorial */
/* The guide is a sticky-note memo. .tut-card glides between center and
   bottom (top + transform transition); .tut-paper plays place/swap/peel. */

.tut-card {
  position: absolute; z-index: 40; left: 50%;
  width: min(440px, calc(100% - 40px));
  top: 50%; transform: translate(-50%, -50%);
  transition: top .7s cubic-bezier(.22, 1, .36, 1), transform .7s cubic-bezier(.22, 1, .36, 1);
  pointer-events: none;
}
.tut-card[data-pos="bottom"] { top: 100%; transform: translate(-50%, calc(-100% - 26px)); }
.tut-paper {
  pointer-events: auto; position: relative;
  background: #fbf3c8 var(--noise); color: #2e2a24;
  border-radius: 2px 2px 3px 3px;
  box-shadow: 0 1px 1px rgba(60, 40, 15, .18), 0 6px 16px rgba(60, 40, 15, .16), 0 22px 40px -18px rgba(60, 40, 15, .35);
  transform: rotate(-1.4deg);
  font-family: var(--ui-font);
  user-select: none;
}
.tut-paper::after { /* curl shadow, as on memos */
  content: ""; position: absolute; right: 8px; bottom: 5px; width: 46%; height: 20px; z-index: -1;
  box-shadow: 5px 10px 14px rgba(50, 30, 10, .3); transform: rotate(3deg);
}
.tut-paper.place { animation: tut-place .8s cubic-bezier(.2, .9, .25, 1) both; }
.tut-paper.swap .tut-body > * { animation: tut-swap .45s cubic-bezier(.2, .8, .3, 1) both; }
.tut-paper.peel { animation: tut-peel .4s cubic-bezier(.5, 0, .75, .2) forwards; pointer-events: none; }
@keyframes tut-place {
  0%   { opacity: 0; transform: translateY(-46px) rotate(7deg) scale(1.08); box-shadow: 0 40px 60px -10px rgba(60, 40, 15, .25); }
  55%  { opacity: 1; transform: translateY(4px) rotate(-2.6deg) scale(.995); }
  78%  { transform: translateY(-2px) rotate(-1deg) scale(1.002); }
  100% { opacity: 1; transform: rotate(-1.4deg); }
}
@keyframes tut-swap { from { opacity: 0; transform: translateY(6px); } }
@keyframes tut-peel {
  0%   { transform: rotate(-1.4deg); opacity: 1; }
  100% { transform: translateY(-34px) rotate(5deg) scale(.94); opacity: 0; }
}
.tut-head {
  display: flex; align-items: center; gap: 8px; height: 32px; padding: 0 6px 0 10px;
  font-size: 13px; color: rgba(46, 42, 36, .7); font-weight: 700;
  background: color-mix(in srgb, #fbf3c8 80%, #8a7350 20%);
  background-image: linear-gradient(rgba(255, 255, 255, .25), rgba(255, 255, 255, 0));
  border-radius: 2px 2px 0 0;
}
.tut-head::before { /* washi tape */
  content: ""; position: absolute; left: 50%; top: -11px; width: 84px; height: 22px; transform: translateX(-50%) rotate(-2deg);
  background: rgba(240, 220, 160, .7); background-image: repeating-linear-gradient(90deg, rgba(255, 255, 255, .3) 0 5px, transparent 5px 10px);
  box-shadow: 0 1px 1px rgba(60, 40, 15, .12);
  clip-path: polygon(3% 0, 97% 4%, 100% 50%, 96% 100%, 2% 96%, 0 50%);
}
.tut-grip { width: 10px; height: 12px; opacity: .5; background: radial-gradient(circle, currentColor 1px, transparent 1.3px) 0 0 / 4px 4px; }
.tut-head-label { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tut-dots { display: flex; gap: 4px; }
.tut-dots i { width: 7px; height: 7px; border-radius: 50%; background: rgba(46, 42, 36, .18); transition: background .3s, transform .3s; }
.tut-dots i.done { background: rgba(47, 93, 138, .55); }
.tut-dots i.cur { background: var(--accent); transform: scale(1.35); }
.tut-x { border: 0; background: none; width: 26px; height: 26px; border-radius: 5px; font-size: 18px; line-height: 1; color: inherit; opacity: .6; }
.tut-x:hover { opacity: 1; background: rgba(255, 255, 255, .45); }
.tut-body {
  --row: 34px;
  padding: 6px 20px 14px;
  background-image: linear-gradient(to top, #d9c98e 1px, transparent 1px);
  background-size: 100% var(--row);
  background-position: 0 6px;
  interpolate-size: allow-keywords;
  transition: height .45s cubic-bezier(.22, 1, .36, 1);
}
.tut-text { margin: 0; font-size: 21px; line-height: var(--row); font-weight: 700; min-height: var(--row); white-space: pre-line; }
.tut-text.ok::after { content: " ✓"; color: #3c7a3a; }
.tut-caret { display: inline-block; width: 2px; height: 1.05em; margin-left: 2px; vertical-align: -.15em; background: var(--accent); animation: tut-blink 1s steps(2) infinite; }
@keyframes tut-blink { 50% { opacity: 0; } }
.tut-sub { margin: 0; font-size: 15.5px; line-height: var(--row); color: rgba(46, 42, 36, .72); min-height: 0; }
.tut-sub:empty { display: none; }
.tut-actions { display: flex; flex-direction: column; align-items: flex-start; }
.tut-choice {
  display: inline-flex; align-items: center; gap: 10px; height: var(--row); padding: 0 8px 0 2px;
  border: 0; background: none; font-size: 16px; color: inherit; border-radius: 4px; text-align: left;
  opacity: 0; transform: translateX(-8px); transition: opacity .35s, transform .35s cubic-bezier(.22, 1, .36, 1), background .15s;
  pointer-events: none;
}
.tut-actions.shown .tut-choice { opacity: 1; transform: none; pointer-events: auto; }
.tut-choice:hover { background: rgba(243, 211, 107, .55); }
.tut-choice.primary { font-weight: 700; color: var(--accent); }
.tut-choice.primary span:last-child { background: linear-gradient(transparent 58%, rgba(243, 211, 107, .9) 58%); }
.tut-box { width: 16px; height: 16px; border: 1.8px solid currentColor; border-radius: 3px; opacity: .7; flex: none; }
.tut-choice.primary .tut-box { background: none; position: relative; }
.tut-choice:hover .tut-box::after, .tut-choice:focus-visible .tut-box::after { content: "✓"; position: absolute; margin: -5px 0 0 1px; font-size: 15px; }
.tut-box { position: relative; }
.tut-spot {
  position: fixed; z-index: 45; pointer-events: none; border-radius: 10px;
  border: 3px solid #e6b93a; box-shadow: 0 0 0 5px rgba(243, 211, 107, .35), 0 0 26px rgba(243, 211, 107, .8);
  animation: tut-spot-in .4s ease-out, tut-pulse 1.4s ease-in-out .4s infinite;
  transition: left .45s cubic-bezier(.22, 1, .36, 1), top .45s cubic-bezier(.22, 1, .36, 1), width .45s cubic-bezier(.22, 1, .36, 1), height .45s cubic-bezier(.22, 1, .36, 1), opacity .3s;
}
.tut-spot.out { opacity: 0; }
@keyframes tut-spot-in { from { opacity: 0; transform: scale(1.12); } }
@keyframes tut-pulse { 50% { box-shadow: 0 0 0 10px rgba(243, 211, 107, .15), 0 0 34px rgba(243, 211, 107, .9); } }

/* zoom readout shown while zooming */
.zoom-hud {
  position: absolute; left: 50%; top: 18px; z-index: 30; transform: translate(-50%, -6px);
  padding: 6px 16px; border-radius: 18px; background: rgba(58, 49, 39, .86); color: #fbf6e8;
  font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; pointer-events: none;
  opacity: 0; transition: opacity .2s, transform .2s;
}
.zoom-hud.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------------------------------------------------- inline rename */

input.inline-edit {
  font: inherit; color: inherit; width: 100%; min-width: 6em;
  border: 0; border-bottom: 2px solid var(--accent); border-radius: 0;
  background: rgba(255, 253, 247, .85); padding: 0 2px; outline: none;
  user-select: text; -webkit-user-select: text;
}
.memo-title.editing-name { overflow: visible; }
.ws-name.editing-name { overflow: visible; min-width: 12em; }

/* ------------------------------------------------- app-version peek (web) */

.app-promo {
  position: absolute; right: 26px; bottom: 0; z-index: 35; width: 290px;
  background: #e8f0f6 var(--noise); color: var(--ink);
  border-radius: 3px 3px 0 0;
  box-shadow: 0 -2px 10px rgba(60, 40, 15, .14), 0 0 0 1px rgba(80, 110, 140, .14);
  transform: translateY(100%) rotate(0deg);
  transition: transform .55s cubic-bezier(.22, 1.2, .36, 1);
  font-size: 14px;
}
/* Peeks: only the top strip shows until hovered or focused. */
.app-promo.in { transform: translateY(calc(100% - 46px)) rotate(-1.5deg); }
.app-promo.in:hover, .app-promo.in:focus-within { transform: translateY(0) rotate(-.6deg); }
.app-promo.out { transform: translateY(100%) rotate(2deg); transition-duration: .4s; }
.promo-tape {
  position: absolute; left: 50%; top: -10px; width: 70px; height: 20px; transform: translateX(-50%) rotate(2deg);
  background: rgba(240, 220, 160, .75); background-image: repeating-linear-gradient(90deg, rgba(255, 255, 255, .3) 0 5px, transparent 5px 10px);
  clip-path: polygon(3% 0, 97% 4%, 100% 50%, 96% 100%, 2% 96%, 0 50%);
}
.promo-peek { display: flex; align-items: center; gap: 8px; height: 46px; padding: 0 40px 0 16px; font-weight: 700; cursor: default; }
.promo-ico { font-size: 18px; }
.app-promo.in .promo-peek { animation: promo-nudge 2.6s ease-in-out 1.2s 2; }
@keyframes promo-nudge { 0%, 70%, 100% { transform: none; } 80% { transform: translateY(-3px); } 90% { transform: translateY(1px); } }
.promo-more { padding: 0 16px 16px; }
.promo-more p { margin: 0 0 12px; line-height: 1.6; color: var(--ink-soft); font-size: 13.5px; }
.promo-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.promo-dl {
  display: inline-flex; align-items: center; height: 34px; padding: 0 14px; border-radius: 5px;
  background: var(--accent); color: #fdfaf2; text-decoration: none; font-weight: 700;
}
.promo-dl:hover { background: #356a9c; }
.promo-note { font-size: 13px; color: var(--ink-faint); }
.promo-later { border: 0; background: none; color: var(--ink-soft); text-decoration: underline; padding: 0; }
.promo-x { position: absolute; right: 6px; top: 8px; width: 30px; height: 30px; border: 0; background: none; border-radius: 6px; font-size: 18px; color: var(--ink-soft); }
.promo-x:hover { background: rgba(255, 255, 255, .6); }
