/* =========================================
   1. GLOBAL & RESET
   ========================================= */
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Arial', sans-serif;
    background-image: url('baggrund.jpg'); /* Sørg for at filen ligger i roden eller /assets/ */
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    overflow-x: hidden;
    color: #333;
    /* Forhindrer "pull-to-refresh" på mobil */
    overscroll-behavior-y: none;
}

/* FIX: Forhindrer iOS zoom når man klikker på input felter */
input, select, textarea {
    font-size: 16px !important;
}

/* Lyd-elementer skjules */
audio {
    display: none;
}

/* =========================================
   2. SNE EFFEKT
   ========================================= */
#snow-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.snowflake {
    position: absolute;
    top: -10px;
    color: #fff;
    text-shadow: 0 0 5px #000;
    animation: fall linear infinite;
    user-select: none;
}

@keyframes fall {
    to { transform: translateY(110vh); }
}

/* =========================================
   3. LAYOUT & HEADER
   ========================================= */
.calendar-wrapper {
    position: relative;
    z-index: 10;
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.header {
    padding: 15px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: gold;
    font-weight: bold;
    background: rgba(0, 0, 0, 0.4);
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

.stat-box {
    background: rgba(255, 255, 255, 0.2);
    padding: 6px 14px;
    border-radius: 20px;
    border: 2px solid gold;
    display: flex;
    align-items: center;
    gap: 8px;
    color: white;
    font-size: 15px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    white-space: nowrap;
}

.audio-btn {
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid gold;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    color: gold;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 20px;
    transition: transform 0.1s;
}
.audio-btn:active { transform: scale(0.9); }

/* Knapper i header */
.admin-btn {
    background: #8e44ad;
    border: none;
    padding: 6px 12px;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    color: white;
    margin-right: 5px;
}
.hs-btn {
    background: gold;
    padding: 8px 15px;
    border-radius: 20px;
    cursor: pointer;
    font-weight: bold;
    color: #8b0000;
    border: 2px solid #b8860b;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}
.logout-link {
    color: #ddd;
    font-size: 12px;
    text-decoration: underline;
    margin-left: 10px;
}

/* Responsiv Header */
.desktop-only { display: flex; width: 100%; }
.mobile-only { display: none; }

@media (max-width: 768px) {
    .header { padding: 10px; background: rgba(0, 0, 0, 0.6); }
    .desktop-only { display: none; }
    .mobile-only { display: flex; width: 100%; justify-content: space-between; align-items: center; }
    
    .mobile-stats { display: flex; gap: 5px; align-items: center; }
    .stat-box { padding: 4px 8px; font-size: 12px; border-width: 1px; border-radius: 10px; }
    .audio-btn { width: 32px; height: 32px; font-size: 14px; }
}

/* =========================================
   4. DØR GRID (LÅGER)
   ========================================= */
.grid-container {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 15px;
    padding: 20px 40px;
    flex-grow: 1;
    align-content: center;
}

@media (max-width: 768px) {
    .grid-container { 
        grid-template-columns: repeat(4, 1fr); 
        padding: 15px; 
        gap: 8px; 
    }
}

.door {
    background: rgba(255, 255, 255, 0.15);
    border: 2px dashed rgba(255, 255, 255, 0.6);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-size: 36px;
    font-weight: bold;
    color: white;
    text-shadow: 0 0 10px #000;
    cursor: pointer;
    transition: transform 0.1s, background 0.2s;
    position: relative;
    aspect-ratio: 1 / 1; /* Kvadratiske låger */
}

.door:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.05);
    z-index: 2;
}
.door:active { transform: scale(0.95); }

.door.completed {
    border-style: solid;
    border-color: rgba(255, 255, 255, 0.4);
    color: gold;
    background: rgba(255, 255, 255, 0.2);
    box-shadow: inset 0 0 10px rgba(255, 255, 255, 0.1);
}

.door.locked {
    opacity: 0.6;
    cursor: default;
}
.door.locked:hover {
    transform: none;
    background: rgba(255, 255, 255, 0.15);
}

/* =========================================
   5. MODALS & POPUPS (GENERISK)
   ========================================= */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(13, 27, 42, 0.9);
    z-index: 4000;
    display: none; /* Skjult som standard */
    flex-direction: column;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
}

.nisse-box {
    background: #fdf5e6; /* Lys sand/papir farve */
    padding: 25px;
    border-radius: 15px;
    border: 4px solid #8b0000;
    text-align: center;
    max-width: 450px;
    width: 90%;
    color: #333;
    position: relative;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    max-height: 90vh;
    overflow-y: auto;
    overflow-x: hidden;
    box-sizing: border-box;
}

