/* ==========================================================================
   Styles communs
   ========================================================================== */
:root {
    --bg: #12141c;
    --surface: #1b1e2a;
    --surface-2: #252937;
    --border: #343a4d;
    --text: #eef0f6;
    --muted: #9ca3b8;
    --primary: #5b7cfa;
    --primary-hover: #7390ff;
    --green: #22c55e;
    --green-dark: #15803d;
    --red: #e5383b;
    --red-dark: #a4161a;
    --amber: #f59e0b;
    --grey: #6b7280;
    --radius: 14px;
    --radius-sm: 9px;
    --shadow: 0 10px 30px rgba(0, 0, 0, .35);
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
    color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.45;
}

h1, h2, h3 { line-height: 1.2; margin: 0 0 .6em; }
h1 { font-size: clamp(1.6rem, 4vw, 2.3rem); }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
a { color: var(--primary-hover); }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: .88rem; margin: .5rem 0; }

/* ------------------------------------------------------------ Barre du haut */
.topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    padding-top: max(10px, env(safe-area-inset-top));
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}
.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 800;
    font-size: 1.15rem;
    color: var(--text);
    text-decoration: none;
    letter-spacing: .02em;
}
.brand-dot {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #ff8a8c, var(--red) 55%, var(--red-dark));
    box-shadow: 0 0 10px rgba(229, 56, 59, .6);
}
.topbar .lang-switch { margin-left: auto; }
.topbar-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.topbar-actions .lang-switch { margin-left: 6px; }

.lang-switch { display: flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.lang-switch a {
    padding: 4px 10px;
    font-size: .8rem;
    font-weight: 700;
    color: var(--muted);
    text-decoration: none;
}
.lang-switch a.active { background: var(--primary); color: #fff; }

/* ------------------------------------------------------------ Cartes */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: .6em; }
.card-head h2 { margin: 0; }
.counter {
    font-size: .85rem;
    color: var(--muted);
    background: var(--surface-2);
    padding: 2px 10px;
    border-radius: 999px;
    white-space: nowrap;
}

/* ------------------------------------------------------------ Formulaires */
.label { display: block; font-weight: 600; margin-bottom: 6px; }
.input {
    width: 100%;
    padding: 11px 13px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font: inherit;
    min-height: 44px;
}
.input:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: transparent; }
select.input { cursor: pointer; }

/* ------------------------------------------------------------ Boutons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 44px;
    padding: 9px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: background .15s, transform .08s, opacity .15s;
    white-space: nowrap;
}
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--surface-2); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: #2f3446; }
.btn-success { background: var(--green); color: #06260f; }
.btn-warning { background: var(--amber); color: #2b1a00; }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-chip { min-height: 34px; padding: 4px 12px; font-size: .85rem; background: var(--surface-2); border-radius: 999px; }
.btn-lg { min-height: 52px; font-size: 1.05rem; padding: 12px 22px; }
.btn-block { width: 100%; }
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--muted);
    font-size: 1.1rem;
    cursor: pointer;
}
.btn-icon:hover { background: var(--surface-2); color: var(--text); }

/* ------------------------------------------------------------ Messages */
.alert { padding: 10px 14px; border-radius: var(--radius-sm); margin: 12px 0 0; font-size: .92rem; }
.alert-error { background: rgba(229, 56, 59, .15); border: 1px solid rgba(229, 56, 59, .5); color: #ffb3b4; }
.alert-info { background: rgba(91, 124, 250, .13); border: 1px solid rgba(91, 124, 250, .45); color: #c8d3ff; }

.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translate(-50%, 30px);
    background: #2c3142;
    color: var(--text);
    padding: 10px 18px;
    border-radius: 999px;
    box-shadow: var(--shadow);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s, transform .2s;
    z-index: 1000;
    max-width: calc(100vw - 32px);
    text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--red-dark); }

.offline-banner {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 900;
    background: var(--red-dark);
    color: #fff;
    text-align: center;
    padding: 6px;
    font-weight: 600;
    font-size: .9rem;
}
body.offline .offline-banner { display: block; }

