/* ==========================================================================
   Card Generator — interfaccia
   ========================================================================== */

:root {
    --font-ui: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --font-display: 'Outfit', 'Inter', system-ui, sans-serif;
    --font-mono: ui-monospace, 'Cascadia Code', Consolas, monospace;

    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;

    --accent: #8b6cff;
    --accent-2: #4f8cff;
    --accent-grad: linear-gradient(135deg, #9d7cff 0%, #5a8dff 100%);
    --accent-soft: rgba(139, 108, 255, 0.16);
    --accent-ring: rgba(139, 108, 255, 0.45);
    --danger: #f06a6a;
    --danger-soft: rgba(240, 106, 106, 0.14);
    --success: #34d399;
    --warning: #fbbf24;

    --rail-w: 80px;
    --panel-w: 420px;
    --topbar-h: 60px;
    --ease: cubic-bezier(0.2, 0.8, 0.2, 1);

    color-scheme: dark;
    --bg: #0a0c11;
    --bg-2: #0e1117;
    --surface: #141720;
    --surface-2: #1a1e29;
    --surface-3: #232836;
    --field: #0c0f15;
    --line: rgba(255, 255, 255, 0.07);
    --line-2: rgba(255, 255, 255, 0.12);
    --line-3: rgba(255, 255, 255, 0.2);
    --text: #e9ecf3;
    --text-2: #b6bdcc;
    --muted: #7f889b;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.5);
    --stage-bg: #0b0d13;
    --stage-dot: rgba(255, 255, 255, 0.055);
    --card-shadow: 0 40px 80px rgba(0, 0, 0, 0.55), 0 12px 24px rgba(0, 0, 0, 0.35);
}

[data-theme="light"] {
    color-scheme: light;
    --bg: #eceef5;
    --bg-2: #f3f4f9;
    --surface: #ffffff;
    --surface-2: #f4f5fa;
    --surface-3: #e9ecf4;
    --field: #f6f7fb;
    --line: rgba(15, 23, 42, 0.08);
    --line-2: rgba(15, 23, 42, 0.13);
    --line-3: rgba(15, 23, 42, 0.22);
    --text: #111726;
    --text-2: #394256;
    --muted: #6b7489;
    --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 24px 60px rgba(15, 23, 42, 0.16);
    --stage-bg: #e2e5ee;
    --stage-dot: rgba(15, 23, 42, 0.09);
    --accent-soft: rgba(124, 92, 255, 0.12);
    --card-shadow: 0 34px 70px rgba(30, 35, 60, 0.28), 0 10px 20px rgba(30, 35, 60, 0.16);
}

/* ---- Base ---- */

*,
*::before,
*::after { box-sizing: border-box; }

html,
body { height: 100%; }

body {
    margin: 0;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.45 var(--font-ui);
    -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea { font: inherit; color: inherit; }

button { cursor: pointer; }
button:disabled { cursor: default; }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

[hidden] { display: none !important; }

::selection { background: var(--accent-ring); }

.scroll {
    scrollbar-width: thin;
    scrollbar-color: var(--surface-3) transparent;
}

.muted { color: var(--muted); }
.small { font-size: 0.8em; }

/* ---- Struttura ---- */

.app {
    display: grid;
    grid-template-columns: var(--rail-w) var(--panel-w) minmax(0, 1fr);
    grid-template-rows: var(--topbar-h) minmax(0, 1fr);
    grid-template-areas:
        "top top top"
        "rail panel stage";
    height: 100dvh;
}

/* ---- Barra superiore ---- */

.topbar {
    grid-area: top;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 14px 0 18px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
    text-decoration: none;
    flex: none;
}

.brand img {
    width: 30px;
    height: 30px;
    filter: drop-shadow(0 4px 10px rgba(139, 108, 255, 0.35));
}

.brand-name {
    font: 700 17px/1 var(--font-display);
    letter-spacing: -0.01em;
}

.brand-name b {
    background: var(--accent-grad);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.doc {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    padding-left: 16px;
    border-left: 1px solid var(--line-2);
}

.doc-title {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
}

.doc-status {
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 9px;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.doc-status.is-saved { color: var(--success); background: rgba(52, 211, 153, 0.1); }
.doc-status.is-draft { color: var(--warning); background: rgba(251, 191, 36, 0.1); }

.topbar-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 6px;
}

.topbar-sep {
    width: 1px;
    height: 22px;
    margin: 0 4px;
    background: var(--line-2);
}

/* ---- Barra laterale (sezioni) ---- */

.rail {
    grid-area: rail;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 14px 0;
    background: var(--surface);
    border-right: 1px solid var(--line);
}

.rail-btn {
    position: relative;
    width: 62px;
    padding: 9px 0 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    transition: color 0.15s, background 0.15s;
}

.rail-btn .bi { font-size: 20px; line-height: 1; }
.rail-btn:hover { color: var(--text); background: var(--surface-2); }
.rail-btn.is-active { color: var(--text); background: var(--accent-soft); }
.rail-btn.is-active .bi { color: var(--accent); }

.rail-badge {
    position: absolute;
    top: 4px;
    right: 8px;
    min-width: 17px;
    height: 17px;
    padding: 0 5px;
    border-radius: 999px;
    background: var(--accent);
    color: #fff;
    font-size: 10px;
    line-height: 17px;
}

/* ---- Pannello ---- */

.panel {
    grid-area: panel;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-2);
    border-right: 1px solid var(--line);
}

.view {
    min-height: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.panel-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 18px 14px;
    border-bottom: 1px solid var(--line);
}

.panel-head-text { min-width: 0; flex: 1; }

.panel-title {
    margin: 0;
    font: 600 17px/1.2 var(--font-display);
    letter-spacing: -0.01em;
}

.panel-sub {
    margin: 3px 0 0;
    color: var(--muted);
    font-size: 12.5px;
}

.panel-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 14px 14px 48px;
}

.panel-body::-webkit-scrollbar { width: 12px; }
.panel-body::-webkit-scrollbar-thumb {
    border: 4px solid transparent;
    border-radius: 12px;
    background: var(--surface-3) padding-box;
}

.section-label {
    margin: 18px 4px 8px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.section-label:first-child { margin-top: 2px; }

/* ---- Gruppi di campi ---- */

.group {
    margin-bottom: 10px;
    overflow: clip;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
}

.group-head {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 11px 14px;
    border: 0;
    background: none;
    text-align: left;
    font-weight: 600;
}

.group-icon {
    flex: none;
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    border-radius: 9px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 15px;
}

.group-chev {
    margin-left: auto;
    color: var(--muted);
    transition: transform 0.2s var(--ease);
}

.group.is-collapsed .group-chev { transform: rotate(-90deg); }

.group-body {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 14px 10px;
    padding: 6px 14px 16px;
}

.group.is-collapsed .group-body { display: none; }

.field { grid-column: span 6; min-width: 0; }
.field.w-half { grid-column: span 3; }
.field.w-third { grid-column: span 2; }
.field.w-twothirds { grid-column: span 4; }

.field.is-highlight {
    border-radius: 10px;
    animation: field-flash 1.2s ease-out;
}

@keyframes field-flash {
    0%, 30% { box-shadow: 0 0 0 4px var(--accent-soft), 0 0 0 1px var(--accent); }
    100% { box-shadow: 0 0 0 4px transparent, 0 0 0 1px transparent; }
}

.field-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    margin-bottom: 6px;
    color: var(--text-2);
    font-size: 12.5px;
    font-weight: 600;
}

.field-label-extra { color: var(--muted); font-weight: 500; }

.field-hint {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.4;
}

/* ---- Controlli ---- */

.input,
.textarea,
.select {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--line-2);
    border-radius: var(--radius-sm);
    background: var(--field);
    color: var(--text);
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.input:hover,
.textarea:hover,
.select:hover { border-color: var(--line-3); }

.input:focus,
.textarea:focus,
.select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.input::placeholder,
.textarea::placeholder { color: var(--muted); opacity: 0.8; }

.textarea {
    min-height: 68px;
    resize: vertical;
    line-height: 1.45;
}

.textarea.is-code {
    font-family: var(--font-mono);
    font-size: 12.5px;
}

.select {
    appearance: none;
    padding-right: 32px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 16 16' fill='%238a93a6'%3E%3Cpath d='M1.6 5.3a.75.75 0 0 1 1.06 0L8 10.6l5.34-5.3a.75.75 0 1 1 1.06 1.06l-5.87 5.87a.75.75 0 0 1-1.06 0L1.6 6.36a.75.75 0 0 1 0-1.06z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 11px center;
}

.select option { background: var(--surface); color: var(--text); }

.input-wrap { position: relative; }
.input-wrap .input { padding-right: 40px; }

.input-unit {
    position: absolute;
    right: 11px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    font-size: 12px;
    pointer-events: none;
}

input[type="number"].input { font-variant-numeric: tabular-nums; }

/* Segmentato */

.seg {
    display: flex;
    gap: 3px;
    padding: 3px;
    border: 1px solid var(--line-2);
    border-radius: 10px;
    background: var(--field);
}

.seg button {
    flex: 1 1 0;
    min-width: 0;
    padding: 6px 8px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--text-2);
    font-size: 12.5px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.15s, color 0.15s;
}

