* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Tajawal', sans-serif;
}

body {
    background-color: #2c3e50;
    color: #ecf0f1;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
}

header {
    margin-top: 20px;
    margin-bottom: 20px;
    text-align: center;
}

header h1 {
    font-size: 2.2rem;
    color: #f1c40f;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.game-container {
    display: flex;
    flex-direction: row-reverse;
    align-items: flex-start;
    justify-content: center;
    gap: 30px;
    background-color: transparent;
    padding: 15px;
    width: 80vw;
    /* Leaves 10vw on each side */
    max-width: none;
}

.game-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: #34495e;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    flex-grow: 1;
    /* Allow the game area to expand to fill available space */
}

.sidebar {
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: rgba(52, 73, 94, 0.8);
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    width: 480px;
}

.sidebar.hidden {
    display: none;
}

.dp-header-img {
    width: 80%;
    max-width: 500px;
    height: auto;
    margin-bottom: 30px;
    border-radius: 5px;
}

.dev-text {
    text-align: center;
    font-size: 1.4rem;
    color: #ecf0f1;
    line-height: 1.8;
    background-color: rgba(0, 0, 0, 0.4);
    padding: 20px;
    border-radius: 8px;
    border-top: 3px solid #f1c40f;
    width: 80%;
    max-width: 500px;
}

.dev-text strong {
    color: #f1c40f;
    font-size: 1.5rem;
}

.fullscreen-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 20;
    background-color: rgba(0, 0, 0, 0.5);
    color: white;
    border: 2px solid #ecf0f1;
    border-radius: 5px;
    width: 40px;
    height: 40px;
    font-size: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    padding: 0;
    transition: background-color 0.2s;
}

.fullscreen-btn:hover {
    background-color: rgba(0, 0, 0, 0.8);
    transform: none;
    /* Override default button hover */
    box-shadow: none;
}

