:root {
    /* Palette eterea e scura */
    --bg-base:      #0a0a0f;
    --bg-surface:   #12121a;
    --bg-elevated:  #1b1b26;
    --border:       #2a2a3d;
    --border-hover: #454563;
    --text-primary: #e6e6f0;
    --text-muted:   #8a8a9e;
    --text-dim:     #7a7a8c; /* Migliorato per accessibilità */
    
    /* Colori Magici/Sognanti */
    --accent:       #64d8cb; /* Verde acqua magico */
    --accent-hover: #8cf2e6;
    --accent-dim:   rgba(100, 216, 203, 0.15);
    --danger:       #f26d7d; /* Rosso rosato */
    --danger-dim:   rgba(242, 109, 125, 0.12);
    --gold:         #f2d479; /* Oro tenue */
    --gold-dim:     rgba(242, 212, 121, 0.15);
    --purple:       #b388ff; /* Viola onirico */
    --purple-dim:   rgba(179, 136, 255, 0.15);
    
    --radius-sm:    6px;
    --radius-md:    10px;
    --radius-lg:    16px;
    --shadow:       0 8px 32px rgba(0,0,0,0.6);
    --font-display: 'Cinzel', serif;
    --font-ui:      'Nunito', sans-serif;
}

/* ── SCROLLBARS CUSTOM (Webkit + Firefox) ── */
* { box-sizing: border-box; }

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: transparent; 
}
::-webkit-scrollbar-thumb {
    background: var(--border); 
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--border-hover); 
}

body {
    margin: 0;
    background: var(--bg-base);
    color: var(--text-primary);
    font-family: var(--font-ui);
    height: 100vh;
    overflow: hidden;
}

/* ── LAYOUT PRINCIPALE ── */
#main-layout { display: flex; height: 100vh; flex-direction: column; }

/* ── TOOLBAR ── */
#toolbar {
    background: var(--bg-surface);
    padding: 0 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 20px;
    height: 70px;
    align-items: center;
    flex-shrink: 0;
    z-index: 100;
}

.app-title-container {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.app-title {
    font-family: var(--font-display);
    font-size: 1.6em;
    color: var(--text-primary);
    letter-spacing: 3px;
    white-space: nowrap;
    text-shadow: 0 0 10px rgba(179, 136, 255, 0.3);
}
.app-subtitle {
    font-size: 0.65em;
    color: var(--accent);
    letter-spacing: 2px;
    text-transform: uppercase;
    opacity: 0.8;
}

#player-top-status {
    display: flex;
    align-items: center;
    gap: 20px;
    flex: 1;
    min-width: 0;
    margin-left: 20px;
}

.top-char-info { display: flex; flex-direction: column; line-height: 1.3; min-width: 120px; }
.top-char-name { font-weight: 600; font-size: 1.1em; color: var(--gold); font-family: var(--font-display); letter-spacing: 1px;}
.top-char-loc  { font-size: 0.8em; color: var(--text-muted); }

.top-bars { display: flex; gap: 16px; width: 240px; flex-shrink: 0; }
.bar-wrapper { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.bar-label {
    font-size: 0.7em; font-weight: 700; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 1px;
    display: flex; justify-content: space-between;
}
.bar-container { background: var(--bg-base); height: 6px; border-radius: 3px; overflow: hidden; border: 1px solid var(--border); }
.bar-fill { height: 100%; width: 0%; transition: width 0.4s ease; }
.hp-fill { background: linear-gradient(90deg, #8b0000, var(--danger)); }
.mp-fill { background: linear-gradient(90deg, #1f3a93, var(--accent)); }

.self-actions {
    display: flex; gap: 8px;
    border-left: 1px solid var(--border);
    padding-left: 20px;
    overflow-x: auto;
    scrollbar-width: none;
}
.self-actions::-webkit-scrollbar { display: none; }

.self-btn {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.85em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex; align-items: center; gap: 6px;
    white-space: nowrap;
}
.self-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--bg-surface);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px var(--accent-dim);
}

/* ── AREA CENTRALE ── */
#game-area {
    flex: 1;
    display: flex;
    flex-direction: row;
    overflow: hidden;
    position: relative;
}

/* ── PANNELLO SINISTRA (Scene) ── */
#left-panel {
    flex: 0 0 400px;
    background: var(--bg-base);
    padding: 16px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
}

.scene-card {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    height: 100%;
    border: 1px solid var(--border);
    overflow: hidden;
    box-shadow: var(--shadow);
    position: relative;
}

#room-visual {
    flex: 0 0 35%;
    position: relative;
    overflow: hidden;
    background: #000;
}
#room-image {
    width: 100%; height: 100%;
    object-fit: cover;
    opacity: 0.7;
    transition: opacity 0.6s ease;
    mix-blend-mode: luminosity; /* Effetto onirico sull'immagine */
}
#room-visual::after {
    content: '';
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 60%;
    background: linear-gradient(transparent, var(--bg-surface));
    pointer-events: none;
}