.seg button:hover { color: var(--text); }

.seg button.is-active {
    background: var(--surface-3);
    color: var(--text);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25), inset 0 0 0 1px var(--line-2);
}

[data-theme="light"] .seg button.is-active { background: #fff; }

/* Scelte con anteprima */

/* Colonne adattive: nel pannello stretto le etichette non vengono troncate. */
.choices {
    --choice-min: 62px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(var(--choice-min), 1fr));
    gap: 6px;
}

.choices.is-icon-only { --choice-min: 42px; }

.choice {
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    padding: 6px 4px;
    border: 1px solid var(--line-2);
    border-radius: 10px;
    background: var(--field);
    color: var(--text-2);
    font-size: 11.5px;
    font-weight: 600;
    line-height: 1.15;
    text-align: center;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.choice:hover { border-color: var(--accent-ring); color: var(--text); }

.choice.is-active {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--text);
    box-shadow: inset 0 0 0 1px var(--accent);
}

.choice-label {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.choice-swatch {
    width: 100%;
    height: 22px;
    border-radius: 6px;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25);
}

.choice-icon {
    display: grid;
    place-items: center;
    height: 28px;
    font-size: 26px;
    line-height: 1;
}

.choices.is-icon-only .choice { padding: 7px 4px; }
.choices.is-icon-only .choice-label { display: none; }
.choices.is-icon-only .choice.has-text { justify-content: center; }
.choices.is-icon-only .choice.has-text .choice-label { display: block; font-size: 15px; }
.choices.is-icon-only .choice-swatch { width: 26px; height: 26px; border-radius: 50%; }

/* Interruttore */

.switch {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-2);
    font-weight: 500;
    cursor: pointer;
    user-select: none;
}

.switch input {
    position: relative;
    flex: none;
    width: 38px;
    height: 22px;
    margin: 0;
    appearance: none;
    border-radius: 999px;
    background: var(--surface-3);
    box-shadow: inset 0 0 0 1px var(--line-2);
    cursor: pointer;
    transition: background 0.2s;
}

.switch input::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
    transition: transform 0.2s var(--ease);
}

.switch input:checked { background: var(--accent); box-shadow: none; }
.switch input:checked::after { transform: translateX(16px); }

/* Cursore */

.range {
    display: flex;
    align-items: center;
    gap: 10px;
}

.range input[type="range"] {
    flex: 1;
    min-width: 0;
    height: 4px;
    margin: 0;
    appearance: none;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--accent) var(--pct, 50%), var(--surface-3) var(--pct, 50%));
    outline: none;
}

.range input[type="range"]::-webkit-slider-thumb {
    width: 16px;
    height: 16px;
    appearance: none;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 0 4px var(--accent-soft), 0 1px 3px rgba(0, 0, 0, 0.4);
    cursor: grab;
}

.range input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border: 0;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 0 4px var(--accent-soft), 0 1px 3px rgba(0, 0, 0, 0.4);
    cursor: grab;
}

