/* ===========================
   GLOBAL RESET & FONT
   =========================== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Fredoka', sans-serif;
}

#app {
    position: relative;
    width: 100vw;
    height: 100vh;
    background: #000;
    overflow: hidden;
}

/* ===========================
   LOADING SCREEN
   =========================== */
#loading-screen {
    position: absolute;
    inset: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #FFCD29;
    color: white;
    transition: opacity 0.8s ease;
}

#loading-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-title {
    font-size: clamp(2rem, 6vw, 3.75rem);
    font-weight: 900;
    margin-bottom: 1.5rem;
    text-align: center;
    padding: 0 1rem;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

.loading-bar-bg {
    width: clamp(12rem, 40vw, 16rem);
    height: 1rem;
    background: rgba(255,255,255,0.3);
    border-radius: 9999px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.loading-bar-fill {
    height: 100%;
    background: white;
    border-radius: 9999px;
    transition: width 0.3s ease-out;
    width: 0%;
}

.loading-pct {
    font-size: 1.5rem;
    font-weight: 600;
    opacity: 0.9;
}

/* ===========================
   NAVBAR
   =========================== */
#navbar {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 50;
    padding: clamp(1rem, 2.5vw, 1.5rem) clamp(1.25rem, 3vw, 2rem);
    display: flex;
    justify-content: space-between;
    align-items: center;
    pointer-events: none;
}

.navbar-logo {
    display: flex;
    align-items: center;
    gap: clamp(0.5rem, 1.5vw, 0.75rem);
    pointer-events: auto;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.navbar-logo:hover {
    transform: scale(1.05);
}

.logo-icon {
    width: clamp(2.5rem, 5vw, 3.5rem);
    height: clamp(2.5rem, 5vw, 3.5rem);
    background: white;
    border-radius: 1rem;
    border: 4px solid #FFCD29;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1.25rem, 3vw, 1.875rem);
    font-weight: 900;
    box-shadow: 0 6px 0 rgba(0,0,0,0.1);
}

.logo-text {
    color: white;
    font-size: clamp(1.5rem, 4vw, 2.5rem);
    font-weight: 900;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
    letter-spacing: 0.05em;
}

.logo-accent {
    color: #FFCD29;
}

.navbar-menu-btn {
    pointer-events: auto;
    background: white;
    border: 4px solid white;
    border-radius: 1rem;
    padding: clamp(0.5rem, 1.5vw, 0.75rem);
    cursor: pointer;
    box-shadow: 0 6px 0 #eee;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.navbar-menu-btn:hover {
    transform: translateY(-4px);
    border-color: #FFCD29;
}

.navbar-menu-btn:active {
    transform: translateY(4px);
    box-shadow: none;
}

/* ===========================
   THREE.JS CANVAS
   =========================== */
#canvas-container {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
}

#canvas-container canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

/* ===========================
   UI LAYER
   =========================== */
#ui-layer {
    position: absolute;
    inset: 0;
    z-index: 10;
    pointer-events: none;
    overflow: hidden;
}

/* ===========================
   MUTE BUTTON
   =========================== */
.mute-btn {
    position: absolute;
    bottom: clamp(1rem, 3vw, 1.5rem);
    right: clamp(1rem, 3vw, 1.5rem);
    z-index: 60;
    pointer-events: auto;
    background: #FFCD29;
    color: white;
    border: 4px solid white;
    border-radius: 50%;
    width: clamp(3rem, 6vw, 4rem);
    height: clamp(3rem, 6vw, 4rem);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 6px 0 rgba(0,0,0,0.1);
    transition: all 0.2s ease;
}

.mute-btn:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 0 rgba(0,0,0,0.1);
}

.mute-btn:active {
    transform: translateY(4px);
    box-shadow: none;
}

/* ===========================
   SCORE BAR
   =========================== */
