/* style.css - Responsive Design for Interactive Smartboard & Compact Screens */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #87CEEB;
}

#game-container {
    position: relative;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#particle-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 100;
}

#background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

.sky {
    height: 65%;
    background: linear-gradient(to bottom, #4facfe 0%, #00f2fe 100%);
    position: relative;
}

.cloud {
    position: absolute;
    background: white;
    border-radius: 50px;
    opacity: 0.7;
    pointer-events: none;
}
.cloud::before, .cloud::after {
    content: '';
    position: absolute;
    background: white;
    border-radius: 50%;
}
.c1 { 
    width: clamp(60px, 9vw, 100px); 
    height: clamp(18px, 2.8vh, 30px); 
    top: 6%; 
    left: 8%; 
}
.c1::before { 
    width: clamp(30px, 4.5vw, 50px); 
    height: clamp(30px, 4.5vw, 50px); 
    top: -60%; 
    left: 15%; 
}
.c1::after { 
    width: clamp(24px, 3.8vw, 40px); 
    height: clamp(24px, 3.8vw, 40px); 
    top: -30%; 
    left: 50%; 
}

.c2 { 
    width: clamp(70px, 11vw, 120px); 
    height: clamp(20px, 3.2vh, 35px); 
    top: 9%; 
    right: 8%; 
}
.c2::before { 
    width: clamp(35px, 5.5vw, 60px); 
    height: clamp(35px, 5.5vw, 60px); 
    top: -65%; 
    left: 18%; 
}
.c2::after { 
    width: clamp(26px, 4vw, 45px); 
    height: clamp(26px, 4vw, 45px); 
    top: -35%; 
    left: 55%; 
}

.c3 { 
    width: clamp(80px, 13vw, 140px); 
    height: clamp(22px, 3.5vh, 38px); 
    top: 14%; 
    left: 42%; 
}
.c3::before { 
    width: clamp(38px, 6vw, 65px); 
    height: clamp(38px, 6vw, 65px); 
    top: -65%; 
    left: 20%; 
}
.c3::after { 
    width: clamp(28px, 4.5vw, 50px); 
    height: clamp(28px, 4.5vw, 50px); 
    top: -35%; 
    left: 55%; 
}

.ground {
    height: 35%;
    background: linear-gradient(to bottom, #8bc34a 0%, #558b2f 100%);
    position: relative;
    border-top: clamp(3px, 0.6vh, 6px) solid #689f38;
}

/* ============================================================
   HEADER SECTION
   ============================================================ */
#header {
    position: relative;
    z-index: 25;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: clamp(4px, 0.8vh, 10px) clamp(10px, 2vw, 24px);
    background: rgba(0, 0, 0, 0.25);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    flex-shrink: 0;
}

.title-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(2px, 0.4vh, 6px);
}

.flags {
    font-size: clamp(0.95rem, 2.4vh, 1.55rem);
    font-weight: 800;
    color: white;
    letter-spacing: clamp(1px, 0.3vw, 3px);
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
    white-space: nowrap;
}

.emblem-container {
    display: flex;
    gap: clamp(4px, 0.8vw, 10px);
    flex-wrap: wrap;
    justify-content: center;
}

.emblem {
    display: inline-flex;
    align-items: center;
    padding: clamp(2px, 0.4vh, 4px) clamp(6px, 1vw, 12px);
    border-radius: 16px;
    font-size: clamp(0.62rem, 1.35vh, 0.8rem);
    font-weight: 700;
    color: white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.25), inset 0 1px 2px rgba(255,255,255,0.3);
    text-shadow: 1px 1px 2px rgba(0,0,0,0.6);
    border: 1.5px solid rgba(255,255,255,0.4);
    letter-spacing: 0.3px;
    text-transform: uppercase;
    white-space: nowrap;
}

.emblem .icon {
    margin-right: 4px;
    font-size: clamp(0.72rem, 1.45vh, 0.92rem);
}

