/* General Styles */
body { font-family: Arial, sans-serif; margin: 0; padding: 0; background-color: #f4f4f9; }

/* Splash Screen Styles */
#splash-screen { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100vh; background-color: #1e90ff; color: #fff; padding: 20px; box-sizing: border-box; }
#splash-screen h1 { font-size: 4em; margin-bottom: 40px; text-align: center; }
#splash-buttons { display: flex; gap: 10px; margin-bottom: 40px; flex-wrap: wrap; justify-content: center; }
#splash-screen button { padding: 15px 30px; font-size: 1.2em; cursor: pointer; background-color: #fff; color: #1e90ff; border: none; border-radius: 5px; font-weight: bold; }
#splash-screen button:hover { background-color: #e0e0e0; }

#existing-boards { width: 100%; max-width: 900px; text-align: center; }
#existing-boards h2 { font-size: 2em; margin-bottom: 20px; color: #fff; }
#board-list { list-style-type: none; padding: 0; }
#board-list li { display: flex; align-items: center; justify-content: space-between; background-color: #fff; color: #1e90ff; padding: 15px 20px; margin: 10px 0; border-radius: 5px; word-wrap: break-word; font-size: 1.2em; font-weight: bold; }
#board-list li div { display: flex; gap: 5px; flex-wrap: wrap; }
#board-list li button { padding: 8px 15px; background-color: #1e90ff; color: #fff; font-size: 0.9em; border: none; border-radius: 3px; cursor: pointer; }
#board-list li button:hover { background-color: #0073e6; }

/* Edit Mode Styles */
#edit-mode { padding: 40px; }
#edit-mode-buttons { margin-bottom: 20px; }
#edit-mode button { padding: 10px 20px; font-size: 1em; margin-right: 10px; cursor: pointer; background-color: #1e90ff; color: #fff; border: none; border-radius: 5px; transition: background-color 0.3s; }
#edit-grid { display: grid; grid-template-columns: repeat(6, 1fr); grid-gap: 10px; }

#edit-grid input, #edit-grid textarea { border: 1px solid #ccc; padding: 15px; text-align: center; font-size: 1em; border-radius: 5px; width: 100%; box-sizing: border-box; font-family: inherit; }
#edit-grid input { text-overflow: ellipsis; white-space: nowrap; overflow: hidden; }

/* --- NY DESIGN FÖR POPUP-CELLER (FRÅGA + FACIT) --- */
.edit-cell { position: relative; width: 100%; min-height: 60px; }

.cell-editor {
    position: relative;
    width: 100%;
    height: 60px;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 5px;
    z-index: 1;
    transition: all 0.2s ease-in-out;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-sizing: border-box;
}

/* När man klickar i behållaren (fokus) expanderar den! */
.cell-editor:focus-within {
    position: absolute;
    top: 0; left: 0;
    height: 160px;
    z-index: 10;
    box-shadow: 0px 8px 16px rgba(0,0,0,0.3);
    border-color: #1e90ff;
}

.cell-editor textarea {
    width: 100%;
    border: none !important;
    resize: none;
    outline: none;
    font-family: inherit;
    text-align: center;
    box-sizing: border-box;
    border-radius: 0 !important;
}

.q-input {
    height: 60px;
    padding: 15px 10px !important;
    flex-grow: 1;
    transition: height 0.2s;
}

/* När behållaren är öppen, krymp frågan lite och lägg till en avdelare */
.cell-editor:focus-within .q-input {
    height: 90px;
    padding: 10px !important;
    border-bottom: 1px dashed #ccc !important;
}

/* Facit är dolt som standard... */
.a-input {
    display: none;
    height: 70px;
    padding: 15px 10px !important;
    background-color: #f8f9fa;
    font-size: 0.9em !important;
}

/* ...och visas bara när behållaren har fokus! */
.cell-editor:focus-within .a-input {
    display: block;
}

.incomplete { border: 2px solid red !important; }

/* Media toggle buttons in toolbar */
.media-toggle { background-color: #6c757d !important; font-size: 0.85em !important; padding: 8px 14px !important; }
.media-toggle.active { background-color: #ff8c00 !important; animation: pulse-glow 1.5s infinite alternate; }
@keyframes pulse-glow { from { box-shadow: 0 0 4px rgba(255,140,0,0.4); } to { box-shadow: 0 0 12px rgba(255,140,0,0.8); } }

/* Media indicator below textarea */
.media-indicator { font-size: 0.7em; background: #1e90ff; color: #fff; padding: 2px 6px; border-radius: 3px; cursor: pointer; text-align: center; margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-indicator:hover { background: #dc3545; }

/* Media pick mode overlay on cells */
.media-pick-mode { cursor: pointer; }
.media-pick-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; background: rgba(255,140,0,0.15); border: 2px dashed #ff8c00; border-radius: 5px; font-size: 1.5em; z-index: 5; cursor: pointer; box-sizing: border-box; }
.media-pick-overlay:hover { background: rgba(255,140,0,0.3); }

/* Media share block modal */
.media-share-block { border: 3px solid #ffc107; }
.media-share-icon { font-size: 3em; margin-bottom: 10px; }
.media-share-block h2 { color: #dc3545 !important; }
.media-share-block p { color: #333; line-height: 1.5; }

/* Play Mode Styles */
#play-mode { flex: 1; flex-direction: column; padding: 12px 16px 0 16px; min-height: 0; box-sizing: border-box; }
#game-name { text-align: center; font-size: clamp(1.2em, 3.2vh, 2.4em); margin: 0 0 8px 0; color: #1e90ff; flex-shrink: 0; }
#game-board { display: grid; grid-template-columns: repeat(6, 1fr); grid-template-rows: auto repeat(5, 1fr); grid-gap: 5px; flex: 1; min-height: 0; }
.category-cell, .question-cell { display: flex; align-items: center; justify-content: center; text-align: center; box-sizing: border-box; min-height: 0; min-width: 0; overflow: hidden; }
.category-cell { background-color: #00008b; color: #fff; padding: 6px 4px; font-size: clamp(0.65em, 1.3vw, 1.1em); font-weight: bold; text-transform: uppercase; border-radius: 5px; line-height: 1.15; }

.question-cell { background-color: #2b5c8f; color: #ffd700; padding: 4px 6px; font-size: clamp(1em, 3vw, 2em); font-weight: bold; cursor: pointer; border-radius: 5px; text-shadow: 2px 2px 0 #000; }
.question-cell:hover { background-color: #3b76b3; }
.question-cell.clicked { background-color: #999; cursor: default; text-shadow: none; }

/* Teams Section (Anpassad för Buzzer-sidobar) */
#teams { flex-shrink: 0; width: 100%; background-color: #00008b; padding: 8px 5px; box-sizing: border-box; overflow-y: hidden; border-top: 3px solid #ffd700; margin-top: 8px; }
#teams h2 { color: #fff; text-align: center; margin: 0 0 5px 0; font-size: 1.1em; }
#team-list { display: flex; justify-content: space-between; flex-wrap: nowrap; gap: 5px; align-items: flex-start; }
.team { display: flex; flex-direction: column; align-items: center; color: #fff; background: rgba(255,255,255,0.1); padding: 5px; border-radius: 8px; flex: 1; min-width: 0; }
.team input { text-align: center; font-size: 1em; font-weight: bold; margin-bottom: 3px; background-color: transparent; border: none; border-bottom: 1px solid #fff; color: #fff; width: 100%; text-overflow: ellipsis; overflow: hidden; white-space: nowrap; }
.team input:focus { outline: none; border-bottom: 2px solid #ffd700; }
.team p { font-size: 1.2em; margin: 0; font-weight: bold; color: #ffd700; }

/* Drag and Drop Spelare (NY) */
.team-players { width: 100%; min-height: 40px; display: flex; flex-direction: column; align-items: center; gap: 4px; overflow-y: auto; max-height: 80px; margin-top: 5px; padding-bottom: 5px; }
.player-chip { background: rgba(255,255,255,0.2); padding: 4px 8px; border-radius: 12px; font-size: 0.85em; cursor: grab; width: 90%; box-sizing: border-box; white-space: nowrap; overflow: hidden; display: flex; align-items: center; gap: 4px; }
.player-chip:active { cursor: grabbing; }
.player-action-btn { background: none; border: none; color: rgba(255,255,255,0.7); cursor: pointer; padding: 0 2px; font-size: 0.8em; line-height: 1; flex-shrink: 0; }
.player-action-btn:hover { color: #fff; }
.player-kick-btn:hover { color: #ff4444; }
.drag-over { background: rgba(255, 215, 0, 0.2) !important; border-radius: 8px; border: 1px dashed #ffd700; }

/* Modals (Anpassad för Buzzer-sidobar) */
.custom-modal { position: fixed; top: 0; left: 0; width: calc(100% - 300px); height: 100%; background-color: rgba(0,0,0,0.85); display: flex; align-items: center; justify-content: center; z-index: 100; }
#team-setup-modal { width: 100% !important; z-index: 300; } /* Ska täcka hela skärmen */

.modal-content { background-color: #fff; padding: 30px; width: 90%; max-width: 500px; border-radius: 10px; text-align: center; position: relative; color: #333; }
.modal-content h2 { margin-top: 0; color: #1e90ff; }
.modal-content input[type="text"], .modal-content input[type="number"], .modal-content textarea { width: 100%; padding: 10px; margin: 10px 0 20px 0; border: 1px solid #ccc; border-radius: 5px; font-size: 1em; box-sizing: border-box; }
.modal-content button { padding: 10px 20px; font-size: 1em; background-color: #1e90ff; color: #fff; border: none; cursor: pointer; border-radius: 5px; margin: 5px; }
.modal-content button.cancel-btn { background-color: #ccc; color: #333; }
.close-x { position: absolute; top: 10px; right: 15px; font-size: 1.5em; cursor: pointer; color: #999; }

/* Question Popup (Anpassad för Buzzer-sidobar) */
#question-popup { position: fixed; top: 0; left: 0; width: calc(100% - 300px); height: 100%; background-color: rgba(0,0,0,0.9); display: flex; align-items: center; justify-content: center; z-index: 50; }
#question-content { background-color: #fff; padding: 40px; width: 80%; max-width: 900px; border-radius: 15px; text-align: center; border: 5px solid #1e90ff; position: relative; }
#event-banner { display: none; padding: 10px; font-size: 1.5em; font-weight: bold; color: #fff; border-radius: 8px; margin-bottom: 20px; }
#question-text { font-size: 3em; font-weight: bold; margin-bottom: 40px; color: #00008b; word-wrap: break-word; }
#adjust-points { display: flex; justify-content: center; flex-wrap: wrap; gap: 15px; margin-top: 20px; }

.adjust-team { display: flex; flex-direction: column; align-items: center; background: #f0f0f0; padding: 10px 15px; border-radius: 10px; min-width: 120px; transition: 0.3s; }
.adjust-team p { font-size: 1.2em; font-weight: bold; margin: 0 0 10px 0; color: #333; }
.adjust-team .btn-group { display: flex; gap: 10px; }
.adjust-team button { padding: 15px 20px; font-size: 1.2em; font-weight: bold; border: none; cursor: pointer; border-radius: 5px; color: #fff; }
.btn-plus { background-color: #28a745; }
.btn-plus:hover { background-color: #218838; }
.btn-minus { background-color: #dc3545; }
.btn-minus:hover { background-color: #c82333; }
.team-frozen { opacity: 0.3; pointer-events: none; }

#close-question-btn { margin-top: 30px; padding: 15px 30px; font-size: 1.2em; background-color: #333; color: white; border: none; border-radius: 5px; cursor: pointer; }

/* Event Animations (Anpassad för Buzzer-sidobar) */
.event-splash { position: fixed; top: 0; left: 0; width: calc(100% - 300px); height: 100%; background-size: 300% 300%; display: flex; align-items: center; justify-content: center; flex-direction: column; z-index: 200; color: white; text-transform: uppercase; text-align: center; }
@keyframes explode { 0% { background-position: 0% 50%; } 100% { background-position: 100% 50%; } }
.event-splash h1 { font-size: 6em; font-weight: 900; text-shadow: 6px 6px 0 #000; animation: zoomInOut 1s infinite alternate; margin: 0; }
.event-splash h2 { font-size: 3em; text-shadow: 3px 3px 0 #000; margin-top: 20px; }
@keyframes zoomInOut { from { transform: scale(1); } to { transform: scale(1.15); } }

#generic-event-continue-btn { margin-top: 40px; padding: 15px 30px; font-size: 1.5em; background-color: #fff; color: #333; border: none; border-radius: 8px; cursor: pointer; font-weight: bold; box-shadow: 2px 2px 10px rgba(0,0,0,0.5); transition: transform 0.2s; }
#generic-event-continue-btn:hover { transform: scale(1.05); }

/* End Screen */
#end-screen { padding: 40px; text-align: center; min-height: 100vh; background-color: #1e90ff; color: white; }
#end-screen h1 { font-size: 5em; margin-bottom: 20px; color: #ffd700; text-shadow: 2px 2px 0 #000; }
#results { margin-top: 20px; background: rgba(0,0,0,0.2); padding: 30px; border-radius: 15px; display: inline-block; }
#results h2 { font-size: 3em; margin-bottom: 30px; }
.team-result { font-size: 2em; margin-bottom: 15px; border-bottom: 1px solid rgba(255,255,255,0.3); padding-bottom: 10px;}
#back-to-main { display: block; margin: 40px auto 0 auto; padding: 15px 30px; font-size: 1.5em; cursor: pointer; border: none; border-radius: 5px; background-color: #fff; color: #1e90ff; font-weight: bold; }

/* --- MODERN TOAST NOTIFICATION --- */
#toast-msg {
    visibility: hidden;
    min-width: 250px;
    background-color: #333;
    color: #fff;
    text-align: center;
    border-radius: 8px;
    padding: 16px;
    position: fixed;
    z-index: 1000;
    left: 50%;
    bottom: 20px;
    font-size: 1.2em;
    transform: translateX(-50%);
    box-shadow: 0 4px 15px rgba(0,0,0,0.4);
    transition: opacity 0.3s, bottom 0.3s;
    opacity: 0;
}
#toast-msg.show {
    visibility: visible;
    opacity: 1;
    bottom: 40px;
}

/* QR Code Widget */
#qr-widget {
    position: fixed;
    right: 20px;
    bottom: 20px;
    width: 200px;
    height: 230px;
    min-width: 120px;
    min-height: 150px;
    max-width: 90vw;
    max-height: 90vh;
    background: #fff;
    border: 2px solid #1e90ff;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
    z-index: 9999;
    box-sizing: border-box;
    padding: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    user-select: none;
}

#qr-resize-handle {
    position: absolute;
    top: 0;
    left: 0;
    width: 18px;
    height: 18px;
    cursor: nwse-resize;
    background: linear-gradient(135deg, #1e90ff 0%, #1e90ff 50%, transparent 50%);
    border-top-left-radius: 6px;
}

#qr-minimize-btn {
    position: absolute;
    top: 2px;
    right: 4px;
    background: none;
    border: none;
    font-size: 1.2em;
    font-weight: bold;
    color: #1e90ff;
    cursor: pointer;
    padding: 2px 8px;
    line-height: 1;
}
#qr-minimize-btn:hover { color: #0073e6; }

#qr-label {
    font-size: 0.9em;
    font-weight: bold;
    color: #1e90ff;
    margin-bottom: 6px;
    margin-top: 4px;
}

#qr-code {
    flex: 1;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

#qr-code img, #qr-code canvas {
    max-width: 100%;
    max-height: 100%;
    width: auto !important;
    height: auto !important;
    object-fit: contain;
}

#qr-show-btn {
    position: fixed;
    right: 20px;
    bottom: 20px;
    width: 50px;
    height: 50px;
    background: #1e90ff;
    color: #fff;
    border: none;
    border-radius: 50%;
    font-weight: bold;
    font-size: 1em;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
    z-index: 9999;
}
#qr-show-btn:hover { background: #0073e6; }