#score-bar-wrap {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.score-bar {
    position: relative;
    width: 700px;
    height: 60px;
    background: #f0f0f2;
    border-radius: 9999px;
    border: 6px solid #e8e8ea;
    box-shadow: inset 0 4px 6px rgba(0,0,0,0.05);
    margin-top: 2rem;
    margin-bottom: 2rem;
    transform-origin: top center;
}

.score-center-line {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 6px;
    background: #fb923c;
    opacity: 0.8;
    z-index: 0;
}

.score-marks {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    z-index: 0;
}

.score-mark {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    color: #a0a0aa;
    font-weight: 900;
    font-size: 1.5rem;
    position: relative;
    z-index: 1;
}

.score-mark.is-zero {
    background: white;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    color: #111;
}

.score-flag {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 20;
    transition: left 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    pointer-events: auto;
}

.flag-bubble-wrap {
    position: absolute;
    bottom: 0.5rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transition: transform 0.2s ease;
    filter: drop-shadow(0 4px 6px rgba(0,0,0,0.15));
}

.flag-bubble-wrap:hover {
    transform: translateX(-50%) translateY(-8px);
}

.flag-bubble {
    background: #fcd34d;
    width: 64px;
    height: 64px;
    border-radius: 1.125rem;
    border: 4px solid white;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 1;
}

.flag-pointer {
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%) rotate(45deg);
    width: 1.5rem;
    height: 1.5rem;
    background: #fcd34d;
    border-right: 4px solid white;
    border-bottom: 4px solid white;
    z-index: 2;
}

/* ===========================
   START BUTTON
   =========================== */
#start-screen {
    position: absolute;
    bottom: clamp(2rem, 5vw, 2.5rem);
    left: 50%;
    transform: translateX(-50%);
    pointer-events: auto;
    z-index: 50;
}

.start-btn {
    background: #FFCD29;
    color: white;
    font-family: 'Fredoka', sans-serif;
    font-size: clamp(1.25rem, 3vw, 1.5rem);
    font-weight: 900;
    padding: 0.75rem clamp(1.75rem, 4vw, 2rem);
    border-radius: 0.625rem;
    border: 4px solid white;
    box-shadow: 0 6px 0 rgba(0,0,0,0.1);
    cursor: pointer;
    letter-spacing: 0.05em;
    transition: all 0.2s ease;
}

.start-btn:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 0 rgba(0,0,0,0.1);
}

.start-btn:active {
    transform: translateY(6px);
    box-shadow: none;
}

/* ===========================
   GAME SCREEN
   =========================== */
#game-screen {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

/* ===========================
   TEAM PANELS
   =========================== */
.team-panel {
    position: absolute;
    pointer-events: auto;
    border-radius: 1.75rem;
    border: 6px solid;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    user-select: none;
    transition: box-shadow 0.2s;
}

.team-panel.dragging {
    box-shadow: 0 30px 80px rgba(0,0,0,0.3);
    z-index: 50;
    transform-origin: center;
}

/* Left Panel theme */
.panel-left {
    background: #fffaf8;
    border-color: #E2A67B;
}

/* Right Panel theme */
.panel-right {
    background: #f6fcff;
    border-color: #81d4fa;
}

.panel-badge {
    position: absolute;
    top: -2rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 1.5rem;
    border: 4px solid;
    font-size: clamp(1rem, 2.5vw, 1.5rem);
    font-weight: 900;
    box-shadow: 0 6px 0 rgba(0,0,0,0.05);
    white-space: nowrap;
    cursor: grab;
    z-index: 10;
    transition: transform 0.15s;
}

.panel-badge:hover {
    transform: translateX(-50%) scale(1.05);
}

.panel-badge:active {
    cursor: grabbing;
}

.badge-left {
    background: #feeadd;
    border-color: #E2A67B;
}

.badge-right {
    background: #e1f5fe;
    border-color: #81d4fa;
}