.bg-primary {
    background: linear-gradient(135deg, #1976D2, #1565C0);
    border-color: #bbdefb;
}

.bg-secondary {
    background: linear-gradient(135deg, #d32f2f, #c62828);
    border-color: #ffcdd2;
}

.bg-accent {
    background: linear-gradient(135deg, #F57C00, #E65100);
    border-color: #ffe0b2;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: clamp(6px, 1vw, 12px);
}

#fullscreen-btn {
    background: #00bcd4;
    color: white;
    border: 2px solid #0097a7;
    padding: clamp(4px, 0.8vh, 8px) clamp(8px, 1.2vw, 14px);
    font-size: clamp(0.72rem, 1.7vh, 0.92rem);
    font-weight: bold;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 clamp(2px, 0.4vmin, 4px) 0 #00838f;
    transition: transform 0.1s, box-shadow 0.1s;
    white-space: nowrap;
}
#fullscreen-btn:active {
    transform: translateY(clamp(2px, 0.4vmin, 3px));
    box-shadow: 0 0 0 #00838f;
}

#settings-btn {
    background: #ff9800;
    color: white;
    border: 2px solid #ef6c00;
    padding: clamp(4px, 0.8vh, 8px) clamp(8px, 1.2vw, 14px);
    font-size: clamp(0.72rem, 1.7vh, 0.92rem);
    font-weight: bold;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 clamp(2px, 0.4vmin, 4px) 0 #ef6c00;
    transition: transform 0.1s, box-shadow 0.1s;
    white-space: nowrap;
}
#settings-btn:active {
    transform: translateY(clamp(2px, 0.4vmin, 3px));
    box-shadow: 0 0 0 #ef6c00;
}

/* ============================================================
   PLAYERS CONTAINER & SPLIT SCREEN
   ============================================================ */
#players-container {
    position: relative;
    flex: 1 1 0;
    min-height: 0;
    width: 100%;
    display: flex;
    z-index: 10;
}

.player-section {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    align-items: center;
    position: relative;
}

#divider {
    width: clamp(3px, 0.5vw, 6px);
    background: rgba(255,255,255,0.7);
    height: 100%;
    z-index: 20;
    box-shadow: 0 0 12px rgba(0,0,0,0.25);
    flex-shrink: 0;
}

/* Stats (Score & Combo) */
.stats {
    width: 100%;
    display: flex;
    justify-content: space-around;
    align-items: center;
    font-size: clamp(0.82rem, 2.2vh, 1.25rem);
    font-weight: bold;
    color: white;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.6);
    margin: clamp(4px, 1vh, 12px) 0 clamp(2px, 0.5vh, 6px) 0;
    z-index: 11;
    flex-shrink: 0;
}

/* ============================================================
   PANJAT PINANG GAME AREA (MAXIMIZED FOR TALL POLE FEELING)
   ============================================================ */
.game-area {
    position: relative;
    flex: 1 1 0;
    min-height: 0;
    width: 100%;
    display: flex;
    justify-content: center;
    overflow: visible;
}

/* Vertical Progress Bar */
.progress-bar-container {
    position: absolute;
    left: clamp(8px, 3%, 24px);
    top: clamp(15px, 3.5vh, 35px);
    bottom: clamp(10px, 2vh, 20px);
    width: clamp(14px, 2vw, 22px);
    background: rgba(255, 255, 255, 0.45);
    border: clamp(2px, 0.35vmin, 3px) solid white;
    border-radius: 12px;
    box-shadow: 0 0 8px rgba(0,0,0,0.2);
}

.progress-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 0%;
    background: linear-gradient(to top, #ff9800, #ffeb3b);
    border-radius: 8px;
    transition: height 0.5s ease-out;
}

/* The Pole */
.pole {
    position: absolute;
    bottom: 0;
    width: clamp(26px, 4vw, 52px);
    height: calc(100% - clamp(36px, 7.5vh, 64px));
    background: linear-gradient(to right, #795548, #4E342E, #795548);
    border-radius: 8px 8px 0 0;
    box-shadow: 4px 0 14px rgba(0,0,0,0.3);
}

.pole::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background-image: repeating-linear-gradient(to bottom, transparent, transparent 30px, rgba(0,0,0,0.12) 30px, rgba(0,0,0,0.12) 35px);
}

