/* ============================================================
   Projet : تحدي الحروف (Tahadi Al Horouf)
   Fichier : assets/css/game.css
   Description : Interface complète du jeu
   Compatible : LWS Linux PHP 8.2+ / PHP 9.0
   Direction : RTL
   ============================================================ */

/* ============================================================
   1. Page du jeu
   ============================================================ */

.game-page {
    width: 100%;
    min-height: 100vh;
    padding: 40px 20px 60px;
    background: #f8fafc;
    direction: rtl;
    text-align: right;
    font-family:
        "Cairo",
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Tahoma,
        Arial,
        sans-serif;
    overflow-x: hidden;
    box-sizing: border-box;
}

.game-page *,
.game-page *::before,
.game-page *::after {
    box-sizing: inherit;
}

/* ============================================================
   2. En-tête
   ============================================================ */

.game-header {
    width: 100%;
    max-width: 900px;
    margin: 0 auto 35px;
    text-align: center;
}

.game-header h1 {
    margin: 0 0 12px;
    color: #1e3a8a;
    font-size: 42px;
    font-weight: 800;
    line-height: 1.3;
}

.game-header p {
    margin: 0;
    color: #475569;
    font-size: 19px;
    font-weight: 500;
    line-height: 1.8;
}

/* ============================================================
   3. Tableau de bord
   ============================================================ */

.game-board {
    width: 100%;
    max-width: 900px;
    margin: 0 auto 30px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
}

.letter-box,
.timer-box,
.score-box {
    position: relative;
    min-height: 130px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 25px 20px;
    background: #ffffff;
    border-radius: 18px;
    box-shadow:
        0 4px 6px -1px rgba(0, 0, 0, 0.05),
        0 2px 4px -1px rgba(0, 0, 0, 0.03);
    color: #334155;
    font-size: 20px;
    font-weight: 600;
    text-align: center;
    transition:
        transform 0.2s ease,
        box-shadow 0.2s ease;
}

.letter-box:hover,
.timer-box:hover,
.score-box:hover {
    transform: translateY(-2px);
    box-shadow:
        0 10px 20px -5px rgba(0, 0, 0, 0.08);
}

/* ============================================================
   4. Lettre
   ============================================================ */

.letter-box {
    border-top: 4px solid #7c3aed;
    overflow: hidden;
}

.letter-box::before {
    content: "🎯";
    position: absolute;
    top: 12px;
    left: 15px;
    font-size: 25px;
    line-height: 1;
}

.letter-box span {
    display: block;
    margin-bottom: 5px;
    color: #64748b;
    font-size: 16px;
    font-weight: 600;
}

.letter-box strong {
    display: block;
    color: #7c3aed;
    font-size: 48px;
    font-weight: 800;
    line-height: 1.2;
}

/* ============================================================
   5. Chronomètre
   ============================================================ */

.timer-box {
    border-top: 4px solid #2563eb;
    color: #334155;
}

.timer-box #timer {
    display: inline-block;
    margin: 5px 6px 0;
    color: #2563eb;
    font-size: 36px;
    font-weight: 800;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
    direction: ltr;
    unicode-bidi: isolate;
    transition:
        color 0.2s ease,
        transform 0.2s ease,
        opacity 0.2s ease;
}

.timer-box #timer.critical {
    color: #dc2626;
    animation: pulseTimer 0.8s infinite alternate ease-in-out;
}

@keyframes pulseTimer {
    from {
        transform: scale(1);
        opacity: 1;
    }

    to {
        transform: scale(1.12);
        opacity: 0.7;
    }
}

/* ============================================================
   6. Score
   ============================================================ */

.score-box {
    border-top: 4px solid #16a34a;
    color: #166534;
}

.score-box span {
    display: inline-block;
    margin-top: 5px;
    color: #16a34a;
    font-size: 36px;
    font-weight: 800;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
    direction: ltr;
    unicode-bidi: isolate;
}

.score-animation {
    animation:
        scorePop
        0.3s
        cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes scorePop {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.15);
    }

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

/* ============================================================
   6bis. Démarrage du défi individuel
   ============================================================ */

.game-start-panel {
    width: 100%;
    max-width: 900px;
    margin: 0 auto 30px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 24px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 22px;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
}

