:root {
    --bg: #0f2e25;
    --bg-2: #16443a;
    --panel: #1b4a3f;
    --panel-2: #23594c;
    --text: #fdf6e3;
    --muted: #b9d4c9;
    --gold: #f2c94c;
    --board: #fff8e7;
    --c0: #e53935;
    --c1: #43a047;
    --c2: #f9c80e;
    --c3: #1e88e5;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: radial-gradient(circle at 50% 0%, var(--bg-2), var(--bg) 70%);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 18px;
}

.hidden {
    display: none !important;
}

.top {
    text-align: center;
    padding: 12px 16px 0;
}

.top h1 {
    margin: 0;
    font-size: 1.8rem;
    color: var(--gold);
}

/* ---------- Réglages ---------- */

.setup {
    max-width: 560px;
    margin: 16px auto;
    padding: 20px 16px 28px;
}

.setup h2 {
    margin: 0 0 6px;
    font-size: 1.6rem;
}

.setup-hint {
    margin: 0 0 18px;
    color: var(--muted);
}

.setup-rows {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.setup-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: var(--panel);
    border-radius: 14px;
}

.chip {
    flex: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.85);
}

.c0 { background: var(--c0); }
.c1 { background: var(--c1); }
.c2 { background: var(--c2); }
.c3 { background: var(--c3); }

.setup-row input,
.setup-row select {
    min-width: 0;
    padding: 10px 12px;
    font-size: 1rem;
    color: var(--text);
    background: var(--bg);
    border: 2px solid var(--panel-2);
    border-radius: 10px;
}

.setup-row input {
    flex: 1;
}

.setup-error {
    min-height: 1.4em;
    margin: 12px 0 0;
    color: #ffb4a8;
}

.big-button {
    display: block;
    width: 100%;
    margin-top: 8px;
    padding: 16px;
    font-size: 1.3rem;
    font-weight: 700;
    color: #3a2a00;
    background: var(--gold);
    border: 0;
    border-radius: 14px;
    cursor: pointer;
}

.big-button:hover {
    filter: brightness(1.08);
}

.small-button {
    padding: 10px 14px;
    font-size: 1rem;
    color: var(--text);
    background: var(--panel-2);
    border: 0;
    border-radius: 10px;
    cursor: pointer;
}

.small-button:hover {
    background: #2d6b5b;
}

/* ---------- Partie ---------- */

.game {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 20px;
    align-items: start;
    max-width: 1200px;
    margin: 0 auto;
    padding: 12px 16px 24px;
}

.board-wrap {
    width: min(100%, calc(100vh - 100px));
    margin: 0 auto;
}

#board {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 1;
    border-radius: 18px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
}

.panel {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 16px;
    background: var(--panel);
    border-radius: 18px;
}

.turn {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.4rem;
    font-weight: 700;
}

.message {
    min-height: 2.8em;
    margin: 0;
    color: var(--muted);
}

.dice {
    position: relative;
    align-self: center;
    display: grid;
    grid-template: repeat(3, 1fr) / repeat(3, 1fr);
    width: 120px;
    height: 120px;
    padding: 14px;
    background: #fff;
    border: 0;
    border-radius: 22px;
    box-shadow: 0 6px 0 #c9bfa6, 0 10px 18px rgba(0, 0, 0, 0.35);
    cursor: pointer;
}

.dice span {
    place-self: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: transparent;
}

.dice span.on {
    background: #222;
}

.dice:disabled {
    cursor: default;
    opacity: 0.85;
}

.dice.ready {
    animation: ready 1s ease-in-out infinite;
}

.dice.rolling {
    animation: shake 0.16s linear infinite;
}

@keyframes ready {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.07); }
}

@keyframes shake {
    0% { transform: rotate(-6deg); }
    50% { transform: rotate(6deg); }
    100% { transform: rotate(-6deg); }
}

.players {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.players li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    background: var(--panel-2);
    border-radius: 12px;
    border: 3px solid transparent;
}

.players li.active {
    border-color: var(--gold);
}

.players .chip {
    width: 22px;
    height: 22px;
    border-width: 2px;
}

.players .name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.players .score {
    color: var(--muted);
}

.actions {
    display: flex;
    gap: 10px;
    justify-content: space-between;
}

.rules {
    color: var(--muted);
    font-size: 0.95rem;
}

.rules summary {
    cursor: pointer;
    color: var(--text);
}

.rules ul {
    margin: 8px 0 0;
    padding-left: 20px;
}

.rules li {
    margin-bottom: 6px;
}

/* ---------- Pions ---------- */

.piece {
    transition: transform 0.17s ease-out;
}

.piece .body {
    stroke: rgba(0, 0, 0, 0.55);
    stroke-width: 0.06;
}

.piece text {
    pointer-events: none;
    font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", sans-serif;
}

.piece.movable {
    cursor: pointer;
}

.piece.movable .halo {
    display: block;
    animation: halo 0.8s ease-in-out infinite;
}

.piece .halo {
    display: none;
    fill: none;
    stroke: #fff;
    stroke-width: 0.12;
}

@keyframes halo {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.25; }
}

/* ---------- Victoire ---------- */

.win {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(0, 0, 0, 0.6);
}

.win-box {
    width: 100%;
    max-width: 420px;
    padding: 28px 22px;
    text-align: center;
    background: var(--panel);
    border: 3px solid var(--gold);
    border-radius: 20px;
}

.win-box h2 {
    margin: 0 0 8px;
    font-size: 2rem;
    color: var(--gold);
}

.win-box .small-button {
    margin-top: 12px;
}

.confetti {
    position: fixed;
    top: -20px;
    z-index: 11;
    width: 10px;
    height: 16px;
    pointer-events: none;
    animation: fall linear forwards;
}

@keyframes fall {
    to { transform: translateY(110vh) rotate(720deg); }
}

/* ---------- Petits écrans ---------- */

@media (max-width: 860px) {
    .game {
        grid-template-columns: minmax(0, 1fr);
    }

    .board-wrap {
        width: min(100%, 90vh);
    }
}