/* Gifts Wheel on Top */
.gift-wheel {
    position: absolute;
    top: clamp(-8px, -1.2vh, -12px);
    left: 50%;
    transform: translateX(-50%);
    width: clamp(76px, 14vw, 150px);
    height: clamp(10px, 1.8vh, 18px);
    background: #8D6E63;
    border-radius: 8px;
    border: clamp(1px, 0.3vmin, 2px) solid #5D4037;
    z-index: 14;
}

.gifts {
    position: absolute;
    top: clamp(-28px, -5.2vh, -46px);
    left: 50%;
    transform: translateX(-50%);
    font-size: clamp(18px, 3.8vh, 38px);
    white-space: nowrap;
    text-shadow: 0 0 12px gold;
    z-index: 15;
    pointer-events: none;
}

/* Climber Characters */
.climber {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translate(-50%, 0);
    font-size: clamp(24px, 5.2vh, 52px);
    line-height: 1;
    transition: bottom 0.5s cubic-bezier(0.25, 1, 0.5, 1), transform 0.2s;
    z-index: 16;
    pointer-events: none;
}

/* Spectators cheering at bottom */
.spectators {
    position: absolute;
    bottom: clamp(-2px, -0.5vh, -6px);
    width: 100%;
    text-align: center;
    font-size: clamp(16px, 3.5vh, 32px);
    line-height: 1;
    white-space: nowrap;
    z-index: 15;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
    pointer-events: none;
    overflow: hidden;
}

@keyframes wiggle {
    0% { transform: translate(-50%, 0) rotate(0deg); }
    25% { transform: translate(-50%, -8px) rotate(-10deg); }
    50% { transform: translate(-50%, 0) rotate(0deg); }
    75% { transform: translate(-50%, 8px) rotate(10deg); }
    100% { transform: translate(-50%, 0) rotate(0deg); }
}

.climbing {
    animation: wiggle 0.5s ease-in-out;
}

@keyframes slideDownWobble {
    0% { transform: translate(-50%, 0) rotate(0deg); }
    25% { transform: translate(-50%, 0) rotate(-14deg); }
    50% { transform: translate(-50%, 0) rotate(14deg); }
    75% { transform: translate(-50%, 0) rotate(-8deg); }
    100% { transform: translate(-50%, 0) rotate(0deg); }
}

.falling {
    animation: slideDownWobble 0.5s ease-in-out;
}

/* ============================================================
   RESPONSIVE UI LAYER (QUESTIONS & ANSWER BUTTONS)
   ============================================================ */
.ui-layer {
    width: 100%;
    height: clamp(118px, 28vh, 230px);
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 -6px 16px rgba(0,0,0,0.12);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: clamp(6px, 1.2vh, 12px) clamp(8px, 1.5vw, 16px);
    box-sizing: border-box;
    z-index: 20;
    flex-shrink: 0;
}

#player1 .ui-layer {
    border-top: clamp(4px, 0.7vh, 6px) solid #d32f2f;
}

#player2 .ui-layer {
    border-top: clamp(4px, 0.7vh, 6px) solid #1976D2;
}

.question-text {
    font-size: clamp(0.78rem, 2vh, 1.12rem);
    margin: 0 0 clamp(4px, 0.8vh, 8px) 0;
    text-align: center;
    color: #1a1a1a;
    font-weight: 800;
    width: 96%;
    line-height: 1.25;
    flex: 0 1 auto;
    max-height: clamp(38px, 8vh, 65px);
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
}

.answers {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: clamp(4px, 0.8vh, 10px) clamp(6px, 1.2vw, 12px);
    width: 96%;
    max-width: 650px;
    flex: 0 0 auto;
}

.answer-btn {
    padding: clamp(4px, 0.9vh, 10px) clamp(6px, 1vw, 12px);
    font-size: clamp(0.72rem, 1.8vh, 0.95rem);
    font-weight: bold;
    border: clamp(2px, 0.4vmin, 4px) solid;
    border-radius: clamp(8px, 1.5vmin, 12px);
    color: white;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.1s, background-color 0.15s;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
    min-height: clamp(28px, 4.6vh, 46px);
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    line-height: 1.15;
    word-break: break-word;
}

