/* ==========================================================================
   Poké Lanoël — échange de cartes entre amis
   Pensé d'abord pour le téléphone : barre d'onglets en bas, grille 3 colonnes
   ========================================================================== */

:root {
    color-scheme: dark;
    --ground: #0b0b10;
    --panel: #15151c;
    --panel-2: #1d1d26;
    --line: rgba(255,255,255,.08);
    --line-2: rgba(255,255,255,.16);
    --text: #f5f2ec;
    --muted: rgba(245,242,236,.6);
    --faint: rgba(245,242,236,.35);

    --yellow: #ffcb05;
    --yellow-ink: #1a1200;
    --red: #ff2e2e;
    --blue: #5bb8ff;
    --green: #6cff7a;

    --radius: 16px;
    --radius-sm: 10px;
    --tabbar-h: 64px;
    --safe-b: env(safe-area-inset-bottom, 0px);
    --font: 'Outfit', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --mono: 'JetBrains Mono', ui-monospace, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
    font-family: var(--font);
    background:
        radial-gradient(120% 60% at 50% -10%, rgba(255,203,5,.10), transparent 60%),
        var(--ground);
    background-attachment: fixed;
    color: var(--text);
    line-height: 1.45;
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.link { color: var(--yellow); text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Header ---------- */
.top {
    position: sticky; top: 0; z-index: 30;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
    background: rgba(11,11,16,.85);
    backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 1.1rem; letter-spacing: -.01em; }
.brand b { color: var(--yellow); font-weight: 800; }
.ball {
    width: 24px; height: 24px; border-radius: 50%; flex: none;
    background:
        radial-gradient(circle at 50% 50%, #fff 0 18%, #111 19% 27%, transparent 28%),
        linear-gradient(#ff2e2e 0 46%, #111 46% 54%, #f5f2ec 54%);
    box-shadow: 0 0 0 2px #111 inset;
}
.ball.big { width: 84px; height: 84px; box-shadow: 0 0 0 5px #111 inset, 0 10px 40px rgba(255,46,46,.35); }
.me { display: flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--muted); max-width: 50%; }
.me span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me img, .avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex: none; background: var(--panel-2); }

/* ---------- Page ---------- */
.page {
    max-width: 720px; margin: 0 auto;
    padding: 16px 16px calc(var(--tabbar-h) + var(--safe-b) + 24px);
}
.h1 { font-size: 1.6rem; font-weight: 800; letter-spacing: -.02em; margin-bottom: 4px; }
.h2 { font-size: 1.05rem; font-weight: 700; margin: 24px 0 10px; display: flex; align-items: center; gap: 8px; }
.count {
    font-family: var(--mono); font-size: .75rem; font-weight: 700;
    background: var(--panel-2); border: 1px solid var(--line-2);
    border-radius: 999px; padding: 1px 8px; color: var(--yellow);
}
.empty { text-align: center; color: var(--muted); padding: 40px 12px; }
.stack { display: grid; gap: 12px; margin-top: 16px; }
.back { display: inline-block; color: var(--muted); font-size: .9rem; margin-bottom: 10px; padding: 4px 0; }

.flash {
    max-width: 720px; margin: 12px auto 0; padding: 12px 14px;
    width: calc(100% - 32px);
    background: rgba(108,255,122,.1); border: 1px solid rgba(108,255,122,.35);
    border-radius: var(--radius-sm); font-size: .92rem;
}
.alert {
    margin: 12px 0; padding: 12px 14px; border-radius: var(--radius-sm);
    background: rgba(255,46,46,.12); border: 1px solid rgba(255,46,46,.4);
}
.callout {
    margin-top: 14px; padding: 12px 14px; border-radius: var(--radius-sm);
    background: rgba(255,203,5,.08); border: 1px solid rgba(255,203,5,.3); font-size: .92rem;
}

/* ---------- Boutons & formulaires ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 44px; padding: 0 18px; border-radius: 999px;
    border: 1px solid var(--line-2); background: var(--panel-2);
    font-weight: 600; font-size: .95rem; transition: transform .1s, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--yellow); color: var(--yellow-ink); border-color: var(--yellow); }
.btn.ghost { background: transparent; }
.btn.block { display: flex; width: 100%; }
.btn:disabled { opacity: .4; pointer-events: none; }

.form { display: grid; gap: 14px; margin: 18px 0; color: var(--muted); font-size: .9rem; }
.form label { display: grid; gap: 6px; }
input[type=text], input[type=password], input[type=search], textarea {
    width: 100%; min-height: 46px; padding: 10px 14px;
    background: var(--panel); border: 1px solid var(--line-2); border-radius: 12px;
    color: var(--text); font-size: 16px; /* pas de zoom auto sur iOS */
    outline: none;
}
input:focus, textarea:focus { border-color: var(--yellow); }
textarea { resize: vertical; }

/* ---------- Connexion ---------- */
.auth { max-width: 380px; margin: 6vh auto 0; text-align: center; }
.auth .form { text-align: left; }
.auth-hero { display: flex; justify-content: center; margin-bottom: 18px; }
.auth h1 { font-size: 1.8rem; font-weight: 800; letter-spacing: -.02em; }

/* ---------- Collection ---------- */
.collection .sticky {
    position: sticky; top: calc(53px + env(safe-area-inset-top, 0px)); z-index: 20;
    margin: -16px -16px 12px; padding: 12px 16px 10px;
    background: rgba(11,11,16,.92);
    backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--line);
}
.seg {
    display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px;
    background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
}
.seg button {
    border: 0; background: transparent; border-radius: 10px; padding: 8px 6px;
    font-weight: 600; font-size: .9rem; color: var(--muted); line-height: 1.2;
}
.seg button small { display: block; font-family: var(--mono); font-size: .72rem; font-weight: 500; opacity: .8; }
.seg button.on { background: var(--panel-2); color: var(--text); box-shadow: 0 0 0 1px var(--line-2); }
.seg button.on small { color: var(--yellow); }
.bar { height: 4px; background: var(--panel-2); border-radius: 99px; margin: 10px 2px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--red), var(--yellow)); transition: width .4s; }
.tools { margin-bottom: 8px; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.chips::-webkit-scrollbar { display: none; }
.chips button {
    flex: none; border: 1px solid var(--line-2); background: transparent;
    border-radius: 999px; padding: 6px 12px; font-size: .85rem; color: var(--muted);
}
.chips button.on { background: var(--text); color: var(--ground); border-color: var(--text); font-weight: 600; }

.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

.tile { position: relative; display: grid; gap: 5px; }
.tile .art {
    position: relative; aspect-ratio: 63 / 88; border-radius: 7px; overflow: hidden;
    background: var(--panel-2); border: 0; padding: 0;
}
.tile .art img { width: 100%; height: 100%; object-fit: cover; transition: filter .25s, opacity .25s; }
.tile.missing .art img { filter: grayscale(1) brightness(.55); opacity: .55; }
.tile .num {
    position: absolute; left: 4px; bottom: 4px; font-family: var(--mono); font-size: .62rem;
    background: rgba(0,0,0,.7); padding: 1px 5px; border-radius: 5px; color: var(--muted);
}
.tile .qty {
    position: absolute; top: 4px; right: 4px; min-width: 24px; height: 24px; padding: 0 6px;
    display: grid; place-items: center; border-radius: 999px;
    font-family: var(--mono); font-size: .75rem; font-weight: 700;
    background: rgba(0,0,0,.75); color: var(--text); border: 1px solid var(--line-2);
}
.tile.double .qty { background: var(--yellow); color: var(--yellow-ink); border-color: var(--yellow); }
.tile .offer {
    position: absolute; top: 4px; left: 4px; width: 22px; height: 22px; border-radius: 50%;
    display: grid; place-items: center; font-size: .7rem; font-weight: 700;
    background: var(--blue); color: #001a2e;
}
.stepper {
    display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
    background: var(--panel); border: 1px solid var(--line); border-radius: 999px; height: 34px;
}
.stepper button {
    border: 0; background: transparent; height: 100%; font-size: 1.15rem; font-weight: 600; color: var(--muted);
    touch-action: manipulation;
}
.stepper button:active { color: var(--yellow); }
.stepper button[data-step="1"] { color: var(--text); }
.stepper output { font-family: var(--mono); font-size: .8rem; min-width: 1.4em; text-align: center; }
.tile .name { font-size: .72rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center; }

/* ---------- Fiche carte (dialog) ---------- */
.sheet {
    margin: auto auto 0; width: 100%; max-width: 520px; max-height: 92dvh;
    border: 1px solid var(--line-2); border-bottom: 0; border-radius: 22px 22px 0 0;
    background: var(--panel); color: var(--text); padding: 0;
}
.sheet::backdrop { background: rgba(0,0,0,.65); backdrop-filter: blur(3px); }
.sheet[open] { animation: up .25s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@media (min-width: 560px) { .sheet { margin: auto; border-radius: 22px; border-bottom: 1px solid var(--line-2); } }
.sheet-close { position: sticky; top: 0; display: flex; justify-content: flex-end; padding: 8px 8px 0; z-index: 2; }
.sheet-close button {
    width: 36px; height: 36px; border-radius: 50%; border: 0;
    background: var(--panel-2); font-size: 1.3rem; line-height: 1;
}
.sheet-body { padding: 0 18px calc(22px + var(--safe-b)); }
.sheet-img { width: min(72%, 300px); margin: -20px auto 14px; border-radius: 12px; box-shadow: 0 20px 50px rgba(0,0,0,.5); aspect-ratio: 63/88; object-fit: cover; }
.sheet h2 { font-size: 1.3rem; font-weight: 800; text-align: center; }
.sheet .meta { text-align: center; color: var(--muted); font-size: .85rem; font-family: var(--mono); margin: 4px 0 14px; }
.sheet .stepper { height: 48px; max-width: 220px; margin: 0 auto 16px; }
.sheet .stepper output { font-size: 1.1rem; }
.who { margin-top: 14px; }
.who h3 { font-size: .85rem; color: var(--muted); font-weight: 600; margin-bottom: 8px; }
.who ul { list-style: none; display: grid; gap: 6px; }
.who li a {
    display: flex; justify-content: space-between; align-items: center; gap: 10px;
    padding: 10px 12px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--line);
}
.who li a span:last-child { color: var(--yellow); font-size: .85rem; white-space: nowrap; }

/* ---------- Bourse ---------- */
.friend, .trade {
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px;
    display: grid; gap: 12px;
}
.friend header, .trade header { display: flex; align-items: center; gap: 10px; }
.friend header > div, .trade header > div { display: grid; flex: 1; min-width: 0; }
.friend header .avatar, .trade header .avatar { width: 40px; height: 40px; }
.tag {
    font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
    padding: 3px 9px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line-2); color: var(--muted);
    white-space: nowrap;
}
.tag.good, .tag.done { background: rgba(108,255,122,.12); border-color: rgba(108,255,122,.4); color: var(--green); }
.tag.pending { background: rgba(255,203,5,.1); border-color: rgba(255,203,5,.4); color: var(--yellow); }
.tag.accepted { background: rgba(91,184,255,.12); border-color: rgba(91,184,255,.4); color: var(--blue); }
.row h3 { font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.row h3 b { color: var(--text); font-family: var(--mono); }
.thumbs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; align-items: center; }
.thumbs::-webkit-scrollbar { display: none; }
.thumbs img { width: 52px; aspect-ratio: 63/88; object-fit: cover; border-radius: 4px; flex: none; background: var(--panel-2); }
.thumbs .more { font-family: var(--mono); font-size: .8rem; color: var(--muted); padding: 0 6px; flex: none; }

