/* --- Global Styling & Terraria Theme --- */
:root {
    --font-pixel: 'Press Start 2P', cursive;
    --text-color: #FFFFFF;
    
    /* Warna Panel Terraria */
    --panel-bg: #4A433C;
    --panel-border-light: #C8B494;
    --panel-border-dark: #201D19;

    /* Warna UI */
    --health-color: #CF4242;
    --mana-color: #3865D6;
    --gold-accent: #FFD700;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-pixel);
    color: var(--text-color);
    image-rendering: pixelated; /* Penting untuk font pixel agar tidak blur */
    position: relative; /* Diperlukan untuk pseudo-element bintang jatuh */
    overflow: hidden; /* Pastikan bintang jatuh tidak menyebabkan scrollbar */
    min-height: 100vh; /* Pastikan body mengambil tinggi penuh viewport */

    /* Lapisan Gradasi Utama (Langit) */
    background: linear-gradient(to bottom, 
        #080c21 0%,  /* Biru malam paling gelap di atas */
        #1a234a 50%, /* Biru tua di tengah */
        #3a325a 100% /* Sedikit ungu di cakrawala */
    );

    /* Lapisan Bintang-Bintang Statis (dibuat dengan multi-background) */
    background-image: 
        /* Bintang kecil & banyak */
        radial-gradient(circle at 10% 20%, white 1px, transparent 2px),
        radial-gradient(circle at 70% 30%, white 1px, transparent 2px),
        radial-gradient(circle at 40% 80%, white 1px, transparent 2px),
        radial-gradient(circle at 90% 60%, white 1px, transparent 2px),
        /* Bintang sedang & lebih jarang */
        radial-gradient(circle at 25% 65%, white 1.5px, transparent 3px),
        radial-gradient(circle at 60% 10%, white 1.5px, transparent 3px),
        /* Lapisan Gradasi Langit (ditaruh paling bawah) */
        linear-gradient(to bottom, #080c21 0%, #1a234a 50%, #3a325a 100%);
    
    background-attachment: fixed; /* Membuat background tidak ikut scroll */
}

/* --- Efek Bintang Jatuh --- */
body::before {
    content: '';
    position: absolute;
    top: -100px; /* Mulai dari atas layar */
    left: 20%; /* Posisi horizontal acak */
    width: 2px;
    height: 100px; /* Panjang ekor bintang */
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0));
    animation: shootingStar 10s linear infinite; /* Animasi bintang jatuh */
    transform-origin: center top;
    filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.6));
    z-index: 0; /* Pastikan di belakang UI */
}

/* Duplikasi bintang jatuh untuk variasi */
body::after {
    content: '';
    position: absolute;
    top: -150px;
    left: 70%;
    width: 3px;
    height: 150px;
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0));
    animation: shootingStar 15s linear infinite 5s; /* Delay 5 detik */
    transform-origin: center top;
    filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.6));
    z-index: 0;
}

@keyframes shootingStar {
    0% {
        transform: translate(0, 0) rotate(20deg); /* Miring sedikit */
        opacity: 0;
    }
    10% {
        opacity: 1; /* Muncul */
    }
    100% {
        transform: translate(-500px, 1200px) rotate(20deg); /* Jatuh ke bawah-kiri */
        opacity: 0;
    }
}


/* --- Container Utama dengan Golden Ratio --- */
.ui-container {
    display: flex;
    padding: 30px;
    gap: 30px;
    min-height: 100vh;
    position: relative; /* Penting agar UI di atas bintang jatuh */
    z-index: 1; /* Pastikan UI berada di atas bintang jatuh */
}

.sidebar-column {
    flex: 1; /* Bagian yang lebih kecil */
    display: flex;
    flex-direction: column;
    gap: 30px;
}

.main-content-column {
    flex: 1.618; /* Bagian yang lebih besar (Golden Ratio) */
    display: flex;
    flex-direction: column;
    gap: 30px;
}


/* --- Panel Utama Khas Terraria --- */
.terraria-panel {
    background-color: var(--panel-bg);
    padding: 16px;
    border: 4px solid var(--panel-border-dark);
    box-shadow: inset 0 0 0 4px var(--panel-border-light);
    border-radius: 4px; /* Sudut sedikit tumpul */
}

.panel-title {
    font-size: 16px; /* Font pixel ukurannya kecil */
    color: var(--gold-accent);
    text-shadow: 2px 2px #000;
    margin-bottom: 16px;
    text-align: center;
}