/* DAY55 MODAL STYLE (dialog-overlay og dialog-panel) */
.dialog-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    background: rgba(13, 27, 42, 0.95) !important;
    z-index: 8000;
    display: flex !important;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    backdrop-filter: blur(5px);
}

.dialog-overlay.active,
.dialog-overlay[style*="opacity: 1"],
.dialog-overlay[style*="visibility: visible"] {
    opacity: 1 !important;
    visibility: visible !important;
}

.dialog-panel {
    background: #0d1b2a;
    color: #fff;
    width: 95vw;
    max-width: 600px;
    max-height: 90vh;
    padding: 30px;
    border-radius: 20px;
    border: 6px solid #c0392b;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    box-shadow: 0 5px 30px rgba(0,0,0,0.5);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    position: relative;
    box-sizing: border-box;
}

.dialog-button {
    padding: 15px 50px;
    background: #c0392b;
    color: white;
    border: 4px solid #f1c40f;
    border-radius: 50px;
    font-size: 22px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 0 20px rgba(192, 57, 43, 0.8);
    transition: transform 0.1s;
    margin-bottom: 15px;
    flex-shrink: 0;
    animation: btnPulse 1.5s infinite;
    width: 100%;
    max-width: 400px;
}

@keyframes btnPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.dialog-button:active {
    transform: scale(0.95);
    animation: none;
}

.dialog-button:hover {
    transform: scale(1.05);
    filter: brightness(1.1);
}

.dialog-elf {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: 4px solid #f1c40f;
    margin-bottom: 15px;
    background: #fff;
    object-fit: cover;
    flex-shrink: 0;
}

.dialog-panel h2 {
    color: #f1c40f;
    margin: 0 0 10px 0;
    font-size: 28px;
    text-shadow: 2px 2px 0 #000;
    flex-shrink: 0;
}

.dialog-panel p {
    font-size: 16px;
    line-height: 1.5;
    margin-bottom: 20px;
    max-width: 500px;
    flex-shrink: 0;
}

.nisse-box h2 {
    color: #c0392b;
    margin-top: 0;
}

.nisse-box input, 
.nisse-box select, 
.nisse-box textarea {
    width: 85%;
    padding: 12px;
    margin: 8px 0;
    font-size: 18px;
    border: 2px solid #daa520;
    border-radius: 5px;
    font-family: Arial, sans-serif;
}

.theme-btn {
    background: #27ae60;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 18px;
    margin-top: 15px;
    font-weight: bold;
    box-shadow: 0 4px 0 #1e8449;
    transition: transform 0.1s;
}
.theme-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #1e8449;
}

/* =========================================
   6. HUSNISSEN & BADGES
   ========================================= */
#cornerElf {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 2000;
    cursor: pointer;
    transition: transform 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
}
#cornerElf:hover { transform: scale(1.1); }

.elf-portrait {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    border: 4px solid #c0392b;
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.6);
    background: #fff;
    object-fit: cover;
}

/* Den røde prik med tal */
.notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #e74c3c;
    color: white;
    border: 2px solid white;
    border-radius: 50%;
    min-width: 24px;
    height: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 12px;
    font-weight: bold;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    z-index: 2005;
    animation: bounce 2s infinite;
}
@keyframes bounce { 
    0%, 100% {transform: translateY(0);} 
    10% {transform: translateY(-5px);} 
    20% {transform: translateY(0);} 
}



/* =========================================
   7. KALLE MENU (Slide-up)
   ========================================= */
#elfMenuPanel {
    display: none;
    position: fixed; 
    bottom: 95px; 
    right: 20px; 
    width: 280px; 
    background: #fdf5e6; 
    border: 4px solid #c0392b; 
    border-radius: 15px; 
    z-index: 3000; 
    box-shadow: 0 0 20px rgba(0,0,0,0.5); 
    padding: 0 15px 15px 15px;
    text-align: center;
}

#elfMenuPanel.visible {
    display: block !important;
}


.menu-header {
    background: #c0392b; 
    color: white; 
    padding: 10px; 
    margin: 0 -15px 15px -15px; /* Negative margins for at fylde bredden */
    border-radius: 10px 10px 0 0; 
    font-weight: bold; 
    display: flex; 
    justify-content: space-between;
    align-items: center;
}