/* Distinct Player 1 (Red) and Player 2 (Blue) Buttons */
#player1 .answer-btn {
    border-color: #c62828;
    background: #f44336;
    box-shadow: 0 clamp(2px, 0.5vmin, 5px) 0 #c62828, 0 4px 8px rgba(0,0,0,0.15);
}
#player1 .answer-btn:hover { 
    background: #e53935; 
}
#player1 .answer-btn:active { 
    box-shadow: 0 0 0 #c62828, 0 2px 2px rgba(0,0,0,0.15); 
    transform: translateY(clamp(2px, 0.5vmin, 5px)); 
}

#player2 .answer-btn {
    border-color: #1565C0;
    background: #2196F3;
    box-shadow: 0 clamp(2px, 0.5vmin, 5px) 0 #1565C0, 0 4px 8px rgba(0,0,0,0.15);
}
#player2 .answer-btn:hover { 
    background: #1E88E5; 
}
#player2 .answer-btn:active { 
    box-shadow: 0 0 0 #1565C0, 0 2px 2px rgba(0,0,0,0.15); 
    transform: translateY(clamp(2px, 0.5vmin, 5px)); 
}

.answer-btn:disabled {
    opacity: 0.65;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: 0 clamp(2px, 0.5vmin, 4px) 0 rgba(0,0,0,0.3) !important;
}

/* Message Feedback Overlay */
.message-overlay {
    position: absolute;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.5);
    font-size: clamp(1.4rem, 4.5vh, 2.5rem);
    font-weight: 900;
    text-align: center;
    width: 90%;
    pointer-events: none;
    transition: opacity 0.4s, transform 0.4s;
    opacity: 0;
    text-shadow: 2px 2px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000;
    z-index: 110;
}

.message-overlay.show {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.15);
}

/* ============================================================
   VICTORY SCREEN
   ============================================================ */
#win-screen {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.96);
    padding: clamp(16px, 3vh, 40px) clamp(20px, 4vw, 50px);
    border-radius: clamp(14px, 2.5vmin, 25px);
    text-align: center;
    box-shadow: 0 15px 40px rgba(0,0,0,0.5);
    border: clamp(4px, 0.8vmin, 8px) solid #ffeb3b;
    z-index: 200;
    width: min(92vw, 560px);
    box-sizing: border-box;
}

.hidden {
    display: none !important;
}

#win-screen h1 {
    color: #d32f2f;
    font-size: clamp(1.6rem, 5vh, 3.2rem);
    margin: 0 0 8px 0;
    text-shadow: 2px 2px 0px #ffeb3b;
}

#win-screen h2 {
    color: #2e7d32;
    font-size: clamp(0.9rem, 2.4vh, 1.4rem);
    margin-top: 0;
}

#win-screen button {
    margin-top: clamp(12px, 2.5vh, 26px);
    padding: clamp(10px, 1.8vh, 18px) clamp(20px, 3.5vw, 40px);
    font-size: clamp(1rem, 2.5vh, 1.6rem);
    background: #ff9800;
    color: white;
    border: clamp(2px, 0.4vmin, 4px) solid #ef6c00;
    border-radius: 12px;
    cursor: pointer;
    font-weight: bold;
    box-shadow: 0 clamp(3px, 0.6vmin, 6px) 0 #ef6c00;
    transition: transform 0.1s;
}

#win-screen button:active {
    transform: translateY(clamp(3px, 0.6vmin, 6px));
    box-shadow: 0 0 0 #ef6c00;
}

/* ============================================================
   SETTINGS MODAL
   ============================================================ */
#settings-modal {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.8);
    z-index: 300;
    display: flex;
    justify-content: center;
    align-items: center;
}

#settings-modal .modal-content {
    background: white;
    width: 92%;
    max-width: 950px;
    max-height: 90vh;
    padding: clamp(14px, 2.5vh, 28px);
    border-radius: 14px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    overflow-y: auto;
}

