/* Universal reset with better inheritance */
html {
    box-sizing: border-box;
}

*, *::before, *::after {
    box-sizing: inherit;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #0a0a0a;
    color: #f0f0f0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: 1.5;
}

/* TOP BAR */
#topbar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 50px;
    background: #111;
    border-bottom: 1px solid #333;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    z-index: 1000;
}

#topbar .logo {
    font-size: 1.2rem;
    font-weight: bold;
    color: #fff;
}

#topbar nav {
    display: flex;
    gap: 20px;
}

#topbar a {
    color: #4a9eff;
    text-decoration: none;
    font-size: 0.95rem;
    transition: text-decoration 0.2s ease;
}

#topbar a:hover {
    text-decoration: underline;
}

/* MAIN CONTENT */
main {
    flex: 1;
    padding: 70px 20px 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* LOGO SECTION */
.logo-section {
    text-align: center;
}

.logo-section img {
    height: 160px;
    display: block;
    margin: 0 auto 10px;
}

/* SERVER INFO */
.server-info {
    background: linear-gradient(135deg, #1a1a1a, #222);
    border-left: 4px solid #4a9eff;
    padding: 12px 20px;
    margin: 20px auto;
    max-width: 800px;
    border-radius: 8px;
    text-align: center;
    color: #4a9eff;
    font-weight: 500;
}

/* SEARCH FORM */
#sj-form {
    width: 100%;
    max-width: 700px;
    margin: 20px auto;
    display: flex;
    gap: 10px;
    justify-content: center;
    align-items: center;
}

#sj-address {
    flex: 1;
    padding: 14px 24px;
    border: 2px solid #333;
    border-radius: 30px;
    background: #1a1a1a;
    color: #fff;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.3s ease;
}

#sj-address:focus {
    border-color: #4a9eff;
    box-shadow: 0 0 0 2px rgba(74, 158, 255, 0.2);
}

#sj-form button {
    padding: 14px 28px;
    background: linear-gradient(135deg, #4a9eff, #357ae8);
    color: white;
    border: none;
    border-radius: 30px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    white-space: nowrap;
    transition: background 0.3s ease, transform 0.1s ease;
}

#sj-form button:hover {
    background: linear-gradient(135deg, #357ae8, #2a65cc);
}

#sj-form button:active {
    transform: scale(0.98);
}

/* NEWS SECTION */
.news-section {
    width: 100%;
    max-width: 1000px;
    margin: 50px auto;
    padding: 0 20px;
}

.news-section h2 {
    text-align: center;
    margin-bottom: 30px;
    color: #fff;
    font-size: clamp(1.5rem, 4vw, 2rem);
}

#learning-news {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.news-card {
    background: #151515;
    border: 1px solid #333;
    border-radius: 12px;
    padding: 20px;
    cursor: pointer;
    transition: border-color 0.3s ease, transform 0.2s ease;
}

.news-card:hover {
    border-color: #4a9eff;
    transform: translateY(-2px);
}

.news-card.big {
    grid-column: span 2;
}

.news-card a {
    color: #4a9eff;
    text-decoration: none;
    font-weight: 600;
    font-size: 1.1rem;
    display: block;
}

/* PROXY IFRAME */
#sj-frame {
    width: 100%;
    max-width: 1200px;
    height: 70vh;
    min-height: 400px;
    border: 1px solid #444;
    border-radius: 12px;
    background: #000;
    margin: 40px auto;
    display: block;
}

/* BOTTOM NAV */
#bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 60px;
    background: #111;
    border-top: 1px solid #333;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 40px;
    z-index: 1000;
    padding: 0 20px;
}

#bottom-nav a {
    color: #4a9eff;
    text-decoration: none;
    font-size: 0.95rem;
    padding: 10px 20px;
    border-radius: 25px;
    transition: background 0.2s ease;
}

#bottom-nav a:hover {
    background: rgba(74, 158, 255, 0.15);
}

