/* ==========================================================
 * Variables
 * ========================================================== */
:root {
    --bg:        #0f1220;
    --card:      #1a1f36;
    --line:      #2a3050;
    --text:      #e6e8f0;
    --muted:     #8890b0;
    --accent:    #4b8bff;
    --ok:        #2ecc71;
    --warn:      #f39c12;
    --danger:    #e74c3c;
    --checked:   #1e3a5f;
    --cell-size: clamp(60px, 11vw, 120px);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    min-height: 100vh;
    background-image:
        linear-gradient(rgba(15,18,32,.82), rgba(15,18,32,.82)),
        url('https://picsum.photos/1920/1080');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
}

.auth-page { display: flex; align-items: center; justify-content: center; padding: 2rem; }

/* ==========================================================
 * Topbar
 * ========================================================== */
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    background: rgba(26,31,54,.85);
    backdrop-filter: blur(10px);
    padding: .6rem 1rem;
    border-bottom: 1px solid var(--line);
    gap: .75rem;
    flex-wrap: wrap;
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar-left { display: flex; align-items: center; gap: .5rem; }
.player-code { letter-spacing: .1em; }
.stats { display: flex; gap: 1rem; font-size: .9rem; align-items: center; }
.stats .icon { color: var(--warn); }
.datetime {
    color: var(--muted);
    font-size: .8rem;
    padding-left: .5rem;
    border-left: 1px solid var(--line);
}
.links { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.links a { color: var(--text); text-decoration: none; font-size: .9rem; }
.links a:hover { color: var(--accent); }
.links a.secondary { color: var(--muted); }
.pill {
    display: inline-block;
    background: var(--accent);
    color: #fff;
    border-radius: 10px;
    padding: 0 .4rem;
    font-size: .7rem;
    font-weight: 700;
    min-width: 1.2em;
    text-align: center;
}

/* ==========================================================
 * Layout
 * ========================================================== */
main, .main-grid {
    max-width: 780px;
    margin: 0 auto;
    padding: 1rem;
}
h1 { margin: 0 0 1rem; font-size: 1.4rem; }
h2 { margin: 0 0 .5rem; font-size: 1.1rem; }

.badge { padding: .1rem .45rem; border-radius: 4px; font-size: .7rem; font-weight: 600; }
.badge-ok   { background: var(--ok);   color: #000; }
.badge-warn { background: var(--warn); color: #000; }

.stack { display: flex; flex-direction: column; gap: .6rem; }
.row   { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

input, select, button {
    font: inherit;
    padding: .5rem .7rem;
    border-radius: 6px;
    border: 1px solid var(--line);
    background: var(--bg);
    color: var(--text);
}
button, .btn {
    background: var(--accent);
    color: #fff;
    border: none;
    cursor: pointer;
    font-weight: 600;
    transition: filter .15s;
}
button:hover { filter: brightness(1.1); }
button.secondary { background: var(--line); color: var(--text); }
button.ok    { background: var(--ok);    color: #000; }
button.warn  { background: var(--warn);  color: #000; }
button.mini-btn { padding: .15rem .4rem; font-size: .75rem; }

.card {
    background: var(--card);
    padding: 1.5rem;
    border-radius: 10px;
    max-width: 380px;
    width: 100%;
    box-shadow: 0 8px 32px rgba(0,0,0,.4);
}

/* ==========================================================
 * Lettres B I N G O
 * ========================================================== */
.bingo-letters {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: .4rem;
    margin-bottom: .4rem;
    padding: 0 .05rem;
}
.bingo-letters span {
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    font-size: clamp(1.2rem, 2.6vw, 1.8rem);
    color: var(--accent);
    letter-spacing: .05em;
    background: rgba(75,139,255,.1);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: .25rem 0;
    text-shadow: 0 0 15px rgba(75,139,255,.4);
}

/* ==========================================================
 * Grille
 * ========================================================== */
.grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: .4rem;
    margin-bottom: 1rem;
}
.cell {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 6px;
    min-height: var(--cell-size);
    padding: .4rem;
    cursor: pointer;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    transition: transform .1s, background .1s, border-color .1s;
    overflow: hidden;
}
.cell:hover { background: #232a48; }
.cell.checked {
    background: var(--checked);
    border-color: var(--accent);
}
.cell.checked::after {
    content: '✓';
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 2.4rem; color: rgba(75,139,255,.3);
    pointer-events: none;
}

.cell-text {
    font-size: clamp(.65rem, 1.3vw, .85rem);
    line-height: 1.15;
    word-break: break-word;
    position: relative;
    z-index: 1;
}

/* Free space */
.cell.free {
    background: linear-gradient(135deg, #1e3a5f 0%, #2a3050 100%);
    border-color: var(--accent);
    cursor: default;
}
.cell.free .cell-text { font-weight: 700; }

/* Verrouillée */
.cell.locked {
    background: #2a1a1a;
    border-color: var(--danger);
    cursor: not-allowed;
    opacity: .85;
}
.cell.locked::before {
    content: '🔒';
    position: absolute;
    top: 2px; right: 4px;
    font-size: .7rem;
    opacity: .7;
}

/* Rejetée */
.cell.rejected {
    background: repeating-linear-gradient(45deg,
        rgba(231,76,60,.25),
        rgba(231,76,60,.25) 6px,
        rgba(231,76,60,.1) 6px,
        rgba(231,76,60,.1) 12px) !important;
    border-color: var(--danger) !important;
    cursor: not-allowed;
}
.cell.rejected .cell-text {
    text-decoration: line-through;
    color: var(--muted);
    opacity: .75;
}

/* Non échangeable (trade/inbox) */
.cell.not-tradeable {
    background: rgba(231,76,60,.2) !important;
    border-color: var(--danger) !important;
    cursor: not-allowed;
    opacity: .7;
}
.cell.already-owned {
    background: rgba(231,76,60,.12) !important;
    border-style: dashed;
}
.cell.already-owned::before {
    content: '✋';
    position: absolute; top: 2px; right: 4px;
    font-size: .7rem; opacity: .7;
}
.cell.selected {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

/* Mini-actions dans la cellule */
.cell-actions {
    position: absolute;
    bottom: 2px; right: 2px;
    display: flex; gap: 2px;
    opacity: 0;
    transition: opacity .15s;
}
.cell:hover .cell-actions { opacity: 1; }
.cell-actions .mini {
    padding: 2px 4px;
    font-size: .65rem;
    background: rgba(0,0,0,.55);
    border: 1px solid var(--line);
    border-radius: 3px;
    color: var(--text);
    cursor: pointer;
}
.cell-actions .mini:hover { background: var(--accent); color: #fff; }

.cell-rejected-badge {
    position: absolute;
    bottom: 2px; left: 2px; right: 2px;
}
.cell-rejected-badge .mini-btn {
    width: 100%;
    font-size: .65rem;
    padding: .2rem;
}

/* ==========================================================
 * Cartes de section (suggest, redeem)
 * ========================================================== */
.section-card, .suggest {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 1rem;
    margin-top: 1rem;
}
.section-card h2 { font-size: 1rem; }
.hint { color: var(--muted); font-size: .85rem; margin: .25rem 0; }
.error { color: var(--danger); }

/* ==========================================================
 * Modal
 * ========================================================== */
.modal {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.75);
    display: flex; align-items: center; justify-content: center;
    z-index: 100;
}
.modal-content {
    background: var(--card);
    padding: 1.5rem;
    border-radius: 12px;
    max-width: 380px;
    width: calc(100% - 2rem);
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
.modal-content h2 { margin: 0 0 .5rem; }
.modal-content .row { justify-content: center; margin-top: 1rem; }

/* ==========================================================
 * Table
 * ========================================================== */
.table {
    width: 100%; border-collapse: collapse;
    background: var(--card);
    border-radius: 10px; overflow: hidden;
}
.table th, .table td { padding: .5rem .7rem; text-align: left; border-bottom: 1px solid var(--line); }
.table th { background: #232a48; font-weight: 600; font-size: .85rem; }
.table tr.me { background: rgba(75,139,255,.1); }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px,1fr)); gap: .75rem; }
.stat-card { background: var(--card); padding: 1rem; border-radius: 8px; text-align: center; }
.stat-value { font-size: 2rem; font-weight: 700; color: var(--accent); }
.stat-label { color: var(--muted); font-size: .8rem; margin-top: .25rem; }

/* ==========================================================
 * Tabs (admin)
 * ========================================================== */
.tabs { display: flex; gap: .25rem; margin-bottom: 1rem; flex-wrap: wrap; }
.tabs a {
    padding: .4rem .8rem; border-radius: 6px; text-decoration: none;
    color: var(--muted); background: var(--card); font-size: .9rem;
}
.tabs a.active { background: var(--accent); color: #fff; }

/* ==========================================================
 * Animation BINGO
 * ========================================================== */
.bingo-flash {
    position: fixed; inset: 0; z-index: 200;
    background: radial-gradient(circle at center, rgba(75,139,255,.8) 0%, rgba(15,18,32,.95) 70%);
    display: flex; align-items: center; justify-content: center;
    animation: flashFade 1.8s ease-out forwards;
    pointer-events: none;
}
.bingo-text {
    font-size: clamp(4rem, 15vw, 8rem); font-weight: 900;
    color: #fff; letter-spacing: .1em;
    text-shadow: 0 0 40px rgba(75,139,255,1), 0 0 80px rgba(75,139,255,.6);
    animation: bingoPop 1.8s cubic-bezier(.2,1.4,.4,1) forwards;
}
@keyframes flashFade {
    0% { opacity: 0; }
    15%, 80% { opacity: 1; }
    100% { opacity: 0; }
}
@keyframes bingoPop {
    0%   { transform: scale(.2) rotate(-15deg); opacity: 0; }
    40%  { transform: scale(1.15) rotate(3deg); opacity: 1; }
    60%  { transform: scale(1); opacity: 1; }
    100% { transform: scale(1.1); opacity: .9; }
}
.confetti {
    position: fixed; width: 8px; height: 8px;
    border-radius: 50%; pointer-events: none; z-index: 201;
    animation: confettiFly 2s ease-out forwards;
}
@keyframes confettiFly {
    0%   { transform: translate(0,0) rotate(0); opacity: 1; }
    100% { transform: translate(var(--tx), var(--ty)) rotate(var(--rot)); opacity: 0; }
}

/* ==========================================================
 * Mini-grilles (inbox)
 * ========================================================== */
.mini-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 2px;
    background: var(--line);
    padding: 3px;
    border-radius: 4px;
    max-width: 180px;
}
.mini-cell {
    aspect-ratio: 1;
    background: var(--bg);
    border-radius: 2px;
    position: relative;
}
.mini-cell.checked { background: var(--checked); }
.mini-cell.free    { background: linear-gradient(135deg, #1e3a5f 0%, #2a3050 100%); }
.mini-cell.locked  { background: #2a1a1a; }
.mini-cell.hl      { box-shadow: 0 0 0 2px currentColor inset; }
.mini-cell.hl-ok    { color: var(--ok); }
.mini-cell.hl-warn  { color: var(--warn); }
.mini-cell.hl-accent{ color: var(--accent); }
.mini-pin {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: .55rem; line-height: 1;
    animation: pulsePin 1.2s ease-in-out infinite;
}
@keyframes pulsePin {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.35); }
}

/* Mini-grille COMPACTE (inbox contre-offre) */
.mini-grid.compact { max-width: 110px; padding: 2px; gap: 1px; }
.mini-grid.compact .mini-cell { border-radius: 1px; }
.mini-grid.compact .mini-cell.hl { box-shadow: 0 0 0 1.5px currentColor inset; }
.mini-grid.compact .mini-pin { font-size: .4rem; }

/* ==========================================================
 * Inbox
 * ========================================================== */
.offer-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 1rem;
    margin-bottom: 1rem;
}
.offer-header {
    display: flex; justify-content: space-between; align-items: baseline;
    gap: 1rem; margin-bottom: .75rem; flex-wrap: wrap;
}
.offer-header h3 { margin: 0; font-size: 1rem; }

.offer-viz {
    display: flex; align-items: center; gap: .75rem;
    flex-wrap: wrap;
    background: var(--bg);
    padding: .75rem;
    border-radius: 8px;
    border: 1px solid var(--line);
}
.offer-viz-side {
    display: flex; flex-direction: column; align-items: center;
    gap: .4rem;
    flex: 1 1 200px;
    min-width: 0;
}
.viz-label { font-size: .75rem; color: var(--muted); margin: 0; }
.viz-caption {
    font-size: .78rem; margin: 0;
    display: flex; align-items: center; gap: .4rem;
    text-align: center;
    line-height: 1.2;
}
.dot {
    display: inline-block; width: 8px; height: 8px;
    border-radius: 50%; flex-shrink: 0;
}
.dot-ok   { background: var(--ok); }
.dot-warn { background: var(--warn); }
.offer-arrow {
    font-size: 1.5rem; color: var(--accent); font-weight: 700;
}

.offer-outgoing {
    border-left: 3px solid var(--accent);
}
.offer-viz-compact {
    gap: .5rem;
    padding: .5rem;
}
.offer-viz-compact .viz-label { font-size: .7rem; }
.offer-viz-compact .viz-caption { font-size: .72rem; }

.counter-zone {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px dashed var(--line);
}
.counter-zone h4 { margin: 0 0 .5rem; font-size: .95rem; }
.counter-zone h5 { margin: 0 0 .4rem; font-size: .85rem; }

.counter-zone .grid {
    gap: 2px;
    --cell-size: 44px;
}
.counter-zone .cell {
    min-height: var(--cell-size);
    padding: 1px;
}
.counter-zone .cell-text { font-size: .6rem; }
.counter-zone .cell-actions { display: none; }

.offer-summary {
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: .75rem;
    font-size: .85rem;
}
.offer-summary p { margin: .2rem 0; }

.history-row {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: .75rem 1rem;
    margin-bottom: .6rem;
    border-left: 3px solid var(--line);
}
.history-row.history-accepted  { border-left-color: var(--ok); }
.history-row.history-refused   { border-left-color: var(--danger); }
.history-row.history-countered { border-left-color: var(--warn); }
.history-row.history-cancelled { border-left-color: var(--muted); }

.history-meta {
    display: flex; align-items: center;
    gap: .75rem; flex-wrap: wrap;
    font-size: .85rem;
}

.history-viz {
    display: flex; align-items: center;
    gap: .75rem; margin-top: .5rem;
    flex-wrap: wrap;
}
.history-case {
    display: flex; align-items: center; gap: .5rem;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: .4rem .6rem;
    flex: 1 1 180px;
}
.history-case-label {
    font-size: .68rem; color: var(--muted);
    text-transform: uppercase; letter-spacing: .04em;
}
.history-case-text { font-weight: 600; font-size: .85rem; margin-top: 1px; }
.history-arrow { font-size: 1.2rem; color: var(--accent); font-weight: 700; }

/* ==========================================================
 * Trade (proposer un échange)
 * ========================================================== */
.trade-page main { max-width: 1000px; }

.trade-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-top: 1rem;
}
.trade-columns section {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: .75rem;
}
.trade-columns h2,
.trade-columns h5 {
    font-size: .95rem;
    margin: 0 0 .5rem;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}
.trade-columns .grid { --cell-size: 56px; gap: 2px; }
.trade-columns .cell { min-height: var(--cell-size); padding: 1px; }
.trade-columns .cell-text { font-size: .6rem; }
.trade-columns .cell-actions { display: none; }

.trade-loader {
    background: var(--card);
    border: 1px dashed var(--line);
    border-radius: 8px;
    padding: 1rem;
    color: var(--muted);
    font-size: .85rem;
    text-align: center;
}

/* ==========================================================
 * Admin grille
 * ========================================================== */
.admin-grid .cell { position: relative; }
.admin-grid .cell-pos {
    position: absolute; top: 2px; left: 4px;
    font-size: .65rem; color: var(--muted); font-weight: 600;
}
.cell-regen-form {
    position: absolute; bottom: 2px; right: 2px;
    margin: 0; z-index: 2;
}
.cell-regen-form .mini {
    padding: 2px 4px; font-size: .7rem;
    background: rgba(0,0,0,.55);
    border: 1px solid var(--line);
    border-radius: 3px;
    color: var(--text); cursor: pointer;
}
.cell-regen-form .mini:hover { background: var(--accent); color: #fff; }

/* ==========================================================
 * Responsive
 * ========================================================== */
@media (max-width: 640px) {
    .topbar { padding: .5rem .75rem; font-size: .85rem; }
    .stats { gap: .75rem; }
    .datetime { display: none; }
    .links a { font-size: .8rem; }
    main, .main-grid { padding: .75rem; }
    .grid { gap: .3rem; }
    .cell-text { font-size: .65rem; }
    .bingo-letters { gap: .3rem; }
    .bingo-letters span { font-size: 1.1rem; padding: .2rem 0; }

    .trade-columns { grid-template-columns: 1fr; }
    .offer-viz { flex-direction: column; }
    .offer-arrow { transform: rotate(90deg); }
}

@media (max-width: 400px) {
    .cell-text { font-size: .6rem; }
    .cell { padding: .25rem; }
    .bingo-letters span { font-size: .95rem; padding: .15rem 0; }
}

/* Topbar — liens universels, toutes pages */
.topbar a {
    color: var(--text);
    text-decoration: none;
    padding: .25rem .5rem;
    border-radius: 6px;
    transition: background .15s, color .15s;
    font-size: .9rem;
}
.topbar a:hover {
    color: var(--accent);
    background: rgba(75,139,255,.1);
}
.topbar a.secondary {
    color: var(--muted);
}
.topbar a.secondary:hover {
    color: var(--text);
}

/* Le premier lien (retour "←") reste discret */
.topbar > a:first-child {
    color: var(--muted);
}

/* Boutons dans la topbar (admin déconnexion, etc.) */
.topbar .btn,
.topbar button {
    padding: .25rem .6rem;
    font-size: .85rem;
}

.card {
    background: var(--card);
    padding: 1.5rem;
    border-radius: 10px;
    max-width: 380px;
    width: 100%;
    box-shadow: 0 8px 32px rgba(0,0,0,.4);
}

.suggest {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 1rem;
    margin-top: 1rem;
}

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px,1fr));
    gap: .75rem;
}
.stat-card {
    background: var(--card);
    border: 1px solid var(--line);
    padding: 1rem;
    border-radius: 8px;
    text-align: center;
}
.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent);
}
.stat-label {
    color: var(--muted);
    font-size: .8rem;
    margin-top: .25rem;
}

.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card);
    border-radius: 10px;
    overflow: hidden;
}
.table th,
.table td {
    padding: .5rem .7rem;
    text-align: left;
    border-bottom: 1px solid var(--line);
}
.table th {
    background: #232a48;
    font-weight: 600;
    font-size: .85rem;
}
.table tr.me {
    background: rgba(75,139,255,.1);
}
.table tr:last-child td {
    border-bottom: none;
}

