/* Strenna — interfaccia dell'editor.
   Concetto: un banco da tipografo sobrio che lascia tutta l'attenzione alla grafica.
   Neutri con leggera tinta abete, un solo accento mirtillo, selezione azzurro ghiaccio
   per restare leggibile sopra rossi, verdi e ori delle composizioni. */
@font-face { font-family: 'Hanken Grotesk'; font-weight: 400; font-style: normal; font-display: swap; src: url(../assets/fonts/hanken-grotesk-latin-400-normal.woff2) format('woff2'); }
@font-face { font-family: 'Hanken Grotesk'; font-weight: 500; font-style: normal; font-display: swap; src: url(../assets/fonts/hanken-grotesk-latin-500-normal.woff2) format('woff2'); }
@font-face { font-family: 'Hanken Grotesk'; font-weight: 600; font-style: normal; font-display: swap; src: url(../assets/fonts/hanken-grotesk-latin-600-normal.woff2) format('woff2'); }
@font-face { font-family: 'Cormorant Wordmark'; font-weight: 600; font-style: italic; font-display: swap; src: url(../assets/fonts/cormorant-garamond-latin-600-italic.woff2) format('woff2'); }

:root {
  --bg: #e4e7e2; --surface: #f7f8f5; --surface-2: #eef0eb; --line: #d5d9d2; --ink: #17201b; --ink-2: #566159; --ink-3: #7c867e;
  --accent: #a31f35; --accent-ink: #ffffff; --accent-soft: #f6e3e5; --select: #1b8ae8; --warn: #a86300; --warn-soft: #f8ecd6; --danger: #b3202e; --ok: #1f6b45;
  --stage: #cfd4cd; --sheet-shadow: 0 10px 40px rgb(23 32 27 / .22); --pop-shadow: 0 8px 30px rgb(23 32 27 / .2);
  --font-ui: 'Hanken Grotesk', system-ui, -apple-system, 'Segoe UI', sans-serif; --font-mark: 'Cormorant Wordmark', Georgia, serif;
  --r: 7px; --top-h: 54px; --left-w: 330px; --right-w: 306px; --rail-w: 68px;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #111613; --surface: #1a201c; --surface-2: #232a25; --line: #2f3831; --ink: #eef1ec; --ink-2: #a9b3ab; --ink-3: #828c84;
  --accent: #e0566a; --accent-ink: #1c0b0e; --accent-soft: #3a1c22; --select: #54b3ff; --warn: #e9b35a; --warn-soft: #3a2d15; --danger: #ef6b74; --ok: #6cc497;
  --stage: #0c100e; --sheet-shadow: 0 10px 40px rgb(0 0 0 / .6); --pop-shadow: 0 8px 30px rgb(0 0 0 / .55); color-scheme: dark;
} }
:root[data-theme="dark"] {
  --bg: #111613; --surface: #1a201c; --surface-2: #232a25; --line: #2f3831; --ink: #eef1ec; --ink-2: #a9b3ab; --ink-3: #828c84;
  --accent: #e0566a; --accent-ink: #1c0b0e; --accent-soft: #3a1c22; --select: #54b3ff; --warn: #e9b35a; --warn-soft: #3a2d15; --danger: #ef6b74; --ok: #6cc497;
  --stage: #0c100e; --sheet-shadow: 0 10px 40px rgb(0 0 0 / .6); --pop-shadow: 0 8px 30px rgb(0 0 0 / .55); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body { background: var(--bg); color: var(--ink); font: 400 13.5px/1.4 var(--font-ui); display: flex; flex-direction: column; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--select); outline-offset: 1px; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.icon { width: var(--icon, 18px); height: var(--icon, 18px); fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.spacer { flex: 1; }

/* Controlli */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 36px; padding: 0 13px; border: 1px solid var(--line); background: var(--surface); border-radius: var(--r); font-weight: 500; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: var(--ink-3); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.small { min-height: 31px; padding: 0 10px; font-size: 12.5px; }
.btn.wide { width: 100%; }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border: 0; background: transparent; border-radius: var(--r); color: var(--ink-2); flex: none; }
.icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
input[type="text"], input[type="number"], input[type="search"], select, textarea { width: 100%; min-height: 32px; padding: 5px 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
textarea { resize: vertical; line-height: 1.35; }
input:focus, select:focus, textarea:focus { border-color: var(--select); outline: none; }
input[type="color"] { width: 34px; height: 32px; padding: 2px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; cursor: pointer; flex: none; }
input[type="range"] { flex: 1; min-width: 0; accent-color: var(--accent); }
.num { position: relative; display: flex; align-items: center; min-width: 0; font-variant-numeric: tabular-nums; }
.num .unit { position: absolute; right: 7px; color: var(--ink-3); font-size: 11px; pointer-events: none; }
.num input { padding-right: 24px; -moz-appearance: textfield; appearance: textfield; }
.num input::-webkit-inner-spin-button { display: none; }
.num.small { width: 66px; flex: none; }
.slider { display: flex; align-items: center; gap: 10px; }
.segmented { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: var(--surface); }
.seg { flex: 1; min-height: 30px; padding: 0 8px; border: 0; background: transparent; color: var(--ink-2); font-size: 12.5px; display: grid; place-items: center; }
.seg + .seg { border-left: 1px solid var(--line); }
.seg[aria-pressed="true"] { background: var(--ink); color: var(--surface); }
.switch { position: relative; display: inline-block; width: 34px; height: 20px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch .track { position: absolute; inset: 0; background: var(--line); border-radius: 10px; pointer-events: none; transition: background .12s; }
.switch .track::after { content: ''; position: absolute; left: 2px; top: 2px; width: 16px; height: 16px; background: var(--surface); border-radius: 50%; transition: transform .12s; box-shadow: 0 1px 2px rgb(0 0 0 / .3); }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(14px); }
.switch input:focus-visible + .track { outline: 2px solid var(--select); outline-offset: 1px; }
.check { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { padding: 1px 8px; min-height: 24px; border: 1px solid var(--line); border-radius: 14px; background: transparent; font-size: 12px; color: var(--ink-2); }
.chip:hover { border-color: var(--ink-3); }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.chips.subtle .chip { border-style: dashed; }
.badge { display: inline-block; padding: 1px 7px; font-size: 11px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); }
.hint { margin: 0; color: var(--ink-2); font-size: 12.5px; }

/* Barra superiore */
.topbar { height: var(--top-h); flex: none; display: flex; align-items: center; gap: 8px; padding-inline: max(14px, env(safe-area-inset-left, 0px)) max(14px, env(safe-area-inset-right, 0px)); background: var(--surface); border-bottom: 1px solid var(--line); z-index: 30; }
.brand { padding-right: 6px; }
.wordmark { font: italic 600 27px/1 var(--font-mark); color: var(--accent); letter-spacing: .01em; }
.project-name { width: 210px; flex: 0 1 210px; min-width: 70px; border-color: transparent !important; background: transparent !important; font-weight: 600; }
.project-name:hover, .project-name:focus { border-color: var(--line) !important; background: var(--surface) !important; }
.format-btn small { color: var(--ink-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.top-group { display: flex; }
.save-status { color: var(--ink-3); font-size: 12px; white-space: nowrap; }

/* Area di lavoro */
.workspace { flex: 1; min-height: 0; display: flex; }
.panel { background: var(--surface); display: flex; min-height: 0; flex: none; }
.panel.left { width: var(--left-w); border-right: 1px solid var(--line); }
.panel.right { width: var(--right-w); border-left: 1px solid var(--line); flex-direction: column; }
.panel-body { flex: 1; min-width: 0; min-height: 0; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.sheet-grip { display: none; }
.rail { width: var(--rail-w); flex: none; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--surface-2); padding-block: 6px; gap: 2px; }
.rail-tab { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 9px 2px; border: 0; background: transparent; color: var(--ink-2); font-size: 11px; font-weight: 500; }
.rail-tab .icon { --icon: 21px; }
.rail-tab:hover { color: var(--ink); }
.rail-tab[aria-selected="true"] { color: var(--accent); background: var(--surface); }
.tabs { display: flex; border-bottom: 1px solid var(--line); flex: none; }
.tab { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px; border: 0; background: transparent; color: var(--ink-2); font-weight: 500; font-size: 12.5px; border-bottom: 2px solid transparent; }
.tab .icon { --icon: 15px; }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }

/* Canvas */
.stage { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--stage); }
.stage-main { flex: 1; min-height: 0; position: relative; }
.viewport { position: absolute; inset: 0; overflow: hidden; touch-action: none; outline: none; user-select: none; -webkit-user-select: none; }
.viewport.is-pan { cursor: grab; }
.viewport.is-drop { box-shadow: inset 0 0 0 3px var(--select); }
/* La scacchiera indica la trasparenza: una pagina senza sfondo esce davvero trasparente nel PNG. */
.page-sheet { position: absolute; box-shadow: var(--sheet-shadow); background: repeating-conic-gradient(#d9d9d9 0 25%, #f4f4f4 0 50%) 0 0 / 20px 20px; }
.page-sheet svg { display: block; width: 100%; height: 100%; }
#overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.ov-box { fill: none; stroke: var(--select); stroke-width: 1.4; }
.ov-box.is-locked { stroke-dasharray: 4 4; }
.ov-box.is-group { stroke-dasharray: 6 3; }
.ov-handle { fill: #fff; stroke: var(--select); stroke-width: 1.6; pointer-events: all; }
.ov-rotate { fill: var(--select); stroke: #fff; stroke-width: 1.6; pointer-events: all; cursor: grab; }
.ov-stem { stroke: var(--select); stroke-width: 1.2; }
.ov-safe { fill: none; stroke: #18c0c9; stroke-width: 1; stroke-dasharray: 5 5; }
.ov-grid { fill: none; stroke: #18c0c9; stroke-opacity: .32; stroke-width: 1; }
.ov-guide { stroke: #ff3ea5; stroke-width: 1; }
.ov-marquee { fill: color-mix(in srgb, var(--select) 12%, transparent); stroke: var(--select); stroke-width: 1; }
.part-focus { stroke: var(--select) !important; stroke-width: 3px !important; vector-effect: non-scaling-stroke; }
.inline-text { position: absolute; z-index: 5; transform-origin: center; background: rgb(255 255 255 / .06); border: 1px dashed var(--select); padding: 0; margin: 0; resize: none; outline: none; overflow: hidden; caret-color: var(--select); min-height: 0; border-radius: 0; }
.stage-bar { flex: none; height: 40px; display: flex; align-items: center; gap: 12px; padding-inline: 10px; background: var(--surface); border-top: 1px solid var(--line); position: relative; }
.stage-group { display: flex; align-items: center; }
.stage-bar .icon-btn { width: 30px; height: 30px; }
.zoom-label { border: 0; background: transparent; min-width: 48px; font-variant-numeric: tabular-nums; font-size: 12.5px; color: var(--ink-2); }
.warn-btn { display: inline-flex; align-items: center; gap: 6px; min-height: 28px; padding: 0 9px; border: 0; border-radius: 14px; background: transparent; color: var(--ok); font-size: 12.5px; font-weight: 500; }
.warn-btn .icon { --icon: 15px; }
.warn-btn.has-warnings { background: var(--warn-soft); color: var(--warn); }
.warn-pop { position: absolute; right: 8px; bottom: 44px; width: min(340px, calc(100vw - 32px)); max-height: 280px; overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--pop-shadow); padding: 8px; z-index: 20; }
.warn-pop ul { list-style: none; margin: 0; padding: 0; }
.warn-row { display: flex; flex-direction: column; width: 100%; text-align: left; border: 0; background: transparent; padding: 6px 8px; border-radius: 6px; border-left: 3px solid var(--line); margin-bottom: 3px; }
.warn-row:hover { background: var(--surface-2); }
.warn-row.level-error { border-left-color: var(--danger); }
.warn-row.level-warn { border-left-color: var(--warn); }
.warn-row span { color: var(--ink-2); font-size: 12.5px; }
.pages-bar { flex: none; height: 88px; display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--surface-2); border-top: 1px solid var(--line); }
.pages-strip { flex: 1; min-width: 0; height: 100%; display: flex; gap: 8px; overflow-x: auto; padding: 2px; }
.page-thumb { position: relative; height: 100%; flex: none; padding: 0; border: 2px solid transparent; border-radius: 4px; background: #fff; overflow: hidden; box-shadow: 0 0 0 1px var(--line); }
.page-thumb svg { display: block; width: 100%; height: 100%; }
.page-thumb[aria-current="true"] { border-color: var(--accent); }
.page-num { position: absolute; left: 3px; bottom: 3px; min-width: 16px; padding: 0 4px; border-radius: 3px; background: rgb(0 0 0 / .62); color: #fff; font-size: 10.5px; }
.pages-tools { display: flex; flex: none; }

/* Libreria */
.search { background: var(--surface-2); border-color: transparent; }
.asset-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.asset { aspect-ratio: 1; padding: 6px; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: var(--surface-2); display: grid; place-items: center; }
.kind-background .asset { padding: 0; }
.kind-frame .asset { padding: 0; }
.asset img { width: 100%; height: 100%; object-fit: contain; display: block; }
.asset:hover { outline: 2px solid var(--select); outline-offset: -2px; }
.panel-title { margin: 8px 0 0; font-size: 12px; font-weight: 600; color: var(--ink-2); letter-spacing: .04em; text-transform: uppercase; }
.template-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; align-items: start; }
.template-grid.wide { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
.tpl { padding: 0; border: 0; background: transparent; text-align: left; position: relative; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.tpl-thumb { display: block; width: 100%; background: var(--surface-2); border-radius: 4px; overflow: hidden; box-shadow: 0 0 0 1px var(--line); }
.tpl-thumb svg { display: block; width: 100%; height: 100%; }
.tpl:hover .tpl-thumb { box-shadow: 0 0 0 2px var(--select); }
.tpl-name { font-size: 12.5px; color: var(--ink-2); }
.tpl .badge { position: absolute; top: 5px; right: 5px; }
.text-presets { display: flex; flex-direction: column; gap: 6px; }
.text-preset { padding: 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); font-size: 25px; line-height: 1.15; text-align: center; }
.text-preset:hover { border-color: var(--select); }
.dropzone { display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 24px 12px; border: 1.5px dashed var(--ink-3); border-radius: var(--r); text-align: center; color: var(--ink-2); cursor: pointer; }
.dropzone strong { color: var(--ink); }
.dropzone.is-over, .dropzone:hover { border-color: var(--select); }
.font-list { margin: 0; padding: 0; list-style: none; font-size: 18px; }

/* Proprietà */
.selection-title { font-weight: 600; font-size: 14px; overflow-wrap: anywhere; }
.section { border-top: 1px solid var(--line); margin-inline: -12px; padding-inline: 12px; }
.section-head { display: flex; align-items: center; justify-content: space-between; width: 100%; min-height: 36px; padding: 0; border: 0; background: transparent; font-weight: 600; font-size: 12.5px; color: var(--ink); }
.section-head .icon { --icon: 14px; color: var(--ink-3); transition: transform .12s; }
.section-head[aria-expanded="true"] .icon { transform: rotate(90deg); }
.section-body { padding-bottom: 12px; display: flex; flex-direction: column; gap: 9px; }
.fields { display: flex; flex-wrap: wrap; gap: 8px; }
.field { width: 100%; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.field.half { width: calc(50% - 4px); }
.field-label { color: var(--ink-2); font-size: 12px; }
.field-title { width: 100%; font-weight: 600; font-size: 12.5px; }
.field.is-toggle { flex-direction: row; align-items: center; justify-content: space-between; }
.color-field { display: flex; flex-direction: column; gap: 5px; }
.color-main { display: flex; gap: 6px; }
.hex { font-variant-numeric: tabular-nums; text-transform: uppercase; }
.role-chips { display: flex; gap: 4px; }
.role-chip { width: 22px; height: 22px; padding: 0; border-radius: 50%; border: 1px solid rgb(0 0 0 / .22); }
.role-chip.is-on { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--select); }
.action-row { display: flex; flex-wrap: wrap; gap: 6px; }
.action-col { display: flex; flex-direction: column; gap: 6px; }
.tool-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 2px; }
.tool-grid .icon-btn { width: 100%; }
.font-field { position: relative; }
.font-btn { display: flex; align-items: center; justify-content: space-between; width: 100%; min-height: 36px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); font-size: 16px; }
.font-btn .icon { --icon: 13px; transform: rotate(90deg); color: var(--ink-3); }
.font-pop { position: absolute; left: 0; right: 0; top: calc(100% + 3px); z-index: 25; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--pop-shadow); padding: 6px; display: flex; flex-direction: column; gap: 5px; }
.font-scroll { max-height: 310px; overflow-y: auto; display: flex; flex-direction: column; }
.font-cat { padding: 6px 6px 2px; font-size: 11px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; }
.font-opt { text-align: left; padding: 4px 6px; border: 0; background: transparent; font-size: 19px; line-height: 1.2; border-radius: 4px; }
.font-opt:hover { background: var(--surface-2); }
.parts { display: flex; flex-direction: column; gap: 2px; max-height: 260px; overflow-y: auto; }
.part-row { display: flex; align-items: center; }
.part-name { flex: 1; text-align: left; border: 0; background: transparent; padding: 5px 6px; border-radius: 4px; font-size: 12.5px; }
.part-name:hover { background: var(--surface-2); }
.part-detail { padding: 4px 6px 10px; display: flex; flex-direction: column; gap: 6px; }

/* Colori */
.palette-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.palette-card { position: relative; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.palette-card.is-on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.palette-card .icon-btn { position: absolute; right: 0; bottom: 0; width: 24px; height: 24px; }
.palette-pick { display: block; width: 100%; padding: 0; border: 0; background: transparent; text-align: left; }
.swatches { display: flex; height: 26px; }
.swatches i { flex: 1; }
.palette-name { display: block; padding: 3px 6px 4px; font-size: 11.5px; line-height: 1.2; min-height: 34px; }
.field.is-role { flex-direction: row; align-items: center; justify-content: space-between; }
.role-field { display: flex; align-items: center; gap: 8px; }
.hex-label { font-variant-numeric: tabular-nums; font-size: 12px; color: var(--ink-2); }
.inline-form { display: flex; gap: 6px; }
.used-colors { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.used-color { display: flex; align-items: center; gap: 6px; }
.used-color input { width: 28px; height: 26px; }
.count { color: var(--ink-3); font-size: 11.5px; margin-left: auto; font-variant-numeric: tabular-nums; }

/* Livelli */
.layer-tools { display: flex; justify-content: space-between; }
.layers { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.layer { display: flex; align-items: center; gap: 4px; padding: 2px 3px 2px 7px; border-radius: 6px; color: var(--ink-2); min-height: 36px; }
.layer .icon-btn { width: 28px; height: 28px; }
.layer > .icon { --icon: 15px; }
.layer:hover { background: var(--surface-2); }
.layer.is-on { background: var(--accent-soft); color: var(--ink); }
.layer.is-hidden .layer-name { opacity: .5; text-decoration: line-through; }
.layer.is-over { box-shadow: inset 0 2px 0 var(--select); }
.layer-name { flex: 1; min-width: 0; border-color: transparent !important; background: transparent !important; padding: 3px 4px; min-height: 26px; font-size: 12.5px; text-overflow: ellipsis; }
.layer-name:focus { border-color: var(--select) !important; background: var(--surface) !important; }
.only-touch { display: none; }

/* Finestre */
.modal { padding: 0; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); max-height: min(88dvh, 860px); width: min(calc(100vw - 24px), 560px); overflow: hidden; flex-direction: column; box-shadow: var(--sheet-shadow); }
.modal[open] { display: flex; }
.modal.size-sm { width: min(calc(100vw - 24px), 420px); }
.modal.size-lg { width: min(calc(100vw - 24px), 960px); }
.modal::backdrop { background: rgb(10 16 13 / .55); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px 10px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 16px; font-weight: 600; overflow-wrap: anywhere; }
.modal-body { padding: 14px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.modal-body p { margin: 0; }
.modal-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }
.new-form { display: grid; grid-template-columns: 1.3fr 1.3fr 1fr auto; gap: 10px; align-items: end; }
.format-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.format-card { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 2px; min-height: 142px; padding: 10px 6px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); font-size: 12.5px; text-align: center; }
.format-card i { display: block; height: 62px; max-width: 100%; margin-bottom: 6px; background: var(--ink); opacity: .85; border-radius: 2px; }
.format-card span { color: var(--ink-2); font-size: 12px; font-variant-numeric: tabular-nums; }
.format-card:hover { border-color: var(--select); }
.format-card.is-on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.custom-size { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.custom-size .field.half { width: 130px; }
.export-form { display: flex; flex-direction: column; gap: 14px; }
.res-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.res-row .segmented { flex: 1 1 220px; }
.res-row .num { width: 106px; }
.ig-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; margin-top: 5px; }
.export-summary { font-weight: 600; font-variant-numeric: tabular-nums; }
.export-warn { display: flex; gap: 9px; padding: 9px 11px; background: var(--warn-soft); color: var(--warn); border-radius: 6px; }
.export-warn ul { margin: 2px 0 0; padding-left: 16px; }
.project-list { display: flex; flex-direction: column; gap: 8px; }
.project-card { display: flex; align-items: center; gap: 12px; padding: 8px; border: 1px solid var(--line); border-radius: var(--r); }
.project-thumb { height: 76px; flex: none; overflow: hidden; border-radius: 3px; box-shadow: 0 0 0 1px var(--line); background: var(--surface-2); }
.project-thumb svg { display: block; width: 100%; height: 100%; }
.project-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; font-size: 12.5px; color: var(--ink-2); }
.project-meta strong { color: var(--ink); font-size: 14px; overflow-wrap: anywhere; }
.project-actions { display: flex; align-items: center; gap: 2px; flex: none; }
.preview-bar { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: center; }
.preview-nav { display: flex; align-items: center; gap: 4px; }
.preview-count { font-variant-numeric: tabular-nums; color: var(--ink-2); }
.preview-stage { background: var(--stage); border-radius: 6px; padding: 16px; display: grid; place-items: center; min-height: 320px; }
.preview-img { max-height: 60dvh; max-width: 100%; display: block; box-shadow: var(--sheet-shadow); }
.preview-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; width: min(100%, 460px); }
.preview-cell { overflow: hidden; display: block; }
.preview-cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.variant-opts { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
.variant-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; align-items: start; }
.variant { display: flex; flex-direction: column; gap: 6px; }
.variant-thumb { display: block; overflow: hidden; border-radius: 4px; box-shadow: 0 0 0 1px var(--line); }
.variant-thumb svg { display: block; width: 100%; height: 100%; }
.variant-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(142px + env(safe-area-inset-bottom, 0px)); z-index: 100; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
.toast { padding: 8px 14px; border-radius: 8px; background: var(--ink); color: var(--surface); box-shadow: var(--pop-shadow); }
.toast.is-error { background: var(--danger); color: #fff; }
.toast.is-warn { background: var(--warn); color: var(--surface); }
.boot { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: 24px; text-align: center; background: var(--bg); color: var(--accent); font: italic 600 42px/1.2 var(--font-mark); }
.mobile-nav { display: none; }

/* Telefoni e tablet stretti: i pannelli diventano fogli dal basso */
@media (max-width: 900px) {
  :root { --top-h: 50px; }
  .topbar { gap: 2px; padding-inline: max(8px, env(safe-area-inset-left, 0px)) max(8px, env(safe-area-inset-right, 0px)); }
  .brand, .save-status, #btn-save { display: none; }
  .project-name { flex: 1 1 60px; width: 60px; padding-inline: 4px; }
  .format-btn { padding: 0 8px; }
  .format-btn span { display: none; }
  .format-btn small { font-size: 11px; }
  #btn-export { padding: 0 9px; }
  #btn-export span { display: none; }
  .panel, .panel.left, .panel.right, .pages-bar { position: fixed; left: 0; right: 0; bottom: calc(58px + env(safe-area-inset-bottom, 0px)); width: auto; height: min(56dvh, 480px); z-index: 40; border: 0; border-top: 1px solid var(--line); border-radius: 14px 14px 0 0; box-shadow: var(--sheet-shadow); flex-direction: column; transform: translateY(calc(100% + 80px)); visibility: hidden; transition: transform .2s ease, visibility .2s; padding-inline: env(safe-area-inset-left, 0px) env(safe-area-inset-right, 0px); }
  body[data-sheet="left"] .panel.left, body[data-sheet="right"] .panel.right, body[data-sheet="pages"] .pages-bar { transform: none; visibility: visible; }
  .pages-bar { height: 150px; background: var(--surface); flex-direction: column; gap: 4px; align-items: stretch; padding: 0 10px 8px; }
  .pages-strip { height: auto; flex: 1; min-height: 0; }
  .pages-tools { justify-content: center; }
  .sheet-grip { display: block; flex: none; height: 16px; position: relative; cursor: pointer; }
  .sheet-grip::after { content: ''; position: absolute; left: 50%; top: 6px; width: 40px; height: 4px; margin-left: -20px; border-radius: 2px; background: var(--line); }
  .rail { width: auto; flex-direction: row; border-right: 0; border-bottom: 1px solid var(--line); padding: 0 4px; overflow-x: auto; flex: none; background: transparent; }
  .rail-tab { flex: 1 0 auto; padding: 6px 10px; flex-direction: row; font-size: 12.5px; gap: 5px; }
  .rail-tab .icon { --icon: 16px; }
  .asset-grid { grid-template-columns: repeat(4, 1fr); }
  .template-grid { grid-template-columns: repeat(3, 1fr); }
  .stage-bar { height: 38px; gap: 2px; padding-inline: 4px; }
  #zoom-out, #zoom-in, #toggle-grid { display: none; }
  .mobile-nav { display: flex; flex: none; height: calc(58px + env(safe-area-inset-bottom, 0px)); padding-bottom: env(safe-area-inset-bottom, 0px); padding-inline: env(safe-area-inset-left, 0px) env(safe-area-inset-right, 0px); background: var(--surface); border-top: 1px solid var(--line); z-index: 45; position: relative; }
  .nav-btn { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border: 0; background: transparent; color: var(--ink-2); font-size: 11px; }
  .only-touch { display: inline-grid; }
  .new-form { grid-template-columns: 1fr; }
  .format-grid { grid-template-columns: repeat(2, 1fr); }
  .ig-grid { grid-template-columns: 1fr; }
  .project-card { flex-wrap: wrap; }
  .toasts { bottom: calc(112px + env(safe-area-inset-bottom, 0px)); }
  .ov-handle { rx: 6; }
}
@media (pointer: coarse) { .icon-btn { min-width: 38px; min-height: 38px; } .slider input[type="range"] { height: 28px; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