.menu-btn {
    display: block;
    width: 100%;
    margin: 10px 0;
    padding: 12px;
    background: #2c3e50;
    color: white;
    border: 2px solid #34495e;
    border-radius: 8px;
    cursor: pointer;
    text-decoration: none;
    font-size: 16px;
    font-weight: bold;
    transition: background 0.2s;
}
.menu-btn:hover { background: #34495e; }

/* =========================================
   8. NISCORD (CHAT) - MED ANIMATION
   ========================================= */
#chatBtn {
    position: fixed; bottom: 20px; left: 20px; z-index: 2000;
    background: #27ae60; color: white; border: 4px solid #fff;
    border-radius: 50%; width: 60px; height: 60px;
    font-size: 30px; cursor: pointer; box-shadow: 0 0 15px rgba(0, 0, 0, 0.5);
    display: flex; justify-content: center; align-items: center;
    transition: transform 0.2s;
}
.chat-glow { animation: glowing 1.5s infinite; border-color: gold !important; }
@keyframes glowing { 0% { box-shadow: 0 0 5px #27ae60; } 50% { box-shadow: 0 0 25px gold; } 100% { box-shadow: 0 0 5px #27ae60; } }

#chatWindow {
    display: flex; /* VIGTIGT: Skal være flex nu, så den findes (men er skubbet væk) */
    position: fixed; bottom: 90px; left: 20px;
    width: 300px; height: 400px; max-height: 60vh;
    background: #fffaf0; border: 4px solid #27ae60; border-radius: 15px;
    z-index: 3000; box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    flex-direction: column; overflow: hidden;
    overscroll-behavior: contain;

    /* SKJULT START MED ANIMATION */
    transform: translateY(150vh);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Denne klasse tilføjes med JS for at vise chatten */
#chatWindow.visible {
    transform: translateY(0);
}

.chat-header {
    background: #27ae60;
    color: white;
    padding: 10px;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-messages {
    flex-grow: 1;
    overflow-y: auto;
    padding: 10px;
    background: #fff;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 14px;
    /* Mobil Fix: Glat scroll */
    -webkit-overflow-scrolling: touch;
}

.chat-input-area {
    padding: 10px;
    background: #eee;
    display: flex;
    gap: 5px;
    border-top: 1px solid #ccc;
}
#chatMsgInput {
    flex-grow: 1;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 5px;
    color: #000;
}
#chatSendBtn {
    background: #27ae60;
    color: white;
    border: none;
    padding: 8px 15px;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
}

/* Besked bobler */
.msg {
    padding: 6px 10px;
    border-radius: 8px;
    background: #f1f1f1;
    max-width: 85%;
    color: #333;
    word-wrap: break-word;
}
.msg strong {
    color: #27ae60;
    font-size: 11px;
    display: block;
}
.msg small {
    color: #999;
    font-size: 10px;
    margin-left: 5px;
}
.msg-own {
    align-self: flex-end;
    background: #d4edda;
    border: 1px solid #c3e6cb;
    color: #155724;
}

/* Skjul chat & nisse når spillet kører (eller på mobil landscape) */
body.game-running #cornerElf,
body.game-running #elfMenuPanel,
body.game-running #chatBtn,
body.game-running #chatWindow {
    display: none !important;
}

@media (max-height: 600px) and (orientation: landscape) {
    #cornerElf, #chatBtn, #chatWindow, #elfMenuPanel {
        display: none !important;
    }
}

/* =========================================
   9. START SKÆRM
   ========================================= */
#startScreen {
    display: flex; /* Flexbox centering fra modal-overlay */
    z-index: 5000;
    background: rgba(13, 27, 42, 0.98);
}

.big-start-btn {
    font-size: 30px;
    padding: 20px 60px;
    background: #c0392b;
    color: white;
    border: 4px solid #f1c40f;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 0 30px rgba(192, 57, 43, 0.8);
    animation: pulse 2s infinite;
    font-weight: bold;
}
@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); box-shadow: 0 0 50px rgba(192, 57, 43, 1); }
    100% { transform: scale(1); }
}

.big-nisse-portrait {
    width: 200px;
    height: 200px;
    border-radius: 50%;
    border: 6px solid #f1c40f;
    object-fit: cover;
    margin-bottom: 30px;
}

/* =========================================
   9B. START SCREEN LOBBY STYLE (DAY55 MIMIC)
   ========================================= */
.start-lobby-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    animation: fadeIn 0.3s ease-out;
    padding: 20px;
}

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

.start-elf-portrait {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    border: 4px solid #f1c40f;
    margin-bottom: 20px;
    background: #fff;
    object-fit: cover;
    box-shadow: 0 0 20px rgba(241, 196, 15, 0.4);
}