.tabs {
    display: flex;
    gap: .25rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.tabs a {
    padding: .4rem .8rem;
    border-radius: 6px;
    text-decoration: none;
    color: var(--muted);
    background: var(--card);
    border: 1px solid var(--line);
    font-size: .9rem;
}
.tabs a.active,
.tabs a:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

main {
    max-width: 780px;
    margin: 0 auto;
    padding: 1rem;
}

/* Sur les pages larges (admin dashboard, trade), on élargit */
body.trade-page main,
body.admin-page main {
    max-width: 1000px;
}

button.secondary,
.btn.secondary {
    background: var(--line);
    color: var(--text);
}
button.secondary:hover {
    background: #3a4270;
}

.mini-btn {
    display: inline-block;
    padding: .25rem .5rem;
    font-size: .8rem;
    border-radius: 5px;
    border: none;
    cursor: pointer;
    text-decoration: none;
    color: #fff;
    background: var(--accent);
    font-weight: 600;
}
.mini-btn.secondary { background: var(--line); color: var(--text); }
.mini-btn.ok        { background: var(--ok); color: #000; }
.mini-btn.warn      { background: var(--warn); color: #000; }

/* ==========================================================
 * Mini-grilles (inbox)
 * ========================================================== */
.mini-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: repeat(5, 1fr);
    gap: 2px;
    background: var(--line);
    padding: 3px;
    border-radius: 5px;
    width: 100%;
    max-width: 180px;
    aspect-ratio: 1 / 1;
    box-sizing: border-box;
}
.mini-cell {
    background: var(--bg);
    border-radius: 2px;
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 0;
    min-width: 0;
}
.mini-cell.checked { background: var(--checked); }
.mini-cell.free    { background: linear-gradient(135deg, #1e3a5f 0%, #2a3050 100%); }
.mini-cell.locked  { background: #2a1a1a; }
.mini-cell.hl      { box-shadow: 0 0 0 2px currentColor inset; }
.mini-cell.hl-ok    { color: var(--ok); }
.mini-cell.hl-warn  { color: var(--warn); }
.mini-cell.hl-accent{ color: var(--accent); }
.mini-pin {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: .55rem; line-height: 1;
    animation: pulsePin 1.2s ease-in-out infinite;
    pointer-events: none;
}
@keyframes pulsePin {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.35); }
}

/* Mini-grille COMPACTE (inbox contre-offre) */
.mini-grid.compact {
    max-width: 110px;
    padding: 2px;
    gap: 1px;
}
.mini-grid.compact .mini-cell { border-radius: 1px; }
.mini-grid.compact .mini-cell.hl { box-shadow: 0 0 0 1.5px currentColor inset; }
.mini-grid.compact .mini-pin { font-size: .4rem; }