/* --- Panel Karakter --- */
.character-info {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.avatar-slot {
    width: 88px;
    height: 88px;
    background-color: var(--panel-border-dark);
    border: 4px solid var(--panel-border-light);
    box-shadow: inset 0 0 0 4px var(--panel-border-dark);
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
}

.avatar-slot img {
    width: 80px;
    height: 80px;
}

.character-stats .stat-line {
    font-size: 10px;
    line-height: 1.8;
}
.character-stats strong {
    color: var(--gold-accent);
}

/* Resource Bars (Health/Mana) */
.resource-bars {
    font-size: 10px;
}
.resource-bars label {
    display: block;
    margin-bottom: 4px;
}

.bar {
    width: 100%;
    height: 24px;
    background-color: var(--panel-border-dark);
    border: 2px solid var(--panel-border-light);
    margin-bottom: 8px;
    position: relative;
    padding: 2px;
}
.bar-fill {
    height: 100%;
    transition: width 0.5s ease-out;
}
.bar.health-bar .bar-fill { background-color: var(--health-color); }
.bar.mana-bar .bar-fill { background-color: var(--mana-color); }

.bar-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 10px;
    text-shadow: 1px 1px #000;
}


/* --- Panel Navigasi (Action Grid) --- */
.action-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.item-slot {
    width: 100%;
    height: 48px;
    background-color: var(--panel-border-dark);
    border: 2px solid var(--panel-border-light);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 9px;
    text-decoration: none;
    color: var(--text-color);
    transition: background-color 0.2s;
}

.item-slot:hover {
    background-color: #5f574f;
    color: var(--gold-accent);
}

.item-slot.close-session {
    color: #ff6b6b;
}


