:root {
    --bg-color: #1a202c;
    --card-bg: #2d3748;
    --text-color: #edf2f7;
    --primary-color: #e53e3e;
    --accent-color: #48bb78;
    --key-bg: #4a5568;
    --key-hover: #718096;
    --modal-overlay: rgba(0, 0, 0, 0.85);
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Tajawal', 'Outfit', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
    margin: 0;
    overflow-x: hidden;
}

.container {
    width: 100%;
    max-width: 600px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    text-align: center;
    position: relative;
    z-index: 10;
}

/* Start Screen */
.start-screen {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: 50;
    background: var(--bg-color);
    display: flex;
    align-items: center;
    justify-content: center;
}

.start-content {
    text-align: center;
    animation: fadeIn 0.5s ease-out;
}

.start-content h1 {
    font-size: 3rem;
    margin-bottom: 0.5rem;
    color: var(--accent-color);
}

.subtitle {
    opacity: 0.8;
    margin-bottom: 3rem;
    font-size: 1.2rem;
}

.language-selection {
    display: flex;
    gap: 20px;
    justify-content: center;
    flex-wrap: wrap;
}

.lang-btn {
    background: var(--card-bg);
    border: 2px solid transparent;
    border-radius: 20px;
    padding: 20px;
    width: 160px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    color: var(--text-color);
}

.lang-btn:hover {
    border-color: var(--accent-color);
    transform: translateY(-5px);
    background: #364152;
}

.lang-btn .flag {
    font-size: 3rem;
    margin-bottom: 10px;
}

.lang-btn .text {
    font-weight: bold;
    font-size: 1.2rem;
}

.lang-btn .sub {
    font-size: 0.8rem;
    opacity: 0.7;
}

.home-link-start {
    display: block;
    margin-top: 40px;
    color: var(--text-color);
    text-decoration: none;
    opacity: 0.5;
    transition: opacity 0.3s;
}

.home-link-start:hover {
    opacity: 1;
}

.player-input-section, #player-status-section {
    margin-bottom: 20px;
    min-height: 80px; /* Prevent layout shift */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

#registration-form {
    display: flex;
    flex-direction: column;
    align-items: center;
}

#player-name-input {
    padding: 12px 20px;
    border-radius: 10px;
    border: 2px solid var(--card-bg);
    background: var(--card-bg);
    color: var(--text-color);
    font-size: 1rem;
    font-family: inherit;
    width: 200px;
    text-align: center;
    transition: border-color 0.3s;
    margin-bottom: 10px;
}

#player-name-input:focus {
    outline: none;
    border-color: var(--accent-color);
}

.small-btn {
    padding: 8px 20px;
    font-size: 0.9rem;
    margin-left: 5px;
}

.error-msg {
    color: var(--primary-color);
    font-size: 0.9rem;
    margin-top: 5px;
}

.highlight-name {
    color: var(--accent-color);
    font-weight: bold;
    font-size: 1.2rem;
}

.icon-btn-text {
    background: none;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    text-decoration: underline;
}

.leaderboard-btn-container {
    margin-top: 30px;
}

/* Header */
.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    background: var(--card-bg);
    padding: 10px 20px;
    border-radius: 15px;
}

header h1 {
    font-size: 1.5rem;
    margin: 0;
}

.icon-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-color);
    padding: 5px;
    border-radius: 50%;
    transition: background 0.2s;
}

.icon-btn:hover {
    background: rgba(255,255,255,0.1);
}

.level-badge {
    display: inline-block;
    background: var(--accent-color);
    color: #fff;
    padding: 5px 15px;
    border-radius: 20px;
    margin-top: 10px;
    font-weight: bold;
    font-size: 0.9rem;
}

