:root {
    --bg: #0d1020;
    --card: rgba(255, 255, 255, .045);
    --card-border: rgba(255, 255, 255, .09);
    --cell: #1a1f3a;
    --cell-2: #151933;
    --text: #eef0fa;
    --muted: #9aa0bd;
    --green-1: #4ade80;
    --green-2: #16a34a;
    --green-3: #0f7a39;
    --gold: #fbbf24;
    --radius: clamp(10px, 2.6vw, 18px);
    --gap: clamp(6px, 2vw, 14px);
    --font: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-y: none;
}

/* Image de fond : un calque "fixed" (background-attachment: fixed ne marche pas sur iPhone) */
.bg {
    position: fixed; inset: 0; z-index: -1; pointer-events: none;
    background:
        linear-gradient(180deg, rgba(13, 16, 32, .55) 0%, rgba(13, 16, 32, .72) 45%, rgba(13, 16, 32, .9) 100%),
        url("bg.jpg") 62% center / cover no-repeat,
        var(--bg);
}

h1 { margin: 0; font-weight: 800; letter-spacing: -.02em; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }

.card {
    background: var(--card);
    border: 1px solid var(--card-border);
    border-radius: calc(var(--radius) + 8px);
    box-shadow: 0 20px 60px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .05);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
}

/* ---------------- Connexion ---------------- */

.login {
    min-height: 100vh; min-height: 100dvh;
    display: grid; place-items: center;
    padding: max(20px, env(safe-area-inset-top)) 18px max(20px, env(safe-area-inset-bottom));
}
.login-card {
    width: min(100%, 400px);
    padding: clamp(26px, 7vw, 40px);
    text-align: center;
}
.login-icon {
    font-size: 44px; width: 76px; height: 76px; margin: 0 auto 14px;
    display: grid; place-items: center; border-radius: 22px;
    background: linear-gradient(145deg, rgba(74, 222, 128, .25), rgba(22, 163, 74, .12));
    border: 1px solid rgba(74, 222, 128, .3);
}
.login-card h1 { font-size: clamp(1.5rem, 6vw, 1.9rem); }
.login-card p { margin: 8px 0 22px; line-height: 1.45; }

