:root {
    --chess-ink: #161616;
    --chess-blue: var(--nexus-green, #00875a);
    --chess-blue-soft: var(--nexus-green-soft, #e9f7f0);
    --chess-gold: #f5c242;
    --chess-board-light: #edf3ef;
    --chess-board-dark: #91ad9f;
    --chess-panel: #ffffff;
    --chess-danger: #ce0500;
}

.nexus-chess-shell {
    min-height: 100vh;
    background:
        linear-gradient(180deg, #f9fafb 0, #f5f6f7 100%);
    color: var(--chess-ink);
}

.chess-header {
    background: rgba(255, 255, 255, .94);
    border-bottom: 1px solid #ddd;
    box-shadow: 0 2px 14px rgba(0, 0, 0, .05);
}

.chess-header__inner,
.chess-game-topbar,
.chess-card__title-row,
.chess-inline-form,
.chess-player-card,
.chess-controls,
.chess-brand {
    display: flex;
    align-items: center;
}

.chess-header__inner {
    min-height: 5rem;
    justify-content: space-between;
    gap: 1rem;
}

.chess-brand {
    text-decoration: none;
    gap: 1rem;
}

.chess-brand__secret {
    display: inline-flex;
    align-items: center;
    gap: .38rem;
    padding-left: .85rem;
    border-left: 1px solid #ddd;
    color: #555;
    font-size: .78rem;
    line-height: 1.2;
    letter-spacing: .015em;
}

.chess-main { padding-block: 2.5rem 4rem; }

.chess-hero {
    display: flex;
    align-items: center;
    gap: .9rem;
    padding: 1rem 1.25rem;
    border-radius: .75rem;
    color: var(--chess-ink);
    background: #fff;
    border: 1px solid #d8d8d8;
    border-left: .3rem solid var(--chess-blue);
    box-shadow: 0 6px 18px rgba(0, 0, 0, .04);
}

.chess-hero h1 {
    margin: 0;
    color: var(--chess-blue);
    font-size: clamp(1.2rem, 2.2vw, 1.65rem);
    line-height: 1.25;
}
.chess-hero__icon {
    display: grid;
    place-items: center;
    flex: 0 0 2.6rem;
    width: 2.6rem;
    height: 2.6rem;
    border-radius: .6rem;
    color: var(--chess-blue);
    background: var(--chess-blue-soft);
    font-size: 1.5rem;
}
.chess-kicker { text-transform: uppercase; letter-spacing: .12em; font-size: .75rem; font-weight: 700; }
.chess-mascot { display: grid; place-items: center; width: 4rem; height: 4rem; border-radius: 1rem; color: var(--chess-blue); background: var(--chess-blue-soft); font-size: 2rem; font-weight: 700; }
.chess-mascot--large { font-size: clamp(4rem, 10vw, 7rem); transform: rotate(-8deg); }

.chess-lobby-grid {
    display: grid;
    grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr);
    gap: 1.5rem;
    margin-top: 1.5rem;
}

.chess-card,
.chess-analysis-panel {
    background: var(--chess-panel);
    border: 1px solid #ddd;
    border-radius: 1rem;
    box-shadow: 0 10px 28px rgba(0, 0, 0, .06);
}

.chess-card { padding: clamp(1.25rem, 3vw, 2rem); }
.chess-bot-settings, .chess-camp-settings { max-width: 22rem; }
.chess-primary-actions { display: flex; flex-wrap: wrap; gap: .75rem; }
.chess-primary-actions .fr-btn { flex: 1 1 14rem; justify-content: center; }
.chess-card__title-row { justify-content: space-between; gap: 1rem; }

.chess-time-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: .5rem;
}

.chess-time-grid button,
.chess-tabs button {
    border: 1px solid #c8c8c8;
    background: #fff;
    cursor: pointer;
}

.chess-time-grid button {
    min-height: 3rem;
    border-radius: .5rem;
    font-weight: 700;
}

.chess-time-grid button:hover,
.chess-time-grid button.is-selected {
    color: #fff;
    border-color: var(--chess-blue);
    background: var(--chess-blue);
}

.chess-room-list { min-height: 12rem; margin-block: 1rem; }
.chess-room-empty { padding: 2rem 1rem; text-align: center; border: 1px dashed #aaa; border-radius: .75rem; color: #666; }
.chess-room-item {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: 1rem;
    padding: .9rem 1rem;
    border-bottom: 1px solid #eee;
}
.chess-room-item:first-child { border-top: 1px solid #eee; }
.chess-room-code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--chess-blue); font-weight: 800; letter-spacing: .08em; }
.chess-code-join { padding-top: 1rem; border-top: 1px solid #eee; }
.chess-inline-form { gap: .5rem; }
.chess-inline-form .fr-input { margin-top: 0; text-transform: uppercase; letter-spacing: .1em; }

.chess-game-topbar { justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.chess-status-pill { padding: .45rem .8rem; border-radius: 999px; background: #eee; font-size: .85rem; font-weight: 700; }
.chess-status-pill.is-live { background: #b8fec9; color: #18753c; }
.chess-status-pill.is-waiting { background: #feecc2; color: #716043; }
.chess-status-pill.is-ended { background: var(--chess-blue-soft); color: var(--chess-blue); }

.chess-game-grid {
    display: grid;
    grid-template-columns: minmax(320px, 760px) minmax(320px, 430px);
    gap: 1.25rem;
    align-items: start;
}

.chess-board-column { min-width: 0; }
.chess-player-card {
    justify-content: space-between;
    gap: 1rem;
    padding: .75rem 1rem;
    background: #fff;
    border: 1px solid #ddd;
}
.chess-player-card:first-child { border-radius: .75rem .75rem 0 0; }
.chess-player-card:nth-of-type(2) { border-radius: 0 0 .75rem .75rem; }
.chess-player-dot { display: inline-block; width: .65rem; height: .65rem; margin-right: .5rem; border-radius: 50%; background: #aaa; }
.chess-player-card.is-connected .chess-player-dot { background: #00a95f; box-shadow: 0 0 0 3px #b8fec9; }
.chess-player-card.is-active { background: #f6fcf9; border-color: var(--nexus-green-border, #55b98d); }
.chess-clock { font: 800 clamp(1.2rem, 3vw, 2rem)/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.chess-clock.is-low { color: var(--chess-danger); animation: chess-pulse .8s infinite alternate; }
@keyframes chess-pulse { to { opacity: .55; } }

.chess-board-wrap { width: 100%; aspect-ratio: 1; background: #fff; border: 1px solid #d6d6d6; border-radius: 0; box-shadow: 0 14px 28px rgba(0,0,0,.12); overflow: hidden; }
.chess-board { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); grid-auto-rows: 1fr; width: 100%; height: 100%; user-select: none; }
.chess-square {
    position: relative;
    display: grid;
    place-items: center;
    aspect-ratio: 1 / 1;
    border: 0;
    padding: 0;
    box-sizing: border-box;
    cursor: pointer;
    overflow: hidden;
}
.chess-piece {
    position: relative;
    z-index: 2;
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "Arial Unicode MS", sans-serif;
    font-size: clamp(1.8rem, 5.2vw, 4.25rem);
    line-height: 1;
    text-shadow: 0 1px 0 rgba(255,255,255,.35), 0 3px 6px rgba(0,0,0,.2);
}
.chess-piece.white { color: #ffffff; -webkit-text-stroke: 1.2px #263248; }
.chess-piece.black { color: #263248; }
.chess-square.light { background: var(--chess-board-light); }
.chess-square.dark { background: var(--chess-board-dark); }
.chess-square.is-selected { box-shadow: inset 0 0 0 .35rem var(--chess-gold); }
.chess-square.is-last { background-image: linear-gradient(rgba(245,194,66,.45), rgba(245,194,66,.45)); }
.chess-square.is-check { background-image: radial-gradient(circle, rgba(206,5,0,.85), transparent 70%); }
.chess-square.is-legal::after {
    content: "";
    position: absolute;
    width: 22%;
    aspect-ratio: 1;
    border-radius: 50%;
    background: rgba(0,0,0,.28);
    z-index: 3;
    pointer-events: none;
}
.chess-square.is-capture::after {
    inset: .16rem;
    width: auto;
    height: auto;
    aspect-ratio: auto;
    border: .28rem solid rgba(206, 5, 0, .82);
    border-radius: .45rem;
    background: transparent;
    box-sizing: border-box;
}
.chess-square-evaluation {
    position: absolute;
    top: .18rem;
    right: .18rem;
    z-index: 5;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.65rem;
    height: 1.65rem;
    padding: 0 .3rem;
    border: 2px solid #fff;
    border-radius: 999px;
    background: #eee;
    box-shadow: 0 2px 8px rgba(0,0,0,.25);
    font: 900 .7rem/1 system-ui, sans-serif;
    color: #161616;
    pointer-events: none;
}
.chess-square-evaluation[data-category="Administrateur des douanes"] { background: #ffe9a6; color: #695240; }
.chess-square-evaluation[data-category="Directeur des services douaniers"] { background: #b8fec9; color: #18753c; }
.chess-square-evaluation[data-category="Inspecteur principal"],
.chess-square-evaluation[data-category="Inspecteur"] { background: var(--chess-blue-soft); color: var(--chess-blue); }
.chess-square-evaluation[data-category="Théorie"] { background: #d8c9ff; color: #4c1d95; }
.chess-square-evaluation[data-category="Petit B"] { background: #feecc2; color: #716043; }
.chess-square-evaluation[data-category="ACP2"] { background: #fddede; color: #b34000; }
.chess-square-evaluation[data-category="Élève douanier"],
.chess-square-evaluation[data-category="Coup de singe"] { background: #f7bfc3; color: #ce0500; }
.chess-coordinate { position: absolute; font: 700 .65rem/1 system-ui, sans-serif; opacity: .72; text-shadow: none; }
.chess-coordinate.file { right: .2rem; bottom: .15rem; }
.chess-coordinate.rank { left: .2rem; top: .15rem; }

.chess-controls { flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
.chess-controls .fr-btn { flex: 1 1 10rem; justify-content: center; }

.chess-analysis-panel { overflow: hidden; position: sticky; top: 1rem; }
.chess-commentator { display: grid; grid-template-columns: auto 1fr; gap: .9rem; padding: 1rem; color: var(--chess-ink); background: #f6fcf9; border-bottom: 1px solid #ddd; }
.chess-commentator p { margin: .25rem 0; color: var(--chess-ink); }
.chess-commentator__title { font-weight: 800; }
.chess-switch { display: flex; align-items: center; gap: .6rem; padding: .75rem 1rem; border-bottom: 1px solid #eee; cursor: pointer; }
.chess-switch input { width: 1.15rem; height: 1.15rem; }
.chess-opening { padding: .75rem 1rem; background: #f6fcf9; border-bottom: 1px solid #ddd; font-weight: 700; }
.chess-opening[hidden] { display: none !important; }
.chess-accuracy-grid { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid #ddd; }
.chess-accuracy-grid div { padding: .8rem 1rem; }
.chess-accuracy-grid div + div { border-left: 1px solid #ddd; }
.chess-accuracy-grid span { display: block; color: #666; font-size: .8rem; }
.chess-accuracy-grid strong { font-size: 1.25rem; }

.chess-tabs { display: grid; grid-template-columns: repeat(2, 1fr); }
.chess-tabs button { padding: .75rem .35rem; border-width: 0 0 1px; font-weight: 700; }
.chess-tabs button.is-active { color: var(--chess-blue); border-bottom: 3px solid var(--chess-blue); background: var(--chess-blue-soft); }
.chess-tab-panel { display: none; max-height: min(45vh, 32rem); overflow: auto; }
.chess-tab-panel.is-active { display: block; }

.chess-move-list { min-height: 12rem; }
.chess-move-row { display: grid; grid-template-columns: 2.2rem 1fr 1fr; border-bottom: 1px solid #eee; }
.chess-move-row > div { min-width: 0; padding: .55rem .45rem; }
.chess-move-number { text-align: center; color: #777; background: #fafafa; }
.chess-move { display: flex; align-items: center; justify-content: flex-start; gap: .4rem; }
.chess-move-piece { display: inline-grid; place-items: center; width: 1.45rem; height: 1.45rem; flex: 0 0 1.45rem; font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "Arial Unicode MS", sans-serif; font-size: 1.25rem; line-height: 1; }
.chess-move-piece.white { color: #fff; -webkit-text-stroke: .65px #263248; text-shadow: 0 1px 2px rgba(0,0,0,.2); }
.chess-move-piece.black { color: #263248; }
.chess-move-san { font-weight: 800; }
.chess-move .chess-badge { margin-left: auto; }
.chess-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 1.55rem; height: 1.55rem; padding: 0 .35rem; border-radius: 999px; font-size: .68rem; font-weight: 900; background: #eee; }
.chess-badge[data-category="Administrateur des douanes"] { background: #ffe9a6; color: #695240; }
.chess-badge[data-category="Directeur des services douaniers"] { background: #b8fec9; color: #18753c; }
.chess-badge[data-category="Inspecteur principal"],
.chess-badge[data-category="Inspecteur"] { background: var(--chess-blue-soft); color: var(--chess-blue); }
.chess-badge[data-category="Théorie"] { background: #d8c9ff; color: #4c1d95; }
.chess-badge[data-category="Petit B"] { background: #feecc2; color: #716043; }
.chess-badge[data-category="ACP2"] { background: #fddede; color: #b34000; }
.chess-badge[data-category="Élève douanier"],
.chess-badge[data-category="Coup de singe"] { background: #f7bfc3; color: #ce0500; }

.chess-scoreboard { padding: 1rem; }
.chess-score-section + .chess-score-section { margin-top: 1.25rem; padding-top: 1.25rem; border-top: 1px solid #ddd; }
.chess-score-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: .55rem; }
.chess-score-accuracy { color: var(--chess-blue); white-space: nowrap; }
.chess-score-line { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: .75rem; min-height: 2.25rem; padding: .3rem 0; border-bottom: 1px dotted #ddd; }
.chess-score-label { display: flex; align-items: center; gap: .55rem; min-width: 0; }
.chess-score-icon { display: inline-flex; align-items: center; justify-content: center; min-width: 1.8rem; height: 1.55rem; padding: 0 .25rem; border-radius: 999px; background: #eee; font-size: .68rem; font-weight: 900; }
.chess-score-icon[data-category="Administrateur des douanes"] { background: #ffe9a6; color: #695240; }
.chess-score-icon[data-category="Directeur des services douaniers"] { background: #b8fec9; color: #18753c; }
.chess-score-icon[data-category="Inspecteur principal"],
.chess-score-icon[data-category="Inspecteur"] { background: var(--chess-blue-soft); color: var(--chess-blue); }
.chess-score-icon[data-category="Théorie"] { background: #d8c9ff; color: #4c1d95; }
.chess-score-icon[data-category="Petit B"] { background: #feecc2; color: #716043; }
.chess-score-icon[data-category="ACP2"] { background: #fddede; color: #b34000; }
.chess-score-icon[data-category="Élève douanier"],
.chess-score-icon[data-category="Coup de singe"] { background: #f7bfc3; color: #ce0500; }

.chess-toast { position: fixed; left: 50%; bottom: 2rem; z-index: 1000; transform: translateX(-50%); max-width: min(90vw, 36rem); padding: .85rem 1.1rem; border-radius: .65rem; color: #fff; background: #161616; box-shadow: 0 10px 30px rgba(0,0,0,.25); }
.chess-dialog { border: 0; border-radius: 1rem; padding: 1.5rem; box-shadow: 0 24px 80px rgba(0,0,0,.3); }
.chess-dialog::backdrop { background: rgba(0,0,0,.55); }
.chess-promotion-options { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; }
.chess-promotion-options button { min-width: 4rem; min-height: 4rem; border: 1px solid #aaa; border-radius: .5rem; background: #fff; font-size: 2.4rem; cursor: pointer; }
.chess-footer { padding-block: 1.5rem; color: #666; background: #fff; border-top: 1px solid #ddd; font-size: .85rem; }

@media (max-width: 1000px) {
    .chess-game-grid, .chess-lobby-grid { grid-template-columns: 1fr; }
    .chess-analysis-panel { position: static; }
    .chess-tab-panel { max-height: none; }
}

@media (max-width: 600px) {
    .chess-header__inner { min-height: 4rem; }
   .chess-brand__secret { display: none; }
    .chess-main { padding-inline: .75rem; padding-top: 1rem; }
    .chess-hero { grid-template-columns: 1fr; }
    .chess-mascot--large { display: none; }
    .chess-time-grid { grid-template-columns: repeat(2, 1fr); }
    .chess-room-item { grid-template-columns: 1fr auto; }
    .chess-room-item .fr-btn { grid-column: 1 / -1; }
    .chess-inline-form { align-items: stretch; flex-direction: column; }
    .chess-square { font-size: clamp(2rem, 11vw, 4.1rem); }
    .chess-controls .fr-btn { flex-basis: calc(50% - .5rem); font-size: .82rem; }
}

@media (max-width: 48rem) {
  .chess-primary-actions { flex-direction: column; }
  .chess-hero { grid-template-columns: 1fr; }
}

/* NEXUS 0.12.39 */
.chess-room-visibility {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    column-gap: .65rem;
    row-gap: .15rem;
    padding: .9rem 1rem;
    border: 1px solid #d8d8d8;
    border-radius: .5rem;
    background: #fafafa;
}
.chess-room-visibility input { width: 1.2rem; height: 1.2rem; }
.chess-room-visibility label { font-weight: 700; cursor: pointer; }
.chess-room-visibility span { grid-column: 2; color: #666; font-size: .82rem; }
.chess-active-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-top: 1.5rem; padding-top: 1.25rem; border-top: 1px solid #ddd; }
.chess-active-heading span { color: #666; font-size: .8rem; }
.chess-room-list--active { min-height: 5rem; }
.chess-room-versus { color: #555; font-size: .88rem; }
.chess-room-meta { display: flex; flex-wrap: wrap; gap: .6rem; color: #666; font-size: .78rem; }
.chess-observer-note { color: var(--chess-blue); font-weight: 700; }
.chess-opening strong { display: block; }
.chess-opening small { display: block; margin-top: .25rem; color: #666; font-weight: 400; line-height: 1.35; }

/* La cible d'une capture est encerclée au niveau de la pièce, pas seulement de la case. */
.chess-square.is-capture::after {
    inset: 7%;
    border-width: .24rem;
    border-radius: 50%;
    z-index: 4;
}
.chess-square.is-capture .chess-piece::after {
    content: "";
    position: absolute;
    inset: 8%;
    z-index: 5;
    border: .28rem solid #ce0500;
    border-radius: 50%;
    box-shadow: 0 0 0 .12rem rgba(255,255,255,.75), 0 0 .8rem rgba(206,5,0,.55);
    pointer-events: none;
}
.chess-game.is-observer .chess-square { cursor: default; }
.chess-game.is-observer .chess-controls #chess-resign,
.chess-game.is-observer .chess-controls #chess-draw,
.chess-game.is-observer .chess-controls #chess-rematch { display: none; }

/* 0.12.40 — transmission rapide et synthèse d'évaluation */
.chess-board-stage {
    display: flex;
    align-items: stretch;
    gap: .55rem;
    width: 100%;
}

.chess-board-stage .chess-board-wrap {
    flex: 1 1 auto;
    min-width: 0;
}

.chess-evaluation {
    display: flex;
    flex: 0 0 2.65rem;
    flex-direction: column;
    align-self: stretch;
    overflow: hidden;
    min-height: 0;
    border: 1px solid #9b9b9b;
    background: #777;
    box-shadow: 0 8px 18px rgba(0, 0, 0, .12);
}

.chess-evaluation[hidden] {
    display: none !important;
}

.chess-evaluation__black,
.chess-evaluation__white {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 0;
    transition: height .35s ease;
}

.chess-evaluation__black {
    color: #fff;
    background: #202020;
}

.chess-evaluation__white {
    color: #161616;
    background: #fff;
    border-top: 1px solid #777;
}

.chess-evaluation span {
    font: 800 .68rem/1 system-ui, sans-serif;
    white-space: nowrap;
}

.chess-scoreboard {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
    align-items: start;
}

.chess-score-section,
.chess-score-section + .chess-score-section {
    min-width: 0;
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
}

.chess-score-section + .chess-score-section {
    padding-left: 1rem;
    border-left: 1px solid #ddd;
}

.chess-score-heading {
    align-items: flex-start;
}

.chess-score-heading h3 {
    overflow-wrap: anywhere;
}

@media (max-width: 600px) {
    .chess-board-stage { gap: .35rem; }
    .chess-evaluation { flex-basis: 2rem; }
    .chess-evaluation span { font-size: .58rem; }
    .chess-scoreboard { gap: .55rem; padding-inline: .55rem; }
    .chess-score-section + .chess-score-section { padding-left: .55rem; }
    .chess-score-heading { display: block; }
    .chess-score-accuracy { display: block; margin-top: .2rem; font-size: .8rem; }
    .chess-score-line { gap: .3rem; font-size: .72rem; }
    .chess-score-label { gap: .3rem; }
    .chess-score-icon { min-width: 1.45rem; height: 1.35rem; font-size: .58rem; }
}