/* Game Area */
.game-area {
    background: var(--card-bg);
    padding: 20px;
    border-radius: 15px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.hangman-draw {
    min-height: 250px;
    width: 100%;
    display: flex;
    justify-content: center;
}

.hangman-svg {
    width: 200px;
    height: 250px;
}

.hangman-svg line, .hangman-svg circle {
    stroke: var(--text-color);
    stroke-width: 4;
    fill: none;
    stroke-linecap: round;
    transition: all 0.5s;
}

.draw.hidden {
    opacity: 0;
    stroke-dasharray: 100;
    stroke-dashoffset: 100;
}

/* Word Display */
.word-display {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    width: 100%;
}

.letter-slot {
    width: 40px;
    height: 50px;
    border-bottom: 3px solid var(--text-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    font-weight: bold;
    margin-bottom: 10px;
    text-transform: uppercase;
}

.letter-slot.revealed {
    animation: popIn 0.3s;
}

.letter-slot.space {
    border-bottom: none;
    width: 20px;
}

/* Keyboard */
.keyboard {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-top: 20px;
}



.key {
    background: var(--key-bg);
    border: none;
    color: white;
    padding: 10px 15px;
    border-radius: 8px;
    font-family: inherit;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 45px;
    height: 50px;
}

.key:hover:not(:disabled) {
    background: var(--key-hover);
    transform: translateY(-2px);
}

.key:disabled {
    opacity: 0.4;
    cursor: default;
    transform: none;
}

.key.correct {
    background: var(--accent-color);
    box-shadow: 0 0 10px var(--accent-color);
}

.key.wrong {
    background: var(--primary-color);
    opacity: 0.6;
}

/* Modal */
.modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: var(--modal-overlay);
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(8px);
    z-index: 100;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--card-bg);
    padding: 40px;
    border-radius: 20px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0,0,0,0.4);
    animation: slideUp 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-icon {
    font-size: 4rem;
    margin-bottom: 20px;
}

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 30px;
}

.action-btn {
    background: var(--accent-color);
    border: none;
    color: white;
    padding: 15px 30px;
    border-radius: 12px;
    font-size: 1.2rem;
    cursor: pointer;
    font-weight: bold;
    transition: transform 0.2s;
}

.action-btn:hover {
    transform: scale(1.05);
}

.secondary-btn {
    background: transparent;
    border: 2px solid var(--text-color);
    color: var(--text-color);
    padding: 12px 30px;
    border-radius: 12px;
    font-size: 1rem;
    cursor: pointer;
    font-weight: bold;
    opacity: 0.7;
    transition: all 0.2s;
}

.secondary-btn:hover {
    opacity: 1;
    background: rgba(255,255,255,0.05);
}

/* Utility */
.hidden {
    display: none !important;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes popIn {
    from { transform: scale(0.5); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

@keyframes slideUp {
    from { transform: translateY(50px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@media (max-width: 500px) {
    .letter-slot {
        width: 30px;
        height: 40px;
        font-size: 1.4rem;
    }
    .key {
        padding: 8px;
        font-size: 1rem;
        min-width: 35px;
        height: 40px;
    }
    .lang-btn {
        width: 100%;
        flex-direction: row;
        padding: 15px;
        justify-content: flex-start;
    }
    .lang-btn .flag {
        font-size: 2rem;
        margin-bottom: 0;
        margin-right: 15px;
    }
    html[dir="rtl"] .lang-btn .flag {
        margin-right: 0;
        margin-left: 15px;
    }
}

/* Leaderboard Styles */
.leaderboard-content {
    max-width: 500px;
    width: 95%;
}

.leaderboard-tabs {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
}

.tab-btn {
    background: transparent;
    border: 2px solid var(--text-color);
    color: var(--text-color);
    padding: 5px 15px;
    border-radius: 15px;
    cursor: pointer;
    opacity: 0.6;
    transition: all 0.2s;
}

.tab-btn.active {
    background: var(--accent-color);
    border-color: var(--accent-color);
    opacity: 1;
}

.leaderboard-list {
    text-align: left;
    max-height: 300px;
    overflow-y: auto;
    background: rgba(0,0,0,0.2);
    border-radius: 10px;
    padding: 10px;
    margin-bottom: 20px;
}

.leaderboard-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 10px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.leaderboard-item:last-child {
    border-bottom: none;
}

.leaderboard-item.current-user {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 5px;
    font-weight: bold;
    color: var(--accent-color);
}

.rank {
    width: 30px;
    font-weight: bold;
    color: var(--accent-color);
}

.p-name {
    flex-grow: 1;
    text-align: center;
}

.p-score {
    width: 50px;
    text-align: right;
    font-weight: bold;
}

.player-rank-display {
    background: var(--card-bg);
    padding: 10px;
    border-radius: 10px;
    margin-bottom: 20px;
    border: 1px solid var(--accent-color);
    font-weight: bold;
}