.code-input {
    width: 100%;
    font: inherit;
    font-size: 18px;               /* ≥ 16px : évite le zoom automatique sur iPhone */
    font-weight: 700;
    letter-spacing: .12em;
    text-align: center;
    padding: 15px 16px;
    color: var(--text);
    background: rgba(0, 0, 0, .28);
    border: 1px solid var(--card-border);
    border-radius: 14px;
    outline: none;
    transition: border-color .2s, box-shadow .2s;
}
.code-input:focus { border-color: var(--green-1); box-shadow: 0 0 0 4px rgba(74, 222, 128, .18); }
.code-input::placeholder { color: #5f6585; letter-spacing: .04em; font-weight: 600; }

.error { color: #fca5a5; margin: 12px 0 0 !important; font-weight: 600; }

.btn {
    width: 100%; margin-top: 16px; min-height: 52px;
    font: inherit; font-size: 17px; font-weight: 800; letter-spacing: .02em;
    color: #04210f; cursor: pointer; border: 0; border-radius: 14px;
    background: linear-gradient(145deg, var(--green-1), var(--green-2));
    box-shadow: 0 10px 26px rgba(22, 163, 74, .35);
    touch-action: manipulation;
    transition: transform .12s, filter .2s;
}
.btn:active { transform: scale(.97); }

.shake { animation: shake .45s; }
@keyframes shake {
    20%, 60% { transform: translateX(-8px); }
    40%, 80% { transform: translateX(8px); }
}

/* ---------------- Jeu ---------------- */

.game {
    width: min(100%, 680px);
    min-height: 100vh; min-height: 100dvh;
    display: flex; flex-direction: column; justify-content: center;
    margin: 0 auto;
    padding:
        max(18px, env(safe-area-inset-top))
        max(12px, env(safe-area-inset-right))
        max(22px, env(safe-area-inset-bottom))
        max(12px, env(safe-area-inset-left));
}

.head { text-align: center; margin: 6px 0 clamp(14px, 4vw, 22px); }
.head h1 {
    font-size: clamp(1.6rem, 7.5vw, 2.6rem);
    background: linear-gradient(90deg, #fff, #c7f9d8 45%, #a5f3fc);
    -webkit-background-clip: text; background-clip: text; color: transparent;
}
.status { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 10px; }
.sync, .lines {
    display: inline-flex; align-items: center; gap: 7px;
    font-size: .82rem; font-weight: 700; padding: 6px 12px; border-radius: 999px;
    background: rgba(255, 255, 255, .06); border: 1px solid var(--card-border); color: var(--muted);
}
.sync i { width: 8px; height: 8px; border-radius: 50%; background: var(--green-1); box-shadow: 0 0 0 0 rgba(74, 222, 128, .6); animation: ping 2s infinite; }
.sync.off i { background: #f87171; animation: none; }
.sync.off span::after { content: " · reconnexion…"; }
@keyframes ping { 70% { box-shadow: 0 0 0 8px rgba(74, 222, 128, 0); } 100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0); } }
.lines[hidden] { display: none; }
.lines { color: #1f1300; background: linear-gradient(145deg, #fde68a, var(--gold)); border-color: transparent; }

.board-card { padding: clamp(10px, 3vw, 22px); }

.board {
    container-type: inline-size;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--gap);
}

.cell {
    position: relative;
    aspect-ratio: 1;
    min-width: 0;
    display: flex; align-items: center; justify-content: center;
    /* marge haute/basse = place du numéro et de la coche */
    padding: clamp(16px, 5.2cqi, 30px) clamp(3px, 1.2cqi, 10px);
    font: inherit;
    /* la taille du texte suit la largeur de la grille : lisible sur un téléphone de 320px */
    font-size: clamp(10.5px, 3.2cqi, 17px);
    font-weight: 700;
    line-height: 1.14;
    text-align: center;
    color: var(--text);
    background: linear-gradient(160deg, var(--cell), var(--cell-2));
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: var(--radius);
    box-shadow: 0 6px 16px rgba(0, 0, 0, .28), inset 0 1px 0 rgba(255, 255, 255, .06);
    cursor: pointer;
    user-select: none; -webkit-user-select: none;
    -webkit-touch-callout: none;
    touch-action: manipulation;     /* pas de zoom au double-tap */
    transition: transform .14s ease, background .25s, box-shadow .25s, border-color .25s;
    overflow: hidden;
}
.label {
    overflow-wrap: break-word;
    hyphens: manual;
}
.num {
    position: absolute; top: clamp(4px, 1.4cqi, 9px); left: clamp(6px, 1.8cqi, 11px);
    font-size: clamp(8.5px, 2cqi, 11px); font-weight: 800; color: rgba(255, 255, 255, .28);
}
.tick {
    position: absolute; top: clamp(4px, 1.4cqi, 8px); right: clamp(4px, 1.4cqi, 8px);
    width: clamp(15px, 4.4cqi, 24px); height: clamp(15px, 4.4cqi, 24px);
    display: grid; place-items: center; border-radius: 50%;
    background: rgba(255, 255, 255, .95);
    transform: scale(0); transition: transform .3s cubic-bezier(.34, 1.56, .64, 1);
}
.tick svg { width: 70%; height: 70%; fill: none; stroke: var(--green-2); stroke-width: 3.4; stroke-linecap: round; stroke-linejoin: round; }

@media (hover: hover) {
    .cell:hover { transform: translateY(-2px); border-color: rgba(255, 255, 255, .18); }
}
.cell:active { transform: scale(.94); }

/* Téléphone : cases un peu plus hautes que larges, on profite de la hauteur de l'écran */
@media (max-width: 560px) {
    .cell { aspect-ratio: 5 / 6; }
}
.cell:focus-visible { outline: 3px solid #a5f3fc; outline-offset: 2px; }

.cell.on {
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, .25);
    background: linear-gradient(150deg, var(--green-1), var(--green-2) 55%, var(--green-3));
    border-color: rgba(187, 247, 208, .55);
    box-shadow: 0 8px 22px rgba(22, 163, 74, .4), inset 0 1px 0 rgba(255, 255, 255, .35);
}
.cell.on .num { color: rgba(255, 255, 255, .6); }
.cell.on .tick { transform: scale(1); }
.cell.pop { animation: pop .38s cubic-bezier(.34, 1.56, .64, 1); }
@keyframes pop { 0% { transform: scale(.9); } 60% { transform: scale(1.06); } 100% { transform: scale(1); } }

.cell.win {
    border-color: var(--gold);
    box-shadow: 0 0 0 2px var(--gold), 0 0 22px rgba(251, 191, 36, .55), inset 0 1px 0 rgba(255, 255, 255, .35);
    animation: glow 1.8s ease-in-out infinite;
}
@keyframes glow { 50% { box-shadow: 0 0 0 2px var(--gold), 0 0 34px rgba(251, 191, 36, .8), inset 0 1px 0 rgba(255, 255, 255, .35); } }

.progress { height: 8px; margin: clamp(14px, 4vw, 20px) 2px 8px; border-radius: 99px; background: rgba(255, 255, 255, .07); overflow: hidden; }
.bar { height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--green-2), var(--green-1)); transition: width .4s ease; }
#count { text-align: center; margin: 0; }

/* ---------------- Bingo ! ---------------- */

.toast {
    position: fixed; left: 50%; top: max(18px, env(safe-area-inset-top));
    z-index: 20; display: flex; flex-direction: column; align-items: center;
    padding: 14px 28px; border-radius: 20px; pointer-events: none;
    background: linear-gradient(145deg, #fde68a, var(--gold) 60%, #f59e0b);
    color: #2a1700; box-shadow: 0 18px 50px rgba(245, 158, 11, .45);
    transform: translate(-50%, -160%); transition: transform .5s cubic-bezier(.34, 1.56, .64, 1);
}
.toast strong { font-size: clamp(1.8rem, 9vw, 2.6rem); font-weight: 900; letter-spacing: .04em; line-height: 1; }
.toast span { font-weight: 700; font-size: .9rem; margin-top: 4px; }
.toast.show { transform: translate(-50%, 0); }

#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 15; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
