@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;600;800&display=swap');

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Outfit', sans-serif;
    /* Space theme: Dark radial gradient with a touch of purple/blue */
    background: radial-gradient(ellipse at bottom, #1B2735 0%, #090A0F 100%);
    color: #fff;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    position: relative;
}

/* Subtle star effect using a pseudo-element overlay */
body::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        radial-gradient(white, rgba(255,255,255,.2) 2px, transparent 40px),
        radial-gradient(white, rgba(255,255,255,.15) 1px, transparent 30px),
        radial-gradient(white, rgba(255,255,255,.1) 2px, transparent 40px);
    background-size: 550px 550px, 350px 350px, 250px 250px;
    background-position: 0 0, 40px 60px, 130px 270px;
    opacity: 0.3;
    pointer-events: none;
    z-index: -1;
}

.game-container {
    display: flex;
    width: 100%;
    height: 100vh;
    padding: 10px;
    gap: 30px;
    justify-content: center;
    align-items: center;
}

.sidebar {
    /* Responsive width: starts fixed, scales down on smaller screens */
    flex: 0 1 200px;
    max-width: 250px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 2vw;
    /* Glassmorphism sidebar */
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.5);
    color: #fff;
}

.sidebar h2 {
    font-size: max(1.2rem, 2vw);
    /* responsive font */
    margin-bottom: 2vh;
    font-weight: 800;
}

.player-icon {
    font-size: max(2rem, 3vw);
    /* responsive icon size */
    line-height: 1;
    margin-bottom: 10px;
    padding: max(10px, 1.5vw);
    border-radius: 50%;
    background-color: #eee;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

/* --- 3D DICE (Cube) --- */
.dice-container {
    perspective: 1000px;
    /* Responsive dice size using variables */
    --dice-size: min(80px, 12vw);
    width: var(--dice-size);
    height: var(--dice-size);
    cursor: pointer;
    transition: transform 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none;
    margin: 5px auto 20px auto;
}

.dice-container:active {
    transform: scale(0.9);
}

.dice-container.disabled {
    opacity: 0.5;
    pointer-events: none;
}

.cube {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 1s ease-out;
}

.face {
    position: absolute;
    width: 100%;
    height: 100%;
    background: #ec1e79;
    border: 2px solid rgba(255, 255, 255, 0.8);
    border-radius: calc(var(--dice-size) * 0.15);
    /* responsive radius */
    color: white;
    font-size: calc(var(--dice-size) * 0.45);
    /* responsive font */
    font-family: 'Fredoka One', cursive;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 0 15px rgba(236, 30, 121, 0.6);
    backdrop-filter: brightness(1.2);
}

.player2-sidebar .face {
    background: #2eace1;
    box-shadow: 0 0 15px rgba(46, 172, 225, 0.6);
}

/* Faces positions using half size for translation */
.front {
    transform: translateZ(calc(var(--dice-size) / 2));
}

.back {
    transform: rotateY(180deg) translateZ(calc(var(--dice-size) / 2));
}

.right {
    transform: rotateY(90deg) translateZ(calc(var(--dice-size) / 2));
}

.left {
    transform: rotateY(-90deg) translateZ(calc(var(--dice-size) / 2));
}

.top {
    transform: rotateX(90deg) translateZ(calc(var(--dice-size) / 2));
}

.bottom {
    transform: rotateX(-90deg) translateZ(calc(var(--dice-size) / 2));
}

button {
    color: white;
    border: none;
    padding: min(1.5vh, 15px) min(3vw, 30px);
    font-size: clamp(1rem, 3vh, 1.2rem);
    font-weight: 600;
    font-family: 'Outfit', sans-serif;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
}

.btn-p1 {
    background: #ec1e79;
    box-shadow: 0 5px 15px rgba(236, 30, 121, 0.4);
}

.btn-p1:hover:not(:disabled) {
    background: #ff4099;
    transform: translateY(-2px);
}

.btn-p2 {
    background: #2eace1;
    box-shadow: 0 5px 15px rgba(46, 172, 225, 0.4);
}

.btn-p2:hover:not(:disabled) {
    background: #4ec2f5;
    transform: translateY(-2px);
}

button:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.status-panel {
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(5px);
    padding: 15px;
    border-radius: 10px;
    width: 100%;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    margin-top: 15px;
}

.status-panel p {
    font-size: max(0.9rem, 1.2vw);
    /* responsive font */
    font-weight: 600;
    margin: 0;
}

.board-wrapper {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    max-height: 98vh;
    position: relative;
}

.board {
    position: relative;
    height: 100%;
    aspect-ratio: 356.16 / 458.35;
    border-radius: 10px;
    background: #0f172a; /* Darker board bg */
    max-width: 100%;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.8);
}