.badge-score {
    position: absolute;
    top: -1rem;
    right: -1rem;
    width: clamp(2rem, 3.5vw, 2.5rem);
    height: clamp(2rem, 3.5vw, 2.5rem);
    background: white;
    border: 3px solid;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(0,0,0,0.12);
    font-weight: 700;
    font-size: clamp(0.875rem, 2vw, 1.25rem);
}

.badge-left .badge-score {
    border-color: #E2A67B;
}

.badge-right .badge-score {
    border-color: #81d4fa;
}

.badge-img {
    width: clamp(2rem, 3.5vw, 2.5rem);
    height: clamp(2rem, 3.5vw, 2.5rem);
    object-fit: contain;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.15));
}

.badge-text-left {
    color: #5d4037;
}

.badge-text-right {
    color: #01579b;
}

.panel-content {
    padding: 0.75rem 1rem;
    padding-top: 3rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    overflow: hidden;
}

.question-box {
    font-size: clamp(1rem, 2.5vw, 1.5rem);
    font-weight: 600;
    color: #5d4037;
    margin-bottom: 0.75rem;
    margin-top: 0.5rem;
    line-height: 1.25;
}

.options-grid {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: clamp(0.5rem, 1.5vw, 1.25rem);
    margin-bottom: 0.75rem;
}

.option-btn {
    background: white;
    color: #666;
    font-family: 'Fredoka', sans-serif;
    font-size: clamp(0.875rem, 2vw, 1.25rem);
    font-weight: 600;
    padding: clamp(0.5rem, 1.5vw, 0.75rem) 0.5rem;
    border-radius: 1.75rem;
    border: none;
    cursor: pointer;
    box-shadow: 0 6px 0 #eee;
    transition: all 0.15s ease;
    letter-spacing: -0.01em;
    pointer-events: auto;
}

.option-btn:hover {
    transform: translateY(-4px);
    filter: brightness(0.95);
}

.option-btn:active {
    transform: translateY(4px);
    box-shadow: none;
}

.option-btn.wrong {
    background: #ef4444 !important;
    color: white !important;
    animation: shake 0.4s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-8px); }
    40% { transform: translateX(8px); }
    60% { transform: translateX(-5px); }
    80% { transform: translateX(5px); }
}

/* Resize Handle */
.resize-handle {
    position: absolute;
    bottom: 0.5rem;
    right: 0.5rem;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.75rem;
    opacity: 0.8;
    cursor: se-resize;
    transition: transform 0.15s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
}

.resize-handle:hover {
    transform: scale(1.1);
}

.resize-left {
    background: #E2A67B;
}

.resize-right {
    background: #81d4fa;
}

.resize-icon {
    width: 1rem;
    height: 1rem;
    border-right: 4px solid rgba(255,255,255,0.6);
    border-bottom: 4px solid rgba(255,255,255,0.6);
    border-radius: 2px;
}

.resize-dot {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    width: 0.375rem;
    height: 0.375rem;
    background: white;
    border-radius: 50%;
}

/* ===========================
   GAME OVER SCREEN
   =========================== */
#gameover-screen {
    position: absolute;
    inset: 0;
    display: none;
    align-items: flex-end;
    justify-content: center;
    z-index: 50;
    pointer-events: auto;
    padding-bottom: 10vh;
}

#gameover-screen.visible {
    display: flex;
}

.gameover-card {
    position: relative;
    z-index: 20;
    width: min(90vw, 500px);
    border-radius: 3rem;
    border: 6px solid;
    box-shadow: 0 25px 80px rgba(0,0,0,0.25);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: clamp(1.5rem, 4vw, 2rem);
    text-align: center;
    animation: zoomIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes zoomIn {
    from { transform: scale(0.5); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.gameover-card.left-theme {
    background: #feeadd;
    border-color: #E2A67B;
}

.gameover-card.right-theme {
    background: #e1f5fe;
    border-color: #81d4fa;
}

.winner-img {
    width: clamp(4rem, 8vw, 6rem);
    height: clamp(4rem, 8vw, 6rem);
    object-fit: contain;
    margin-bottom: 0.75rem;
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.15));
    animation: bounce 1s ease infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-12px); }
}