/* Base canvas wrapper configuration for fullscreen */
.canvas-wrapper:fullscreen,
.canvas-wrapper:-webkit-full-screen,
.canvas-wrapper:-ms-fullscreen {
    width: 100vw;
    height: 100vh;
    border: none;
    background-color: #2c3e50;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Responsive adjustment for internal canvas scale */
.canvas-wrapper:fullscreen canvas,
.canvas-wrapper:-webkit-full-screen canvas,
.canvas-wrapper:-ms-fullscreen canvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.ui-bar {
    width: 100%;
    display: flex;
    justify-content: space-between;
    margin-bottom: 15px;
    font-size: 1.2rem;
    font-weight: bold;
    color: #ecf0f1;
    padding: 0 10px;
}

.canvas-wrapper {
    position: relative;
    width: 800px;
    height: 600px;
    border: 4px solid #ecf0f1;
    border-radius: 5px;
    overflow: hidden;
    background-color: #bdc3c7;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.menus-container {
    width: 100%;
    max-width: 800px;
    background-color: transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.overlay {
    width: 100%;
    background-color: rgba(44, 62, 80, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    text-align: center;
    padding: 40px 20px;
    border-radius: 10px;
    margin-bottom: 20px;
}

/* Container inside overlay to center content horizontally and provide spacing */
.overlay>* {
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

.overlay h2:first-child {
    margin-top: auto;
    /* Push down to visually center if space allows, but can scroll up */
}

.overlay button:last-child {
    margin-bottom: auto;
    /* Push down to visually center if space allows, but can scroll up */
    margin-top: 20px;
}

.overlay.hidden {
    display: none !important;
}

.overlay h2 {
    font-size: 2.5rem;
    color: #f1c40f;
    margin-bottom: 20px;
}

#victoryScreen h2 {
    color: #2ecc71;
}

.character-selection {
    margin-bottom: 25px;
    background: rgba(0, 0, 0, 0.3);
    padding: 15px;
    border-radius: 10px;
}

.character-selection h3 {
    margin-bottom: 15px;
    color: #f1c40f;
}

.name-input {
    width: 100%;
    padding: 12px 15px;
    margin-bottom: 20px;
    font-size: 1.2rem;
    border: 2px solid #bdc3c7;
    border-radius: 8px;
    background-color: #ecf0f1;
    color: #2c3e50;
    text-align: right;
    outline: none;
    transition: border-color 0.3s;
}

.name-input:focus {
    border-color: #f1c40f;
}

.character-options {
    display: flex;
    gap: 20px;
    justify-content: center;
}

.char-btn {
    background-color: #34495e;
    border: 3px solid transparent;
    font-size: 1.5rem;
    padding: 10px 30px;
}

.char-btn.selected {
    border-color: #2ecc71;
    background-color: #2c3e50;
    transform: scale(1.05);
}

.overlay p {
    font-size: 1.2rem;
    margin-bottom: 20px;
    line-height: 1.6;
}

.overlay ul {
    list-style-position: inside;
    margin-bottom: 30px;
    text-align: right;
    font-size: 1.1rem;
}

.overlay ul li {
    margin-bottom: 10px;
}

.educational-tip {
    font-size: 1.3rem !important;
    font-weight: bold;
    color: #f1c40f;
    background-color: rgba(0, 0, 0, 0.4);
    padding: 20px;
    border-radius: 8px;
    border-right: 5px solid #f1c40f;
    margin-bottom: 30px;
    max-width: 90%;
}

button {
    padding: 15px 40px;
    font-size: 1.4rem;
    font-weight: bold;
    color: white;
    background-color: #2ecc71;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

button:hover {
    background-color: #27ae60;
    transform: translateY(-2px);
    box-shadow: 0 6px 8px rgba(0, 0, 0, 0.4);
}

button:active {
    transform: translateY(1px);
    box-shadow: 0 2px 3px rgba(0, 0, 0, 0.3);
}

#restartBtn {
    background-color: #e74c3c;
}

#restartBtn:hover {
    background-color: #c0392b;
}

.mobile-controls {
    display: none;
    flex-direction: column;
    align-items: center;
    margin-top: 15px;
    gap: 10px;
    width: 100%;
}

.control-row {
    display: flex;
    justify-content: center;
    gap: 15px;
}

.d-pad-btn {
    width: 60px;
    height: 60px;
    font-size: 24px;
    border-radius: 50%;
    background-color: #3498db;
    border: none;
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    user-select: none;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

.d-pad-btn:active,
.d-pad-btn.active {
    background-color: #2980b9;
    transform: translateY(2px);
    box-shadow: 0 2px 3px rgba(0, 0, 0, 0.3);
}

/* Responsive adjustment */
@media (max-width: 850px) {
    .game-container {
        flex-direction: column;
        align-items: center;
        width: 95vw;
        padding: 5px;
        gap: 15px;
    }

    .sidebar {
        width: 100%;
        max-width: 500px;
        order: 1;
        padding: 15px;
    }

    .game-area {
        width: 100%;
        max-width: 800px;
        order: 2;
        padding: 10px;
    }

    .dp-header-img {
        min-width: 0;
        max-width: 100%;
        margin-bottom: 15px;
    }

    .canvas-wrapper {
        width: 100%;
        max-width: 800px;
        height: auto;
        aspect-ratio: 4/3;
    }

    .mobile-controls {
        display: flex;
    }

    header {
        margin-top: 10px;
        margin-bottom: 10px;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .ui-bar {
        font-size: 0.9rem;
        flex-direction: column;
        align-items: center;
        gap: 5px;
        margin-bottom: 10px;
    }

    .overlay {
        padding: 15px 10px;
    }

    .overlay h2 {
        font-size: 1.5rem;
        margin-bottom: 10px;
    }

    .character-selection {
        margin-bottom: 15px;
        padding: 10px;
    }

    .character-selection h3 {
        margin-bottom: 10px;
        font-size: 1rem;
    }

    .overlay p,
    .overlay ul {
        font-size: 0.9rem;
        margin-bottom: 10px;
    }

    .char-btn {
        font-size: 1rem;
        padding: 6px 15px;
    }

    button {
        padding: 8px 25px;
        font-size: 1.1rem;
        margin-top: 10px !important;
    }
}