#settings-modal h2 {
    margin-top: 0;
    color: #333;
    text-align: center;
    font-size: clamp(1.1rem, 3vh, 1.8rem);
}

.settings-options {
    background: #f5f5f5;
    padding: clamp(8px, 1.5vh, 14px);
    border-radius: 8px;
    margin-bottom: clamp(10px, 1.8vh, 18px);
}

.checkbox-container {
    font-size: clamp(0.85rem, 2vh, 1.1rem);
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
}

.help-text {
    font-size: clamp(0.72rem, 1.6vh, 0.88rem);
    color: #666;
    margin-top: 4px;
    margin-bottom: 6px;
}

.editors-container {
    display: flex;
    gap: clamp(10px, 2vw, 20px);
    flex: 1;
    min-height: clamp(160px, 35vh, 380px);
}

.editor-section {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.editor-section h3 {
    margin: 0 0 4px 0;
    color: #1976D2;
    font-size: clamp(0.88rem, 2vh, 1.15rem);
}

.editor-section textarea {
    flex: 1;
    width: 100%;
    padding: 8px;
    font-family: monospace;
    font-size: clamp(0.75rem, 1.8vh, 0.92rem);
    border: 2px solid #ccc;
    border-radius: 8px;
    resize: none;
    box-sizing: border-box;
}

.modal-buttons {
    display: flex;
    justify-content: flex-end;
    gap: clamp(8px, 1.5vw, 15px);
    margin-top: clamp(10px, 2vh, 20px);
}

.modal-buttons button {
    padding: clamp(8px, 1.5vh, 12px) clamp(14px, 2vw, 24px);
    font-size: clamp(0.82rem, 2vh, 1.1rem);
    font-weight: bold;
    border-radius: 8px;
    cursor: pointer;
    border: none;
}

.btn-save {
    background: #4CAF50;
    color: white;
    box-shadow: 0 4px 0 #388E3C;
}
.btn-save:active {
    transform: translateY(4px);
    box-shadow: 0 0 0 #388E3C;
}

.btn-cancel {
    background: #f44336;
    color: white;
    box-shadow: 0 4px 0 #d32f2f;
}
.btn-cancel:active {
    transform: translateY(4px);
    box-shadow: 0 0 0 #d32f2f;
}

/* ============================================================
   RESPONSIVE MEDIA QUERIES FOR COMPACT & EMBEDDED SCREENS
   ============================================================ */

/* 1. Medium/Small Screen Heights (Laptops, Embedded Iframes <= 580px) */
@media (max-height: 580px) {
    .emblem-container {
        display: none; /* Hide secondary badges on shorter viewports so pole stays dominant! */
    }
    .stats {
        margin: 2px 0;
    }
    .question-text {
        max-height: 42px;
        -webkit-line-clamp: 2;
    }
    .ui-layer {
        height: clamp(110px, 26vh, 145px);
    }
}

/* 2. Compact Viewports (Iframes <= 440px or Mobile Landscape) */
@media (max-height: 440px) {
    #header {
        padding: 2px 8px;
    }
    .flags {
        font-size: 0.88rem;
        letter-spacing: 1px;
    }
    #fullscreen-btn, #settings-btn {
        padding: 3px 6px;
        font-size: 0.72rem;
    }
    .ui-layer {
        height: 104px;
        padding: 3px 6px;
    }
    .answer-btn {
        min-height: 24px;
        padding: 2px 4px;
        font-size: 0.68rem;
    }
    .question-text {
        font-size: 0.7rem;
        margin-bottom: 2px;
        max-height: 28px;
    }
    .spectators {
        font-size: 13px;
    }
}

/* 3. Narrow Screens / Mobile Portrait (width <= 600px) */
@media (max-width: 600px) {
    .emblem-container {
        display: none;
    }
    .editors-container {
        flex-direction: column;
    }
    .flags {
        font-size: 0.85rem;
        letter-spacing: 0.5px;
    }
    .answers {
        gap: 4px;
    }
    .answer-btn {
        font-size: 0.68rem;
        padding: 3px 4px;
    }
}