.range-value {
    flex: none;
    min-width: 58px;
    padding: 4px 6px;
    border: 1px solid var(--line-2);
    border-radius: 6px;
    background: var(--field);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    text-align: center;
}

/* Colore */

.color {
    display: flex;
    align-items: center;
    gap: 8px;
}

.color-swatch {
    position: relative;
    flex: none;
    width: 38px;
    height: 37px;
    overflow: hidden;
    border-radius: 8px;
    background: conic-gradient(#bbb 25%, #fff 0 50%, #bbb 0 75%, #fff 0) 0 0 / 10px 10px;
    box-shadow: inset 0 0 0 1px var(--line-2);
}

.color-swatch span { position: absolute; inset: 0; }

.color-swatch input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.color .input { font-family: var(--font-mono); font-size: 13px; }

/* Immagine */

.imagefield {
    display: grid;
    grid-template-columns: 92px minmax(0, 1fr);
    gap: 12px;
    align-items: start;
}

.imagefield-thumb {
    position: relative;
    width: 92px;
    height: 92px;
    display: grid;
    place-items: center;
    overflow: hidden;
    border: 1.5px dashed var(--line-3);
    border-radius: 12px;
    background: var(--field);
    color: var(--muted);
    font-size: 26px;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.imagefield-thumb:hover,
.imagefield.is-dragover .imagefield-thumb {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent);
}

.imagefield-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.imagefield.has-image .imagefield-thumb {
    border-style: solid;
    background: conic-gradient(#999 25%, #ccc 0 50%, #999 0 75%, #ccc 0) 0 0 / 12px 12px;
}

.imagefield-side {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.imagefield-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.imagefield-tip {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.35;
}

.imagefield-adjust {
    grid-column: 1 / -1;
    display: grid;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--surface-2);
}

.imagefield-adjust .range-label {
    flex: none;
    width: 56px;
    color: var(--text-2);
    font-size: 12px;
    font-weight: 600;
}

.imagefield.is-compact { grid-template-columns: 64px minmax(0, 1fr); }
.imagefield.is-compact .imagefield-thumb { width: 64px; height: 64px; font-size: 20px; }

/* Stelle */

.stars {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 1px;
}

.stars-btn {
    width: 25px;
    height: 27px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 0;
    background: none;
    font-size: 21px;
    line-height: 1;
    opacity: 0.25;
    filter: grayscale(1);
    transition: opacity 0.12s, transform 0.12s, filter 0.12s;
}

.stars-btn.is-on { opacity: 1; filter: none; }
.stars-btn:hover { transform: scale(1.15); opacity: 1; }

.stars-count {
    min-width: 30px;
    margin-left: 8px;
    padding: 2px 8px;
    border-radius: 6px;
    background: var(--surface-2);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    text-align: center;
}

/* Frecce Link */

.arrowpad {
    display: grid;
    grid-template-columns: repeat(3, 44px);
    grid-template-rows: repeat(3, 44px);
    gap: 6px;
}

.arrowpad button {
    display: grid;
    place-items: center;
    border: 1px solid var(--line-2);
    border-radius: 10px;
    background: var(--field);
    color: var(--muted);
    font-size: 18px;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.arrowpad button:hover { border-color: var(--accent-ring); color: var(--text); }

.arrowpad button.is-on {
    border-color: #ff7a52;
    background: linear-gradient(180deg, #ff6a45, #c0141a);
    color: #fff;
}

.arrowpad-center {
    display: grid;
    place-items: center;
    border-radius: 10px;
    background: var(--surface-3);
    color: var(--text-2);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.02em;
}

/* Energie / simboli */

.energies {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.energies-selected {
    min-height: 40px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    padding: 5px 7px;
    border: 1px solid var(--line-2);
    border-radius: 9px;
    background: var(--field);
}

.energies-selected button,
.energies-palette button {
    display: grid;
    place-items: center;
    padding: 3px;
    border: 0;
    border-radius: 50%;
    background: none;
    line-height: 1;
    transition: transform 0.12s;
}

.energies-selected button { font-size: 24px; }
.energies-selected button:hover { transform: scale(1.12) rotate(-8deg); }
.energies-palette { display: flex; flex-wrap: wrap; gap: 3px; }
.energies-palette button { font-size: 21px; }
.energies-palette button:hover { transform: scale(1.15); }

.energies-empty {
    padding-left: 4px;
    color: var(--muted);
    font-size: 12px;
}

.symbar {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 6px;
}

.symbar button {
    width: 32px;
    height: 30px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 1px solid var(--line-2);
    border-radius: 7px;
    background: var(--field);
    font-size: 18px;
    line-height: 1;
}

.symbar button:hover { border-color: var(--accent); }

.symbol-preview {
    min-height: 24px;
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    margin-top: 7px;
    font-size: 21px;
    line-height: 1;
}

/* Liste ripetibili */

.list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.list-item {
    border: 1px solid var(--line-2);
    border-radius: 11px;
    background: var(--surface-2);
}

.list-item-head {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 6px 6px 12px;
    border-bottom: 1px solid var(--line);
    color: var(--text-2);
    font-size: 12.5px;
    font-weight: 700;
}

.list-item-head span { flex: 1; }

.list-item-body {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 12px 10px;
    padding: 10px 12px 12px;
}

/* ---- Pulsanti ---- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    height: 36px;
    padding: 0 14px;
    border: 1px solid var(--line-2);
    border-radius: 10px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.1s, filter 0.15s;
}

.btn:hover { background: var(--surface-3); border-color: var(--line-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; pointer-events: none; }
.btn .bi { font-size: 15px; line-height: 1; }

.btn-primary {
    border: 0;
    background: var(--accent-grad);
    color: #fff;
    box-shadow: 0 6px 18px rgba(110, 90, 255, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.btn-primary:hover { background: var(--accent-grad); filter: brightness(1.08); }

.btn-ghost {
    border-color: transparent;
    background: transparent;
    color: var(--text-2);
}

.btn-ghost:hover { border-color: transparent; background: var(--surface-2); color: var(--text); }

.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: transparent; background: var(--danger-soft); }

/* Pulsante principale di un'azione distruttiva (es. "Sostituisci tutto"). */
.btn-primary.is-danger,
.btn-primary.is-danger:hover {
    background: linear-gradient(135deg, #f47c7c 0%, #d64545 100%);
    box-shadow: 0 6px 18px rgba(214, 69, 69, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.btn-dashed {
    border-style: dashed;
    background: transparent;
    color: var(--text-2);
}

.btn-icon { width: 36px; padding: 0; }
.btn-sm { height: 30px; padding: 0 10px; border-radius: 8px; font-size: 12.5px; }
.btn-sm.btn-icon { width: 30px; padding: 0; }
.btn-xs { height: 26px; padding: 0 8px; border-radius: 7px; font-size: 12px; }
.btn-xs.btn-icon { width: 26px; padding: 0; }
.btn-block { width: 100%; }

/* ---- Menu a tendina ---- */

.menu {
    position: fixed;
    z-index: 120;
    min-width: 250px;
    padding: 6px;
    border: 1px solid var(--line-2);
    border-radius: 13px;
    background: var(--surface);
    box-shadow: var(--shadow-lg);
    animation: pop 0.14s var(--ease);
}

.menu-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 8px 10px;
    border: 0;
    border-radius: 9px;
    background: none;
    color: var(--text);
    font-size: 13px;
    text-align: left;
}

.menu-item:hover,
.menu-item:focus-visible { background: var(--surface-2); outline: none; }

.menu-item > .bi {
    width: 30px;
    height: 30px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--accent);
    font-size: 15px;
}

.menu-item:hover > .bi { background: var(--surface-3); }
.menu-item-text { min-width: 0; }
.menu-item-text b { display: block; font-weight: 600; }
.menu-item-text small { display: block; color: var(--muted); font-size: 11.5px; }
.menu-item.is-danger { color: var(--danger); }
.menu-item.is-danger > .bi { color: var(--danger); }

.menu-sep {
    height: 1px;
    margin: 5px 6px;
    background: var(--line);
}

@keyframes pop {
    from { opacity: 0; transform: translateY(-4px) scale(0.98); }
    to { opacity: 1; transform: none; }
}

/* ---- Finestre modali ---- */

.modal {
    width: min(560px, calc(100vw - 32px));
    max-height: calc(100dvh - 48px);
    padding: 0;
    border: 1px solid var(--line-2);
    border-radius: 18px;
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-lg);
}

.modal[open] {
    display: flex;
    flex-direction: column;
    animation: pop 0.18s var(--ease);
}

.modal::backdrop {
    background: rgba(5, 7, 12, 0.6);
    backdrop-filter: blur(4px);
}

.modal.is-wide { width: min(880px, calc(100vw - 32px)); }

.modal-head {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 20px 20px 8px;
}

.modal-icon {
    flex: none;
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 19px;
}

.modal-title {
    margin: 0;
    font: 600 18px/1.25 var(--font-display);
}

.modal-sub {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.modal-close { margin-left: auto; }

.modal-body {
    min-height: 0;
    overflow: auto;
    padding: 12px 20px;
}

.modal-foot {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 14px 20px 18px;
}

.modal-foot .spacer { flex: 1; }

.form-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 14px 12px;
}

.kbd-list {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 9px 16px;
    align-items: center;
}

kbd {
    display: inline-block;
    min-width: 24px;
    padding: 2px 7px;
    border: 1px solid var(--line-2);
    border-bottom-width: 2px;
    border-radius: 6px;
    background: var(--surface-2);
    font: 600 12px/1.4 var(--font-ui);
    text-align: center;
}

.callout {
    display: flex;
    gap: 10px;
    padding: 11px 13px;
    border-radius: 11px;
    background: var(--surface-2);
    color: var(--text-2);
    font-size: 13px;
}

.callout .bi { color: var(--accent); font-size: 16px; }

.help-tips {
    display: grid;
    gap: 8px;
    margin-bottom: 18px;
}

.steps {
    margin: 14px 0;
    padding-left: 20px;
    color: var(--text-2);
    line-height: 1.55;
}

.steps li + li { margin-top: 4px; }

.bulk-result { margin-top: 12px; }

code {
    padding: 1px 5px;
    border-radius: 5px;
    background: var(--surface-2);
    font-family: var(--font-mono);
    font-size: 0.92em;
}

.print-list {
    max-height: min(320px, 40dvh);
    overflow: auto;
    border: 1px solid var(--line-2);
    border-radius: 10px;
    background: var(--field);
}

.print-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    background: var(--field);
}

.print-row + .print-row { border-top: 1px solid var(--line); }
.print-row.is-off .print-thumb,
.print-row.is-off .print-row-name { opacity: 0.45; }
.print-row.is-dragging { opacity: 0.4; }

.print-grip {
    flex: none;
    align-self: stretch;
    margin: -6px -4px -6px -8px;
    padding: 0 4px 0 8px;
    border: 0;
    background: none;
    color: var(--muted);
    font-size: 16px;
    cursor: grab;
}

.print-grip:hover,
.print-grip:focus-visible { color: var(--text); }
.print-grip:active { cursor: grabbing; }

.print-thumb {
    flex: none;
    width: 30px;
    height: 42px;
    display: grid;
    place-items: center;
}

.print-sort {
    display: flex;
    align-items: center;
    gap: 1px;
    color: var(--muted);
    font-weight: 500;
}

.print-sort > span { margin-right: 4px; }

.print-row-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
}

.print-row-name small {
    display: block;
    color: var(--muted);
    font-weight: 500;
}

.print-row .input { width: 84px; }

.quality-choice { padding: 12px 6px; }
.quality-choice .choice-icon { font-size: 22px; }
.quality-choice small { color: var(--muted); font-size: 11px; font-weight: 500; }

.tpl-choice-text { margin: 0 0 8px; color: var(--text-2); }

#saveBtn.is-saved .bi { color: var(--success); }

/* Import della workspace */

.ws-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 8px;
}

.ws-stat {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    column-gap: 10px;
    align-items: center;
    padding: 10px 12px;
    border: 1px solid var(--line-2);
    border-radius: 12px;
    background: var(--surface-2);
}

.ws-stat .bi {
    grid-row: span 2;
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 16px;
}

.ws-stat b { font: 700 19px/1.1 var(--font-display); }
.ws-stat span { color: var(--muted); font-size: 12px; }

/* ---- Multiple Creation ---- */

.mc { display: grid; gap: 14px; }

.mc-steps {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.mc-step {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px;
    border: 1px solid var(--line-2);
    border-radius: 14px;
    background: var(--surface-2);
    transition: border-color 0.2s;
}

.mc-step.is-done { border-color: color-mix(in srgb, var(--success) 45%, var(--line-2)); }
.mc-step.is-error { border-color: color-mix(in srgb, var(--danger) 55%, var(--line-2)); }

.mc-step-head {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.mc-step-num {
    flex: none;
    width: 26px;
    height: 26px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--accent-grad);
    color: #fff;
    font: 700 13px/1 var(--font-display);
}

.mc-step.is-done .mc-step-num { background: var(--success); color: #06281c; }

.mc-step-head h3 {
    margin: 1px 0 2px;
    font: 600 14.5px/1.3 var(--font-display);
}

.mc-step-head p {
    margin: 0;
    color: var(--muted);
    font-size: 12.5px;
    line-height: 1.4;
}

.mc-step-head code { white-space: nowrap; }

.mc-drop {
    min-height: 100px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 14px;
    border: 1.5px dashed var(--line-3);
    border-radius: 12px;
    background: var(--field);
    color: var(--text-2);
    text-align: center;
    transition: border-color 0.15s, background 0.15s;
}

.mc-drop .bi { margin-bottom: 4px; color: var(--accent); font-size: 26px; }
.mc-drop b { color: var(--text); font-weight: 600; }
.mc-drop span { color: var(--muted); font-size: 12px; }

.mc-drop:hover,
.mc.is-dragover .mc-drop {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.mc-step-foot {
    min-height: 26px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.mc-status {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    color: var(--muted);
    font-size: 12.5px;
    font-weight: 600;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.mc-status .bi { margin-right: 6px; }
.mc-status.is-ok { color: var(--success); }
.mc-status.is-error { color: var(--danger); }

.mc-target {
    display: grid;
    gap: 6px;
    color: var(--text-2);
    font-size: 12.5px;
    font-weight: 600;
}

.mc-result {
    min-width: 0;
    display: grid;
    gap: 10px;
}

.mc-note { align-items: flex-start; font-size: 12.5px; line-height: 1.45; }
.mc-note span { min-width: 0; overflow-wrap: anywhere; }
.mc-note ul { min-width: 0; margin: 0; padding-left: 16px; }
.mc-note li { overflow-wrap: anywhere; }
.mc-note li + li { margin-top: 3px; }
.mc-note.is-error { background: var(--danger-soft); color: var(--text); }
.mc-note.is-error .bi { color: var(--danger); }
.mc-note.is-warn .bi { color: var(--warning); }

.mc-empty {
    display: grid;
    justify-items: center;
    gap: 6px;
    padding: 22px 16px;
    border: 1.5px dashed var(--line-2);
    border-radius: 14px;
    color: var(--text-2);
    text-align: center;
}

.mc-empty > .bi { color: var(--accent); font-size: 26px; }
.mc-empty p { max-width: 520px; margin: 0; }

.mc-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.mc-pill {
    height: 28px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0 11px;
    border-radius: 999px;
    background: var(--surface-2);
    font-size: 12.5px;
    font-weight: 600;
}

.mc-pill .bi { color: var(--accent); }
.mc-pill.is-ok .bi { color: var(--success); }
.mc-pill.is-warn .bi { color: var(--warning); }
.mc-pill.is-info .bi { color: var(--accent-2); }
.mc-pill.is-accent { background: var(--accent-soft); }

.mc-existing {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px 12px;
    padding: 7px 7px 7px 12px;
    border-radius: 11px;
    background: var(--accent-soft);
    font-size: 12.5px;
    font-weight: 600;
}

.mc-existing .seg { background: var(--surface); }
.mc-existing .seg button { flex: none; padding: 5px 12px; }

.mc-preview {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 236px;
    gap: 12px;
    align-items: start;
}

.mc-list {
    max-height: 330px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    overflow-y: auto;
    padding: 4px;
    border: 1px solid var(--line-2);
    border-radius: 12px;
    background: var(--field);
}

.mc-row {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 5px 9px 5px 5px;
    border: 1px solid transparent;
    border-radius: 9px;
    background: none;
    text-align: left;
    transition: background 0.15s, border-color 0.15s;
}

.mc-row:hover { background: var(--surface-2); }
.mc-row.is-selected { border-color: var(--accent); background: var(--accent-soft); }
.mc-row.is-skipped { opacity: 0.5; }

.mc-thumb {
    flex: none;
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    overflow: hidden;
    border-radius: 7px;
    background: var(--surface-3);
    color: var(--muted);
}

.mc-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.mc-row-text {
    flex: 1;
    min-width: 0;
    display: grid;
}

.mc-row-text b,
.mc-row-text small {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.mc-row-text b { font-size: 13px; font-weight: 600; }
.mc-row-text small { color: var(--muted); font-family: var(--font-mono); font-size: 11.5px; }

.mc-badges {
    flex: none;
    display: flex;
    gap: 7px;
    font-size: 14px;
}

.mc-badges .is-accent { color: var(--accent); }
.mc-badges .is-warn { color: var(--warning); }
.mc-badges .is-info { color: var(--accent-2); }
.mc-badges .is-muted { color: var(--muted); }

.mc-card {
    position: sticky;
    top: 0;
    display: grid;
    justify-items: center;
    gap: 8px;
    padding: 14px 10px 10px;
    border-radius: 14px;
    background:
        radial-gradient(85% 70% at 50% 35%, color-mix(in srgb, var(--tpl-accent, var(--accent)) 38%, transparent), transparent 72%),
        var(--surface-2);
}

.mc-card-host {
    min-height: 288px;
    display: grid;
    place-items: center;
}

.mc-card-caption {
    color: var(--muted);
    font-size: 12px;
    text-align: center;
}

@media (max-width: 720px) {
    .mc-steps,
    .mc-preview { grid-template-columns: minmax(0, 1fr); }
    .mc-card { position: static; }
}

/* ---- Notifiche ---- */

.toasts {
    position: fixed;
    left: 50%;
    bottom: 84px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    transform: translateX(-50%);
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: min(460px, calc(100vw - 32px));
    padding: 10px 16px 10px 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    background: #1c2030;
    color: #f1f3f9;
    box-shadow: var(--shadow-lg);
    font-weight: 500;
    pointer-events: auto;
    animation: toast-in 0.25s var(--ease);
}

.toast .bi { font-size: 18px; }
.toast.is-success .bi { color: var(--success); }
.toast.is-error .bi { color: var(--danger); }
.toast.is-info .bi { color: #8fb3ff; }
.toast.is-leaving { animation: toast-out 0.2s ease forwards; }

.spinner {
    width: 17px;
    height: 17px;
    flex: none;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-top-color: #b9a6ff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px); } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Palco (anteprima) ---- */

.stage {
    grid-area: stage;
    position: relative;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background-color: var(--stage-bg);
    background-image: radial-gradient(var(--stage-dot) 1px, transparent 1.3px);
    background-size: 22px 22px;
}

.stage::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(55% 50% at 50% 45%, var(--tpl-glow, rgba(139, 108, 255, 0.12)), transparent 72%);
    pointer-events: none;
    transition: background 0.4s;
}

.stage-viewport {
    position: absolute;
    inset: 0;
    display: flex;
    overflow: auto;
    padding: 64px 48px 100px;
}

.stage-card {
    position: relative;
    flex: none;
    margin: auto;
    perspective: 1600px;
}

.stage-tilt {
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.35s var(--ease);
    will-change: transform;
}

.stage.is-tilting .stage-tilt { transition: transform 0.08s linear; }

.card-host { transform-origin: 0 0; }

.card-host > .cg-card { box-shadow: var(--card-shadow); }

.stage-glare,
.stage-holo {
    position: absolute;
    inset: 0;
    border-radius: var(--card-radius, 0);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}

.stage-glare {
    mix-blend-mode: soft-light;
    background: radial-gradient(circle at var(--gx, 50%) var(--gy, 30%), rgba(255, 255, 255, 0.75), rgba(255, 255, 255, 0) 55%);
}

.stage.is-3d .stage-glare { opacity: 1; }

.stage-holo {
    mix-blend-mode: color-dodge;
    background-size: 260% 260%;
    background-position: var(--hx, 50%) var(--hy, 50%);
}

.stage.holo-rainbow .stage-holo {
    opacity: 0.5;
    background-image: repeating-linear-gradient(115deg, rgba(255, 0, 128, 0.5) 0%, rgba(255, 200, 0, 0.5) 7%, rgba(0, 255, 170, 0.5) 14%, rgba(0, 170, 255, 0.5) 21%, rgba(170, 0, 255, 0.5) 28%, rgba(255, 0, 128, 0.5) 35%);
}

.stage.holo-gold .stage-holo {
    opacity: 0.55;
    background-image: repeating-linear-gradient(120deg, rgba(255, 215, 110, 0.55) 0%, rgba(160, 110, 20, 0.2) 9%, rgba(255, 240, 180, 0.6) 18%, rgba(140, 90, 10, 0.2) 27%, rgba(255, 215, 110, 0.55) 36%);
}

.stage.holo-glitter .stage-holo {
    opacity: 0.65;
    background-size: 23px 29px, 17px 19px, 260% 260%;
    background-image:
        radial-gradient(circle, rgba(255, 255, 255, 0.95) 0 1px, transparent 1.8px),
        radial-gradient(circle, rgba(200, 240, 255, 0.8) 0 0.8px, transparent 1.6px),
        linear-gradient(120deg, rgba(255, 120, 220, 0.3), rgba(120, 220, 255, 0.3), rgba(255, 240, 120, 0.3));
}

.stage-overlay {
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}

.stage.is-3d .stage-overlay { display: none; }

.guides {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.guides-safe {
    position: absolute;
    border: 1.5px dashed rgba(52, 211, 153, 0.9);
    border-radius: 6px;
}

.guides-label {
    position: absolute;
    left: 0;
    top: -22px;
    padding: 1px 7px;
    border-radius: 6px;
    background: rgba(52, 211, 153, 0.9);
    color: #06281c;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}

.selection {
    position: absolute;
    border: 1.5px solid var(--accent);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3);
    pointer-events: none;
}

.selection-handle {
    position: absolute;
    width: 14px;
    height: 14px;
    border: 2px solid var(--accent);
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
    pointer-events: auto;
    touch-action: none;
}

.selection-handle.is-resize { right: -8px; bottom: -8px; cursor: nwse-resize; }

.selection-handle.is-rotate {
    left: 50%;
    top: -34px;
    margin-left: -7px;
    cursor: grab;
}

.selection-handle.is-rotate::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 12px;
    width: 1.5px;
    height: 20px;
    background: var(--accent);
    transform: translateX(-50%);
}

.stage-info {
    position: absolute;
    top: 16px;
    left: 16px;
    right: 16px;
    z-index: 6;
    display: flex;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}

.stage-info > * { pointer-events: auto; }

.chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 30px;
    padding: 0 12px;
    border: 1px solid var(--line-2);
    border-radius: 999px;
    background: color-mix(in srgb, var(--surface) 82%, transparent);
    backdrop-filter: blur(12px);
    color: var(--text-2);
    font-size: 12.5px;
    font-weight: 600;
    white-space: nowrap;
}

.chip-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--chip-color, var(--accent));
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--chip-color, var(--accent)) 28%, transparent);
}

.stage-hint { margin-left: auto; color: var(--muted); }
.stage-hint .bi { color: var(--accent); }

.stage-toolbar {
    position: absolute;
    left: 50%;
    bottom: 20px;
    z-index: 6;
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 5px;
    border: 1px solid var(--line-2);
    border-radius: 15px;
    background: color-mix(in srgb, var(--surface) 84%, transparent);
    backdrop-filter: blur(16px) saturate(1.4);
    box-shadow: var(--shadow);
    transform: translateX(-50%);
}

.tool {
    height: 34px;
    min-width: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0 10px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--text-2);
    font-size: 12.5px;
    font-weight: 600;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
}

.tool .bi { font-size: 16px; line-height: 1; }
.tool:hover { background: var(--surface-2); color: var(--text); }
.tool.is-active { background: var(--accent-soft); color: var(--accent); }

.tool-zoom {
    min-width: 58px;
    font-variant-numeric: tabular-nums;
}

.tool-sep {
    width: 1px;
    height: 20px;
    margin: 0 4px;
    background: var(--line-2);
}

.stage-drop {
    position: absolute;
    inset: 14px;
    z-index: 30;
    display: grid;
    place-items: center;
    border: 2px dashed var(--accent);
    border-radius: 22px;
    background: rgba(139, 108, 255, 0.12);
    color: var(--text);
    font: 600 18px var(--font-display);
    text-align: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
}

.stage-drop .bi { font-size: 42px; color: var(--accent); }
.stage-drop p { margin: 6px 0 0; }
.stage.is-dragover .stage-drop { opacity: 1; }

/* ---- Galleria template ---- */

.tpl-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.tpl-card {
    position: relative;
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 15px;
    background: var(--surface);
    color: var(--text);
    text-align: left;
    transition: transform 0.2s var(--ease), border-color 0.2s, box-shadow 0.2s;
}

.tpl-card:hover {
    transform: translateY(-2px);
    border-color: var(--line-3);
    box-shadow: var(--shadow);
}

.tpl-card.is-current {
    border-color: var(--accent);
    box-shadow: inset 0 0 0 1px var(--accent);
}

.tpl-thumb {
    position: relative;
    height: 196px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background:
        radial-gradient(85% 70% at 50% 35%, color-mix(in srgb, var(--tpl-accent) 38%, transparent), transparent 72%),
        var(--surface-2);
}

.tpl-thumb-card { flex: none; pointer-events: none; }
.tpl-thumb-card .card-host > .cg-card { box-shadow: 0 16px 30px rgba(0, 0, 0, 0.45); }

.tpl-meta { padding: 10px 12px 12px; }

.tpl-name {
    font: 600 14px/1.25 var(--font-display);
}

.tpl-size {
    margin-top: 2px;
    color: var(--muted);
    font-size: 11.5px;
}

.tpl-badge {
    position: absolute;
    top: 9px;
    right: 9px;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
}

.tpl-choice {
    display: grid;
    grid-template-columns: 180px minmax(0, 1fr);
    gap: 18px;
    align-items: center;
}

.tpl-choice-preview {
    display: flex;
    justify-content: center;
    padding: 12px 0;
    border-radius: 14px;
    background: radial-gradient(85% 70% at 50% 35%, color-mix(in srgb, var(--tpl-accent) 38%, transparent), transparent 72%), var(--surface-2);
}

/* Modalità e template personali */

.tpl-mode button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 8px;
}

.tpl-mode .bi { font-size: 15px; line-height: 1; }

.tpl-mode button.is-active[data-mode="multiple"] {
    background: var(--accent-soft);
    color: var(--accent);
    box-shadow: inset 0 0 0 1px var(--accent-ring);
}

.tpl-tip { margin-top: 12px; }

.tpl-section-head {
    min-height: 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin: 20px 0 10px;
}

.tpl-section-head .section-label { margin: 0 4px; }

.tpl-item {
    position: relative;
    min-width: 0;
}

.tpl-item > .tpl-card { width: 100%; height: 100%; }
.tpl-item .tpl-badge { right: auto; left: 9px; }

.tpl-more {
    position: absolute;
    top: 7px;
    right: 7px;
    z-index: 2;
    border: 0;
    background: rgba(10, 12, 18, 0.55);
    color: #fff;
    backdrop-filter: blur(6px);
    opacity: 0;
    transition: opacity 0.15s, background 0.15s, transform 0.2s var(--ease);
}

.tpl-item:hover .tpl-more,
.tpl-more:focus-visible,
.tpl-more[aria-expanded="true"] { opacity: 1; }

.tpl-item:hover .tpl-more { transform: translateY(-2px); }
.tpl-more:hover { border: 0; background: rgba(10, 12, 18, 0.8); }

@media (hover: none) {
    .tpl-more { opacity: 1; }
}

.tpl-empty {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px;
    border: 1.5px dashed var(--line-2);
    border-radius: 14px;
    color: var(--muted);
    font-size: 13px;
}

.tpl-empty-icon {
    flex: none;
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border-radius: 11px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 18px;
}

.tpl-empty b { color: var(--text); font-weight: 600; }
.tpl-empty p { margin: 3px 0 10px; line-height: 1.45; }

.tpl-usage {
    display: grid;
    gap: 6px;
    margin-top: 10px;
    padding: 0 2px;
    color: var(--muted);
    font-size: 11.5px;
}

.tpl-usage-bar {
    height: 4px;
    overflow: hidden;
    border-radius: 999px;
    background: var(--surface-3);
}

.tpl-usage-bar span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--accent-grad);
}