.game-start-info {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.game-start-info strong {
    color: #0f172a;
    font-size: 21px;
    font-weight: 800;
    line-height: 1.5;
}

.game-start-info span {
    color: #64748b;
    font-size: 16px;
    line-height: 1.7;
}

#startChallenge {
    flex: 0 0 auto;
    min-width: 250px;
    min-height: 64px;
    padding: 14px 30px;
    border: 0;
    border-radius: 16px;
    background: #2563eb;
    color: #ffffff;
    font-family: inherit;
    font-size: 20px;
    font-weight: 800;
    line-height: 1.4;
    cursor: pointer;
    touch-action: manipulation;
    pointer-events: auto;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    box-shadow: 0 10px 24px rgba(37, 99, 235, 0.25);
    transition: transform .18s ease, box-shadow .18s ease, background-color .18s ease;
}

#startChallenge:hover:not(:disabled) {
    background: #1d4ed8;
    transform: translateY(-2px);
    box-shadow: 0 14px 30px rgba(37, 99, 235, 0.30);
}

#startChallenge:active:not(:disabled) {
    transform: scale(.98);
}

#startChallenge:focus-visible {
    outline: 4px solid rgba(37, 99, 235, .22);
    outline-offset: 3px;
}

#startChallenge:disabled {
    cursor: wait;
    opacity: .78;
}

@media (max-width: 700px) {
    .game-start-panel {
        align-items: stretch;
        flex-direction: column;
        gap: 16px;
        padding: 18px;
        border-radius: 18px;
    }

    .game-start-info strong {
        font-size: 19px;
    }

    .game-start-info span {
        font-size: 15px;
    }

    #startChallenge {
        width: 100%;
        min-width: 0;
        min-height: 62px;
        padding: 15px 20px;
        font-size: 19px;
    }
}

@media (prefers-reduced-motion: reduce) {
    #startChallenge {
        transition: none;
    }
}

/* ============================================================
   7. Formulaire
   ============================================================ */

.word-form {
    width: 100%;
    max-width: 900px;
    margin: 0 auto 35px;
    padding: 35px;
    background: #ffffff;
    border-radius: 20px;
    box-shadow:
        0 4px 6px -1px rgba(0, 0, 0, 0.05),
        0 2px 4px -1px rgba(0, 0, 0, 0.03);
}

.word-form h2 {
    margin: 0 0 20px;
    color: #1e3a8a;
    font-size: 24px;
    font-weight: 800;
    line-height: 1.4;
}

.input-group {
    width: 100%;
    display: flex;
    align-items: stretch;
    gap: 15px;
    margin-bottom: 25px;
}

.input-group input {
    flex: 1;
    min-width: 0;
    padding: 15px 20px;
    border: 2px solid #cbd5e1;
    border-radius: 12px;
    outline: none;
    background: #ffffff;
    color: #1e293b;
    font-family: inherit;
    font-size: 18px;
    font-weight: 500;
    line-height: 1.5;
    text-align: right;
    direction: rtl;
    transition:
        border-color 0.2s ease,
        box-shadow 0.2s ease,
        background-color 0.2s ease;
}

.input-group input::placeholder {
    color: #94a3b8;
    opacity: 1;
}

.input-group input:focus:not(:disabled) {
    border-color: #2563eb;
    background-color: #ffffff;
    box-shadow:
        0 0 0 3px rgba(37, 99, 235, 0.12);
}

.input-group input:disabled {
    background-color: #f1f5f9;
    color: #94a3b8;
    cursor: not-allowed;
    opacity: 0.75;
}

.input-group button {
    flex: 0 0 auto;
    min-width: 140px;
    padding: 0 35px;
    border: none;
    border-radius: 12px;
    background: #2563eb;
    color: #ffffff;
    font-family: inherit;
    font-size: 18px;
    font-weight: 700;
    line-height: 1.4;
    cursor: pointer;
    transition:
        background-color 0.2s ease,
        transform 0.2s ease,
        box-shadow 0.2s ease,
        opacity 0.2s ease;
}

.input-group button:hover:not(:disabled) {
    background: #1d4ed8;
    transform: translateY(-1px);
    box-shadow:
        0 5px 12px rgba(37, 99, 235, 0.25);
}

.input-group button:active:not(:disabled) {
    transform: translateY(0);
}

.input-group button:disabled {
    background: #cbd5e1;
    color: #94a3b8;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
    opacity: 0.9;
}

/* ============================================================
   8. Liste des mots
   ============================================================ */