.start-lobby-title {
    font-size: 42px;
    font-weight: bold;
    color: #f1c40f;
    text-shadow: 0 0 15px rgba(241, 196, 15, 0.4);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 2px;
    text-align: center;
}

.start-lobby-subtitle {
    font-size: 18px;
    color: #aaddff;
    margin-bottom: 30px;
    opacity: 0.9;
    text-align: center;
}

.start-card-grid {
    display: flex;
    gap: 20px;
    justify-content: center;
    flex-wrap: wrap;
    max-width: 800px;
}

.start-game-card {
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 15px;
    width: 280px;
    padding: 30px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.start-game-card:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: #f1c40f;
    transform: translateY(-5px) scale(1.02);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.start-card-icon {
    font-size: 60px;
    margin-bottom: 20px;
}

.start-card-title {
    font-size: 22px;
    font-weight: bold;
    margin-bottom: 15px;
    color: white;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.start-card-desc {
    font-size: 14px;
    color: #ccc;
    line-height: 1.5;
}

/* Mobile responsive */
@media (max-width: 768px) {
    .start-lobby-title {
        font-size: 32px;
    }
    .start-lobby-subtitle {
        font-size: 16px;
    }
    .start-card-grid {
        flex-direction: column;
        max-width: 320px;
    }
    .start-game-card {
        width: 100%;
    }
}

/* =========================================
   10. HIGHSCORE TABEL & PAGINATION
   ========================================= */
#totalScoreTable {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
    color: #333;
}
#totalScoreTable th {
    text-align: left;
    border-bottom: 2px solid #daa520;
    padding: 5px;
    color: #8b0000;
}
#totalScoreTable td {
    padding: 8px 5px;
    border-bottom: 1px solid #eee;
}

.pagination-bar {
    display: flex;
    justify-content: space-between;
    margin-top: 15px;
    align-items: center;
}
.page-btn {
    padding: 8px 15px;
    background: #daa520;
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 14px;
    cursor: pointer;
}
.page-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* =========================================
   11. SUPPORT & LISTE STYLES
   ========================================= */
.topic-list {
    max-height: 300px;
    overflow-y: auto;
    text-align: left;
    margin-bottom: 15px;
    border: 1px solid #ccc;
    background: white;
    padding: 10px;
    border-radius: 5px;
}

.topic-item {
    padding: 10px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    background: #f9f9f9;
    transition: background 0.1s;
}
.topic-item:hover {
    background: #eee;
}

.topic-subject {
    font-weight: bold;
    color: #2c3e50;
    display: flex;
    justify-content: space-between;
}

.topic-meta {
    font-size: 11px;
    color: #7f8c8d;
    margin-top: 4px;
}

.topic-status {
    font-size: 10px;
    font-weight: bold;
    padding: 2px 6px;
    border-radius: 4px;
    background: #eee;
}

/* =========================================
   12. SPIL OVERLAY (IFRAME)
   ========================================= */
#gameOverlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    z-index: 1500;
    display: none;
}

#gameFrame {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
    z-index: 1501;
}

#closeGameBtn {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 2000;
    background: rgba(255, 255, 255, 0.8);
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 0 10px rgba(0,0,0,0.5);
}
#closeGameBtn:hover {
    background: #fff;
}

/* --- NISSELAND SCORE HEADER BOX --- */
.nisseland-score-box {
    background: linear-gradient(to bottom, #2c3e50, #000);
    border: 2px solid gold;
    color: white;
    padding: 8px 20px;
    border-radius: 25px;
    font-weight: bold;
    cursor: pointer;
    font-size: 16px;
    text-shadow: 1px 1px 0 #000;
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.3);
    transition: transform 0.2s, box-shadow 0.2s;
    white-space: nowrap;
    display: inline-flex;
    /* FIX: Baseline alignment */
    align-items: baseline; 
    gap: 5px;
}

.nisseland-score-box:hover {
    transform: scale(1.05);
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.6);
    background: #444;
}

/* Mobil version */
.nisseland-score-box.mobile {
    width: 100%;
    justify-content: center;
    margin: 5px 0;
    font-size: 14px;
    padding: 5px;
    background: rgba(0,0,0,0.5);
    border: 1px solid gold;
    align-items: baseline;
}

/* Tabel i Nisseland Modal */
#nisselandTable {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}
#nisselandTable th {
    background: #27ae60;
    color: white;
    padding: 10px;
    text-align: left;
}
#nisselandTable td {
    padding: 10px;
    border-bottom: 1px solid #eee;
    color: #333;
}