/* ============================================================
   LaSpecial — Yatzy Duo (multi-téléphones, 2 joueurs)
   ============================================================ */
:root {
    --bg-dark: #0f0a14;
    --card-bg: #1c1326;
    --text-light: #FFFFFF;
    --gradient-fire: linear-gradient(135deg, #FF7A00 0%, #FF004D 50%, #7000FF 100%);
    --shadow-color: #4a00a8;
    --gold: #FFD700;
}

* { box-sizing: border-box; }
.hidden { display: none !important; }

body {
    margin: 0;
    font-family: 'Fredoka', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-light);
    min-height: 100dvh;
    overflow-x: hidden;
}

#app {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
}

/* ---------- HEADER ---------- */
.yatzy-header {
    display: flex;
    align-items: center;
    padding: 16px 14px 10px;
    gap: 14px;
}
.btn-back {
    background: var(--card-bg);
    border: 2px solid #2d1c3d;
    color: #fff;
    width: 42px; height: 42px;
    border-radius: 13px;
    font-size: 1rem;
    box-shadow: 0 4px 0 #180f21;
    display: flex; align-items: center; justify-content: center;
    text-decoration: none;
    cursor: pointer;
}
.btn-back:active { transform: translateY(4px); box-shadow: 0 0 0 #180f21; }
.titles { flex: 1; min-width: 0; }
.titles h1 {
    margin: 0;
    font-size: 1.4rem;
    font-weight: 900;
    text-transform: uppercase;
    background: var(--gradient-fire);
    -webkit-background-clip: text; background-clip: text;
    color: transparent;
}
.titles p { margin: 2px 0 0; color: #907d9e; font-size: 0.85rem; }
.yatzy-spacer { width: 42px; }

/* ---------- MAIN ---------- */
.yatzy-main {
    flex: 1;
    padding: 8px 16px 32px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
/* Chaque section (lobby / game / end / join) doit aussi espacer ses enfants */
.yatzy-main > section { display: flex; flex-direction: column; gap: 14px; }
.yatzy-main > section.hidden { display: none !important; }

/* ---------- CARD GÉNÉRIQUE ---------- */
.yatzy-card {
    background: var(--card-bg);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    padding: 20px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.yatzy-big-icon {
    display: block;
    font-size: 2.6rem;
    text-align: center;
    color: var(--gold);
    margin-bottom: 10px;
}
.yatzy-title {
    margin: 0 0 6px;
    text-align: center;
    font-size: 1.3rem;
    text-transform: uppercase;
}
.yatzy-subtitle {
    margin: 0 0 16px;
    text-align: center;
    color: #cab5e6;
    font-size: 0.92rem;
}

/* ---------- JOIN ---------- */
.yatzy-form { display: flex; flex-direction: column; gap: 10px; }
.yatzy-input {
    padding: 14px 16px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 14px;
    background: rgba(0, 0, 0, 0.35);
    color: #fff;
    font-size: 1.4rem;
    text-align: center;
    letter-spacing: 6px;
    text-transform: uppercase;
    font-weight: 700;
    font-family: 'Fredoka', sans-serif;
}
.yatzy-input:focus { outline: 2px solid var(--gold); }
.yatzy-submit, .yatzy-start {
    padding: 14px 18px;
    border: none;
    border-radius: 14px;
    background: var(--gradient-fire);
    color: #fff;
    font-weight: 900;
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    box-shadow: 0 6px 0 #3a0052;
    display: inline-flex; align-items: center; justify-content: center; gap: 10px;
}
.yatzy-submit:active, .yatzy-start:active { transform: translateY(4px); box-shadow: 0 2px 0 #3a0052; }
.yatzy-start:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: 0 6px 0 #3a0052; }
.yatzy-leave {
    margin-top: 8px;
    padding: 12px;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 12px;
    color: #cab5e6;
    font-size: 0.9rem;
    cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.yatzy-leave:active { background: rgba(255, 255, 255, 0.06); }
.yatzy-error {
    margin: 8px 0 0;
    color: #ff6b6b;
    font-size: 0.9rem;
    text-align: center;
}
.yatzy-error.global-error {
    background: rgba(255, 0, 77, 0.12);
    border: 1px solid rgba(255, 0, 77, 0.35);
    padding: 10px 14px;
    border-radius: 12px;
}

/* ---------- LOBBY ---------- */
.code-card { text-align: center; }
.code-label { margin: 0 0 6px; color: #cab5e6; font-size: 0.85rem; letter-spacing: 1.5px; }
.code-value {
    margin: 0;
    font-size: 2.4rem;
    font-weight: 900;
    letter-spacing: 6px;
    background: var(--gradient-fire);
    -webkit-background-clip: text; background-clip: text;
    color: transparent;
}
.copy-code {
    margin-top: 10px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.14);
    color: #fff;
    padding: 8px 16px;
    border-radius: 10px;
    font-size: 0.85rem;
    cursor: pointer;
}
.qr-card { text-align: center; }
.qr-label { margin: 0 0 10px; color: #cab5e6; font-size: 0.9rem; }
.qr-img {
    width: 180px; height: 180px;
    background: #fff;
    padding: 10px;
    border-radius: 14px;
    display: block;
    margin: 0 auto;
}
.qr-hint { margin: 10px 0 0; color: #907d9e; font-size: 0.82rem; }

.players-title {
    margin: 0 0 10px;
    font-weight: 700;
    display: flex; align-items: center; gap: 8px;
}
.players-count {
    margin-left: auto;
    background: rgba(255, 215, 0, 0.15);
    color: var(--gold);
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 700;
}
.players-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.player-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 12px;
}
.player-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: var(--gradient-fire);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 800;
    font-size: 0.85rem;
    flex-shrink: 0;
}
.player-avatar.has-image {
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    color: transparent;
    box-shadow: inset 0 0 0 2px rgba(255, 215, 0, 0.45);
}
.player-avatar.is-admin {
    box-shadow: inset 0 0 0 2px rgba(0, 229, 255, 0.55), 0 0 12px rgba(0, 229, 255, 0.35);
}
.player-avatar.has-image.is-admin {
    box-shadow: inset 0 0 0 2px rgba(0, 229, 255, 0.65), 0 0 12px rgba(0, 229, 255, 0.4);
}
.player-admin-tag {
    background: linear-gradient(135deg, #00E5FF 0%, #7000FF 100%);
    color: #fff;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.4px;
    display: inline-flex; align-items: center; gap: 4px;
}
.player-admin-tag i { font-size: 0.62rem; }
.player-name { flex: 1; }
.player-host-tag {
    background: rgba(255, 215, 0, 0.2);
    color: var(--gold);
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
}
.players-hint { margin: 12px 0 0; color: #907d9e; font-size: 0.85rem; text-align: center; }
.players-empty { color: #907d9e; text-align: center; font-style: italic; padding: 8px; }

/* ---------- LOADING ---------- */
.yatzy-loading {
    flex: 1;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 14px;
    color: #cab5e6;
}
.yatzy-spinner {
    width: 36px; height: 36px;
    border: 3px solid rgba(255, 255, 255, 0.15);
    border-top-color: var(--gold);
    border-radius: 50%;
    animation: yatzy-spin 0.9s linear infinite;
}
@keyframes yatzy-spin { to { transform: rotate(360deg); } }

/* ---------- SCOREBOARD (en haut du jeu) ---------- */
.yatzy-scoreboard {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 10px;
    background: var(--card-bg);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 18px;
    padding: 12px;
}
.score-col {
    text-align: center;
    padding: 8px 4px;
    border-radius: 12px;
    transition: background 0.2s;
    display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.score-avatar {
    width: 44px; height: 44px;
    border-radius: 50%;
    background: var(--gradient-fire);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 900;
    font-size: 1rem;
    margin-bottom: 4px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
}
.score-avatar.has-image {
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    color: transparent;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3), inset 0 0 0 2px rgba(255, 215, 0, 0.55);
}
.score-col.is-active .score-avatar {
    box-shadow: 0 3px 14px rgba(255, 0, 77, 0.5), 0 0 0 2px rgba(255, 0, 77, 0.7);
}
.score-col.is-active {
    background: linear-gradient(135deg, rgba(255, 122, 0, 0.18), rgba(255, 0, 77, 0.10));
    box-shadow: inset 0 0 0 1px rgba(255, 0, 77, 0.5);
}
.score-col.is-me .score-player::after { content: ' (toi)'; color: var(--gold); font-size: 0.75rem; }
.score-player {
    margin: 0;
    font-size: 0.9rem;
    font-weight: 700;
    color: #cab5e6;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.score-total {
    margin: 4px 0 0;
    font-size: 2rem;
    font-weight: 900;
    background: var(--gradient-fire);
    -webkit-background-clip: text; background-clip: text;
    color: transparent;
}
.score-vs {
    color: #907d9e;
    font-weight: 900;
    font-size: 0.85rem;
    letter-spacing: 2px;
}

.turn-indicator {
    margin: 0;
    text-align: center;
    font-weight: 700;
    font-size: 1rem;
    padding: 10px 14px;
    border-radius: 14px;
    background: rgba(255, 215, 0, 0.08);
    border: 1px dashed rgba(255, 215, 0, 0.35);
    color: var(--gold);
}
.turn-indicator.is-waiting {
    background: rgba(255, 255, 255, 0.04);
    border: 1px dashed rgba(255, 255, 255, 0.15);
    color: #907d9e;
}

/* ---------- DICE ---------- */
.dice-area {
    background: var(--card-bg);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    padding: 22px 14px 18px;
    text-align: center;
    perspective: 600px;
}
.dice-row {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}

/* --- Dé physique : grille 3x3 de pips --- */
.die {
    position: relative;
    width: 58px; height: 58px;
    border-radius: 14px;
    border: 2px solid rgba(255, 255, 255, 0.18);
    background: linear-gradient(145deg, #ffffff 0%, #e8e2f0 100%);
    cursor: pointer;
    padding: 8px;
    box-shadow: 0 5px 0 rgba(0, 0, 0, 0.3), inset 0 -3px 0 rgba(0, 0, 0, 0.08);
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease, background 0.18s ease;
    transform-style: preserve-3d;
    will-change: transform;
}
.die-face {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    width: 100%; height: 100%;
    gap: 2px;
    pointer-events: none;
}
.pip {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, #4a3a5e 0%, #1c1326 70%);
    box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.18);
    align-self: center;
    justify-self: center;
    max-width: 11px; max-height: 11px;
    visibility: hidden;
}
/* Slots : index 1..7 mappés en grid */
.pip-tl { grid-area: 1 / 1; }
.pip-tr { grid-area: 1 / 3; }
.pip-ml { grid-area: 2 / 1; }
.pip-c  { grid-area: 2 / 2; }
.pip-mr { grid-area: 2 / 3; }
.pip-bl { grid-area: 3 / 1; }
.pip-br { grid-area: 3 / 3; }
/* Configurations des faces */
.die[data-face="1"] .pip-c { visibility: visible; }
.die[data-face="2"] .pip-tl, .die[data-face="2"] .pip-br { visibility: visible; }
.die[data-face="3"] .pip-tl, .die[data-face="3"] .pip-c, .die[data-face="3"] .pip-br { visibility: visible; }
.die[data-face="4"] .pip-tl, .die[data-face="4"] .pip-tr,
.die[data-face="4"] .pip-bl, .die[data-face="4"] .pip-br { visibility: visible; }
.die[data-face="5"] .pip-tl, .die[data-face="5"] .pip-tr, .die[data-face="5"] .pip-c,
.die[data-face="5"] .pip-bl, .die[data-face="5"] .pip-br { visibility: visible; }
.die[data-face="6"] .pip-tl, .die[data-face="6"] .pip-tr,
.die[data-face="6"] .pip-ml, .die[data-face="6"] .pip-mr,
.die[data-face="6"] .pip-bl, .die[data-face="6"] .pip-br { visibility: visible; }
/* État "non lancé" : aucun pip, point d'interrogation centré */
.die[data-face="?"]::after {
    content: '?';
    position: absolute;
    inset: 0;
    display: flex; align-items: center; justify-content: center;
    font-weight: 900;
    font-size: 1.4rem;
    color: #b09cc7;
}

/* État "gardé" : surligné or, légèrement enfoncé */
.die.is-held {
    background: linear-gradient(145deg, #FFE96B 0%, #FFB800 100%);
    border-color: var(--gold);
    transform: translateY(2px);
    box-shadow: 0 3px 0 #8a6a00, inset 0 -2px 0 rgba(0, 0, 0, 0.12);
}
.die.is-held .pip { background: radial-gradient(circle at 35% 35%, #5a4a00 0%, #1f1900 70%); }

.die:disabled { opacity: 0.55; cursor: not-allowed; }

/* --- Animation de jet : rotation 3D + cycling des faces --- */
.die.is-rolling {
    animation: die-tumble 0.55s cubic-bezier(.36,.07,.19,.97) both;
}
@keyframes die-tumble {
    0%   { transform: translateY(0) rotateX(0)   rotateY(0)   rotateZ(0); }
    25%  { transform: translateY(-14px) rotateX(180deg) rotateY(90deg)  rotateZ(45deg); }
    50%  { transform: translateY(-20px) rotateX(360deg) rotateY(180deg) rotateZ(90deg); }
    75%  { transform: translateY(-8px)  rotateX(540deg) rotateY(270deg) rotateZ(135deg); }
    100% { transform: translateY(0)     rotateX(720deg) rotateY(360deg) rotateZ(180deg); }
}
.roll-btn {
    padding: 14px 22px;
    border: none;
    border-radius: 14px;
    background: var(--gradient-fire);
    color: #fff;
    font-weight: 900;
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    box-shadow: 0 6px 0 #3a0052;
    display: inline-flex; align-items: center; gap: 10px;
}
.roll-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #3a0052; }
.roll-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.rolls-left {
    margin: 12px 0 0;
    color: #cab5e6;
    font-size: 0.85rem;
}

/* ---------- SCORECARD ---------- */
.scorecard-wrap {
    background: var(--card-bg);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    padding: 16px;
}
.scorecard-title {
    margin: 0 0 12px;
    font-size: 1rem;
    text-transform: uppercase;
    color: var(--gold);
    display: flex; align-items: center; gap: 8px;
}
.scorecard-section + .scorecard-section { margin-top: 14px; }
.scorecard-section-title {
    margin: 0 0 6px;
    color: #cab5e6;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.scorecard { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.scorecard-row {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 12px;
}
.scorecard-row.is-locked {
    background: rgba(255, 215, 0, 0.06);
    border-color: rgba(255, 215, 0, 0.18);
    opacity: 0.85;
}
.scorecard-row.is-pickable {
    cursor: pointer;
    border-color: rgba(255, 215, 0, 0.45);
    background: rgba(255, 215, 0, 0.08);
}
.scorecard-row.is-pickable:hover {
    background: rgba(255, 215, 0, 0.14);
}
.scorecard-row.is-zero-preview .scorecard-preview { color: #ff8a8a; }
.scorecard-label { font-weight: 700; font-size: 0.92rem; }
.scorecard-label small { display: block; color: #907d9e; font-size: 0.72rem; font-weight: 400; margin-top: 2px; }
.scorecard-preview {
    color: var(--gold);
    font-weight: 700;
    font-size: 0.85rem;
    min-width: 32px;
    text-align: right;
}
.scorecard-value {
    font-weight: 900;
    font-size: 1.05rem;
    min-width: 30px;
    text-align: right;
}
.scorecard-value.is-empty { color: #4a3a5e; font-weight: 400; }
.scorecard-bonus {
    margin: 8px 0 0;
    color: #cab5e6;
    font-size: 0.82rem;
    text-align: center;
}
.scorecard-bonus.is-earned { color: var(--gold); font-weight: 700; }

/* ---------- END ---------- */
.end-card { text-align: center; }
.end-outcome {
    margin: 0 0 6px;
    font-size: 1.8rem;
    font-weight: 900;
    text-transform: uppercase;
    background: var(--gradient-fire);
    -webkit-background-clip: text; background-clip: text;
    color: transparent;
}
.end-outcome.is-lose {
    background: linear-gradient(135deg, #6a6a6a, #444);
    -webkit-background-clip: text; background-clip: text;
    color: transparent;
}
.end-outcome.is-draw {
    background: linear-gradient(135deg, var(--gold), #ffa500);
    -webkit-background-clip: text; background-clip: text;
    color: transparent;
}
.end-winner { margin: 0 0 18px; font-size: 1rem; color: #cab5e6; }
.end-scores {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 18px;
}
.end-score {
    background: rgba(255, 255, 255, 0.04);
    border-radius: 14px;
    padding: 12px;
}
.end-score-name { margin: 0 0 4px; font-size: 0.85rem; color: #cab5e6; }
.end-score-value { margin: 0; font-size: 1.6rem; font-weight: 900; }
.end-hint { margin: 10px 0 0; color: #907d9e; font-size: 0.85rem; }

/* ---------- RESPONSIVE ---------- */
@media (max-width: 360px) {
    .die { width: 48px; height: 48px; }
    .die .die-face { font-size: 1.5rem; }
    .code-value { font-size: 2rem; letter-spacing: 4px; }
}
