* {
    box-sizing: border-box;
}

body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    margin: 0;
    background-color: #32373c; /* TŠRB dark grey background */
    font-family: 'Press Start 2P', system-ui, sans-serif;
    color: #dedfe0; /* Light grey text */
    font-size: 10px;
    user-select: none;
    -webkit-user-select: none;
    cursor: default;
}

input, textarea {
    user-select: auto;
    -webkit-user-select: auto;
    cursor: text;
}

.main-content {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    padding: 20px 0;
}

/* Base text elements use system font for modern readability */
p, div, span {
    font-family: system-ui, -apple-system, sans-serif;
    font-size: 14px;
}

/* Titles and scores keep retro font */
h2, h3, .score-val, canvas, .countdown-text, #top-msg, #main-msg {
    font-family: 'Press Start 2P', monospace;
}

/* Post-Game Teaching Panel */
.teaching-panel {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translate(-50%, -150%);
    transition: transform 0.5s ease-in-out;
    width: 100%;
    max-width: 800px;
    background: linear-gradient(135deg, #475467, #32373c);
    color: #fff;
    padding: 20px 20px 40px 20px; /* extra padding at bottom for close btn */
    border-bottom-left-radius: 15px;
    border-bottom-right-radius: 15px;
    text-align: center;
    z-index: 1000;
    box-shadow: 0px 10px 30px rgba(0,0,0,0.6);
}
.teaching-panel.open {
    transform: translate(-50%, 0);
}
.close-teaching-btn {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background-color: rgba(255, 255, 255, 0.1);
    color: #fff;
    font-weight: bold;
    padding: 10px 0;
    cursor: pointer;
    font-size: 14px;
    border-bottom-left-radius: 15px;
    border-bottom-right-radius: 15px;
    transition: background 0.2s;
    user-select: none;
    -webkit-user-select: none;
}
.close-teaching-btn:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.teaching-panel h3 {
    margin-top: 0;
    color: #ff6900;
    text-shadow: 2px 2px 0 #000;
    font-size: 14px;
    line-height: 1.5;
}

.teaching-panel .last-q {
    font-size: 16px;
    margin: 15px 0;
    line-height: 1.5;
}

.teaching-panel .correct-a {
    font-size: 16px;
    font-weight: bold;
    color: #27272A;
    background-color: #ff8c33; /* Muted Orange */
    display: inline-block;
    padding: 10px 20px;
    border-radius: 8px; /* Modern radius */
    margin-top: 10px;
    box-shadow: 0 4px 10px rgba(255, 140, 51, 0.4); /* Glow effect */
}

.teaching-panel .explanation {
    font-size: 14px;
    margin-top: 15px;
    color: #e0e0e0;
    line-height: 1.4;
    font-weight: normal;
}

.teaching-panel .example {
    font-size: 14px;
    margin-top: 10px;
    color: #f6c231;
    font-family: monospace;
    background: rgba(0,0,0,0.3);
    padding: 10px;
    border-radius: 5px;
}

/* Nokia 3310 Casing -> Modern-Retro hybrid */
.phone-casing {
    background: linear-gradient(135deg, #dedfe0, #b2b2b3); /* Lighter casing to match school grey */
    width: 100%;
    max-width: 380px;
    height: 750px;
    padding: 30px;
    border-radius: 40px;
    border: 4px solid #27272A;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    box-shadow: 10px 20px 40px rgba(0,0,0,0.7), inset 5px 5px 15px rgba(255,255,255,0.8);
}

/* Speaker Slits */
.speaker {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}
.speaker-slit {
    width: 8px;
    height: 25px;
    background-color: #27272A;
    border-radius: 10px;
}

/* Brand Text */
.brand {
    color: #27272A;
    font-size: 18px;
    font-weight: 900;
    margin-bottom: 30px;
    text-align: center;
    letter-spacing: 2px;
}

/* Silver Bezel around Screen */
.screen-bezel {
    background: linear-gradient(to bottom, #ff8c33, #e65c00); /* Muted Orange */
    width: 100%;
    max-width: 320px;
    height: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 15px 24px 60px 24px;
    border-radius: 20px 20px 40px 40px;
    box-shadow: inset 0px 5px 10px rgba(0,0,0,0.4);
}

/* Inner Black Border */
.screen-border {
    background-color: #27272A;
    width: 100%;
    padding: 6px;
    border-radius: 10px;
}

/* The Screen Itself */
.screen {
    background-color: #1a1a1a;
    width: 100%;
    max-width: 260px;
    display: flex;
    flex-direction: column;
    position: relative;
    border-radius: 5px;
    overflow: hidden;
}

/* Score & UI Text Outside Canvas */
.status-bar {
    display: flex;
    justify-content: space-between;
    padding: 8px 10px;
    border-bottom: 2px solid rgba(246, 194, 49, 0.3);
    color: #f6c231;
}

.status-bar span {
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
}

/* The Game Canvas */
canvas {
    display: block;
    margin: 0 auto;
    image-rendering: pixelated;
    width: 100%;
    max-width: 260px;
    height: auto;
}

/* Overlay Messages (Start / Game Over) */
#message-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    width: 100%;
    color: #f6c231;
    text-shadow: 2px 2px 0 #27272A;
}

#top-msg { font-size: 12px; color: #ff6900; margin-bottom: 5px; }
#mid-msg { font-family: system-ui, sans-serif; font-size: 12px; font-weight: bold; margin-bottom: 10px; }
#main-msg { font-size: 16px; margin-bottom: 10px; }
#sub-msg { font-family: system-ui, sans-serif; font-size: 12px; }

.blink {
    animation: blinker 1s linear infinite;
}
@keyframes blinker {
    50% { opacity: 0; }
}

/* Decorative Control Buttons */
.controls-area {
    display: flex;
    justify-content: space-between;
    width: 280px;
    margin-top: 20px;
    z-index: 10;
}
.btn-side {
    width: 60px;
    height: 40px;
    background: linear-gradient(to bottom, #27272A, #18181B);
    border: 2px solid #475467;
    border-radius: 15px 15px 5px 5px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #fff;
    font-size: 14px;
    box-shadow: 0px 5px 10px rgba(0,0,0,0.5);
}
.btn-center {
    width: 80px;
    height: 40px;
    background: linear-gradient(to bottom, #ff6900, #d95800); /* TŠRB Orange */
    border-radius: 20px;
    position: relative;
    top: 10px;
    box-shadow: 0px 5px 10px rgba(0,0,0,0.5);
}

/* Instructions below phone */
.instructions {
    color: #27272A;
    margin-top: 30px;
    text-align: center;
    line-height: 2;
    font-weight: bold;
}
kbd {
    background-color: #ff6900;
    color: #27272A;
    padding: 3px 6px;
    border-radius: 4px;
    font-family: monospace;
}
.game-wrapper {
    display: flex;
    align-items: center;
    gap: 40px;
}

/* Shared Panel Style for Scoreboard and Topic */
.scoreboard-panel, .topic-panel {
    background: #32373c;
    border: 2px solid #475467;
    border-radius: 20px;
    padding: 20px;
    width: 250px;
    height: 600px;
    color: #dedfe0;
    box-shadow: 10px 10px 30px rgba(0,0,0,0.6);
    display: flex;
    flex-direction: column;
    position: relative;
}

.panel-tab {
    display: none; /* Hidden on desktop */
}
.scoreboard-panel h2, .topic-panel h2 {
    text-align: center;
    margin-top: 0;
    border-bottom: 2px solid #444;
    padding-bottom: 15px;
    font-size: 12px;
    color: #f6c231;
}

.score-list, .topic-list {
    list-style: none;
    padding: 0;
    margin: 0;
    overflow-y: auto;
    flex-grow: 1;
}

.score-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid #333;
}

.score-item .rank-info {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow: hidden;
    white-space: nowrap;
}

.score-item .score-val {
    color: #ff8c33;
    font-size: 10px;
}

.crown {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 20px;
    height: 20px;
    font-size: 12px;
    border-radius: 50%;
    color: #27272A;
    flex-shrink: 0;
}
        
.rank-1 .crown { background-color: #f6c231; box-shadow: 0 0 8px #f6c231; }
.rank-2 .crown { background-color: #c0c0c0; box-shadow: 0 0 8px #c0c0c0; }
.rank-3 .crown { background-color: #cd7f32; box-shadow: 0 0 8px #cd7f32; }

.topic-item {
    padding: 15px;
    margin-bottom: 10px;
    background-color: #27272A;
    border: 2px solid #444;
    border-radius: 10px;
    cursor: pointer;
    text-align: center;
    color: #F4F4F5;
    font-weight: bold;
    transition: all 0.2s ease-in-out;
    user-select: none;
    -webkit-user-select: none;
}
.topic-item:hover {
    background-color: #333;
    border-color: #ff6900;
}
.topic-item.active {
    background-color: #f6c231;
    color: #27272A;
    border-color: #f6c231;
    box-shadow: 0 0 15px rgba(246, 194, 49, 0.4);
}

/* Modals */
.name-modal {
    display: none;
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.85);
    backdrop-filter: blur(5px);
    z-index: 100;
    justify-content: center;
    align-items: center;
}

.question-modal {
    display: flex;
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.85);
    backdrop-filter: blur(5px);
    z-index: 100;
    justify-content: center;
    align-items: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.question-modal.open {
    opacity: 1;
    visibility: visible;
}

.countdown-modal {
    display: none;
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: transparent;
    pointer-events: none;
    z-index: 100;
    justify-content: center;
    align-items: center;
}

.name-modal-content {
    background: #27272A;
    padding: 30px;
    text-align: center;
    color: #F4F4F5;
    border-radius: 20px;
    border: 2px solid #ff6900;
    box-shadow: 0 15px 40px rgba(0,0,0,0.8);
}

.name-modal-content input {
    padding: 10px;
    font-size: 16px;
    width: 80%;
    margin: 20px 0;
    background: #1a1a1a;
    color: #F4F4F5;
    border: 2px solid #ff8c33;
    border-radius: 8px;
    text-align: center;
}

.name-modal-content button {
    padding: 15px 30px;
    background: #f6c231;
    color: #27272A;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    transition: 0.2s;
}
.name-modal-content button:hover {
    transform: scale(1.05);
}

.question-modal-content {
    background: #27272A;
    padding: 30px;
    text-align: center;
    color: #F4F4F5;
    border-radius: 20px;
    border: 2px solid #ff6900;
    box-shadow: 0 15px 40px rgba(0,0,0,0.8);
    width: 90%;
    max-width: 600px;
    transform: translateY(-100vh);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.question-modal.open .question-modal-content {
    transform: translateY(0);
}

.timer-text {
    font-size: 24px;
    color: #ff6900;
    margin-bottom: 20px;
    font-weight: bold;
}
.question-text {
    font-size: 18px;
    margin-bottom: 30px;
    line-height: 1.5;
    color: #f6c231;
}
.answers-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}
.answer-btn {
    background-color: #27272A;
    color: #F4F4F5;
    border: 2px solid #444;
    border-radius: 12px;
    padding: 20px;
    cursor: pointer;
    font-size: 14px;
    line-height: 1.4;
    transition: 0.2s;
}
.answer-btn:hover {
    border-color: #ff8c33;
    background-color: #2a2a2a;
}
.answer-btn.correct {
    background-color: #22C55E !important;
    color: #27272A !important;
    border-color: #22C55E !important;
    box-shadow: 0 0 15px rgba(34, 197, 94, 0.5);
}
.answer-btn.wrong {
    background-color: #EF4444 !important;
    color: #fff !important;
    border-color: #EF4444 !important;
    box-shadow: 0 0 15px rgba(239, 68, 68, 0.5);
}

.countdown-text {
    font-size: 120px;
    color: #f6c231;
    text-shadow: 0px 10px 20px rgba(0,0,0,0.8);
}

/* Responsive Design & Mobile Controls */
.mobile-dpad {
    display: none; /* Hidden on desktop */
    grid-template-areas: 
        ". up ."
        "left . right"
        ". down .";
    gap: 15px;
    margin-top: 20px;
    width: 100%;
    max-width: 220px;
    justify-content: center;
}

.dpad-btn {
    background: linear-gradient(135deg, #27272A, #18181B);
    color: #F4F4F5;
    border: 2px solid #ff6900;
    font-size: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%; /* Modern circular dpad buttons */
    box-shadow: 0px 5px 15px rgba(0,0,0,0.4);
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: 0.1s;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}
.dpad-btn:active {
    transform: translateY(4px);
    box-shadow: 0px 1px 5px rgba(0,0,0,0.4);
}

.dpad-btn.up { grid-area: up; }
.dpad-btn.down { grid-area: down; }
.dpad-btn.left { grid-area: left; }
.dpad-btn.right { grid-area: right; }

@media (max-width: 950px) {
    body {
        height: auto;
        padding: 20px 0;
        overflow-x: hidden;
    }
    
    .game-wrapper {
        justify-content: center;
    }
    
    /* Mobile Slide-Out Panels */
    .scoreboard-panel, .topic-panel {
        position: fixed;
        top: 50%;
        transform: translateY(-50%);
        z-index: 1000;
        transition: left 0.3s ease, right 0.3s ease;
        height: 80vh;
        max-height: 600px;
        width: 300px;
    }
    
    .scoreboard-panel {
        left: -300px; /* Hide off screen */
    }
    .scoreboard-panel.open {
        left: 0;
    }
    
    .topic-panel {
        right: -300px; /* Hide off screen */
    }
    .topic-panel.open {
        right: 0;
    }
    
    .panel-tab {
        display: flex;
        position: absolute;
        top: 50%;
        background: #ff6900;
        color: #fff;
        font-weight: bold;
        font-size: 14px;
        padding: 20px 10px;
        cursor: pointer;
        writing-mode: vertical-rl;
        text-align: center;
        border: 2px solid #32373c;
        box-shadow: 0 0 10px rgba(0,0,0,0.5);
        z-index: 1001;
        font-family: 'Press Start 2P', monospace;
        user-select: none;
        -webkit-user-select: none;
    }
    
    .left-tab {
        right: -40px;
        border-radius: 0 10px 10px 0;
        transform: translateY(-50%);
    }
    
    .right-tab {
        left: -40px;
        border-radius: 0 10px 10px 0;
        transform: translateY(-50%) rotate(180deg);
    }

    .answers-grid {
        grid-template-columns: 1fr; /* Stack answers vertically on mobile */
    }
    
    .mobile-dpad {
        display: grid;
    }
    
    .controls-area, .instructions {
        display: none; /* Hide decorative buttons and keyboard instructions on mobile */
    }
    
    .phone-casing {
        height: auto;
        padding-bottom: 40px;
    }
    
    .question-modal-content, .name-modal-content {
        padding: 15px;
        width: 95%;
    }
    
    .timer-text {
        font-size: 20px;
        margin-bottom: 10px;
    }
    
    .question-text {
        font-size: 14px;
        margin-bottom: 15px;
    }

    .school-branding {
        padding-bottom: 20px;
    }
}


/* School Branding */
.school-branding {
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 10px 20px;
    font-family: system-ui, -apple-system, sans-serif;
    color: #98A2B3;
    font-size: 10px;
    z-index: 100;
}

.school-logo {
    width: 40px;
    height: auto;
    border-radius: 5px;
    background: white;
    padding: 5px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.5);
}

.school-desc {
    text-align: left;
}

.school-desc a {
    color: #dedfe0;
    text-decoration: none;
    font-weight: bold;
}
.school-desc a:hover {
    color: #ff6900;
    text-decoration: underline;
}

