:root {
    --bg: #111;              /* Sfondo generale molto scuro */
    --panel: #1e1e1e;        /* Colore dei pannelli/nodi */
    --border: #333;          /* Bordi sottili */
    --accent: #00cc66;       /* Verde principale */
    --accent-hover: #00b359;
    --text: #eee;
    --text-dim: #888;
    --danger: #ff4444;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    overflow: hidden;
    font-size: 13px;
    -webkit-font-smoothing: antialiased;
}

/* ============================
   TOOLBAR (La parte in alto)
   ============================ */
#toolbar {
    height: 54px;
    background: #181818;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 20px; /* Spazio tra i macro-gruppi */
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
    z-index: 100;
    position: relative;
}

/* Logo */
.brand {
    font-weight: 800;
    color: var(--accent);
    font-size: 16px;
    letter-spacing: -0.5px;
    white-space: nowrap;
}

/* Gruppo Centrale: Titolo e Pubblica */
.story-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #1e1e1e;
    padding: 0 12px;
    border: 1px solid #333;
    border-radius: 4px;
    height: 38px;
}

#story-title {
    background: transparent;
    border: none;
    color: white;
    font-weight: 600;
    font-size: 14px;
    width: 250px;
    outline: none;
    padding: 8px 12px;
    border-right: 1px solid #333;
}
#story-title::placeholder { color: #555; }
#story-title:focus {
    background: #1e1e1e;
}

/* Bottone Pubblica */
.btn-publish {
    background: transparent;
    border: 1px solid #444;
    color: #888;
    padding: 6px 16px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-publish:hover {
    background: #2a2a2a;
    color: var(--text);
}

.btn-publish.published {
    background: var(--accent);
    border-color: var(--accent);
    color: #000;
}

.btn-publish.published:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

/* Spacer flessibile per spingere a destra i bottoni utente */
.spacer { flex: 1; }

/* Gruppo Utente e Azioni */
#user-buttons {
    display: flex;
    align-items: center;
    gap: 10px;
}

#user-display {
    font-size: 11px;
    color: #666;
    margin-right: 10px;
    font-family: monospace;
}

/* Separatore Verticale */
.divider {
    width: 1px;
    height: 24px;
    background: #333;
    margin: 0 5px;
}

/* Menu Hamburger Utente */
#user-menu-toggle {
    font-size: 18px;
    padding: 6px 12px;
}

/* Menu Dropdown Utente */
.user-menu {
    position: fixed;
    top: 60px;
    right: 20px;
    background: #1e1e1e;
    border: 1px solid #333;
    border-radius: 6px;
    padding: 8px;
    min-width: 220px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    z-index: 150;
}

.user-menu.hidden {
    display: none;
}

.menu-item {
    width: 100%;
    text-align: left;
    padding: 10px 12px;
    margin-bottom: 4px;
    border-radius: 4px;
    background: transparent;
    border: 1px solid transparent;
    font-size: 12px;
}

.menu-item:hover {
    background: #2a2a2a;
    border-color: #444;
    transform: none;
    box-shadow: none;
}

.menu-item.btn-accent {
    background: var(--accent);
    color: #000;
    font-weight: 600;
}

.menu-item.btn-accent:hover {
    background: var(--accent-hover);
}

.menu-user-info {
    padding: 8px 12px;
    border-bottom: 1px solid #333;
    margin-bottom: 8px;
}

.menu-user-info span {
    color: #888;
    font-size: 11px;
    font-family: monospace;
}

.menu-divider {
    height: 1px;
    background: #333;
    margin: 8px 0;
}

/* STILE BOTTONI GENERALI */
button {
    background: #333;
    border: 1px solid #444;
    color: #ddd;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.2s;
    white-space: nowrap;
}

button:hover {
    background: #444;
    border-color: #555;
    color: white;
}

button:active { transform: translateY(1px); }

/* Bottoni Speciali */
.btn-accent {
    background: var(--accent);
    color: #000;
    border: 1px solid var(--accent);
    font-weight: 700;
}
.btn-accent:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    box-shadow: 0 0 10px rgba(0, 204, 102, 0.2);
}

.btn-danger {
    background: rgba(255, 68, 68, 0.1);
    color: var(--danger);
    border: 1px solid var(--danger);
}
.btn-danger:hover {
    background: var(--danger);
    color: white;
}

/* ============================
   WORKSPACE (Area Nodi)
   ============================ */
#workspace {
    position: relative;
    width: 100vw;
    height: calc(100vh - 54px);
    background-color: #111;
    background-image:
        radial-gradient(#333 1px, transparent 1px),
        linear-gradient(rgba(0,0,0,0.1) 1px, transparent 1px);
    background-size: 20px 20px, 100px 100px; /* Griglia */
    background-attachment: fixed; /* Mantiene la griglia fissa anche con lo zoom */
    overflow: hidden; /* Gestito dal drag */
    cursor: grab;
}

#workspace:active { cursor: grabbing; }

/* Contenitore per il contenuto zoomabile */
#workspace-content {
    position: absolute;
    width: 100%;
    height: 100%;
    transform-origin: center center;
    transition: transform 0.2s ease;
}

#connections {
    position: absolute;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 0;
    overflow: visible;
}

/* Linee curve */
path {
    fill: none;
    stroke: #555;
    stroke-width: 2px;
    transition: stroke 0.2s;
}
path.win { stroke: var(--accent); stroke-width: 3px; }
path.fail { stroke: var(--danger); stroke-dasharray: 5,5; }