#room-info {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.room-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

#room-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.8em;
    color: var(--text-primary);
    margin: 0;
    line-height: 1.1;
    letter-spacing: 1px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.8);
}

.action-icons { display: flex; gap: 8px; flex-shrink: 0; }
.icon-btn {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-muted);
    width: 36px; height: 36px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex; justify-content: center; align-items: center;
    font-size: 1em;
}
.icon-btn:hover { border-color: var(--purple); color: var(--purple); transform: scale(1.1) rotate(5deg); box-shadow: 0 0 10px var(--purple-dim);}

#room-desc {
    font-size: 1em;
    line-height: 1.7;
    color: #d0d0e0;
    margin-bottom: 24px;
    font-weight: 300;
}

.category-label {
    font-size: 0.75em;
    color: var(--text-dim);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 10px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 4px;
}
.chip-container { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }

.chip {
    padding: 6px 14px;
    border-radius: 24px;
    font-size: 0.85em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
    display: flex; align-items: center; gap: 6px;
    background: var(--bg-elevated);
    color: var(--text-muted);
}
.chip:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.4); color: var(--text-primary); border-color: var(--border-hover);}

.chip-npc    { border-color: rgba(179, 136, 255, 0.2); }
.chip-npc:hover { background: var(--purple-dim); border-color: var(--purple); color: var(--purple); }

.chip-player { border-color: rgba(100, 216, 203, 0.2); }
.chip-player:hover { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

.chip-item   { border-color: rgba(242, 212, 121, 0.2); }
.chip-item:hover { background: var(--gold-dim); border-color: var(--gold); color: var(--gold); }

.chip-exit   {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 0.9em;
    letter-spacing: 1px;
    border-color: var(--border);
    background: transparent;
}
.chip-exit:hover { background: var(--text-primary); color: var(--bg-base); border-color: var(--text-primary); }

.empty-hint { color: var(--text-dim); font-size: 0.9em; font-style: italic; }

/* ── FEED (Testo) ── */
#feed-panel {
    flex: 1;
    background: var(--bg-base);
    display: flex;
    flex-direction: column;
    padding: 20px 8% 10px;
    overflow-y: auto;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.msg {
    margin-bottom: 12px;
    padding: 12px 18px;
    border-radius: var(--radius-md);
    font-size: 0.95em;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
    max-width: 85%;
    width: fit-content;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    animation: fadeIn 0.3s ease forwards;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

.msg-system  { background: transparent; color: var(--text-dim); font-size: 0.85em; text-align: center; margin: 8px auto; box-shadow: none; font-style: italic; }
.msg-combat  {
    background: rgba(242, 109, 125, 0.08);
    color: #ffb3ba;
    border-left: 4px solid var(--danger);
    border-radius: 4px var(--radius-md) var(--radius-md) 4px;
}
.msg-chat    { 
    background: rgba(179, 136, 255, 0.08);
    color: #e0ccff;
    border-left: 4px solid var(--purple);
    border-radius: 4px var(--radius-md) var(--radius-md) 4px;
}
.msg-routine {
    background: rgba(255, 255, 255, 0.02);
    color: var(--text-dim);
    border-left: 2px solid var(--border);
    font-size: 0.85em;
}
.hide-routine .msg-routine {
    display: none !important;
}
    background: var(--bg-surface); 
    color: var(--text-primary); 
    border: 1px solid var(--border);
    border-radius: var(--radius-md) var(--radius-md) var(--radius-md) 4px; 
    font-style: italic;
}
.msg-me      {
    background: var(--bg-elevated);
    color: var(--accent);
    border: 1px solid var(--border);
    border-radius: var(--radius-md) var(--radius-md) 4px var(--radius-md);
    align-self: flex-end;
}
.msg-info    { background: transparent; color: #c8c8e0; border-left: 2px solid var(--purple); border-radius: 4px; box-shadow: none; padding-left: 14px;}

/* ── MINIMAP FLOTTANTE ── */
#right-panel {
    position: absolute;
    top: 24px;
    right: 24px;
    width: 280px;
    height: 280px;
    background: rgba(18, 18, 26, 0.85); /* Leggermente trasparente */
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow);
    z-index: 50;
    overflow: hidden;
    transition: transform 0.3s ease;
}
#right-panel:hover { transform: scale(1.02); background: rgba(18, 18, 26, 0.95); }