#words-list {
    width: 100%;
    min-height: 60px;
    max-height: 250px;
    overflow-y: auto;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    padding: 15px;
    background: #f8fafc;
    border: 1px dashed #e2e8f0;
    border-radius: 12px;
    text-align: center;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 #f1f5f9;
}

#words-list::-webkit-scrollbar {
    width: 7px;
}

#words-list::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 10px;
}

#words-list::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}

#words-list::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/*
 * game.js utilise .word-badge.
 * .word-item reste pris en charge pour compatibilité.
 */

.word-badge,
.word-item {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    max-width: 100%;
    padding: 8px 18px;
    background: #eff6ff;
    border: 1px solid #dbeafe;
    border-radius: 100px;
    color: #1d4ed8;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.4;
    text-align: center;
    word-break: break-word;
    overflow-wrap: anywhere;
    animation:
        popWord
        0.3s
        cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

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

/* ============================================================
   9. Actions
   ============================================================ */

.game-actions {
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    text-align: center;
}

.game-actions .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 220px;
    padding: 16px 60px;
    border: none;
    border-radius: 100px;
    font-family: inherit;
    font-size: 20px;
    font-weight: 700;
    line-height: 1.4;
    text-align: center;
    cursor: pointer;
    transition:
        background-color 0.2s ease,
        transform 0.2s ease,
        box-shadow 0.2s ease,
        opacity 0.2s ease;
}

.game-actions .btn-primary {
    background: #2563eb;
    color: #ffffff;
    box-shadow:
        0 4px 14px rgba(37, 99, 235, 0.35);
}

.game-actions .btn-primary:hover:not(:disabled) {
    background: #1d4ed8;
    transform: translateY(-2px);
    box-shadow:
        0 6px 20px rgba(37, 99, 235, 0.45);
}

.game-actions .btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

.game-actions .btn-primary:disabled {
    background: #e2e8f0;
    color: #94a3b8;
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
    opacity: 0.9;
}

/* ============================================================
   10. État de chargement
   ============================================================ */

.game-page .loading {
    pointer-events: none;
    cursor: wait;
    opacity: 0.7;
}

/* ============================================================
   11. Messages éventuels
   ============================================================ */

.game-message {
    width: 100%;
    max-width: 900px;
    margin: 0 auto 20px;
    padding: 14px 18px;
    border-radius: 12px;
    background: #eff6ff;
    border: 1px solid #dbeafe;
    color: #1e40af;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.6;
    text-align: center;
}

.game-message.success {
    background: #dcfce7;
    border-color: #bbf7d0;
    color: #166534;
}

.game-message.warning {
    background: #fef3c7;
    border-color: #fde68a;
    color: #92400e;
}

.game-message.error {
    background: #fee2e2;
    border-color: #fecaca;
    color: #991b1b;
}

/* ============================================================
   12. Responsive
   ============================================================ */

@media (max-width: 768px) {

    .game-page {
        padding: 30px 15px 50px;
    }

    .game-header {
        margin-bottom: 28px;
    }

    .game-header h1 {
        font-size: 34px;
    }

    .game-header p {
        font-size: 17px;
    }

    .game-board {
        grid-template-columns: 1fr;
        gap: 15px;
        margin-bottom: 25px;
    }

    .letter-box,
    .timer-box,
    .score-box {
        min-height: 120px;
        padding: 22px 18px;
    }

    .letter-box strong {
        font-size: 44px;
    }

    .timer-box #timer,
    .score-box span {
        font-size: 32px;
    }

    .word-form {
        padding: 25px 18px;
        border-radius: 18px;
    }

    .word-form h2 {
        font-size: 22px;
        margin-bottom: 18px;
    }

    .input-group {
        flex-direction: column;
        gap: 12px;
    }

    .input-group input {
        width: 100%;
        min-height: 54px;
    }

    .input-group button {
        width: 100%;
        min-height: 54px;
        padding: 14px 20px;
    }

    #words-list {
        max-height: 230px;
        padding: 12px;
    }

    .game-actions .btn {
        width: 100%;
        min-width: 0;
        padding: 15px 25px;
    }
}

