:root {
  --ui: #ffffff; --ui-2: #f4f5f7; --ink: #1f2230; --muted: #6b7080; --line: #e3e5ea;
  --accent: #4262ff; --accent-soft: #e6ebff; --danger: #e5484d;
  --shadow: 0 6px 24px rgba(20, 24, 40, .14), 0 1px 3px rgba(20, 24, 40, .1);
  font-family: 'Inter', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #f2f3f5; color: var(--ink); overflow: hidden; }
button { font: inherit; color: inherit; }
.center { height: 100%; display: flex; flex-direction: column; gap: 16px; align-items: center; justify-content: center; }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--ui); padding: 8px 14px; border-radius: 8px; cursor: pointer; text-decoration: none; font-size: 14px; font-weight: 500; }
.btn:hover { background: var(--ui-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.icon-btn { border: 0; background: transparent; width: 34px; height: 34px; border-radius: 8px; cursor: pointer; font-size: 16px; display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--ui-2); }
.muted { color: var(--muted); }
.spacer { flex: 1; }

/* ---------- home ---------- */
.home { height: 100%; overflow: auto; background: #f7f8fa; }
.home-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 8px; padding: 12px 24px; background: rgba(255,255,255,.9); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; }
.logo-mark { width: 26px; height: 26px; border-radius: 7px; background: linear-gradient(135deg, #fff9b1 0 45%, #2d9bf0 45%); box-shadow: inset 0 0 0 2px #1f2230; }
.home-main { max-width: 1200px; margin: 0 auto; padding: 28px 24px 60px; }
.home-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.home-title h1 { font-size: 24px; margin: 0; }
.boards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 18px; }
.board-card { position: relative; background: var(--ui); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; cursor: pointer; transition: box-shadow .15s, transform .15s; text-align: left; padding: 0; }
.board-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
.board-card.new { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; min-height: 196px; border: 2px dashed #c9cdd6; background: transparent; color: var(--muted); font-weight: 600; }
.board-card.new .plus { font-size: 34px; font-weight: 300; }
.board-thumb { height: 128px; position: relative; }
.thumb-dots { position: absolute; inset: 0; background-image: radial-gradient(circle, rgba(0,0,0,.14) 1.2px, transparent 0); background-size: 16px 16px; }
.thumb-n { position: absolute; left: 10px; bottom: 8px; font-size: 12px; background: rgba(255,255,255,.85); padding: 2px 8px; border-radius: 20px; color: var(--muted); }
.board-info { padding: 12px 14px 14px; }
.board-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.board-date { font-size: 12px; color: var(--muted); margin-top: 3px; }
.board-menu { position: absolute; top: 6px; right: 6px; display: none; gap: 2px; background: rgba(255,255,255,.95); border-radius: 8px; box-shadow: var(--shadow); }
.board-card:hover .board-menu { display: flex; }
@media (hover: none) { .board-menu { display: flex; } }

/* ---------- modali / notifiche ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 18, 30, .35); display: grid; place-items: center; z-index: 1000; padding: 16px; }
.modal { background: var(--ui); border-radius: 14px; padding: 20px; width: min(420px, 100%); box-shadow: var(--shadow); }
.modal.wide { width: min(620px, 100%); max-height: 85vh; overflow: auto; }
.modal h3 { margin: 0 0 14px; font-size: 16px; }
.inp { width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; font: inherit; outline: none; }
.inp:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.keys { width: 100%; border-collapse: collapse; font-size: 14px; }
.keys td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
kbd { background: var(--ui-2); border: 1px solid var(--line); border-radius: 5px; padding: 1px 6px; font-family: inherit; font-size: 12px; white-space: nowrap; }
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 2000; pointer-events: none; }
.toast { background: #1f2230; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); transition: opacity .3s; }
.toast.out { opacity: 0; }

/* ---------- editor ---------- */
.board-app { position: fixed; inset: 0; overflow: hidden; }
.stage { position: absolute; inset: 0; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; outline: none; cursor: default; }
.stage[data-tool="hand"], .stage.space { cursor: grab; }
.stage.panning { cursor: grabbing !important; }
.stage[data-tool="text"], .stage[data-tool="shape"], .stage[data-tool="note"], .stage[data-tool="list"], .stage[data-tool="arrow"], .stage[data-tool="pen"], .stage[data-tool="highlighter"] { cursor: crosshair; }
.stage[data-tool="eraser"] { cursor: cell; }
.stage.drop::after { content: 'Rilascia qui immagini o video'; position: absolute; inset: 12px; border: 3px dashed var(--accent); border-radius: 16px; display: grid; place-items: center; font-size: 20px; font-weight: 600; color: var(--accent); background: rgba(66, 98, 255, .06); pointer-events: none; }
.world { position: absolute; left: 0; top: 0; transform-origin: 0 0; width: 0; height: 0; }

.it { position: absolute; }
.it.locked { cursor: default; }
.it.target { outline: 3px solid var(--accent); outline-offset: 3px; }
.txt { width: 100%; outline: none; white-space: pre-wrap; overflow-wrap: break-word; line-height: 1.35; cursor: inherit; }
.txt:empty::before { content: '\200b'; }
.editing .txt, .editing [contenteditable="true"] { user-select: text; -webkit-user-select: text; cursor: text; }
.it-shape { display: flex; justify-content: center; padding: 12px 14px; overflow: hidden; }
.it-shape.note { box-shadow: 0 6px 14px -4px rgba(0,0,0,.22), 0 1px 2px rgba(0,0,0,.08); }
.it-text { padding: 4px 6px; min-width: 20px; border-radius: 4px; }
.it-text .txt { white-space: pre-wrap; }
.it-text.editing .txt:empty::before, .it-shape.editing .txt:empty::before { content: 'Scrivi…'; opacity: .35; }
.it-list { padding: 12px 14px 10px; min-height: 40px; overflow: hidden; }
.l-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.l-title { flex: 1; font-weight: 700; font-size: 1.1em; outline: none; min-height: 1.3em; line-height: 1.3; overflow-wrap: anywhere; }
.l-count { font-size: .75em; opacity: .5; font-weight: 600; }
.l-row { display: flex; align-items: flex-start; gap: 9px; padding: 3px 0; }
.l-check { flex: none; width: 1.05em; height: 1.05em; margin-top: .17em; border: 2px solid currentColor; opacity: .55; border-radius: 4px; cursor: pointer; position: relative; }
.l-check:hover { opacity: 1; }
.l-row.done .l-check { background: #0ca789; border-color: #0ca789; opacity: 1; }
.l-row.done .l-check::after { content: ''; position: absolute; left: 30%; top: 8%; width: 28%; height: 55%; border: solid #fff; border-width: 0 2.5px 2.5px 0; transform: rotate(45deg); }
.l-txt { flex: 1; outline: none; min-height: 1.35em; line-height: 1.35; overflow-wrap: anywhere; }
.l-row.done .l-txt { text-decoration: line-through; opacity: .5; }
[data-ph]:empty::before { content: attr(data-ph); opacity: .35; }
.l-add { font-size: .85em; opacity: .55; padding: 6px 0 2px 2px; cursor: pointer; }
.l-add:hover { opacity: 1; }
.it-image, .it-video { overflow: hidden; background: rgba(0,0,0,.04); }
.it-image img, .it-video video { width: 100%; height: 100%; display: block; object-fit: fill; pointer-events: none; }
.it-video video { background: #000; object-fit: contain; }
.vid-cover { position: absolute; inset: 0; }
.it-video.player video { pointer-events: auto; }
.it-video.player .vid-cover { bottom: 56px; }
.it-stroke { pointer-events: none; }
.it-stroke svg { width: 100%; height: 100%; overflow: visible; display: block; }
.it-stroke path { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.it-stroke path.hit { pointer-events: stroke; }
.stage[data-tool="pen"] .it-stroke path.hit, .stage[data-tool="highlighter"] .it-stroke path.hit { pointer-events: none; }
.draw-live { position: absolute; left: 0; top: 0; width: 1px; height: 1px; overflow: visible; pointer-events: none; }
.draw-live path { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.upbar { position: absolute; left: 0; right: 0; bottom: 0; height: 26px; background: rgba(0,0,0,.55); color: #fff; font-size: 12px; display: flex; align-items: center; justify-content: center; }
.upfill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent); opacity: .8; transition: width .2s; }
.uptxt { position: relative; }
.ghost-shape { position: absolute; border: 2px dashed var(--accent); background: rgba(66, 98, 255, .06); pointer-events: none; }

svg.arrows { position: absolute; left: 0; top: 0; width: 1px; height: 1px; overflow: visible; pointer-events: none; }
svg.arrows path { fill: none; }
svg.arrows path.hit { stroke: transparent; pointer-events: stroke; cursor: pointer; }
.stage:not([data-tool="select"]) svg.arrows path.hit { pointer-events: none; }
svg.arrows g.sel path.line { filter: drop-shadow(0 0 2.5px rgba(66, 98, 255, .9)); }
.alabels { position: absolute; left: 0; top: 0; }
.alabel { position: absolute; transform: translate(-50%, -50%); padding: 2px 6px; border-radius: 4px; white-space: pre; font-weight: 500; cursor: pointer; outline: none; min-width: 10px; }
.alabel.editing { cursor: text; user-select: text; -webkit-user-select: text; box-shadow: 0 0 0 2px var(--accent); }

.overlay { position: absolute; inset: 0; pointer-events: none; }
.sel-outline { position: absolute; border: 1.5px solid var(--accent); pointer-events: none; }
.sel-group { position: absolute; border: 1.5px dashed var(--accent); pointer-events: none; }
.handle { position: absolute; width: 11px; height: 11px; margin: -5.5px 0 0 -5.5px; background: #fff; border: 1.5px solid var(--accent); border-radius: 3px; pointer-events: auto; touch-action: none; }
.handle.round, .handle.mid { border-radius: 50%; width: 13px; height: 13px; margin: -6.5px 0 0 -6.5px; }
.handle.mid { background: var(--accent); border-color: #fff; cursor: move; }
.handle.aend { cursor: crosshair; }
.h-nw, .h-se { cursor: nwse-resize; } .h-ne, .h-sw { cursor: nesw-resize; }
.h-n, .h-s { cursor: ns-resize; } .h-e, .h-w { cursor: ew-resize; }
.conn { position: absolute; width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50%; background: #fff; border: 2px solid var(--accent); pointer-events: auto; cursor: crosshair; opacity: .75; transition: transform .1s, opacity .1s; }
.conn:hover { opacity: 1; transform: scale(1.3); background: var(--accent); }
.lock-badge { position: absolute; transform: translate(-50%, -50%); font-size: 13px; background: #fff; border-radius: 50%; width: 24px; height: 24px; display: grid; place-items: center; box-shadow: var(--shadow); }
.marquee { position: absolute; border: 1px solid var(--accent); background: rgba(66, 98, 255, .08); pointer-events: none; }

/* barre */
.topbar { position: absolute; top: 10px; left: 10px; right: 10px; height: 48px; display: flex; align-items: center; gap: 6px; padding: 0 8px; background: var(--ui); border-radius: 12px; box-shadow: var(--shadow); pointer-events: auto; max-width: calc(100% - 20px); }
.topbar .back { padding: 6px 10px; font-size: 18px; }
.board-title { border: 0; background: transparent; font-weight: 700; font-size: 15px; padding: 6px 10px; border-radius: 8px; cursor: pointer; max-width: 40vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.board-title:hover { background: var(--ui-2); }
.save-status { font-size: 12px; color: var(--muted); white-space: nowrap; }
.save-status.ok::before { content: '✓ '; color: #0ca789; }
.save-status.err { color: var(--danger); }
.zoom-box { display: flex; align-items: center; gap: 2px; background: var(--ui-2); border-radius: 9px; padding: 2px; }
.zoom-lbl { border: 0; background: transparent; min-width: 56px; font-size: 13px; font-weight: 600; cursor: pointer; padding: 6px 4px; border-radius: 6px; }
.zoom-lbl:hover { background: #fff; }
.leftbar { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 2px; padding: 6px; background: var(--ui); border-radius: 12px; box-shadow: var(--shadow); max-height: calc(100% - 90px); overflow: auto; scrollbar-width: none; margin-top: 29px; }
.leftbar .sep, .sep { height: 1px; background: var(--line); margin: 4px 4px; flex: none; }
.tool { width: 40px; height: 40px; border: 0; background: transparent; border-radius: 9px; cursor: pointer; display: grid; place-items: center; flex: none; }
.tool:hover { background: var(--ui-2); }
.tool.active { background: var(--accent-soft); color: var(--accent); }
.ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; display: block; }
.toolopts { position: absolute; left: 66px; padding: 6px; background: var(--ui); border-radius: 12px; box-shadow: var(--shadow); }
.toolopts.hidden { display: none; }
.opts-col { display: flex; flex-direction: column; align-items: center; gap: 5px; }
.sep-h { height: 1px; width: 100%; background: var(--line); margin: 2px 0; }
.wbtn { width: 32px; height: 32px; border: 0; background: transparent; border-radius: 8px; display: grid; place-items: center; cursor: pointer; }
.wbtn span { border-radius: 50%; display: block; }
.wbtn.on, .wbtn:hover { background: var(--ui-2); }
.sw { width: 24px; height: 24px; border-radius: 50%; border: 1px solid rgba(0,0,0,.15); cursor: pointer; padding: 0; flex: none; }
.sw.on { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--accent); }
.sw.none { background: linear-gradient(135deg, #fff 45%, #e5484d 45% 55%, #fff 55%) !important; }
.cinput { width: 28px; height: 28px; padding: 0; border: 0; background: none; cursor: pointer; }

.ctxbar { position: absolute; left: 0; top: 0; display: flex; align-items: center; gap: 2px; padding: 4px; background: var(--ui); border-radius: 11px; box-shadow: var(--shadow); z-index: 20; white-space: nowrap; max-width: calc(100vw - 20px); overflow-x: auto; scrollbar-width: none; }
.ctxbar.hidden { display: none; }
.cgrp { display: flex; align-items: center; gap: 1px; padding: 0 3px; }
.cgrp + .cgrp { border-left: 1px solid var(--line); }
.cbtn { min-width: 32px; height: 32px; border: 0; background: transparent; border-radius: 7px; cursor: pointer; display: inline-grid; place-items: center; font-size: 15px; padding: 0 6px; color: inherit; text-decoration: none; }
.cbtn:hover { background: var(--ui-2); }
.cbtn.on { background: var(--accent-soft); color: var(--accent); }
.cbtn .ic { width: 19px; height: 19px; }
.cbtn.txtbtn { font-size: 13px; font-weight: 600; padding: 0 10px; }
.csel { height: 30px; border: 1px solid transparent; background: transparent; border-radius: 7px; font: inherit; font-size: 13px; padding: 0 4px; cursor: pointer; }
.csel:hover { background: var(--ui-2); }
.csize { width: 40px; height: 28px; text-align: center; border: 1px solid var(--line); border-radius: 6px; font: inherit; font-size: 13px; }
.swatch { width: 18px; height: 18px; border-radius: 50%; display: block; border: 1px solid rgba(0,0,0,.18); background-clip: padding-box; }
.swatch.ring { background: transparent; border-width: 4px; }
.tcol { font-weight: 700; font-size: 15px; display: flex; flex-direction: column; align-items: center; line-height: 1; }
.tcol i { display: block; width: 16px; height: 4px; border-radius: 2px; margin-top: 2px; border: 1px solid rgba(0,0,0,.15); }
.hl { background: #f5d128; padding: 0 3px; border-radius: 3px; font-weight: 700; font-size: 13px; }
.popup { position: absolute; z-index: 30; background: var(--ui); border-radius: 12px; box-shadow: var(--shadow); padding: 10px; }
.palette { display: grid; grid-template-columns: repeat(6, 26px); gap: 7px; align-items: center; }
.palette .custom { grid-column: span 6; display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.pop-col { display: flex; flex-direction: column; gap: 8px; min-width: 200px; }
.pop-row { display: flex; align-items: center; justify-content: space-between; gap: 6px; font-size: 13px; }
.pop-label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.pop-col input[type=range] { width: 100%; accent-color: var(--accent); }

@media (max-width: 700px) {
  .topbar { height: 44px; }
  .save-status { display: none; }
  .board-title { max-width: 34vw; }
  .leftbar { top: auto; bottom: 10px; left: 50%; transform: translateX(-50%); flex-direction: row; max-width: calc(100% - 20px); max-height: none; margin: 0; overflow-x: auto; }
  .leftbar .sep { width: 1px; height: auto; margin: 4px 2px; }
  .toolopts { left: 50%; transform: translateX(-50%); top: auto !important; bottom: 66px; }
  .opts-col { flex-direction: row; flex-wrap: wrap; justify-content: center; max-width: 92vw; }
  .sep-h { width: 1px; height: 24px; }
}
