/* ==========================================================
   VARIABLES
   ========================================================== */
:root {
    --bg: #121016;
    --bg-soft: #17141d;
    --card-bg: #1e1a25;
    --card-bg-2: #241f2c;
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.14);

    --text: #efe9de;
    --text-dim: #a89fb0;
    --text-faint: #6f6779;

    --gold: #cda44e;
    --gold-bright: #e6c273;
    --gold-dim: rgba(205, 164, 78, 0.16);

    --success: #5fbf82;
    --danger: #d9685f;
    --info: #6f9bd6;

    --board-light: #ece3cf;
    --board-dark: #4b3a2f;

    --radius: 14px;
    --radius-sm: 9px;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    --shadow-soft: 0 4px 16px rgba(0, 0, 0, 0.25);
    --transition: all 0.2s ease;
}

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

html, body {
    height: 100%;
}

body {
    font-family: 'Inter', sans-serif;
    background:
        radial-gradient(1200px 600px at 20% -10%, rgba(205, 164, 78, 0.07), transparent 60%),
        radial-gradient(900px 500px at 100% 0%, rgba(111, 155, 214, 0.06), transparent 55%),
        var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

h1, h2 {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 600;
    letter-spacing: 0.02em;
}

button, select {
    font-family: inherit;
}

.hidden { display: none !important; }

/* ==========================================================
   APP LAYOUT
   ========================================================== */
.app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding-bottom: 78px; /* place pour l'action-bar mobile */
}

/* ==========================================================
   HEADER
   ========================================================== */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.2rem;
    background: linear-gradient(180deg, var(--bg-soft), var(--bg));
    border-bottom: 1px solid var(--border);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.7rem;
}

.brand-mark {
    font-size: 1.7rem;
    color: var(--gold);
    line-height: 1;
}

.brand-text h1 {
    font-size: 1.4rem;
    color: var(--text);
}

.brand-text p {
    font-family: 'Space Mono', monospace;
    font-size: 0.68rem;
    letter-spacing: 0.03em;
    color: var(--text-faint);
    margin-top: 0.15rem;
}

.icon-btn {
    background: var(--card-bg);
    border: 1px solid var(--border);
    color: var(--text-dim);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
}

.icon-btn:hover {
    color: var(--gold-bright);
    border-color: var(--gold-dim);
    background: var(--card-bg-2);
}

/* ==========================================================
   LAYOUT PRINCIPAL
   ========================================================== */
.layout {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
    max-width: 1100px;
    width: 100%;
    margin: 0 auto;
}

.board-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.board-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.9rem;
    box-shadow: var(--shadow-soft);
    width: 100%;
    max-width: 520px;
}

.board-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.7rem;
    padding: 0 0.15rem;
}

.turn-indicator {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-dim);
    padding: 0.3rem 0.7rem;
    border-radius: 999px;
    background: var(--card-bg-2);
    border: 1px solid var(--border);
}

.turn-indicator.player-turn {
    color: var(--gold-bright);
    border-color: var(--gold-dim);
    background: var(--gold-dim);
}

.turn-indicator.opponent-turn {
    color: var(--text-faint);
}

.engine-label {
    font-family: 'Space Mono', monospace;
    font-size: 0.65rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-faint);
}

.board {
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    border-radius: var(--radius-sm);
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

/* couleurs des cases (chessboard.js génère des divs .white-1e1d7 / .black-3c85d,
   on cible via les data-square pour rester robuste aux versions) */
.board .white-1e1d7 { background: var(--board-light) !important; }
.board .black-3c85d { background: var(--board-dark) !important; }

.selected-square {
    box-shadow: inset 0 0 0 3px var(--gold-bright) !important;
}

.legal-move::after {
    content: "";
    position: absolute;
    width: 26%;
    height: 26%;
    border-radius: 50%;
    background: rgba(205, 164, 78, 0.55);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.legal-move { position: relative; }

.last-move-from, .last-move-to {
    box-shadow: inset 0 0 0 3px rgba(111, 155, 214, 0.55) !important;
}

.in-check {
    box-shadow: inset 0 0 0 3px var(--danger) !important;
}

/* Éval bar */
.eval-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-top: 0.8rem;
}

.eval-bar-track {
    flex: 1;
    height: 8px;
    border-radius: 999px;
    background: var(--card-bg-2);
    border: 1px solid var(--border);
    overflow: hidden;
}

.eval-bar-fill {
    height: 100%;
    width: 50%;
    background: linear-gradient(90deg, var(--gold), var(--gold-bright));
    transition: width 0.4s ease;
}

.eval-score {
    font-family: 'Space Mono', monospace;
    font-size: 0.75rem;
    color: var(--text-dim);
    min-width: 3.4em;
    text-align: right;
}

/* ==========================================================
   PANNEAU D'INFOS
   ========================================================== */
.info-zone {
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    max-width: 520px;
    width: 100%;
    margin: 0 auto;
}

.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.1rem;
    box-shadow: var(--shadow-soft);
}

.card h2 {
    font-size: 1.1rem;
    color: var(--gold-bright);
    margin-bottom: 0.5rem;
}

.status-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    margin-bottom: 0.35rem;
}