/* NODO */
.node {
    position: absolute;
    width: 240px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.4);
    z-index: 10;
    user-select: none;
    transition: box-shadow 0.2s, border-color 0.2s;
}

.node:hover {
    box-shadow: 0 8px 25px rgba(0,0,0,0.6);
    border-color: #666;
}

.node.selected {
    border: 2px solid var(--accent);
    box-shadow: 0 0 15px rgba(0,204,102, 0.1);
}

.node-header {
    background: #181818;
    padding: 8px 12px;
    border-radius: 7px 7px 0 0;
    font-weight: 700;
    font-size: 11px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: grab;
    color: #888;
    border-bottom: 1px solid #2a2a2a;
}
.node-header span { font-family: monospace; }

.node-body {
    padding: 12px;
    font-size: 12px;
    color: #ccc;
    max-height: 80px;
    overflow: hidden;
    line-height: 1.4;
    white-space: pre-wrap; /* Mantiene a capo */
}

/* ============================
   EDITOR PANEL (Laterale Destro)
   ============================ */
#editor-panel {
    position: fixed;
    right: 0; top: 54px; bottom: 0;
    width: 350px;
    background: #181818;
    border-left: 1px solid var(--border);
    padding: 20px;
    overflow-y: auto;
    display: none;
    box-shadow: -5px 0 20px rgba(0,0,0,0.3);
    z-index: 50;
}
#editor-panel.open { display: block; }
#editor-panel h3 { margin-top: 0; color: var(--accent); border-bottom: 1px solid #333; padding-bottom: 10px; }

.form-group { margin-bottom: 15px; }

label {
    display: block;
    color: #888;
    font-size: 10px;
    margin-bottom: 6px;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 1px;
}

input[type="text"], input[type="number"], textarea, select {
    width: 100%;
    box-sizing: border-box;
    background: #0a0a0a;
    border: 1px solid #333;
    color: white;
    padding: 8px 10px;
    border-radius: 4px;
    font-family: inherit;
    font-size: 13px;
    transition: border 0.2s;
}

input:focus, textarea:focus, select:focus {
    border-color: var(--accent);
    outline: none;
}

textarea {
    resize: vertical;
    line-height: 1.5;
    min-height: 100px;
}

hr { border: 0; border-top: 1px solid #333; margin: 20px 0; }

/* OPZIONI (CARD) */
.options-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.option-item {
    background: #222;
    padding: 15px;
    border: 1px solid #333;
    margin-bottom: 12px;
    border-radius: 6px;
    position: relative;
}
.option-item:hover { border-color: #444; }

.option-top-bar {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
}

.tag {
    font-size: 9px;
    padding: 2px 5px;
    border-radius: 3px;
    font-weight: bold;
    text-transform: uppercase;
}
.tag.normal { background: #333; color: #aaa; }
.tag.check { background: rgba(0, 204, 102, 0.2); color: var(--accent); border: 1px solid var(--accent); }

.btn-mini { padding: 2px 6px; font-size: 10px; height: 20px; line-height: 1; }

/* ============================
   MODALI
   ============================ */
.modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.85);
    z-index: 200;
    display: flex; justify-content: center; align-items: center;
    backdrop-filter: blur(5px);
}
.modal.hidden { display: none; }

.modal-content {
    background: #1e1e1e;
    padding: 30px;
    border-radius: 12px;
    border: 1px solid #333;
    width: 320px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0,0,0,0.8);
}
.modal-content.large { width: 600px; text-align: left; }
.modal-content h3 { margin-top: 0; color: white; }

.modal-actions {
    margin-top: 25px;
    display: flex;
    gap: 10px;
    justify-content: center;
}

/* Lista Storie */
.story-row {
    padding: 12px;
    border-bottom: 1px solid #333;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s;
}
.story-row:hover { background: #2a2a2a; }
.story-row:last-child { border-bottom: none; }

/* ============================
   CONTROLLI ZOOM
   ============================ */
#zoom-controls {
    position: fixed;
    bottom: 20px;
    left: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 150;
}

.zoom-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #1e1e1e;
    border: 1px solid #444;
    color: var(--accent);
    font-size: 24px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    box-shadow: 0 4px 10px rgba(0,0,0,0.4);
    line-height: 1;
    padding: 0;
}

.zoom-btn:hover {
    background: #2a2a2a;
    border-color: var(--accent);
    box-shadow: 0 6px 15px rgba(0,0,0,0.6);
    transform: scale(1.05);
}

.zoom-btn:active {
    transform: scale(0.95);
}

/* Bottone Info - più squadrato */
.zoom-btn.info-btn {
    border-radius: 8px;
    font-size: 18px;
    font-style: italic;
    font-weight: 600;
}

/* Pannello Info Storia */
#story-info-panel {
    position: fixed;
    bottom: 20px;
    left: 80px;
    background: #1e1e1e;
    border: 1px solid #444;
    border-radius: 6px;
    padding: 15px;
    min-width: 280px;
    box-shadow: 0 8px 20px rgba(0,0,0,0.6);
    z-index: 149;
    display: none;
}

#story-info-panel.visible {
    display: block;
}

#story-info-panel h4 {
    margin: 0 0 12px 0;
    color: var(--accent);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 1px solid #333;
    padding-bottom: 8px;
}

#story-info-panel .stat-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 12px;
    border-bottom: 1px solid #222;
}

#story-info-panel .stat-row:last-child {
    border-bottom: none;
}

#story-info-panel .stat-label {
    color: #888;
}

#story-info-panel .stat-value {
    color: var(--accent);
    font-weight: 700;
}