.tpl-usage.is-warn { color: var(--warning); }
.tpl-usage.is-warn .tpl-usage-bar span { background: linear-gradient(90deg, var(--warning), var(--danger)); }

/* In modalità Multiple Creation le miniature diventano un mazzetto di carte. */
.is-multiple .tpl-thumb .mini-card {
    border-radius: 7px;
    box-shadow:
        7px -7px 0 -1px color-mix(in srgb, var(--tpl-accent) 55%, var(--surface-3)),
        14px -14px 0 -2px color-mix(in srgb, var(--tpl-accent) 28%, var(--surface-3));
    transform: translate(-7px, 7px);
}

/* ---- Livelli ---- */

.layer-add {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
}

.layer-add button {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 4px 10px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text-2);
    font-size: 12px;
    font-weight: 600;
    transition: border-color 0.15s, color 0.15s, transform 0.15s;
}

.layer-add button .bi { font-size: 21px; color: var(--accent); }
.layer-add button:hover { border-color: var(--accent-ring); color: var(--text); transform: translateY(-1px); }
.layer-add button.is-active { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }

.layer-props { margin-top: 16px; }
.layer-props .group-head { cursor: default; }

.layer-tools {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 14px 12px;
}

.layer-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.layer-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 5px 5px 10px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.layer-row:hover { border-color: var(--line-3); }
.layer-row.is-selected { border-color: var(--accent); background: var(--accent-soft); }
.layer-row.is-hidden .layer-row-name { opacity: 0.45; text-decoration: line-through; }