/* --- Panel Konten Utama --- */
.log-area {
    background-color: rgba(0,0,0,0.3);
    padding: 8px;
    height: 150px;
    overflow-y: auto;
    font-size: 10px;
    line-height: 2;
}
.log-area p { margin: 0; }
.log-info { color: #87CEEB; } /* Sky Blue */
.log-warning { color: #FFD700; } /* Gold */
.log-success { color: #90EE90; } /* Light Green */

.world-info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    font-size: 10px;
}
.info-box {
    background-color: rgba(0,0,0,0.3);
    padding: 8px;
    text-align: center;
}
.info-label {
    display: block;
    color: #AAAAAA;
    margin-bottom: 6px;
}
.info-value {
    font-size: 12px;
    font-weight: bold;
}
.difficulty-expert { color: #DC143C; } /* Crimson */
.weather-rain { color: #4682B4; } /* Steel Blue */


/* --- Responsif --- */
@media (max-width: 900px) {
    .ui-container {
        flex-direction: column;
    }
    .sidebar-column, .main-content-column {
        flex: none; /* Hapus golden ratio di layar kecil */
        width: 100%;
    }
}

/* --- Styles for Integrated Login Form --- */
.login-form-integrated {
    padding-top: 10px;
}

.form-field {
    margin-bottom: 20px;
}

.form-field label {
    display: block;
    margin-bottom: 8px;
    font-size: 10px;
    color: var(--gold-accent);
    text-shadow: 1px 1px #000;
}

.terraria-input {
    width: 100%;
    background-color: var(--panel-border-dark);
    border: 2px solid var(--panel-border-light);
    box-shadow: inset 2px 2px 2px rgba(0,0,0,0.5);
    padding: 12px;
    font-family: var(--font-pixel);
    font-size: 12px;
    color: var(--text-color);
    outline: none;
    transition: border-color 0.3s;
}

.terraria-input:focus {
    border-color: var(--gold-accent);
}

.login-button {
    width: 100%;
    margin-top: 10px;
    font-size: 12px;
    color: var(--gold-accent);
    font-weight: bold;
    text-shadow: 1px 1px #000;
}

.login-button:hover {
    color: #FFFFFF;
}

.terraria-error {
    background-color: #5d1a1a;
    border: 2px solid #CF4242;
    padding: 12px;
    margin-bottom: 20px;
    font-size: 10px;
    color: #ffcdd2;
    text-align: center;
    text-shadow: 1px 1px #000;
}

/* --- Style untuk menonaktifkan tombol lain saat belum login --- */
.disabled-slot {
    background-color: #332e29;
    color: #777;
    cursor: not-allowed;
    pointer-events: none; /* Mencegah klik */
}

.disabled-slot:hover {
    color: #777;
    background-color: #332e29;
}

/* --- Penyesuaian Style untuk Ikon Cuaca Emoji --- */
.weather-icon-emoji {
    font-size: 48px; /* Ukuran ikon emoji */
    line-height: 1;
    text-shadow: 2px 2px 2px #000;
}

/* Menghapus style lama untuk <img> jika ada */
.weather-icon {
    display: none;
}


/* --- Styles for World Event Tracker --- */
.world-event-tracker {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 2px solid var(--panel-border-light);
    font-size: 10px;
    text-align: center;
}
.event-label {
    color: #AAAAAA;
    margin-right: 8px;
}
.event-name {
    font-size: 12px;
    font-weight: bold;
    text-shadow: 2px 2px #000;
    transition: color 0.5s ease;
}
.event-pop {
    animation: pop 0.5s ease-out;
}
@keyframes pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

/* --- Styles for Modal Window --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease-in-out;
}
.modal-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    position: relative;
    width: 90%;
    max-width: 500px;
    animation: slideIn 0.4s ease-out forwards;
    transform: translateY(-50px);
}
@keyframes slideIn {
    to { transform: translateY(0); }
}

.modal-close-button {
    position: absolute;
    top: 0px;
    right: 8px;
    font-family: sans-serif;
    font-size: 32px;
    font-weight: bold;
    color: var(--panel-border-light);
    background: none;
    border: none;
    cursor: pointer;
    text-shadow: 2px 2px #000;
}
.modal-close-button:hover {
    color: var(--gold-accent);
}

.crafting-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 8px;
}
.crafting-item {
    background-color: var(--panel-border-dark);
    padding: 10px;
    text-align: center;
    font-size: 10px;
    border: 2px solid var(--panel-border-light);
}
.crafting-item.disabled-craft {
    color: #777;
    background-color: #332e29;
}

/* --- Styles for Map Modal --- */
.modal-map-content {
    width: 90%;
    max-width: 800px; /* Lebarkan modal untuk peta */
    height: 80vh; /* Tinggikan modal */
    display: flex;
    flex-direction: column;
}

#map-container {
    width: 100%;
    height: 100%; /* Peta mengisi sisa ruang di modal */
    background-color: #1a234a; /* Warna latar belakang peta saat loading */
    border: 4px solid var(--panel-border-dark);
    box-shadow: inset 0 0 0 4px var(--panel-border-light);
    margin-top: 10px;
}

/* Kustomisasi tampilan popup Leaflet agar sesuai tema */
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
    background: var(--panel-bg);
    color: var(--text-color);
    border: 2px solid var(--panel-border-light);
    box-shadow: none;
}
.leaflet-popup-content {
    font-family: var(--font-pixel);
    font-size: 10px;
    line-height: 1.5;
}
.leaflet-popup-content b {
    color: var(--gold-accent);
}
.leaflet-container a.leaflet-popup-close-button {
    color: var(--panel-border-light);
    font-family: sans-serif;
    font-size: 24px;
    padding: 4px 4px 0 0;
}
.leaflet-container a.leaflet-popup-close-button:hover {
    color: var(--gold-accent);
}

/* GANTI filter yang lama dengan yang ini */
.leaflet-tile-pane {
    /* Filter untuk membuat tile OSM terlihat gelap dan retro */
    filter: grayscale(0.8) contrast(1.2) brightness(0.8);
    image-rendering: pixelated;
}

/* --- Styles for Day/Night & Seasonal Cycle --- */

/* Variabel warna default (Malam Musim Semi) */
:root {
    --sky-top-color: #2c3e50;
    --sky-bottom-color: #4ca1af;
    --star-opacity: 1;
}

body {
    /* Transisi halus saat mengganti background */
    transition: background 5s linear;
    background: linear-gradient(to bottom, var(--sky-top-color), var(--sky-bottom-color));
}

/* --- Definisi Warna per Musim & Waktu --- */

/* Musim Panas (Juni, Juli, Agustus) */
.season-summer.time-dawn { --sky-top-color: #f7b733; --sky-bottom-color: #fc4a1a; --star-opacity: 0; }
.season-summer.time-day { --sky-top-color: #00c6ff; --sky-bottom-color: #0072ff; --star-opacity: 0; }
.season-summer.time-dusk { --sky-top-color: #ff512f; --sky-bottom-color: #dd2476; --star-opacity: 0; }
.season-summer.time-night { --sky-top-color: #232526; --sky-bottom-color: #414345; --star-opacity: 1; }

/* Musim Gugur (September, Oktober, November) */
.season-autumn.time-dawn { --sky-top-color: #f5a623; --sky-bottom-color: #d0021b; --star-opacity: 0; }
.season-autumn.time-day { --sky-top-color: #74ebd5; --sky-bottom-color: #acb6e5; --star-opacity: 0; }
.season-autumn.time-dusk { --sky-top-color: #cb2d3e; --sky-bottom-color: #ef473a; --star-opacity: 0; }
.season-autumn.time-night { --sky-top-color: #141e30; --sky-bottom-color: #243b55; --star-opacity: 1; }

/* Musim Dingin (Desember, Januari, Februari) */
.season-winter.time-dawn { --sky-top-color: #e6dada; --sky-bottom-color: #274046; --star-opacity: 0; }
.season-winter.time-day { --sky-top-color: #c9d6ff; --sky-bottom-color: #e2e2e2; --star-opacity: 0; }
.season-winter.time-dusk { --sky-top-color: #485563; --sky-bottom-color: #29323c; --star-opacity: 0.5; }
.season-winter.time-night { --sky-top-color: #000428; --sky-bottom-color: #004e92; --star-opacity: 1; }

/* Musim Semi (Maret, April, Mei) */
.season-spring.time-dawn { --sky-top-color: #ff9a9e; --sky-bottom-color: #fad0c4; --star-opacity: 0; }
.season-spring.time-day { --sky-top-color: #a1c4fd; --sky-bottom-color: #c2e9fb; --star-opacity: 0; }
.season-spring.time-dusk { --sky-top-color: #ff7e5f; --sky-bottom-color: #feb47b; --star-opacity: 0; }
.season-spring.time-night { --sky-top-color: #2c3e50; --sky-bottom-color: #4ca1af; --star-opacity: 1; }

/* Menyesuaikan Bintang Statis */
.static-stars {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background-image: radial-gradient(circle at 10% 20%, white 1px, transparent 2px), radial-gradient(circle at 70% 30%, white 1px, transparent 2px), radial-gradient(circle at 40% 80%, white 1px, transparent 2px), radial-gradient(circle at 90% 60%, white 1px, transparent 2px), radial-gradient(circle at 25% 65%, white 1.5px, transparent 3px), radial-gradient(circle at 60% 10%, white 1.5px, transparent 3px);
    z-index: -1;
    opacity: var(--star-opacity);
    transition: opacity 5s linear;
}

/* Efek Salju untuk Musim Dingin */
.snow-container {
    position: fixed; top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 10;
    display: none;
}
.season-winter .snow-container {
    display: block;
}
.snowflake {
    position: absolute;
    width: 8px; height: 8px;
    background: white;
    border-radius: 50%;
    opacity: 0.8;
    animation: snowfall linear infinite;
}
@keyframes snowfall {
    0% { transform: translate(0, -10vh); }
    100% { transform: translate(10vw, 110vh); }
}

/* --- Styles for NEW Features --- */

/* FITUR 1: MINI-GAME CLICKER */
.clicker-game {
    padding: 10px;
    text-align: center;
}
#clicker-target {
    width: 80px;
    height: 60px;
    cursor: pointer;
    transition: transform 0.1s ease;
}
#clicker-target:active, #clicker-target.clicked {
    transform: scale(0.9);
}
.clicker-score {
    font-size: 12px;
    color: var(--gold-accent);
    margin-top: 10px;
}

/* FITUR 2: PLAYER LIST */
.player-list {
    list-style: none;
    padding: 0;
    max-height: 150px;
    overflow-y: auto;
}
.player-item {
    display: flex;
    align-items: center;
    padding: 6px;
    font-size: 10px;
    border-bottom: 2px solid var(--panel-border-dark);
}
.player-avatar {
    width: 24px;
    height: 24px;
    background-color: #c0c0c0;
    border: 2px solid var(--panel-border-light);
    margin-right: 8px;
    flex-shrink: 0;
}
.player-name {
    flex-grow: 1;
}
.status {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.status.online { background-color: #90EE90; }
.status.offline { background-color: #777; }

/* FITUR 3: ACHIEVEMENT TOAST */
.achievement-toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background-color: var(--panel-bg);
    border: 2px solid var(--gold-accent);
    padding: 12px 20px;
    font-size: 10px;
    color: var(--gold-accent);
    z-index: 2000;
    transform: translateX(120%);
    transition: transform 0.5s ease-in-out;
}
.achievement-toast.visible {
    transform: translateX(0);
}

/* FITUR 4: BIOME INDICATOR */
.biome-forest { color: #90EE90; }
.biome-jungle { color: #3CB371; }
.biome-corrupt { color: #9932CC; }
.biome-snow { color: #ADD8E6; }

/* FITUR 5: INVENTORY & TOOLTIP */
.inventory-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
    gap: 8px;
    padding-top: 10px;
}
.inv-slot {
    width: 48px;
    height: 48px;
    background-color: var(--panel-border-dark);
    border: 2px solid var(--panel-border-light);
    display: flex;
    justify-content: center;
    align-items: center;
}
.inv-slot img {
    width: 32px; height: 32px;
    image-rendering: pixelated;
}
.item-tooltip {
    position: fixed;
    background-color: rgba(0, 0, 0, 0.8);
    border: 2px solid var(--panel-border-light);
    color: white;
    padding: 8px;
    font-size: 10px;
    line-height: 1.6;
    z-index: 3000;
    pointer-events: none;
    display: none;
}
.item-tooltip.visible {
    display: block;
}

/* FITUR 6: CURRENCY DISPLAY */
.currency-display {
    position: fixed;
    top: 20px;
    right: 20px;
    background-color: var(--panel-bg);
    border: 2px solid var(--panel-border-light);
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 100;
}
.currency-display img {
    width: 20px; height: 20px;
}
.currency-display span {
    font-size: 14px;
    color: var(--gold-accent);
}

/* Perbaikan Umum untuk Modal Close Button */
.modal-close-button {
    z-index: 10;
}

/* --- Styles for Status Bars (HP/FP/SP) --- */

.status-bars-container {
    display: flex;
    flex-direction: column;
    gap: 12px; /* Jarak antar bar */
    padding: 5px 0;
}

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

.status-bar label {
    font-size: 10px;
    font-weight: bold;
    flex-basis: 20px; /* Lebar label */
    color: var(--gold-accent);
}

.bar-container {
    flex-grow: 1;
    height: 22px;
    background-color: var(--panel-border-dark);
    border: 2px solid var(--panel-border-light);
    position: relative;
    padding: 2px;
}

.bar-fill {
    height: 100%;
    transition: width 0.5s ease-in-out;
    /* Animasi denyut halus */
    animation: pulse 3s infinite ease-in-out;
}

.hp-fill { background-color: var(--health-color); }
.fp-fill { background-color: var(--mana-color); }
.sp-fill { background-color: #00A86B; } /* Warna hijau untuk stamina */

.bar-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 10px;
    text-shadow: 1px 1px #000;
    color: white;
}

@keyframes pulse {
    0% { filter: brightness(1); }
    50% { filter: brightness(1.2); }
    100% { filter: brightness(1); }
}

/* --- Styles for World Chatbox --- */

.chat-container {
    display: flex;
    flex-direction: column;
    height: 180px; /* Atur tinggi chatbox */
}

.chat-messages {
    flex-grow: 1;
    overflow-y: auto;
    background-color: rgba(0,0,0,0.2);
    padding: 8px;
    border-bottom: 2px solid var(--panel-border-dark);
}

.chat-message {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 10px;
    line-height: 1.4;
}

.chat-avatar {
    flex-shrink: 0;
    font-size: 14px;
}

.chat-username {
    font-weight: bold;
    margin-right: 4px;
}

/* Warna untuk setiap role */
.user-player { color: #90EE90; } /* Hijau */
.user-npc { color: var(--gold-accent); } /* Emas */
.user-system { color: #ADD8E6; } /* Biru muda */

.chat-input {
    width: 100%;
    background-color: var(--panel-border-dark);
    border: 2px solid var(--panel-border-light);
    padding: 8px;
    font-family: var(--font-pixel);
    font-size: 10px;
    color: var(--text-color);
    outline: none;
    margin-top: 4px;
}

/* Indikator sedang mengetik */
.typing-indicator {
    display: none; /* Sembunyi secara default */
    align-items: center;
    gap: 3px;
    padding: 4px 8px;
    height: 20px;
}
.typing-indicator span {
    width: 5px;
    height: 5px;
    background-color: #aaa;
    border-radius: 50%;
    animation: typing 1.2s infinite ease-in-out;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 100% { opacity: 0.3; transform: translateY(0); }
    50% { opacity: 1; transform: translateY(-3px); }
}