.gameover-title {
    font-size: clamp(1.75rem, 5vw, 2.5rem);
    font-weight: 900;
    margin-bottom: 0.5rem;
    letter-spacing: 0.05em;
}

.gameover-card.left-theme .gameover-title,
.gameover-card.left-theme .gameover-subtitle {
    color: #5d4037;
}

.gameover-card.right-theme .gameover-title,
.gameover-card.right-theme .gameover-subtitle {
    color: #01579b;
}

.gameover-subtitle {
    font-size: clamp(1.25rem, 4vw, 2rem);
    font-weight: 700;
    opacity: 0.9;
    margin-bottom: clamp(1.5rem, 4vw, 2rem);
}

.play-again-btn {
    font-family: 'Fredoka', sans-serif;
    font-size: clamp(1.25rem, 3vw, 1.5rem);
    font-weight: 900;
    padding: clamp(0.75rem, 2vw, 1rem) clamp(2rem, 5vw, 2.5rem);
    border-radius: 1.75rem;
    border: 4px solid white;
    cursor: pointer;
    box-shadow: 0 6px 0 rgba(0,0,0,0.1);
    letter-spacing: 0.05em;
    transition: all 0.2s ease;
    color: white;
}

.play-again-btn:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 0 rgba(0,0,0,0.1);
}

.play-again-btn:active {
    transform: translateY(6px);
    box-shadow: none;
}

.gameover-card.left-theme .play-again-btn {
    background: #E2A67B;
}

.gameover-card.right-theme .play-again-btn {
    background: #81d4fa;
}

/* ===========================
   PANEL ANIMATIONS
   =========================== */
@keyframes slideInUp {
    from { opacity: 0; transform: translate(calc(-50% + var(--ox,0px)), calc(-50% + var(--oy,0px) + 6rem)); }
    to   { opacity: 1; transform: translate(calc(-50% + var(--ox,0px)), calc(-50% + var(--oy,0px))); }
}

.team-panel.entering {
    animation: slideInUp 0.5s ease forwards;
}

/* ===========================
   RESPONSIVE
   =========================== */
@media (max-width: 768px) {
    .score-bar {
        width: 95vw;
        transform: scale(0.75);
        transform-origin: top center;
    }

    /* Compact question cards: panel width/height is set by
       applyPanelSize() in app.js; these shrink the chrome inside so the
       card doesn't dwarf a phone screen. */
    .team-panel {
        border-width: 4px;
        border-radius: 1.25rem;
    }

    .panel-content {
        padding: 0.5rem 0.75rem;
        padding-top: 2.25rem;
    }

    .question-box {
        font-size: clamp(0.85rem, 3.5vw, 1.05rem);
        margin-top: 0.25rem;
        margin-bottom: 0.5rem;
    }

    .options-grid {
        gap: 0.4rem;
        margin-bottom: 0.5rem;
    }

    .option-btn {
        font-size: clamp(0.75rem, 3vw, 0.95rem);
        padding: 0.4rem;
        border-radius: 1.25rem;
        box-shadow: 0 4px 0 #eee;
    }

    .panel-badge {
        top: -1.5rem;
        padding: 0.35rem 0.75rem;
        font-size: 0.95rem;
        border-width: 3px;
    }

    .badge-img {
        width: 1.6rem;
        height: 1.6rem;
    }

    .badge-score {
        top: -0.75rem;
        right: -0.75rem;
        width: 1.6rem;
        height: 1.6rem;
        font-size: 0.8rem;
    }

    .resize-handle {
        width: 1.75rem;
        height: 1.75rem;
        bottom: 0.4rem;
        right: 0.4rem;
        border-radius: 0.5rem;
    }
}

/* ===========================
   NO-3D FALLBACK BACKGROUND
   =========================== */
#canvas-container.fallback {
    background: linear-gradient(180deg, #B75412 0%, #8B3A0A 100%);
}