#map-header {
    padding: 12px 16px;
    font-size: 0.75em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-dim);
    border-bottom: 1px solid rgba(255,255,255,0.05);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(0,0,0,0.2);
    z-index: 51;
}

#minimap-container {
    flex: 1;
    position: relative;
    width: 100%;
    height: 100%;
}

#minimap { 
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    width: 100%;
    height: 100%;
}

#layerSelect {
    appearance: none;
    -webkit-appearance: none;
    background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238a8a9e' d='M3 4l3 4 3-4z'/%3E%3C/svg%3E") no-repeat right 0px center;
    color: var(--text-muted);
    border: none;
    font-size: 0.9em;
    font-family: var(--font-ui);
    font-weight: 600;
    outline: none;
    cursor: pointer;
    max-width: 130px;
    padding-right: 16px;
}
#layerSelect option { background: var(--bg-surface); color: var(--text-primary); }

/* ── INPUT ── */
#input-area {
    background: var(--bg-base);
    border-top: 1px solid var(--border);
    padding: 16px 8%;
    display: flex;
    gap: 16px;
    flex-shrink: 0;
    box-shadow: 0 -10px 40px rgba(0,0,0,0.5);
    z-index: 100;
}

#cmd-input {
    flex: 1;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 14px 24px;
    font-size: 1.05em;
    font-family: var(--font-ui);
    border-radius: 30px;
    outline: none;
    transition: all 0.3s ease;
    box-shadow: inset 0 2px 6px rgba(0,0,0,0.3);
}
#cmd-input::placeholder { color: var(--text-dim); font-style: italic; }
#cmd-input:focus { border-color: var(--purple); background: var(--bg-elevated); box-shadow: 0 0 15px var(--purple-dim); }

button.action-btn {
    background: linear-gradient(135deg, var(--purple), var(--accent));
    color: #000;
    border: none;
    padding: 0 28px;
    font-size: 1.05em;
    font-weight: 700;
    font-family: var(--font-ui);
    cursor: pointer;
    border-radius: 30px;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}
button.action-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 20px var(--purple-dim); }

button.danger-btn {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.85em;
    font-family: var(--font-ui);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
button.danger-btn:hover { border-color: var(--danger); color: var(--danger); background: var(--danger-dim); }

/* ── CONTEXT MENU DINAMICO ── */
#dynamic-context-menu {
    display: none;
    position: fixed;
    z-index: 2000;
    background: rgba(27, 27, 38, 0.95);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-hover);
    border-radius: var(--radius-md);
    box-shadow: 0 15px 45px rgba(0,0,0,0.8);
    width: 200px;
    overflow: hidden;
    padding: 8px 0;
    animation: scaleIn 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    transform-origin: top left;
}

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

