/* ==========================================================================
   Corkboard — styles
   ========================================================================== */
:root {
  --ink: #2a2119;
  --paper: #fbf6ea;
  --paper-2: #f1e8d4;
  --line: #d9ccb0;
  --accent: #b8352a;
  --accent-ink: #fff;
  --wood-a: #5a3720;
  --wood-b: #7a4c2c;
  --wood-c: #3f2615;
  --hand: 'Caveat', 'Segoe Print', 'Bradley Hand', 'Comic Sans MS', cursive;
  --type: 'Special Elite', 'American Typewriter', 'Courier New', monospace;
  --ui: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --z: 1; --px: 0px; --py: 0px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: var(--ui); color: var(--ink); background: var(--wood-c);
  -webkit-tap-highlight-color: transparent; overscroll-behavior: none;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.ico { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

#app { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* ---------- Top bar: a strip of paper tacked across the frame ---------- */
.topbar {
  position: relative; z-index: 20; display: flex; align-items: center; gap: 6px;
  padding: 8px max(10px, env(safe-area-inset-right)) 8px max(10px, env(safe-area-inset-left));
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--paper);
  background-image: linear-gradient(to bottom, rgba(255,255,255,.6), transparent 40%);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 10px rgba(0,0,0,.35);
  overflow-x: auto; scrollbar-width: none;
}
.topbar::-webkit-scrollbar { display: none; }
.spacer { flex: 1; }
.tb-group { display: flex; align-items: center; gap: 2px; padding-left: 6px; margin-left: 2px; border-left: 1px solid var(--line); }
.tb-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; min-width: 36px; padding: 0 9px;
  border: 0; background: transparent; border-radius: 8px; cursor: pointer; white-space: nowrap;
  font-size: 14px; justify-content: center;
}
.tb-btn:hover { background: rgba(80,50,20,.09); }
.tb-btn:active { background: rgba(80,50,20,.16); }
.tb-btn:disabled { opacity: .35; cursor: default; background: transparent; }
.zoom-label { font-variant-numeric: tabular-nums; min-width: 56px; font-size: 13px; }
.board-title {
  border: 0; background: transparent; cursor: text; padding: 4px 8px; border-radius: 6px;
  font-family: var(--type); font-size: 19px; max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.board-title:hover { background: rgba(80,50,20,.08); }
.save-status { font-size: 12px; color: #8a7a62; white-space: nowrap; min-width: 52px; }
.save-status.err { color: var(--accent); font-weight: 600; }
@media (max-width: 860px) { #add-group .tb-btn span { display: none; } .board-title { font-size: 16px; } }
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; row-gap: 2px; overflow: visible; }
  .board-title { flex: 1; max-width: none; text-align: left; }
  .topbar .spacer { display: none; }
  #add-group { order: 5; flex-basis: 100%; justify-content: space-around; border-left: 0; padding-left: 0; margin-left: 0; border-top: 1px solid var(--line); padding-top: 2px; }
  #add-group .tb-btn span { display: inline; font-size: 12px; }
  #add-group .tb-btn { flex-direction: column; gap: 0; height: 46px; padding: 0 6px; }
}
@media (max-width: 520px) { .save-status { display: none; } .zoom-group #btn-zoom-in, .zoom-group #btn-zoom-out { display: none; } }

/* ---------- Wooden frame ---------- */
.frame {
  position: relative; flex: 1; min-height: 0; padding: 14px;
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  background:
    repeating-linear-gradient(92deg, rgba(0,0,0,.0) 0 7px, rgba(0,0,0,.07) 7px 9px, rgba(255,255,255,.03) 9px 13px),
    repeating-linear-gradient(88deg, rgba(0,0,0,.05) 0 23px, rgba(255,230,190,.05) 23px 31px),
    linear-gradient(180deg, var(--wood-b), var(--wood-a) 60%, var(--wood-c));
  box-shadow: inset 0 0 0 1px rgba(255,220,180,.12), inset 0 2px 3px rgba(255,220,180,.15);
}

/* ---------- Cork ---------- */
#viewport {
  position: absolute; inset: 14px; overflow: hidden; outline: none; border-radius: 2px;
  bottom: max(14px, env(safe-area-inset-bottom));
  touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none;
  background-color: #bf8d5c;
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='a'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' seed='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .28 0 0 0 0 .16 0 0 0 0 .07 2.6 0 0 0 -1.25'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23a)'/%3E%3C/svg%3E"),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260'%3E%3Cfilter id='b'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.6' numOctaves='2' seed='11' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .93 0 0 0 0 .76 0 0 0 0 .53 0 2.8 0 0 -1.45'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23b)'/%3E%3C/svg%3E"),
    radial-gradient(25% 20% at 29% 26%, rgba(85,48,18,.16), rgba(85,48,18,0)),
    radial-gradient(30% 22.5% at 70% 70%, rgba(85,48,18,.13), rgba(85,48,18,0)),
    radial-gradient(20% 17.5% at 77.5% 22.5%, rgba(255,226,180,.12), rgba(255,226,180,0)),
    radial-gradient(19% 15% at 24% 77.5%, rgba(255,226,180,.09), rgba(255,226,180,0));
  background-size: calc(220px * var(--z)) calc(220px * var(--z)), calc(260px * var(--z)) calc(260px * var(--z)), calc(820px * var(--z)) calc(820px * var(--z)), calc(820px * var(--z)) calc(820px * var(--z)), calc(820px * var(--z)) calc(820px * var(--z)), calc(820px * var(--z)) calc(820px * var(--z));
  background-position: var(--px) var(--py);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.35);
}
#viewport::after { /* inner bevel shadow from the frame */
  content: ''; position: absolute; inset: 0; pointer-events: none; z-index: 2;
  box-shadow: inset 0 6px 14px rgba(0,0,0,.45), inset 0 -2px 8px rgba(0,0,0,.25), inset 4px 0 10px rgba(0,0,0,.25), inset -4px 0 10px rgba(0,0,0,.25);
}
#viewport.panning { cursor: grabbing; }
#viewport.connecting, #viewport.connecting .item { cursor: crosshair; }
#world { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }

/* ---------- Strings ---------- */
#strings { position: absolute; left: 0; top: 0; overflow: visible; z-index: 2147480000; pointer-events: none; }
.yarn { fill: none; stroke: var(--sc, #c62a22); stroke-width: 2.6; stroke-linecap: round; filter: url(#yarn-shadow); pointer-events: none; }
.yarn-hi { fill: none; stroke: rgba(255,255,255,.28); stroke-width: .8; stroke-dasharray: 3 4; pointer-events: none; }
.yarn-hit { fill: none; stroke: transparent; stroke-width: 16; pointer-events: stroke; cursor: pointer; }
.string.selected .yarn { stroke-width: 4; }
.string.selected .yarn-hit { stroke: rgba(255,255,255,.28); }
.knot { fill: var(--sc, #c62a22); pointer-events: none; }
#string-temp { stroke-dasharray: 7 5; display: none; }

/* ---------- Items (shared) ---------- */
.item { position: absolute; transform-origin: 50% 50%; cursor: grab; touch-action: none; }
.item > .body { position: absolute; inset: 0; overflow: hidden; }
.item.selected { outline: 2px dashed rgba(255,255,255,.9); outline-offset: 5px; }
.item.connect-source { outline: 2px solid #fff; outline-offset: 5px; }
.dragging-any .item { cursor: grabbing; }
.dragging-any iframe { pointer-events: none; }
.item img { -webkit-user-drag: none; user-select: none; }

.pin {
  position: absolute; left: 50%; top: 2px; width: 18px; height: 18px; margin-left: -9px; border-radius: 50%; z-index: 5;
  background: radial-gradient(circle at 34% 30%, rgba(255,255,255,.85) 0 1.5px, rgba(255,255,255,0) 3.5px),
              radial-gradient(circle at 40% 38%, var(--pin) 0 45%, color-mix(in srgb, var(--pin), #000 50%) 100%);
  box-shadow: 1px 1px 0 rgba(0,0,0,.25), 3px 5px 5px rgba(0,0,0,.4);
  cursor: crosshair;
}
.pin::after { /* larger touch target */ content: ''; position: absolute; inset: -10px; border-radius: 50%; }
.item:hover .pin { box-shadow: 0 0 0 3px rgba(255,255,255,.45), 3px 5px 5px rgba(0,0,0,.4); }

.h { position: absolute; scale: calc(1 / var(--z)); width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 2px solid #333; z-index: 6; display: none; box-shadow: 0 1px 4px rgba(0,0,0,.4); }
.item.selected .h { display: block; }
.h-resize { right: -11px; bottom: -11px; cursor: nwse-resize; }
.h-rotate { left: 50%; top: -38px; margin-left: -11px; cursor: grab; background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23333' stroke-width='2.6' stroke-linecap='round'%3E%3Cpath d='M20 12a8 8 0 1 1-2.3-5.6'/%3E%3Cpath d='M20 4v5h-5'/%3E%3C/svg%3E") center/13px no-repeat; }
.h-rotate::before { content: ''; position: absolute; left: 50%; top: 20px; width: 0; height: 15px; border-left: 2px dashed rgba(255,255,255,.85); }
.h::after { content: ''; position: absolute; inset: -9px; border-radius: 50%; }

.editor {
  position: absolute; inset: 0; width: 100%; height: 100%; border: 0; outline: none; resize: none; background: transparent;
  font: inherit; color: inherit; line-height: inherit; text-align: inherit; letter-spacing: inherit; text-transform: inherit; padding: inherit; cursor: text;
  user-select: text; -webkit-user-select: text; overflow: hidden;
}

/* ---------- Post-it ---------- */
.type-note > .body {
  background: var(--c, #fff27a);
  background-image: linear-gradient(to bottom, rgba(0,0,0,.07), rgba(0,0,0,0) 16%), linear-gradient(160deg, rgba(255,255,255,.35), rgba(255,255,255,0) 40%), linear-gradient(to top left, rgba(0,0,0,.08), rgba(0,0,0,0) 22%);
  box-shadow: 0 1px 1px rgba(0,0,0,.15), 0 12px 14px -8px rgba(0,0,0,.55);
  padding: 26px 16px 14px; font-family: var(--hand); font-size: 25px; line-height: 1.08; font-weight: 500;
  white-space: pre-wrap; overflow-wrap: anywhere; color: #2b2a26;
  border-bottom-right-radius: 26px 6px;
}
.type-note .text:empty::before { content: 'Double-click to write…'; opacity: .35; }

/* ---------- Labels ---------- */
.type-label > .body { display: flex; align-items: center; justify-content: center; text-align: center; padding: 6px 18px; white-space: pre-wrap; overflow-wrap: anywhere; }
.type-label .editor { padding: 13px 18px 0; text-align: center; }
.lbl-dymo, .lbl-dymo-red, .lbl-dymo-blue {
  font-family: 'Arial Black', 'Helvetica Neue', Arial, sans-serif; font-weight: 900; text-transform: uppercase; letter-spacing: .16em; font-size: 19px;
  color: #f4f4f4; text-shadow: 0 1px 0 rgba(255,255,255,.35), 0 -1px 0 rgba(0,0,0,.6);
  background: linear-gradient(to bottom, rgba(255,255,255,.18), rgba(255,255,255,0) 30%, rgba(0,0,0,.25)), var(--tape, #161616);
  border-radius: 3px; box-shadow: 0 3px 5px rgba(0,0,0,.45);
}
.lbl-dymo-red { --tape: #b7221b; }
.lbl-dymo-blue { --tape: #1f4f9a; }
.lbl-kraft {
  font-family: var(--type); font-size: 21px; color: #2a1f15; background: #d2b48c;
  background-image: linear-gradient(to bottom, rgba(255,255,255,.18), rgba(0,0,0,.06)), repeating-linear-gradient(115deg, rgba(0,0,0,.03) 0 2px, transparent 2px 6px);
  box-shadow: 0 2px 4px rgba(0,0,0,.4); clip-path: polygon(0 3%, 3% 0, 97% 2%, 100% 0, 99% 50%, 100% 97%, 96% 100%, 4% 98%, 0 100%, 1% 50%);
}
.lbl-tape {
  font-family: var(--hand); font-size: 27px; font-weight: 700; color: #1d3b7a; background: rgba(246,238,214,.93);
  clip-path: polygon(2% 0, 98% 0, 100% 12%, 98% 25%, 100% 38%, 98% 50%, 100% 62%, 98% 75%, 100% 88%, 98% 100%, 2% 100%, 0 88%, 2% 75%, 0 62%, 2% 50%, 0 38%, 2% 25%, 0 12%);
}
.lbl-index {
  font-family: var(--type); font-size: 22px; color: #222; background: #fffdf6;
  background-image: linear-gradient(to bottom, transparent 0 10px, rgba(214,58,47,.5) 10px 11px, transparent 11px), repeating-linear-gradient(to bottom, transparent 0 21px, rgba(60,110,190,.25) 21px 22px);
  box-shadow: 0 3px 5px rgba(0,0,0,.35);
}

/* ---------- Photos ---------- */
.type-image > .body { background: #fdfcf8; padding: 9px 9px 9px; display: flex; flex-direction: column; box-shadow: 0 2px 3px rgba(0,0,0,.25), 0 14px 18px -10px rgba(0,0,0,.6); }
.type-image.has-caption > .body { padding-bottom: 0; }
.photo { flex: 1; min-height: 0; background: #ddd linear-gradient(135deg, #e8e4dc, #cfc8bb); position: relative; overflow: hidden; }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo .broken { position: absolute; inset: 0; display: grid; place-items: center; color: #8b8170; font-size: 12px; text-align: center; padding: 8px; }
.caption { height: 38px; flex: none; display: flex; align-items: center; justify-content: center; font-family: var(--hand); font-size: 22px; color: #333; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 6px; }

/* ---------- Documents ---------- */
.type-doc > .body {
  background: #fff; display: flex; flex-direction: column; padding: 26px 12px 10px; gap: 8px;
  box-shadow: 0 2px 3px rgba(0,0,0,.22), 0 14px 18px -10px rgba(0,0,0,.55);
  clip-path: polygon(0 0, calc(100% - 26px) 0, 100% 26px, 100% 100%, 0 100%);
}
.type-doc > .body::before { /* folded corner */
  content: ''; position: absolute; right: 0; top: 0; width: 26px; height: 26px;
  background: linear-gradient(225deg, transparent 50%, #e2dccf 50%, #cbc3b2); box-shadow: -2px 2px 3px rgba(0,0,0,.15);
}
.doc-top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.badge { flex: none; font: 700 11px/1 var(--ui); color: #fff; background: var(--b, #666); padding: 5px 6px; border-radius: 4px; letter-spacing: .04em; text-transform: uppercase; }
.doc-name { font: 600 13px/1.25 var(--ui); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.doc-preview { flex: 1; min-height: 0; overflow: hidden; border: 1px solid #ece7dc; background: #fafafa; position: relative; }
.doc-preview img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
.doc-preview pre { margin: 0; padding: 8px; font: 10px/1.35 ui-monospace, Menlo, Consolas, monospace; color: #444; white-space: pre-wrap; overflow-wrap: anywhere; }
.doc-preview .doc-icon { position: absolute; inset: 0; display: grid; place-items: center; }
.doc-preview .doc-icon svg { width: 54px; height: 54px; stroke: #bbb; stroke-width: 1.4; fill: none; }
.doc-meta { font: 11px var(--ui); color: #888; display: flex; justify-content: space-between; }

/* ---------- Links ---------- */
.type-link > .body { background: #fff; display: flex; flex-direction: column; box-shadow: 0 2px 3px rgba(0,0,0,.22), 0 14px 18px -10px rgba(0,0,0,.55); padding: 8px; gap: 8px; }
.link-media { position: relative; flex: 1; min-height: 40px; background: #1b1b1b; overflow: hidden; }
.link-media img.thumb { width: 100%; height: 100%; object-fit: cover; display: block; }
.link-media iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.link-media.empty { background: linear-gradient(135deg, #f1ece1, #e3dccd); display: grid; place-items: center; }
.link-media.empty img { width: 40px; height: 40px; opacity: .85; }
.link-media.loading::after { content: 'Fetching preview…'; position: absolute; inset: 0; display: grid; place-items: center; font-size: 12px; color: #8b8170; }
.play {
  position: absolute; left: 50%; top: 50%; width: 64px; height: 44px; margin: -22px 0 0 -32px; border: 0; border-radius: 12px;
  background: rgba(205,25,25,.92); cursor: pointer; display: grid; place-items: center; box-shadow: 0 2px 10px rgba(0,0,0,.4);
}
.play::before { content: ''; border-style: solid; border-width: 10px 0 10px 17px; border-color: transparent transparent transparent #fff; margin-left: 4px; }
.play:hover { background: #e21d1d; }
.link-text { flex: none; min-width: 0; }
.link-site { display: flex; align-items: center; gap: 6px; font: 11px var(--ui); color: #888; margin-bottom: 3px; }
.link-site img { width: 14px; height: 14px; }
.link-title { font: 600 14px/1.25 var(--ui); color: #222; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.link-desc { font: 12px/1.3 var(--ui); color: #666; margin-top: 3px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* ---------- Hint / drop overlay ---------- */
.hint {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%); z-index: 5; pointer-events: none;
  background: rgba(30,20,12,.85); color: #fff; padding: 8px 14px; border-radius: 20px; font-size: 13px; opacity: 0; transition: opacity .2s;
  white-space: nowrap; max-width: 90%; overflow: hidden; text-overflow: ellipsis;
}
.hint.show { opacity: 1; }
.drop-overlay { position: absolute; inset: 0; z-index: 6; display: none; place-items: center; background: rgba(255,250,235,.18); border: 4px dashed rgba(255,255,255,.75); pointer-events: none; }
.drop-overlay span { background: rgba(30,20,12,.85); color: #fff; padding: 10px 18px; border-radius: 22px; }
.drop-overlay.show { display: grid; }

/* ---------- Inspector (selection toolbar) ---------- */
.inspector {
  position: fixed; left: 50%; bottom: max(26px, calc(env(safe-area-inset-bottom) + 16px)); transform: translateX(-50%); z-index: 30;
  display: flex; align-items: center; gap: 2px; flex-wrap: wrap; justify-content: center; max-width: calc(100vw - 24px);
  background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 5px 6px;
  box-shadow: 0 8px 26px rgba(0,0,0,.45);
}
.inspector .sep { width: 1px; height: 24px; background: var(--line); margin: 0 3px; }
.inspector .tb-btn { height: 34px; min-width: 34px; padding: 0 7px; font-size: 13px; }
.inspector .tb-btn.danger { color: var(--accent); }
.swatch { width: 24px; height: 24px; border-radius: 50%; border: 2px solid rgba(0,0,0,.18); cursor: pointer; padding: 0; margin: 0 2px; background: var(--s); }
.swatch.on { box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px #333; }
.swatch.lbl { border-radius: 4px; width: 30px; }
.inspector .tb-btn.icon-only span { display: none; }
@media (max-width: 600px) {
  .inspector { flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start; left: 12px; right: 12px; transform: none; max-width: none; scrollbar-width: none; }
  .inspector::-webkit-scrollbar { display: none; }
  .inspector .tb-btn span { display: none; }
  .inspector > * { flex: none; }
}

/* ---------- Drawer ---------- */
.drawer {
  position: fixed; left: 0; top: 0; bottom: 0; width: min(330px, 88vw); z-index: 50; background: var(--paper);
  transform: translateX(-104%); transition: transform .22s ease; display: flex; flex-direction: column; gap: 10px;
  padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  box-shadow: 6px 0 30px rgba(0,0,0,.4);
}
.drawer.open { transform: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; }
.drawer-head h2 { margin: 0; font-family: var(--type); font-weight: normal; font-size: 24px; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 45; opacity: 0; pointer-events: none; transition: opacity .2s; }
.scrim.show { opacity: 1; pointer-events: auto; }
.board-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 4px; }
.board-list li { display: flex; align-items: center; gap: 4px; border-radius: 10px; padding: 2px 2px 2px 0; }
.board-list li.current { background: rgba(184,53,42,.1); }
.board-list .open { flex: 1; min-width: 0; border: 0; background: transparent; text-align: left; padding: 8px 10px; cursor: pointer; border-radius: 8px; }
.board-list .open:hover { background: rgba(80,50,20,.07); }
.board-list .name { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.board-list .meta { display: block; font-size: 12px; color: #8a7a62; }
.board-list .tb-btn { height: 32px; min-width: 32px; padding: 0; }
.drawer-foot { display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--line); padding-top: 10px; }
.storage-mode { font-size: 12px; color: #7d6e57; line-height: 1.4; }
.storage-mode b { color: var(--ink); }
.shortcuts { font-size: 13px; }
.shortcuts summary { cursor: pointer; color: #6d5e47; }
.shortcuts ul { padding-left: 18px; margin: 8px 0 0; line-height: 1.45; }
kbd { font: 11px ui-monospace, monospace; background: #fff; border: 1px solid #ccc; border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-size: 14px; }
.btn:hover { background: #fffaf0; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: #fff; background: #9b1c14; border-color: transparent; }
.btn.wide { width: 100%; }

/* ---------- Menu popover ---------- */
.menu { position: fixed; z-index: 60; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.3); padding: 4px; min-width: 170px; }
.menu button { display: flex; width: 100%; align-items: center; gap: 10px; border: 0; background: transparent; padding: 9px 10px; border-radius: 7px; cursor: pointer; text-align: left; font-size: 14px; }
.menu button:hover { background: var(--paper); }
.menu button.danger { color: var(--accent); }

/* ---------- Dialog ---------- */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(440px, calc(100vw - 28px)); background: var(--paper); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.5); }
dialog::backdrop { background: rgba(20,12,6,.5); }
dialog form { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
dialog h3 { margin: 0; font-family: var(--type); font-weight: normal; font-size: 21px; }
dialog label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: #6d5e47; }
dialog input[type=text], dialog input[type=url], dialog textarea { font: inherit; font-size: 16px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: var(--ink); width: 100%; }
dialog p { margin: 0; line-height: 1.45; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* ---------- Lightbox ---------- */
.lightbox { position: fixed; inset: 0; z-index: 70; background: rgba(10,6,3,.88); display: grid; place-items: center; padding: 50px 16px 16px; }
.lb-content { max-width: 100%; max-height: 100%; display: grid; place-items: center; width: 100%; height: 100%; }
.lb-content img { max-width: 100%; max-height: calc(100vh - 80px); object-fit: contain; box-shadow: 0 10px 40px rgba(0,0,0,.6); background: #fff; }
.lb-content iframe { width: min(1100px, 100%); height: 100%; border: 0; background: #fff; border-radius: 4px; }
.lb-close { position: absolute; top: max(10px, env(safe-area-inset-top)); right: 12px; color: #fff; }
.lb-close:hover { background: rgba(255,255,255,.12); }

.toast { position: fixed; left: 50%; top: 70px; transform: translateX(-50%); background: #2a1d12; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 80; font-size: 14px; box-shadow: 0 8px 20px rgba(0,0,0,.4); max-width: calc(100vw - 30px); }
.toast.err { background: #8f1a12; }

/* ---------- Demo-mode link cards & document viewer ---------- */
.link-media.demo { display: grid; place-items: center; align-content: center; gap: 10px; background: linear-gradient(135deg, hsl(var(--h, 20) 42% 44%), hsl(var(--h, 20) 45% 28%)); }
.link-media.demo.video { background: linear-gradient(135deg, #2c2c2c, #0f0f0f); }
.link-media.demo .ltr { font: 800 46px/1 var(--ui); color: rgba(255,255,255,.88); }
.play-badge { width: 64px; height: 44px; border-radius: 12px; background: #d61f1f; display: grid; place-items: center; box-shadow: 0 2px 10px rgba(0,0,0,.4); }
.play-badge::before { content: ''; border-style: solid; border-width: 10px 0 10px 17px; border-color: transparent transparent transparent #fff; margin-left: 4px; }
.demo-note { font: 11px var(--ui); color: rgba(255,255,255,.7); }
.lb-content .viewer { width: min(940px, 100%); height: 100%; overflow: auto; background: #f3f0ea; border-radius: 4px; padding: 14px; -webkit-overflow-scrolling: touch; }
.viewer canvas, .viewer img { display: block; width: 100%; height: auto; margin: 0 auto 14px; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.25); max-height: none; }
.viewer pre { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font: 13px/1.5 ui-monospace, Menlo, Consolas, monospace; color: #222; background: #fff; padding: 16px; }
.viewer-msg { margin: 30px auto; max-width: 46ch; text-align: center; color: #5b5045; line-height: 1.5; }
a.tb-btn { text-decoration: none; }