.layer-row-type {
    width: 28px;
    height: 28px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--text-2);
}

.layer-row-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}

.layer-empty {
    padding: 18px;
    border: 1.5px dashed var(--line-2);
    border-radius: 12px;
    color: var(--muted);
    font-size: 13px;
    text-align: center;
}

.icon-gallery {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 6px;
    margin-top: 10px;
}

.icon-gallery button {
    aspect-ratio: 1;
    padding: 7px;
    border: 1px solid var(--line-2);
    border-radius: 9px;
    background: var(--field);
    transition: border-color 0.15s, transform 0.15s;
}

.icon-gallery button:hover { border-color: var(--accent); transform: scale(1.05); }

.icon-gallery img,
.icon-gallery-svg,
.icon-gallery-svg > svg {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.icon-gallery-svg { color: var(--text-2); }

/* ---- Collezione ---- */

.col-toolbar {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.col-search { position: relative; flex: 1; }
.col-search .input { padding-left: 34px; }

.col-search .bi {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
}

.col-selection {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: -2px 0 12px;
    padding: 8px 8px 8px 12px;
    border-radius: 11px;
    background: var(--accent-soft);
    font-size: 12.5px;
    font-weight: 600;
}

.col-selection span { flex: 1; }

.col-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
    gap: 12px;
}

.col-item {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 13px;
    background: var(--surface);
    cursor: pointer;
    transition: border-color 0.15s, transform 0.2s var(--ease), box-shadow 0.2s;
}

.col-item:hover { border-color: var(--line-3); transform: translateY(-2px); box-shadow: var(--shadow); }
.col-item.is-current { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.col-item.is-selected { border-color: var(--accent); }

.col-thumb {
    height: 166px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: var(--surface-2);
}

.col-meta { padding: 7px 10px 9px; }

.col-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12.5px;
    font-weight: 600;
}

.col-tpl {
    overflow: hidden;
    color: var(--muted);
    font-size: 11px;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.col-check {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 2;
    width: 22px;
    height: 22px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 1.5px solid rgba(255, 255, 255, 0.8);
    border-radius: 7px;
    background: rgba(10, 12, 18, 0.45);
    color: #fff;
    font-size: 13px;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s;
}

.col-item:hover .col-check,
.col-grid.has-selection .col-check { opacity: 1; }
.col-item.is-selected .col-check { background: var(--accent); border-color: var(--accent); opacity: 1; }

.col-menu {
    position: absolute;
    top: 6px;
    right: 6px;
    z-index: 2;
    opacity: 0;
    border: 0;
    background: rgba(10, 12, 18, 0.55);
    color: #fff;
    backdrop-filter: blur(6px);
}

.col-item:hover .col-menu,
.col-menu:focus-visible { opacity: 1; }
.col-menu:hover { background: rgba(10, 12, 18, 0.8); }

.empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 40px 20px;
    color: var(--muted);
    text-align: center;
}

.empty > .bi {
    width: 64px;
    height: 64px;
    display: grid;
    place-items: center;
    border-radius: 20px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 28px;
}

.empty h3 {
    margin: 4px 0 0;
    color: var(--text);
    font: 600 16px/1.3 var(--font-display);
}

.empty p { margin: 0; max-width: 300px; font-size: 13px; }

/* Anteprime ridotte (galleria, collezione, stampa) */

.mini-card {
    position: relative;
    flex: none;
}

.mini-card > .card-host {
    position: absolute;
    left: 0;
    top: 0;
}

/* ---- Avvio ---- */

.boot {
    position: fixed;
    inset: 0;
    z-index: 500;
    display: grid;
    place-items: center;
    background: var(--bg);
    transition: opacity 0.35s, visibility 0.35s;
}

.boot.is-done { opacity: 0; visibility: hidden; }

.boot-logo {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    color: var(--muted);
    font-weight: 500;
}

.boot-logo img { width: 56px; height: 56px; animation: float 1.6s ease-in-out infinite; }

@keyframes float { 50% { transform: translateY(-6px) rotate(-3deg); } }

.boot-error {
    max-width: 520px;
    padding: 28px;
    border: 1px solid var(--line-2);
    border-radius: 18px;
    background: var(--surface);
    box-shadow: var(--shadow-lg);
    color: var(--text-2);
    line-height: 1.55;
}

.boot-error h1 {
    margin: 0 0 8px;
    color: var(--text);
    font: 600 20px/1.3 var(--font-display);
}

.boot-error code {
    padding: 2px 6px;
    border-radius: 6px;
    background: var(--surface-2);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 13px;
}

/* ---- Responsive ---- */

@media (max-width: 1240px) {
    :root { --panel-w: 370px; }
    .stage-hint { display: none; }
}

@media (max-width: 980px) {
    .doc { display: none; }
}

@media (max-width: 860px) {
    :root { --topbar-h: 56px; }

    .app {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: var(--topbar-h) minmax(250px, 46dvh) minmax(0, 1fr) auto;
        grid-template-areas: "top" "stage" "panel" "rail";
    }

    .hide-sm { display: none !important; }
    .topbar { gap: 8px; padding: 0 10px; }
    .brand-name { display: none; }
    .topbar-actions { gap: 4px; }
    .topbar-actions .btn:not(.btn-icon) { padding: 0 11px; }

    .rail {
        flex-direction: row;
        justify-content: space-around;
        padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
        border-top: 1px solid var(--line);
        border-right: 0;
    }

    .rail-btn { flex: 1; width: auto; }
    .panel { border-right: 0; }
    .panel-head { padding: 12px 14px 10px; }
    .stage-viewport { padding: 50px 16px 70px; }
    .stage-toolbar { bottom: 10px; }
    .stage-info { top: 10px; left: 10px; }
    #stageSize { display: none; }
}