.context-header {
    color: var(--gold);
    font-family: var(--font-display);
    padding: 6px 16px 12px;
    font-size: 1.1em;
    font-weight: 700;
    letter-spacing: 1px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    margin-bottom: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.context-btn {
    display: flex;
    width: 100%;
    background: none;
    border: none;
    color: var(--text-primary);
    text-align: left;
    padding: 10px 16px;
    font-size: 0.9em;
    font-family: var(--font-ui);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    align-items: center;
    gap: 10px;
}
.context-btn:hover { background: var(--bg-surface); padding-left: 20px; border-left: 2px solid var(--accent); }

/* Classi colore iniettate dal server (tramite API) */
.ctx-color-danger { color: var(--danger); }
.ctx-color-danger:hover { background: var(--danger-dim); border-left-color: var(--danger); }
.ctx-color-warning { color: #f0a050; }
.ctx-color-warning:hover { background: rgba(240,160,80,0.1); border-left-color: #f0a050; }
.ctx-color-gold { color: var(--gold); }
.ctx-color-gold:hover { background: var(--gold-dim); border-left-color: var(--gold); }
.ctx-color-romance { color: #f07090; }
.ctx-color-romance:hover { background: rgba(240,112,144,0.1); border-left-color: #f07090; }

.ctx-divider {
    height: 1px;
    background: rgba(255,255,255,0.05);
    margin: 6px 16px;
}

.ctx-loading {
    padding: 16px;
    text-align: center;
    color: var(--text-dim);
    font-size: 0.85em;
    font-style: italic;
}

/* ── MODAL LOGIN ── */
.modal-bg {
    display: none;
    position: fixed;
    z-index: 3000;
    inset: 0;
    background: rgba(10, 10, 15, 0.9);
    backdrop-filter: blur(12px);
    align-items: center;
    justify-content: center;
}
.modal-content {
    background: var(--bg-surface);
    border: 1px solid var(--border-hover);
    padding: 40px;
    border-radius: var(--radius-lg);
    width: 360px;
    box-shadow: 0 25px 80px rgba(0,0,0,0.8);
    text-align: center;
    position: relative;
    overflow: hidden;
}
.modal-content::before {
    content: ''; position: absolute; top: 0; left: 0; right: 0; height: 4px;
    background: linear-gradient(90deg, var(--purple), var(--accent));
}
.modal-content h2 {
    font-family: var(--font-display);
    color: var(--text-primary);
    margin: 0 0 8px;
    font-size: 2.2em;
    letter-spacing: 3px;
    text-shadow: 0 0 15px rgba(179, 136, 255, 0.4);
}
.modal-subtitle {
    color: var(--text-muted);
    font-size: 0.9em;
    margin-bottom: 30px;
    letter-spacing: 1px;
    text-transform: uppercase;
}
.modal-content input {
    width: 100%;
    margin: 8px 0;
    padding: 14px 16px;
    font-size: 1em;
    font-family: var(--font-ui);
    background: var(--bg-base);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    transition: all 0.3s;
}
.modal-content input::placeholder { color: var(--text-dim); }
.modal-content input:focus { border-color: var(--purple); outline: none; box-shadow: 0 0 10px var(--purple-dim); }

.modal-content button {
    width: 100%;
    padding: 14px;
    margin-top: 24px;
    font-size: 1.05em;
    font-weight: 700;
    font-family: var(--font-ui);
    cursor: pointer;
    background: linear-gradient(135deg, var(--purple), var(--accent));
    color: #000;
    border: none;
    border-radius: var(--radius-sm);
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}
.modal-content button:hover { transform: translateY(-2px); box-shadow: 0 6px 20px var(--purple-dim); }
.modal-content button:disabled { background: var(--bg-elevated); color: var(--text-dim); cursor: not-allowed; box-shadow: none; transform: none; border: 1px solid var(--border); }
.login-feedback { color: var(--danger); font-size: 0.85em; margin-top: 16px; min-height: 20px; font-weight: 600; }

/* ── INVENTORY MODAL (PANNELLO LATERALE/CENTRALE) ── */
#inventory-panel {
    display: none;
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 380px;
    max-height: 70vh;
    background: rgba(18, 18, 26, 0.95);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-hover);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 60px rgba(0,0,0,0.8);
    z-index: 1500;
    flex-direction: column;
    overflow: hidden;
    animation: scaleIn 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.inv-header {
    padding: 16px 20px;
    background: rgba(0,0,0,0.3);
    border-bottom: 1px solid rgba(255,255,255,0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.inv-title {
    font-family: var(--font-display);
    color: var(--gold);
    font-size: 1.3em;
    font-weight: 700;
    letter-spacing: 1px;
    margin: 0;
}
.close-inv {
    background: none; border: none; color: var(--text-muted); font-size: 1.5em; cursor: pointer; transition: color 0.2s;
}
.close-inv:hover { color: var(--danger); }

.inv-list {
    padding: 12px;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.inv-item {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    padding: 12px 16px;
    border-radius: var(--radius-md);
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
}
.inv-item:hover {
    border-color: var(--accent);
    background: var(--bg-surface);
    transform: translateX(4px);
}
.inv-item-name { font-weight: 600; color: var(--text-primary); font-size: 0.95em; }
.inv-item-type { font-size: 0.7em; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px;}

/* ── RESPONSIVE ── */
@media (max-width: 900px) {
    #left-panel { flex: 0 0 320px; }
    #right-panel { display: none; }
    .top-char-info { display: none; }
    #toolbar { padding: 0 16px; }
}
@media (max-width: 768px) {
    #game-area {
        flex-direction: column;
    }
    #left-panel { 
        display: flex; 
        flex: 1 1 auto; 
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding: 8px;
    }
    #room-visual { flex: 0 0 20%; }
    
    #feed-panel-container { 
        flex: 1 1 auto;
        min-height: 250px;
        order: 2;
    }
    #feed-panel { padding: 16px 5% 10px; }
    
    #right-panel { display: none; }
    
    #toolbar { padding: 0 10px; height: 60px; gap: 10px; }
    .app-title { font-size: 1.2em; }
    .top-char-info, .self-actions button { font-size: 0.8em; }
    .self-actions button { padding: 4px 8px; }
    
    .msg {
        max-width: 100%;
        margin-bottom: 8px;
        padding: 8px 12px;
    }
}