.badge {
    font-family: 'Space Mono', monospace;
    font-size: 0.65rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-dim);
    background: var(--card-bg-2);
    border: 1px solid var(--border);
    padding: 0.25rem 0.55rem;
    border-radius: 999px;
    white-space: nowrap;
}

.status-text {
    color: var(--text-dim);
    font-size: 0.9rem;
}

.history-list {
    font-family: 'Space Mono', monospace;
    font-size: 0.85rem;
    color: var(--text-dim);
    max-height: 220px;
    overflow-y: auto;
    line-height: 1.9;
}

.history-list .empty-hint {
    color: var(--text-faint);
    font-style: italic;
}

.history-move {
    display: inline-block;
    margin-right: 0.4rem;
}

.history-move .num {
    color: var(--text-faint);
    margin-right: 0.25rem;
}

/* ==========================================================
   ACTION BAR
   ========================================================== */
.action-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    gap: 0.6rem;
    padding: 0.7rem 0.8rem calc(0.7rem + env(safe-area-inset-bottom));
    background: linear-gradient(180deg, transparent, var(--bg) 30%);
    z-index: 50;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.btn svg { flex-shrink: 0; }

.btn-primary {
    flex: 1;
    background: var(--card-bg-2);
    color: var(--text);
    border-color: var(--border-strong);
    box-shadow: var(--shadow-soft);
}
.btn-primary:hover { border-color: var(--gold-dim); color: var(--gold-bright); }

.btn-gold {
    flex: 1;
    background: linear-gradient(135deg, var(--gold), #b8873c);
    color: #1a140a;
    border-color: transparent;
    box-shadow: 0 6px 18px rgba(205, 164, 78, 0.25);
}
.btn-gold:hover { filter: brightness(1.08); }

.btn-ghost {
    background: var(--card-bg);
    color: var(--text-faint);
}
.btn-ghost:hover { color: var(--text-dim); }

.btn-block { width: 100%; margin-top: 0.6rem; }

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* ==========================================================
   MODALES (réglages + promotion)
   ========================================================== */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(8, 6, 12, 0.65);
    backdrop-filter: blur(3px);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 200;
}

.settings-card, .promotion-card {
    background: var(--card-bg);
    border: 1px solid var(--border-strong);
    border-radius: 18px 18px 0 0;
    padding: 1.3rem 1.3rem calc(1.3rem + env(safe-area-inset-bottom));
    width: 100%;
    max-width: 460px;
    box-shadow: var(--shadow);
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.9rem;
}

.settings-header h2 { color: var(--gold-bright); }

.settings-section {
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.settings-section label {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-faint);
}

select {
    background: var(--card-bg-2);
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 0.65rem 0.8rem;
    font-size: 0.95rem;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a89fb0' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.7rem center;
    background-size: 18px;
}

.promotion-card { text-align: center; }
.promotion-card p { color: var(--text-dim); margin-bottom: 0.8rem; }

.promotion-choices {
    display: flex;
    justify-content: center;
    gap: 0.7rem;
}

.promotion-choices button {
    width: 62px;
    height: 62px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--card-bg-2);
    cursor: pointer;
    transition: var(--transition);
    padding: 6px;
}

.promotion-choices button:hover {
    border-color: var(--gold);
    background: var(--gold-dim);
}

.promotion-choices img { width: 100%; height: 100%; }

/* ==========================================================
   NOTIFICATIONS
   ========================================================== */
.notification {
    position: fixed;
    top: 1rem;
    left: 50%;
    transform: translateX(-50%) translateY(-140%);
    background: var(--card-bg-2);
    border: 1px solid var(--border-strong);
    color: var(--text);
    padding: 0.8rem 1.3rem;
    border-radius: 999px;
    box-shadow: var(--shadow);
    font-weight: 600;
    font-size: 0.9rem;
    z-index: 300;
    transition: transform 0.35s cubic-bezier(.2, .8, .2, 1);
    white-space: nowrap;
}

.notification.show { transform: translateX(-50%) translateY(0); }
.notification.win { border-color: rgba(95, 191, 130, 0.5); color: var(--success); }
.notification.loss { border-color: rgba(217, 104, 95, 0.5); color: var(--danger); }
.notification.draw { border-color: rgba(111, 155, 214, 0.5); color: var(--info); }
.notification.info { border-color: var(--gold-dim); color: var(--gold-bright); }

/* ==========================================================
   RESPONSIVE — DESKTOP
   ========================================================== */
@media (min-width: 860px) {
    .app { padding-bottom: 0; }

    .layout {
        flex-direction: row;
        align-items: flex-start;
        padding: 1.6rem;
        gap: 1.6rem;
    }

    .board-zone { flex: 1.15; }
    .info-zone { flex: 1; max-width: 380px; margin: 0; position: sticky; top: 1.6rem; }

    .board-card { max-width: 560px; }
    .board { max-width: 520px; }

    .action-bar {
        position: static;
        background: none;
        padding: 0 1.6rem 1.2rem;
        max-width: 1100px;
        margin: 0 auto;
        justify-content: flex-start;
    }

    .btn-primary, .btn-gold { flex: 0 0 auto; padding: 0.75rem 1.4rem; }

    .modal-backdrop { align-items: center; }
    .settings-card, .promotion-card { border-radius: var(--radius); }
}

@media (max-width: 380px) {
    .brand-text p { display: none; }
}