@media (max-width: 420px) {

    .game-page {
        padding: 25px 12px 40px;
    }

    .game-header h1 {
        font-size: 29px;
    }

    .game-header p {
        font-size: 16px;
        line-height: 1.7;
    }

    .letter-box,
    .timer-box,
    .score-box {
        min-height: 110px;
        padding: 20px 15px;
    }

    .letter-box::before {
        top: 10px;
        left: 10px;
        font-size: 21px;
    }

    .letter-box strong {
        font-size: 40px;
    }

    .timer-box #timer,
    .score-box span {
        font-size: 30px;
    }

    .word-form {
        padding: 22px 14px;
    }

    .word-form h2 {
        font-size: 21px;
    }

    .input-group input {
        font-size: 17px;
    }

    .input-group button {
        font-size: 17px;
    }

    .word-badge,
    .word-item {
        padding: 7px 14px;
        font-size: 15px;
    }

    .game-actions .btn {
        font-size: 18px;
        padding: 14px 20px;
    }
}

/* ============================================================
   13. Accessibilité
   ============================================================ */

.game-page button:focus-visible,
.game-page input:focus-visible {
    outline: 3px solid #2563eb;
    outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {

    .game-page *,
    .game-page *::before,
    .game-page *::after {
        animation: none !important;
        transition: none !important;
        transform: none !important;
    }
}

/* ============================================================
   14. Impression
   ============================================================ */

@media print {

    .game-page {
        min-height: auto;
        padding: 0;
        background: #ffffff;
    }

    .game-actions,
    .input-group {
        display: none !important;
    }

    .letter-box,
    .timer-box,
    .score-box,
    .word-form {
        box-shadow: none;
        border: 1px solid #cbd5e1;
    }
}

.player-identity-panel {
    margin: 24px auto;
    max-width: 900px;
    padding: 22px;
    border: 1px solid #dbe3ef;
    border-radius: 18px;
    background: #ffffff;
    box-shadow: 0 8px 24px rgba(0,0,0,.06);
    display: flex;
    gap: 24px;
    align-items: center;
    justify-content: space-between;
}
.player-identity-panel h2 { margin: 6px 0; }
.player-identity-panel p { margin: 0; color: #5f6b7a; }
.player-identity-form { min-width: 280px; display: flex; flex-direction: column; gap: 8px; }
.player-identity-form input { width: 100%; box-sizing: border-box; padding: 12px 14px; border: 1px solid #cbd5e1; border-radius: 12px; font-size: 16px; }
.player-identity-form input:disabled { background: #f1f5f9; cursor: not-allowed; }
#playerIdDisplay { color: #64748b; }
@media (max-width: 700px) { .player-identity-panel { flex-direction: column; align-items: stretch; } .player-identity-form { min-width: 0; } }
/* V34 premium game surface */
.game-page{position:relative;background:radial-gradient(circle at 10% 5%,rgba(37,99,235,.10),transparent 28%),radial-gradient(circle at 90% 15%,rgba(124,58,237,.10),transparent 30%),#f8fafc}
.game-page::before{content:"";position:absolute;inset:0;pointer-events:none;background:linear-gradient(180deg,rgba(255,255,255,.25),transparent 35%)}
.game-header,.game-board,.word-form,.categories-section,.game-actions{position:relative;z-index:1}
.letter-box,.timer-box,.score-box,.word-form,.category-card{border:1px solid rgba(148,163,184,.20)!important;box-shadow:0 14px 34px rgba(15,23,42,.08)!important}
.category-card:hover{transform:translateY(-3px);box-shadow:0 18px 38px rgba(15,23,42,.11)!important}
@media(max-width:700px){.game-page{padding:18px 9px 35px}.game-header{margin-bottom:18px}.game-header h1{font-size:clamp(30px,9vw,40px)}.game-header p{font-size:16px}.game-board{grid-template-columns:1fr!important;gap:12px}.letter-box,.timer-box,.score-box{min-height:105px;padding:18px}.letter-box strong{font-size:42px}.timer-box #timer,.score-box span{font-size:32px}.word-form{padding:20px 14px;border-radius:18px}.input-group{flex-direction:column;gap:10px}.category-grid{grid-template-columns:1fr!important}.category-input{min-height:52px!important;font-size:18px!important}.game-actions .btn{width:100%;min-height:52px}}

.player-identity-form select{width:100%;min-height:52px;margin-top:8px;padding:12px 14px;border:1px solid #cbd5e1;border-radius:14px;background:#fff;font:inherit;color:inherit}.player-identity-form label{display:block;margin-top:12px;font-weight:800}.main-navbar .nav-home,.main-navbar .nav-ranking{min-height:44px;padding-inline:16px;border-radius:12px}
@media(max-width:700px){.main-navbar{min-height:60px}.nav-links{gap:8px}.nav-item{min-height:44px}.player-identity-form select,.player-identity-form input{font-size:16px}}

/* V45 — pays détecté automatiquement par IP */
.player-country-detected {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .45rem;
    padding: .85rem 1rem;
    border: 1px solid rgba(37, 99, 235, .18);
    border-radius: 14px;
    background: rgba(37, 99, 235, .06);
    color: #1e3a8a;
}
.player-country-detected small { flex-basis: 100%; opacity: .78; }

/* V48 - barre de navigation de session */
.game-session-nav{width:min(900px,calc(100% - 10px));margin:0 auto 18px;display:flex;justify-content:center;gap:10px;flex-wrap:wrap;position:relative;z-index:5;direction:rtl}
.game-session-nav a{display:inline-flex;align-items:center;justify-content:center;min-height:48px;padding:11px 18px;border-radius:14px;background:#fff;color:#173b8f;border:1px solid #dbe4f0;text-decoration:none;font-weight:900;box-shadow:0 7px 18px rgba(15,23,42,.07);transition:transform .18s ease,box-shadow .18s ease;touch-action:manipulation}
.game-session-nav a:hover{transform:translateY(-2px);box-shadow:0 12px 24px rgba(15,23,42,.11)}
.game-session-nav a.rank{background:linear-gradient(135deg,#fff7ed,#fffbeb);color:#9a3412;border-color:#fed7aa}
.game-session-nav a.play{background:linear-gradient(135deg,#2563eb,#4f46e5);color:#fff;border-color:transparent}
@media(max-width:520px){.game-session-nav{width:100%;gap:8px}.game-session-nav a{flex:1 1 calc(50% - 8px);min-height:50px;padding:10px 8px;font-size:15px}}

/* V52 — توحيد جلسة اللعب */
.game-page{max-width:1180px;margin:0 auto;padding:24px 16px 50px;background:transparent}
.game-header,.game-board,.player-identity-panel,.game-start-panel,.game-rules,.categories-section,.game-message,.game-actions{width:100%;max-width:1040px;margin-left:auto;margin-right:auto}
.game-header{padding:28px 22px;border:1px solid #dbe7f5;border-radius:26px;background:linear-gradient(135deg,#fff,#f5f9ff);box-shadow:0 15px 45px rgba(15,23,42,.07)}
.game-board{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:14px;margin-top:18px}.letter-box,.timer-box,.score-box{min-height:118px;border-radius:20px;padding:18px;display:flex;flex-direction:column;align-items:center;justify-content:center;border:1px solid #dbe4f0;background:#fff;box-shadow:0 10px 28px rgba(15,23,42,.06)}
.player-identity-panel{display:flex;align-items:center;justify-content:space-between;gap:20px;margin-top:18px;padding:20px 22px;border:1px solid #dbe7f5;border-radius:22px;background:#fff;box-shadow:0 10px 30px rgba(15,23,42,.06)}.player-identity-summary{display:flex;gap:8px;flex-wrap:wrap;justify-content:flex-end}.identity-chip{display:inline-flex;align-items:center;justify-content:center;min-height:42px;padding:8px 13px;border-radius:12px;background:#f8fafc;border:1px solid #e2e8f0;color:#334155;font-weight:800}
.game-start-panel{margin-top:18px;border-radius:22px}.game-start-panel #startChallenge,.game-actions #finishChallenge{min-height:58px;min-width:250px;font-size:18px;font-weight:900;border-radius:16px}
.categories-section{margin-top:18px;padding:22px;border:1px solid #e2e8f0;border-radius:24px;background:#fff;box-shadow:0 12px 35px rgba(15,23,42,.06)}.category-grid{gap:14px}.category-card{min-height:126px;border-radius:18px}
@media(max-width:760px){.game-page{padding:14px 8px 40px}.game-header{padding:20px 15px;border-radius:20px}.game-board{grid-template-columns:1fr;gap:10px}.letter-box,.timer-box,.score-box{min-height:90px}.player-identity-panel{flex-direction:column;align-items:stretch;padding:17px}.player-identity-summary{justify-content:stretch}.identity-chip{flex:1}.game-start-panel{padding:17px!important}.game-start-panel #startChallenge,.game-actions #finishChallenge{width:100%;min-width:0}.categories-section{padding:15px;border-radius:19px}}