/* ------------------------------------------------------------ Puces (noms) */
.chip-list { list-style: none; padding: 0; margin: 10px 0 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 6px 6px 6px 14px;
    font-weight: 600;
    max-width: 100%;
}
.chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-remove {
    border: 0;
    background: transparent;
    color: var(--muted);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
}
.chip-remove:hover { background: rgba(229, 56, 59, .25); color: #fff; }

.code-badge {
    font-family: var(--mono);
    font-weight: 700;
    letter-spacing: .08em;
    background: var(--surface-2);
    border: 1px solid var(--border);
    padding: 2px 9px;
    border-radius: 7px;
    font-size: .9rem;
}

/* ------------------------------------------------------------ Fenêtres */
.dialog {
    width: min(720px, calc(100vw - 24px));
    max-height: calc(100dvh - 24px);
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(5, 6, 10, .7); }
.dialog-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 1;
}
.dialog-head h2 { margin: 0; }
.dialog-body { padding: 16px 18px 20px; }

.qr { background: #fff; padding: 12px; border-radius: 10px; display: inline-block; line-height: 0; }
.qr img, .qr canvas { display: block; max-width: 100%; height: auto; }

/* ------------------------------------------------------------ Écran de démarrage */
.start-overlay {
    position: fixed;
    inset: 0;
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(8, 9, 14, .88);
    backdrop-filter: blur(4px);
    padding: 16px;
}
.start-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 34px 40px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 20px;
    font: inherit;
    font-size: 1.25rem;
    cursor: pointer;
    box-shadow: var(--shadow);
    max-width: 420px;
    text-align: center;
}
.start-box .muted { font-size: .95rem; }
.start-icon { font-size: 2.6rem; }

/* ------------------------------------------------------------ Accueil */
.home { max-width: 980px; margin: 0 auto; padding: 32px 16px 48px; }
.hero { text-align: center; margin-bottom: 28px; }
.home-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; }
.join-form { display: flex; flex-direction: column; gap: 10px; }
.input-code {
    font-family: var(--mono);
    font-size: 1.5rem;
    text-align: center;
    letter-spacing: .15em;
    text-transform: uppercase;
    min-height: 58px;
}
.my-rooms { margin-top: 20px; border-top: 1px solid var(--border); padding-top: 14px; }
.my-rooms ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.my-rooms a { display: block; padding: 8px 12px; background: var(--surface-2); border-radius: var(--radius-sm); text-decoration: none; color: var(--text); }
.my-rooms a:hover { background: #2f3446; }

/* ------------------------------------------------------------ Choix du nom */
.pick { max-width: 720px; margin: 0 auto; padding: 28px 16px 48px; text-align: center; }
.pick-team { margin-top: 1.4em; color: var(--muted); font-size: 1rem; text-transform: uppercase; letter-spacing: .06em; }
.pick-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }

/* ------------------------------------------------------------ Erreurs */
.center-msg { min-height: 80vh; display: flex; align-items: center; justify-content: center; padding: 16px; text-align: center; }

@media (max-width: 640px) {
    .hide-sm { display: none; }
    .card { padding: 14px; }
}

/* Page de diagnostic (check.php) */
.check-table { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: .93rem; }
.check-table td { padding: 8px 6px; border-top: 1px solid var(--border); vertical-align: top; }
.check-detail { color: var(--muted); word-break: break-word; font-family: var(--mono); font-size: .82rem; }
.check-badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.check-ok { background: rgba(34, 197, 94, .18); color: #86efac; }
.check-warn { background: rgba(245, 158, 11, .18); color: #fcd34d; }
.check-fail { background: rgba(229, 56, 59, .2); color: #ffb3b4; }
@media (max-width: 560px) {
    .check-table tr { display: grid; grid-template-columns: 1fr auto; }
    .check-table td { border-top: 0; }
    .check-table tr { border-top: 1px solid var(--border); }
    .check-detail { grid-column: 1 / -1; padding-top: 0 !important; }
}
