:root {
    --bg-dark: #000000;
    --panel-bg: #1a1a1a;
    --border-color: #ffffff;
    --text-color: #d3d3d3;
    --highlight: #f8e136; /* Giallo tipico retro */
    --sys-color: #4CAF50;
    --font-fam: 'Press Start 2P', cursive, sans-serif;
}

body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-dark);
    font-family: var(--font-fam);
    color: var(--text-color);
    overflow: hidden;
    user-select: none;
    font-size: 10px; /* Base per il font 8-bit */
}

/* --- PANNELLI STILE JRPG --- */
.pixel-panel {
    background-color: var(--panel-bg);
    border: 4px solid var(--border-color);
    border-radius: 8px; /* Appena accentuato */
    padding: 15px;
    box-shadow: inset -4px -4px 0px rgba(0,0,0,0.5);
    color: white;
}

.pixel-btn {
    background-color: var(--bg-dark);
    border: 3px solid var(--border-color);
    color: white;
    font-family: var(--font-fam);
    padding: 10px;
    cursor: pointer;
    text-transform: uppercase;
}

.pixel-btn:hover {
    background-color: var(--text-color);
    color: var(--bg-dark);
}

.hidden { display: none !important; }

/* --- LOGIN OVERLAY --- */
#login-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #000;
    background-image: url('assets/bg_login.png');
    background-size: cover;
    background-position: center;
    image-rendering: pixelated;
    z-index: 1000;
}

#login-overlay .pixel-panel {
    max-width: 600px;
    text-align: center;
}

#login-overlay h1 {
    font-size: 20px;
    color: var(--highlight);
    margin-bottom: 20px;
    line-height: 1.5;
}

.character-creator {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    margin: 20px 0;
}

.preview-box {
    width: 64px; height: 64px;
    image-rendering: pixelated;
    filter: drop-shadow(0 5px 0px rgba(0,0,0,0.5));
}

.preview-box img {
    width: 100%; height: 100%;
}

.options {
    display: flex;
    flex-direction: column;
    gap: 10px;
    text-align: left;
    width: 100%;
}

.select-group {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.select-group label {
    font-size: 10px;
    color: var(--highlight);
}

.pixel-select {
    background: #000;
    color: white;
    border: 2px solid var(--border-color);
    font-family: var(--font-fam);
    padding: 5px;
    font-size: 10px;
    outline: none;
    cursor: pointer;
}

#username-input {
    width: 80%;
    padding: 10px;
    margin-bottom: 20px;
    background: #000;
    border: 2px solid white;
    color: var(--highlight);
    font-family: var(--font-fam);
    text-align: center;
    font-size: 12px;
}

/* --- MAIN ENVIRONMENT --- */
#main-ui {
    width: 100%; height: 100%;
    display: flex;
    flex-direction: column;
}

.top-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 10px;
    padding: 15px;
}

.nav-btn {
    background: none;
    border: none;
    color: #888;
    font-family: var(--font-fam);
    font-size: 14px;
    cursor: pointer;
}

.nav-btn:hover { color: white; }
.nav-btn.active { color: var(--highlight); text-shadow: 2px 2px 0 #000; }

.player-hud {
    font-size: 12px;
    color: var(--sys-color);
}

/* VIEWS */
.view {
    flex-grow: 1;
    margin: 0 10px 10px 10px;
    position: relative;
    overflow: hidden;
}

.layout-scroll {
    overflow-y: auto;
    padding: 30px;
}

/* --- VIEW ESPLORA / ROOMS --- */
.room-nav {
    display: none; /* Disabilitata a favore dei portali fisici */
}

.room-btn {
    background: none;
    border: none;
    color: #888;
    font-family: var(--font-fam);
    font-size: 10px;
    text-align: left;
    cursor: pointer;
}
.room-btn:hover { color: white; }
.room-btn.active { color: var(--highlight); }
.room-btn.active::before { content: "► "; }

#room-stage {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background-size: cover;
    background-position: center;
    image-rendering: pixelated; /* Crucial for generating a crispy pixel look */
    background-color: #111;
}

#cursor-indicator {
    position: absolute;
    width: 20px; height: 20px;
    border: 2px solid var(--highlight);
    pointer-events: none;
    transform: translate(-50%, -50%);
    z-index: 5;
}

.avatar-entity {
    position: absolute;
    width: 64px; height: 64px;
    transform: translate(-50%, -100%);
    image-rendering: pixelated;
    transition: left 0.6s linear, top 0.6s linear; 
    z-index: 10;
}

@keyframes walk-wobble {
    0% { transform: translate(-50%, -100%) rotate(0deg); }
    25% { transform: translate(-50%, -105%) rotate(-8deg); }
    50% { transform: translate(-50%, -100%) rotate(0deg); }
    75% { transform: translate(-50%, -105%) rotate(8deg); }
    100% { transform: translate(-50%, -100%) rotate(0deg); }
}