/* FOOTER */
footer {
    margin-top: auto;
    text-align: center;
    padding: 25px 20px;
    background: #111;
    color: #888;
    font-size: 0.9rem;
}

/* CHAT WIDGET */
#chat-container {
    position: fixed;
    top: 60px;
    left: 20px;
    width: 400px;
    height: 600px;
    z-index: 9999;
    border: 2px solid #555;
    border-radius: 10px;
    background: #1a1a1a;
    color: #f0f0f0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#chat-header {
    background: #222;
    color: #fff;
    padding: 8px 12px;
    cursor: grab;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#chat-header:active {
    cursor: grabbing;
}

#chat-close,
#chat-toggle {
    background: #ff4444;
    border: none;
    padding: 4px 8px;
    border-radius: 5px;
    cursor: pointer;
    margin-left: 5px;
    color: white;
    font-weight: bold;
    transition: background 0.2s ease;
}

#chat-close:hover,
#chat-toggle:hover {
    background: #ff1a1a;
}

#update-logs {
    flex: 1;
    border: none;
    width: 100%;
    background: #0a0a0a;
    color: #f0f0f0;
    font-family: inherit;
    overflow-y: auto;
}

/* LOADING OVERLAY */
#loading-overlay {
    position: fixed;
    top: 50px;
    left: 0;
    width: 100%;
    height: calc(100vh - 110px);
    background: rgba(10, 10, 10, 0.95);
    z-index: 9998;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
}

.loading-content {
    text-align: center;
    background: rgba(26, 26, 26, 0.95);
    padding: 40px;
    border-radius: 20px;
    border: 1px solid #333;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    max-width: 400px;
    width: 90%;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(74, 158, 255, 0.2);
    border-top: 4px solid #4a9eff;
    border-radius: 50%;
    margin: 0 auto 20px;
    animation: spin 1s linear infinite;
    will-change: transform;
}

.loading-content p {
    color: #fff;
    margin-bottom: 20px;
    font-size: 1.1rem;
}

.loading-progress {
    width: 100%;
    height: 6px;
    background: #333;
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #4a9eff, #357ae8);
    width: 0%;
    animation: progress-pulse 2s ease-in-out infinite;
    will-change: transform;
}

/* Fancy loading dots */
.loading-dots {
    display: inline-block;
    margin-left: 5px;
}

.loading-dots::after {
    content: '';
    animation: dots 1.5s steps(4, end) infinite;
}

/* ANIMATIONS */
@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes dots {
    0%, 20% { content: ''; }
    40% { content: '.'; }
    60% { content: '..'; }
    80%, 100% { content: '...'; }
}

@keyframes progress-pulse {
    0%, 100% { transform: translateX(-100%); }
    50% { transform: translateX(200%); }
}

/* Auto-fade out — apply class `.loading-fade-out` via JS when done */
#loading-overlay.loading-fade-out {
    animation: fadeOut 0.8s forwards;
}

@keyframes fadeOut {
    to {
        opacity: 0;
        visibility: hidden;
    }
}

/* RESPONSIVE */
@media (max-width: 768px) {
    #sj-form {
        flex-direction: column;
        padding: 0 20px;
    }

    #sj-address,
    #sj-form button {
        width: 100%;
        border-radius: 30px;
    }

    .news-card.big {
        grid-column: span 1 !important;
    }

    #bottom-nav {
        gap: 15px;
        flex-wrap: wrap;
        height: auto;
        padding: 10px;
    }

    #chat-container {
        width: 350px;
        height: 500px;
    }
}

@media (max-width: 480px) {
    #topbar {
        padding: 0 10px;
    }

    #topbar nav {
        gap: 10px;
    }

    .logo-section img {
        height: 60px;
        margin-bottom: 8px;
    }

    #bottom-nav {
        gap: 8px;
        padding: 8px;
    }

    #chat-container {
        width: calc(100% - 40px);
        height: 450px;
        left: 10px;
        right: 10px;
    }

    .news-section h2 {
        font-size: 1.5rem;
    }
}