.board-svg {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.pawn {
    position: absolute;
    width: 5%;
    height: 5%;
    transform: translate(-50%, -50%);
    transition: all 0.4s ease-in-out;
    z-index: 10;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(14px, 3vh, 32px); /* Responsive pawn icon size */
    line-height: 1;
    background-color: #ffffff;
    border-radius: 50%;
    border: 3px solid #333;
    animation: hotspotPulse 1.2s infinite alternate ease-in-out;
}

@keyframes hotspotPulse {
    0% {
        box-shadow: 0 0 0 0px rgba(255, 255, 255, 0.9), 0 5px 10px rgba(0, 0, 0, 0.5);
        transform: translate(-50%, -50%) scale(0.95);
    }

    100% {
        box-shadow: 0 0 0 12px rgba(255, 255, 255, 0), 0 10px 25px rgba(0, 0, 0, 0.5);
        transform: translate(-50%, -50%) scale(1.1);
    }
}

.pawn.p1 {
    border-color: #ec1e79;
}

.pawn.p2 {
    border-color: #2eace1;
}

/* Shield Visual Indicator */
.pawn.has-shield {
    box-shadow: 0 0 20px 5px rgba(0, 242, 255, 0.8), inset 0 0 10px rgba(0, 242, 255, 0.5);
    border: 3px solid #00f2ff !important;
    animation: shieldPulse 1.5s infinite alternate ease-in-out !important;
}

@keyframes shieldPulse {
    from { filter: brightness(1) drop-shadow(0 0 5px #00f2ff); }
    to { filter: brightness(1.5) drop-shadow(0 0 15px #00f2ff); }
}

.special-effect-marker {
    position: absolute;
    width: 0;
    height: 0;
    z-index: 5;
    pointer-events: none;
}

.special-square-label {
    position: absolute;
    bottom: 4vh; /* Responsive position relative to board height */
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    padding: 0.4vh 0.8vh; /* Responsive padding */
    border-radius: 0.6vh; /* Responsive border radius */
    font-size: clamp(8px, 1.2vh, 14px); /* Scales between 8px and 14px based on height */
    white-space: nowrap;
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 0.4vh 1.2vh rgba(0, 0, 0, 0.8);
    text-transform: uppercase;
    font-weight: 800;
    letter-spacing: 0.1vh;
    pointer-events: none;
    text-shadow: 0 0 0.5vh rgba(0,0,0,0.5);
    animation: labelPulse 2s infinite alternate ease-in-out;
}

@keyframes labelPulse {
    0% {
        transform: translateX(-50%) scale(0.9);
        opacity: 0.8;
    }
    100% {
        transform: translateX(-50%) scale(1.1);
        opacity: 1;
        box-shadow: 0 6px 16px rgba(0, 0, 0, 0.9);
    }
}



/* Modal Styling */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: #fff;
    color: #333;
    padding: min(4vh, 40px) min(4vw, 40px);
    border-radius: 20px;
    max-width: 500px;
    width: 95%;
    max-height: 95vh;
    overflow-y: auto;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    border: 5px solid transparent;
    transition: border-color 0.3s ease;
}

.modal-content.p1-turn {
    border-color: #ec1e79;
}

.modal-content.p2-turn {
    border-color: #2eace1;
}

.modal-content h2 {
    margin-bottom: min(2vh, 20px);
    color: #1e3c72;
    font-size: clamp(1.2rem, 3.5vh, 1.8rem);
}

.options {
    display: flex;
    flex-direction: column;
    gap: min(1.5vh, 15px);
}

.q-input {
    padding: 10px;
    font-size: 1.2rem;
    border-radius: 8px;
    border: 2px solid #ddd;
    outline: none;
    text-align: center;
    font-family: 'Outfit', sans-serif;
    width: 100%;
}

.q-input:focus {
    border-color: #29aae1;
}

/* Drag and Drop Word Order Styles */
.sortable-container {
    display: flex;
    flex-wrap: wrap;
    gap: min(1vh, 10px);
    justify-content: center;
    padding: min(1.5vh, 15px);
    background: #f8f9fa;
    border: 2px dashed #ccc;
    border-radius: 12px;
    min-height: min(6vh, 60px);
}

.word-block {
    background: #2eace1;
    color: white;
    padding: min(1vh, 10px) min(2vw, 15px);
    border-radius: 8px;
    font-size: clamp(0.9rem, 2.5vh, 1.2rem);
    font-weight: bold;
    cursor: grab;
    user-select: none;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    transition: transform 0.1s, background 0.2s;
    font-family: 'Outfit', sans-serif;
}

.word-block:active {
    cursor: grabbing;
    transform: scale(1.05);
    background: #1b8ebf;
}

.word-block.sortable-ghost {
    opacity: 0.4;
    background: #ddd;
    color: transparent;
    box-shadow: none;
}

/* Listening Question Styles */
.q-audio-player {
    width: 100%;
    margin-bottom: min(1vh, 5px);
    height: min(5vh, 40px);
    outline: none;
}

.q-subtext {
    font-size: clamp(1rem, 3vh, 1.25rem);
    font-weight: 700;
    color: #333;
    margin-bottom: min(1.5vh, 15px);
}

/* Speaking Question Styles */
.q-speaking-img {
    width: 100%;
    max-height: min(25vh, 200px);
    object-fit: contain;
    border-radius: 8px;
    margin-bottom: min(1.5vh, 15px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.submit-btn {
    background: #27ae60;
    color: white;
    border: none;
    padding: min(1.5vh, 12px);
    border-radius: 8px;
    font-size: clamp(1rem, 3vh, 1.2rem);
    cursor: pointer;
    font-family: 'Outfit', sans-serif;
    font-weight: bold;
    margin-top: min(1vh, 5px);
    transition: background 0.2s;
}

.submit-btn:hover:not(:disabled) {
    background: #219653;
}

.option-btn {
    background: #f1f1f1;
    color: #333;
    box-shadow: none;
    border: 2px solid transparent;
}

.option-btn:hover {
    background: #e1e1e1;
    border-color: #29aae1;
}

.option-btn.correct {
    background: #8bc53f !important;
    color: #fff !important;
}

.option-btn.wrong {
    background: #ec1e79 !important;
    color: #fff !important;
}

#feedback {
    margin-top: min(1.5vh, 20px);
    font-weight: bold;
    font-size: clamp(1.1rem, 3.5vh, 1.5rem);
    min-height: min(3.5vh, 28px);
    white-space: pre-line;
    line-height: 1.3;
}

#landscape-warning {
    display: none;
    /* hidden by default */
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: #1a1a1a;
    color: white;
    z-index: 9999;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 20px;
}

#landscape-warning img {
    width: 100px;
    height: 100px;
    margin-bottom: 20px;
    animation: rotatePhone 2s infinite ease-in-out;
    filter: invert(1);
}

#landscape-warning p {
    font-size: 1.5rem;
    font-weight: 600;
    font-family: 'Outfit', sans-serif;
}

@keyframes rotatePhone {
    0% {
        transform: rotate(0deg);
    }

    50% {
        transform: rotate(-90deg);
    }

    100% {
        transform: rotate(-90deg);
    }
}

/* Win Overlay Styling */
#win-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 1;
    transition: opacity 0.5s;
}

#win-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

#win-box {
    background: linear-gradient(135deg, #f1c40f, #f39c12);
    padding: 60px 40px;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    border: 4px solid #fff;
    transform: scale(1);
    animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

#win-box h2 {
    font-size: max(2rem, 3vw);
    color: #fff;
    margin-bottom: 30px;
    font-family: 'Fredoka One', cursive;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

#restart-btn {
    background: #e74c3c;
    width: auto;
    font-size: 1.5rem;
    padding: 15px 50px;
    box-shadow: 0 5px 15px rgba(231, 76, 60, 0.4);
}

#restart-btn:hover {
    background: #c0392b;
    transform: translateY(-2px);
}

@media (max-width: 900px) and (orientation: portrait) {
    #landscape-warning {
        display: flex;
    }

    .game-container {
        display: none;
        /* Hide the game while warning is shown */
    }
}

/* Small adjustments for very narrow landscapes but keep the same structure */
@media (max-height: 500px) and (orientation: landscape) {
    .sidebar {
        padding: 5px;
        min-width: 120px;
    }

    .sidebar h2 {
        font-size: 1rem;
        margin-bottom: 5px;
    }

    .player-icon {
        font-size: 1.5rem;
        margin-bottom: 5px;
        padding: 5px;
    }

    .dice-container {
        --dice-size: 50px;
    }

    .special-square-label {
        bottom: 3vh;
        font-size: clamp(7px, 1.5vh, 10px);
        padding: 2px 4px;
    }
}