.avatar-entity.walking {
    animation: walk-wobble 0.3s infinite;
}

.portal-sign {
    position: absolute;
    border: 2px solid var(--highlight);
    background: rgba(0,0,0,0.8);
    color: var(--highlight);
    font-size: 8px;
    padding: 6px;
    text-align: center;
    pointer-events: none;
    z-index: 2;
    transform: translate(-50%, -50%);
    animation: float-sign 2s ease-in-out infinite;
}

@keyframes float-sign {
    0%, 100% { transform: translate(-50%, -50%); }
    50% { transform: translate(-50%, -60%); }
}

.avatar-entity img {
    width: 100%; height: 100%;
    filter: drop-shadow(0 4px 4px rgba(0,0,0,0.5));
}

.name-tag {
    position: absolute;
    bottom: -15px; left: 50%;
    transform: translateX(-50%);
    font-size: 8px;
    background: rgba(0,0,0,0.8);
    padding: 2px 4px;
    color: white;
    white-space: nowrap;
    text-align: center;
    line-height: 1.2;
}

/* --- CHAT / ROLEPLAY --- */
.chat-container {
    position: absolute;
    bottom: 10px; right: 10px;
    width: 400px;
    height: 250px;
    display: flex;
    flex-direction: column;
    padding: 10px;
}

.chat-messages {
    flex-grow: 1;
    overflow-y: auto;
    font-size: 10px;
    line-height: 1.6;
    margin-bottom: 10px;
}

.chat-msg { margin-bottom: 8px; }
.chat-msg .auth { color: var(--highlight); }
.chat-msg.sys { color: var(--sys-color); }

.chat-input-wrapper { display: flex; gap: 5px; }

#chat-input {
    flex-grow: 1;
    background: #000;
    border: 2px solid #555;
    color: white;
    font-family: var(--font-fam);
    padding: 8px;
}

/* --- CLASSIFICA & INCARICHI --- */
h2 {
    font-size: 20px;
    color: var(--highlight);
    text-align: center;
    margin-bottom: 40px;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 10px;
}

.quest-list li {
    font-size: 14px;
    margin-bottom: 20px;
    line-height: 1.5;
}

.q-rank { color: #f44336; }

.rank-group {
    margin-bottom: 30px;
    text-align: center;
}

.rank-group h3 {
    color: var(--sys-color);
    font-size: 16px;
    margin-bottom: 15px;
}

.rank-item {
    font-size: 12px;
    margin-bottom: 10px;
}

.pts { color: var(--highlight); }

/* --- SPEECH BUBBLES --- */
.speech-bubble {
    position: absolute;
    bottom: 75px; 
    left: 50%;
    transform: translateX(-50%);
    font-size: 8px;
    white-space: pre-wrap;
    max-width: 150px;
    width: max-content;
    text-align: center;
    z-index: 20;
    pointer-events: none;
    background-color: var(--panel-bg);
    border: 3px solid var(--border-color);
    color: white;
    border-radius: 4px;
    padding: 6px;
    filter: drop-shadow(0 4px 4px rgba(0,0,0,0.8));
}

.speech-bubble::after {
    content: '';
    position: absolute;
    bottom: -9px;
    left: 50%;
    transform: translateX(-50%);
    border-width: 6px 6px 0;
    border-style: solid;
    border-color: var(--border-color) transparent transparent transparent;
}
.speech-bubble::before {
    content: '';
    position: absolute;
    bottom: -5px;
    left: 50%;
    transform: translateX(-50%);
    border-width: 5px 5px 0;
    border-style: solid;
    border-color: var(--panel-bg) transparent transparent transparent;
    z-index: 1;
}

/* --- ROOM TRANSITION OVERLAY --- */
#room-transition-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: #000;
    z-index: 9999;
    pointer-events: none;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
}

#room-transition-overlay.active {
    opacity: 1;
}

#room-title-text {
    color: white;
    font-size: 24px;
    letter-spacing: 4px;
    text-shadow: 2px 2px 0px rgba(255,255,255,0.3);
    text-transform: uppercase;
    transform: scale(0.8);
    opacity: 0;
    transition: opacity 1.5s ease-in-out, transform 1.5s ease-out;
}

#room-transition-overlay.show-text #room-title-text {
    opacity: 1;
    transform: scale(1);
}

/* Wardrobe UI */
#wardrobe-overlay {
    position: fixed;
    top:0; left:0; width:100%; height:100%;
    background: rgba(0,0,0,0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5000;
}
.wardrobe-panel {
    width: 380px;
    max-width: 95%;
    text-align: center;
}
#wardrobe-preview {
    image-rendering: pixelated;
    width: 64px;
    height: 64px;
}