/* ---------- Proposer un échange ---------- */
.trade-head { display: flex; align-items: center; gap: 12px; }
.trade-head .avatar { width: 44px; height: 44px; }
.trade-head .h1 { font-size: 1.35rem; margin: 0; }
.pick { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 560px) { .pick { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.pick-card {
    position: relative; display: grid; gap: 4px; text-align: center;
    border: 2px solid transparent; background: transparent; border-radius: 10px; padding: 3px;
    transition: border-color .15s, transform .1s;
}
.pick-card:active { transform: scale(.97); }
.pick-card img { aspect-ratio: 63/88; width: 100%; object-fit: cover; border-radius: 6px; opacity: .6; transition: opacity .15s; }
.pick-card.wanted img { opacity: .9; }
.pick-card.sel { border-color: var(--yellow); background: rgba(255,203,5,.08); }
.pick-card.sel img { opacity: 1; }
.pick-name { font-size: .72rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pick-flag {
    position: absolute; top: 6px; left: 6px; right: 6px; font-size: .6rem; font-weight: 700;
    background: var(--blue); color: #001a2e; border-radius: 5px; padding: 1px 4px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pick-max { position: absolute; bottom: 24px; left: 6px; font-family: var(--mono); font-size: .6rem; background: rgba(0,0,0,.75); border-radius: 4px; padding: 1px 4px; }
.pick-count {
    position: absolute; top: -6px; right: -6px; width: 28px; height: 28px; border-radius: 50%;
    display: grid; place-items: center; background: var(--yellow); color: var(--yellow-ink);
    font-family: var(--mono); font-weight: 700; font-size: .85rem; box-shadow: 0 2px 8px rgba(0,0,0,.4);
}
.submit-bar {
    position: sticky; bottom: calc(var(--tabbar-h) + var(--safe-b) + 8px); z-index: 5;
    padding-top: 8px;
}
.submit-bar .btn { box-shadow: 0 8px 30px rgba(0,0,0,.6); }

/* ---------- Mes échanges ---------- */
.trade.done, .trade.refused, .trade.cancelled { opacity: .7; }
.msg { font-style: italic; color: var(--muted); font-size: .92rem; }
.swap { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.swap h3 { font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.swap-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 6px; }
.swap-cards figure { display: grid; gap: 3px; }
.swap-cards img { aspect-ratio: 63/88; width: 100%; object-fit: cover; border-radius: 4px; }
.swap-cards figcaption { font-size: .62rem; color: var(--muted); line-height: 1.2; overflow-wrap: anywhere; }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.actions:empty { display: none; }
.actions form { display: contents; }

/* ---------- Barre d'onglets ---------- */
.tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    display: grid; grid-template-columns: repeat(3, 1fr);
    height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
    background: rgba(15,15,21,.92);
    backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--line);
}
.tabbar a {
    position: relative; display: grid; place-content: center; justify-items: center; gap: 3px;
    font-size: .72rem; font-weight: 600; color: var(--faint);
}
.tabbar a.on { color: var(--yellow); }
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar .dot {
    position: absolute; top: 8px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px;
    border-radius: 999px; background: var(--red); color: #fff; font-style: normal;
    font-size: .68rem; font-weight: 700; display: grid; place-items: center;
}
