/* =====================================================================
   RankingMesa — Estilos
   Concepto: una mesa de juego. Fondo de fieltro, cartas de cartulina,
   fichas de colores, dados y trofeos.
   ===================================================================== */

/* ---------- Tokens ---------- */
:root {
    --felt-900: #0d2b22;
    --felt-800: #123a2e;
    --felt-700: #17493a;
    --felt-600: #1f5c49;
    --wood-900: #3b2314;
    --wood-700: #5c3a21;
    --wood-500: #8a5a34;
    --wood-300: #c08a55;

    --paper: #fbf5e6;
    --paper-2: #f3ead2;
    --paper-line: #e6d9b8;
    --ink: #2a1f17;
    --ink-soft: #6b5a4a;
    --ink-faint: #9a8a78;

    --red: #e4572e;
    --yellow: #f3a712;
    --green: #29bf12;
    --blue: #2e86ab;
    --purple: #7b2cbf;
    --pink: #ff6f91;

    --bronce: #c27c3e;
    --plata: #9aa6b2;
    --oro: #e8b931;
    --legendario: #9b5de5;

    --radius-sm: 8px;
    --radius: 14px;
    --radius-lg: 22px;
    --shadow-card: 0 2px 0 rgba(0, 0, 0, .08), 0 10px 24px -8px rgba(0, 0, 0, .45);
    --shadow-tile: 0 4px 0 var(--wood-700), 0 8px 18px -6px rgba(0, 0, 0, .5);

    --font-display: "Lilita One", "Trebuchet MS", system-ui, sans-serif;
    --font-body: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;

    color-scheme: light;
}

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

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

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.55;
    color: var(--paper);
    background-color: var(--felt-800);
    background-image:
        radial-gradient(ellipse at 50% -10%, rgba(255, 255, 255, .09), transparent 60%),
        radial-gradient(circle at 20% 80%, rgba(0, 0, 0, .25), transparent 50%),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .09 0'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)'/%3E%3C/svg%3E");
    background-attachment: fixed;
}

img { max-width: 100%; display: block; }
a { color: inherit; }
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 400; line-height: 1.15; margin: 0 0 .5em; letter-spacing: .3px; }
h1 { font-size: clamp(1.9rem, 4vw, 2.8rem); }
h2 { font-size: clamp(1.4rem, 3vw, 1.85rem); }
h3 { font-size: 1.2rem; }
p { margin: 0 0 1em; }
small, .small { font-size: .85rem; }
hr { border: 0; border-top: 2px dashed var(--paper-line); margin: 1.5rem 0; }
:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; border-radius: 4px; }

.container { width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 16px; }
.main { flex: 1; padding: 28px 0 56px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Utilidades ---------- */
.flex { display: flex; } .items-center { align-items: center; } .justify-between { justify-content: space-between; }
.wrap { flex-wrap: wrap; } .gap-1 { gap: .5rem; } .gap-2 { gap: 1rem; } .gap-3 { gap: 1.5rem; }
.grid { display: grid; gap: 1.25rem; grid-template-columns: minmax(0, 1fr); }
.grid > *, .sheet > *, .admin-layout > *, .hero > * { min-width: 0; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fill, minmax(min(100%, 210px), 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 900px) { .grid-main { grid-template-columns: 1fr; } }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.75rem; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: .5rem; } .mb-2 { margin-bottom: 1rem; } .mb-3 { margin-bottom: 1.75rem; }
.text-center { text-align: center; } .text-right { text-align: right; }
.muted { color: var(--ink-soft); } .faint { color: var(--ink-faint); }
.on-felt-muted { color: rgba(251, 245, 230, .72); }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.hidden { display: none !important; }
.display { font-family: var(--font-display); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Header de madera ---------- */
.site-header {
    position: sticky; top: 0; z-index: 40;
    background:
        repeating-linear-gradient(90deg, rgba(255, 255, 255, .03) 0 2px, transparent 2px 9px),
        linear-gradient(180deg, var(--wood-500), var(--wood-700));
    border-bottom: 4px solid var(--wood-900);
    box-shadow: 0 6px 18px rgba(0, 0, 0, .35);
}
.nav { display: flex; align-items: center; gap: 1rem; min-height: 66px; }
.brand { display: flex; align-items: center; gap: .55rem; text-decoration: none; font-family: var(--font-display); font-size: 1.45rem; color: var(--paper); text-shadow: 0 2px 0 var(--wood-900); flex-shrink: 0; }
.brand svg { width: 38px; height: 38px; filter: drop-shadow(0 2px 0 var(--wood-900)); transition: transform .3s; }
.brand:hover svg { transform: rotate(-12deg) scale(1.08); }
.brand span b { color: var(--yellow); font-weight: 400; }

.nav-links { display: flex; align-items: center; gap: .15rem; list-style: none; margin: 0; padding: 0; flex: 1; }
.nav-links a {
    display: flex; align-items: center; gap: .35rem;
    padding: .45rem .75rem; border-radius: 999px;
    text-decoration: none; font-weight: 800; color: var(--paper);
    transition: background .15s;
}
.nav-links a:hover { background: rgba(0, 0, 0, .18); }
.nav-links a.active { background: var(--paper); color: var(--wood-900); box-shadow: 0 3px 0 var(--wood-900); }
.nav-actions { display: flex; align-items: center; gap: .6rem; margin-left: auto; }
.nav-toggle { display: none; background: none; border: 0; color: var(--paper); font-size: 1.6rem; cursor: pointer; padding: .25rem .5rem; }

.user-menu { position: relative; }
.user-menu > button { display: flex; align-items: center; gap: .4rem; background: rgba(0, 0, 0, .2); border: 2px solid rgba(255, 255, 255, .2); border-radius: 999px; padding: 3px 10px 3px 3px; color: var(--paper); font: inherit; font-weight: 800; cursor: pointer; }
.user-menu .dropdown {
    position: absolute; right: 0; top: calc(100% + 10px); min-width: 220px;
    background: var(--paper); color: var(--ink); border-radius: var(--radius); padding: .5rem;
    box-shadow: var(--shadow-card); display: none;
}
.user-menu.open .dropdown { display: block; animation: pop .18s ease-out; }
.dropdown a, .dropdown button { display: flex; gap: .5rem; width: 100%; padding: .55rem .7rem; border-radius: var(--radius-sm); text-decoration: none; font: inherit; font-weight: 700; color: var(--ink); background: none; border: 0; cursor: pointer; text-align: left; }
.dropdown a:hover, .dropdown button:hover { background: var(--paper-2); }
.dropdown .sep { height: 2px; background: var(--paper-line); margin: .35rem 0; border-radius: 2px; }

@media (max-width: 1020px) {
    .nav-toggle { display: block; }
    .nav-links {
        position: absolute; top: 100%; left: 0; right: 0; flex-direction: column; align-items: stretch;
        background: var(--wood-700); padding: .75rem 16px 1rem; gap: .25rem;
        border-bottom: 4px solid var(--wood-900); display: none;
    }
    .nav-links.open { display: flex; }
    .nav-links a { padding: .7rem 1rem; border-radius: var(--radius-sm); }
    .nav-actions .btn-label { display: none; }
    .nav-toggle { order: 3; }
}
@media (max-width: 480px) {
    .nav { gap: .5rem; }
    .brand { font-size: 1.15rem; gap: .35rem; }
    .brand svg { width: 30px; height: 30px; }
    .nav-actions { gap: .4rem; }
    .nav-actions .btn-sm { padding: .38rem .65rem; }
    .nav-actions .btn-join { display: none; }
}

/* ---------- Botones (fichas) ---------- */
.btn {
    --btn-bg: var(--yellow); --btn-fg: var(--wood-900); --btn-edge: #b37400;
    display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
    padding: .62rem 1.1rem; border-radius: 999px; border: 0;
    font: inherit; font-weight: 900; line-height: 1.1; text-decoration: none; cursor: pointer;
    background: var(--btn-bg); color: var(--btn-fg);
    box-shadow: 0 4px 0 var(--btn-edge), 0 6px 14px -4px rgba(0, 0, 0, .4);
    transition: transform .08s, box-shadow .08s, filter .15s;
    white-space: nowrap;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--btn-edge), 0 2px 6px -2px rgba(0, 0, 0, .4); }
.btn-red { --btn-bg: var(--red); --btn-fg: #fff; --btn-edge: #a53412; }
.btn-blue { --btn-bg: var(--blue); --btn-fg: #fff; --btn-edge: #1b5874; }
.btn-green { --btn-bg: var(--green); --btn-fg: #fff; --btn-edge: #1a7d0b; }
.btn-paper { --btn-bg: var(--paper); --btn-fg: var(--ink); --btn-edge: var(--paper-line); }
.btn-ghost { --btn-bg: transparent; --btn-fg: inherit; --btn-edge: transparent; box-shadow: none; border: 2px solid currentColor; }
.btn-ghost:active { transform: none; box-shadow: none; }
.btn-sm { padding: .4rem .8rem; font-size: .88rem; }
.btn-lg { padding: .85rem 1.5rem; font-size: 1.1rem; }
.btn-block { width: 100%; }
.btn[disabled], .btn.htmx-request { opacity: .6; pointer-events: none; }

/* ---------- Cartas de cartulina ---------- */
.card {
    position: relative;
    background: var(--paper);
    color: var(--ink);
    border-radius: var(--radius);
    padding: 1.35rem;
    box-shadow: var(--shadow-card);
}
.card-tight { padding: 1rem; }
.card-flush { padding: 0; overflow: hidden; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; flex-wrap: wrap; }
.card-title h2, .card-title h3 { margin: 0; }
.card-link { text-decoration: none; display: block; transition: transform .18s, box-shadow .18s; }
.card-link:hover { transform: translateY(-4px) rotate(-.6deg); box-shadow: 0 2px 0 rgba(0, 0, 0, .08), 0 18px 30px -10px rgba(0, 0, 0, .55); }
.card-stripe { position: absolute; inset: 0 0 auto 0; height: 7px; border-radius: var(--radius) var(--radius) 0 0; background: var(--stripe, var(--red)); }

.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin: 2.25rem 0 1rem; }
.section-head h2 { margin: 0; text-shadow: 0 3px 0 rgba(0, 0, 0, .25); }
.section-head p { margin: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.page-head h1 { margin: 0; text-shadow: 0 4px 0 rgba(0, 0, 0, .28); }
.page-head p { margin: .25rem 0 0; }
.eyebrow { font-weight: 900; font-size: .78rem; letter-spacing: .14em; text-transform: uppercase; color: var(--yellow); }

/* ---------- Avatar (ficha de jugador) ---------- */
.avatar {
    --size: 40px;
    width: var(--size); height: var(--size); flex-shrink: 0;
    border-radius: 50%;
    display: inline-grid; place-items: center;
    background: var(--c, var(--red)); color: #fff;
    font-family: var(--font-display); font-size: calc(var(--size) * .4);
    box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .22), 0 0 0 3px var(--paper);
    overflow: hidden; text-decoration: none; text-shadow: 0 1px 0 rgba(0, 0, 0, .25);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-xs { --size: 26px; box-shadow: 0 0 0 2px var(--paper); }
.avatar-sm { --size: 32px; }
.avatar-lg { --size: 72px; }
.avatar-xl { --size: 128px; box-shadow: inset 0 -6px 0 rgba(0, 0, 0, .22), 0 0 0 6px var(--paper), 0 0 0 10px var(--c, var(--red)); }
.avatar-stack { display: flex; }
.avatar-stack .avatar + .avatar { margin-left: -8px; }

.player-chip { display: inline-flex; align-items: center; gap: .45rem; text-decoration: none; font-weight: 800; min-width: 0; }
.player-chip:hover .name { text-decoration: underline; }

/* ---------- Badges ---------- */
.badge {
    display: inline-flex; align-items: center; gap: .3rem;
    padding: .18rem .6rem; border-radius: 999px;
    font-size: .78rem; font-weight: 900; line-height: 1.4;
    background: var(--paper-2); color: var(--ink-soft);
}
.badge-win { background: #fff1c2; color: #8a5a00; }
.badge-admin { background: #dbeafe; color: #1e40af; }
.badge-super { background: #ede0ff; color: #5b21b6; }
.badge-off { background: #fde2e2; color: #9b1c1c; }
.tier { color: #fff; text-shadow: 0 1px 0 rgba(0, 0, 0, .25); }
.tier-bronce { background: var(--bronce); }
.tier-plata { background: var(--plata); }
.tier-oro { background: var(--oro); color: #5a3d00; text-shadow: none; }
.tier-legendario { background: linear-gradient(135deg, var(--legendario), #f15bb5); }
.game-pill { display: inline-flex; align-items: center; gap: .35rem; padding: .2rem .65rem; border-radius: 999px; font-weight: 800; font-size: .85rem; background: color-mix(in srgb, var(--gc, var(--blue)) 16%, white); color: color-mix(in srgb, var(--gc, var(--blue)) 75%, black); text-decoration: none; }

/* ---------- Hero ---------- */
.hero { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 2rem; align-items: center; padding: 1rem 0 1.5rem; }
.hero h1 { font-size: clamp(2.2rem, 5.5vw, 3.6rem); text-shadow: 0 5px 0 rgba(0, 0, 0, .3); margin-bottom: .35em; }
.hero h1 em { font-style: normal; color: var(--yellow); }
.hero .lead { font-size: 1.15rem; color: rgba(251, 245, 230, .85); max-width: 34rem; }
.hero-stats { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: 1.5rem; }
.hero-stat { background: rgba(0, 0, 0, .22); border: 2px solid rgba(255, 255, 255, .12); border-radius: var(--radius); padding: .6rem 1rem; min-width: 104px; }
.hero-stat b { display: block; font-family: var(--font-display); font-size: 1.7rem; font-weight: 400; line-height: 1; color: var(--yellow); }
.hero-stat span { font-size: .82rem; font-weight: 800; color: rgba(251, 245, 230, .75); }
@media (max-width: 860px) { .hero { grid-template-columns: 1fr; } }

/* ---------- Podio ---------- */
.podium { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: end; gap: .75rem; padding-top: 1.5rem; }
.podium-spot { text-align: center; text-decoration: none; display: flex; flex-direction: column; align-items: center; min-width: 0; }
.podium-spot .who { display: flex; flex-direction: column; align-items: center; gap: .35rem; margin-bottom: .6rem; min-width: 0; max-width: 100%; }
.podium-spot .who strong { font-family: var(--font-display); font-weight: 400; font-size: 1.05rem; max-width: 100%; }
.podium-spot .who small { color: var(--yellow); font-weight: 900; }
.podium-block {
    width: 100%; border-radius: 12px 12px 4px 4px;
    display: grid; place-items: center;
    font-family: var(--font-display); font-size: 2.4rem; color: rgba(0, 0, 0, .35);
    box-shadow: inset 0 -8px 0 rgba(0, 0, 0, .18), inset 0 4px 0 rgba(255, 255, 255, .25);
}
.podium-1 { order: 2; } .podium-2 { order: 1; } .podium-3 { order: 3; }
.podium-1 .podium-block { height: 150px; background: var(--oro); }
.podium-2 .podium-block { height: 110px; background: var(--plata); }
.podium-3 .podium-block { height: 80px; background: var(--bronce); }
.podium-1 .crown { font-size: 2rem; line-height: 1; animation: bob 2.4s ease-in-out infinite; }
.podium-empty .avatar { opacity: .35; }

/* ---------- Tabla tipo hoja de puntuación ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.score-table { width: 100%; border-collapse: collapse; min-width: 560px; }
.score-table th { text-align: left; font-size: .75rem; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-soft); padding: .8rem .9rem; border-bottom: 3px double var(--paper-line); font-weight: 900; }
.score-table td { padding: .7rem .9rem; border-bottom: 1px solid var(--paper-line); vertical-align: middle; }
.score-table tbody tr { transition: background .12s; }
.score-table tbody tr:hover { background: rgba(243, 167, 18, .08); }
.score-table .rank { width: 64px; }
.score-table .pts { font-family: var(--font-display); font-size: 1.25rem; color: var(--wood-700); }
.rank-token {
    width: 38px; height: 38px; display: inline-grid; place-items: center;
    border-radius: 10px; font-family: var(--font-display); font-size: 1.05rem;
    background: var(--paper-2); color: var(--ink-soft);
    box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .1);
}
.rank-1 .rank-token { background: var(--oro); color: #5a3d00; transform: rotate(-6deg); }
.rank-2 .rank-token { background: var(--plata); color: #fff; transform: rotate(4deg); }
.rank-3 .rank-token { background: var(--bronce); color: #fff; transform: rotate(-3deg); }
.me-row { background: rgba(46, 134, 171, .08); }

.meter { height: 9px; background: var(--paper-2); border-radius: 999px; overflow: hidden; min-width: 60px; box-shadow: inset 0 1px 2px rgba(0, 0, 0, .1); }
.meter > span { display: block; height: 100%; border-radius: inherit; background: var(--mc, var(--green)); }
.meter-lg { height: 14px; }

/* ---------- Filtros (segmentado) ---------- */
.filters { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; margin-bottom: 1.25rem; }
.segmented { display: inline-flex; background: rgba(0, 0, 0, .25); border-radius: 999px; padding: 4px; gap: 2px; flex-wrap: wrap; }
.segmented a, .segmented button { padding: .4rem .9rem; border-radius: 999px; text-decoration: none; font-weight: 800; color: rgba(251, 245, 230, .85); background: none; border: 0; font: inherit; cursor: pointer; }
.segmented a.active, .segmented button.active { background: var(--paper); color: var(--ink); }
.seg-radio { position: relative; cursor: pointer; }
.seg-radio input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.seg-radio span { display: block; padding: .4rem .9rem; border-radius: 999px; font-weight: 800; color: rgba(251, 245, 230, .85); }
.seg-radio input:checked + span { background: var(--paper); color: var(--ink); }
.seg-radio input:focus-visible + span { outline: 3px solid var(--yellow); outline-offset: 2px; }
.select-felt { appearance: none; background: rgba(0, 0, 0, .25) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23fbf5e6' stroke-width='2' fill='none'/%3E%3C/svg%3E") no-repeat right 14px center; color: var(--paper); border: 2px solid rgba(255, 255, 255, .15); border-radius: 999px; padding: .5rem 2.4rem .5rem 1rem; font: inherit; font-weight: 800; cursor: pointer; max-width: 100%; }
.select-felt option { color: var(--ink); background: var(--paper); }

/* ---------- Partidas ---------- */
.match-list { display: grid; gap: .85rem; }
.match-card { display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; gap: 1rem; align-items: center; padding: .9rem 1.1rem; text-decoration: none; }
.match-icon { width: 56px; height: 56px; border-radius: 14px; display: grid; place-items: center; font-size: 1.8rem; background: color-mix(in srgb, var(--gc, var(--blue)) 18%, white); box-shadow: inset 0 -4px 0 color-mix(in srgb, var(--gc, var(--blue)) 30%, transparent); }
.match-meta { display: flex; flex-wrap: wrap; gap: .35rem .9rem; font-size: .85rem; color: var(--ink-soft); }
.match-winners { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; margin-top: .3rem; font-weight: 800; }
.match-side { text-align: right; }
@media (max-width: 560px) {
    .match-card { grid-template-columns: 44px minmax(0, 1fr); }
    .match-icon { width: 44px; height: 44px; font-size: 1.4rem; }
    .match-side { grid-column: 1 / -1; text-align: left; display: flex; align-items: center; gap: .5rem; }
}

.feed { list-style: none; margin: 0; padding: 0; display: grid; gap: .25rem; }
.feed li { display: flex; gap: .75rem; align-items: center; padding: .55rem 0; border-bottom: 1px dashed var(--paper-line); min-width: 0; }
.feed li:last-child { border-bottom: 0; }
.feed .feed-icon { font-size: 1.5rem; width: 42px; height: 42px; display: grid; place-items: center; background: var(--paper-2); border-radius: 12px; flex-shrink: 0; }
.feed .feed-body { min-width: 0; flex: 1; }

/* ---------- Juegos (cajas) ---------- */
.game-box { overflow: hidden; padding: 0; height: 100%; display: flex; flex-direction: column; }
.game-cover {
    height: 140px; display: grid; place-items: center; font-size: 4rem; position: relative;
    background:
        repeating-linear-gradient(45deg, rgba(255, 255, 255, .08) 0 12px, transparent 12px 24px),
        linear-gradient(160deg, color-mix(in srgb, var(--gc) 85%, white), var(--gc));
    text-shadow: 0 6px 12px rgba(0, 0, 0, .25);
}
.game-cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.game-body { padding: 1rem 1.15rem 1.15rem; flex: 1; display: flex; flex-direction: column; gap: .4rem; }
.game-body h3 { margin: 0; }
.game-facts { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: auto; padding-top: .5rem; }
.game-hero { border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-card); margin-bottom: 1.5rem; }
.game-hero .game-cover { height: 220px; font-size: 6rem; }
.game-hero .game-body { background: var(--paper); color: var(--ink); padding: 1.5rem; }

/* ---------- Logros / trofeos ---------- */
.trophy-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); }
.trophy { display: flex; gap: .9rem; align-items: flex-start; padding: 1rem; position: relative; }
.medal {
    --tc: var(--bronce);
    width: 62px; height: 62px; flex-shrink: 0; border-radius: 50%;
    display: grid; place-items: center; font-size: 1.85rem;
    background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--tc) 40%, white), var(--tc) 70%);
    box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .2), 0 0 0 4px color-mix(in srgb, var(--tc) 35%, white), 0 6px 14px -4px rgba(0, 0, 0, .4);
    position: relative;
}
.medal-plata { --tc: var(--plata); } .medal-oro { --tc: var(--oro); } .medal-legendario { --tc: var(--legendario); }
.medal-legendario::after { content: ""; position: absolute; inset: -6px; border-radius: 50%; border: 2px dashed var(--legendario); animation: spin 12s linear infinite; }
.trophy h4 { font-family: var(--font-display); font-weight: 400; font-size: 1.05rem; margin: 0 0 .15rem; }
.trophy p { margin: 0; font-size: .88rem; color: var(--ink-soft); }
.trophy .trophy-foot { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .5rem; align-items: center; }
.trophy.locked .medal { filter: grayscale(1) brightness(1.15); opacity: .55; }
.trophy.locked h4 { color: var(--ink-soft); }
.trophy.unlocked { box-shadow: 0 0 0 3px var(--yellow), var(--shadow-card); }
.trophy .progress-label { font-size: .75rem; font-weight: 800; color: var(--ink-faint); }

.shelf { display: flex; flex-wrap: wrap; gap: .9rem; padding: 1rem 1rem 1.4rem; border-radius: var(--radius); background: linear-gradient(180deg, transparent 72%, var(--wood-500) 72%, var(--wood-700)); }
.shelf .medal { width: 54px; height: 54px; font-size: 1.6rem; cursor: help; transition: transform .2s; }
.shelf .medal:hover { transform: translateY(-6px) rotate(-8deg); }

/* ---------- Hoja de vida ---------- */
.sheet { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 1.5rem; align-items: start; }
@media (max-width: 900px) { .sheet { grid-template-columns: 1fr; } }
.sheet-id { text-align: center; padding-top: 2rem; background: var(--paper); border: 3px dashed var(--paper-line); background-clip: padding-box; }
.sheet-id .avatar-xl { margin: 0 auto 1rem; }
.sheet-id h1 { font-size: 1.9rem; margin-bottom: .1rem; color: var(--ink); }
.sheet-id .handle { color: var(--ink-faint); font-weight: 800; }
.sheet-id .motto { font-style: italic; color: var(--ink-soft); margin: .9rem 0; }
.level-box { background: var(--paper-2); border-radius: var(--radius); padding: .9rem; text-align: left; margin-top: 1rem; }
.level-box .level-title { font-family: var(--font-display); font-size: 1.15rem; display: flex; align-items: center; gap: .45rem; }
.level-box .level-next { font-size: .8rem; color: var(--ink-soft); margin-top: .35rem; }
.rank-badge { display: inline-flex; flex-direction: column; align-items: center; background: var(--felt-700); color: var(--paper); border-radius: var(--radius); padding: .5rem 1rem; box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .25); }
.rank-badge b { font-family: var(--font-display); font-weight: 400; font-size: 1.8rem; line-height: 1; color: var(--yellow); }
.rank-badge span { font-size: .72rem; font-weight: 900; letter-spacing: .1em; text-transform: uppercase; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 140px), 1fr)); gap: .75rem; }
.stat-tile { background: var(--paper-2); border-radius: var(--radius); padding: .85rem 1rem; position: relative; overflow: hidden; }
.stat-tile .label { font-size: .74rem; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); }
.stat-tile .value { font-family: var(--font-display); font-size: 1.85rem; line-height: 1.1; color: var(--ink); }
.stat-tile .hint { font-size: .8rem; color: var(--ink-faint); }
.stat-tile .deco { position: absolute; right: -6px; bottom: -12px; font-size: 3.2rem; opacity: .14; transform: rotate(-12deg); }

.rival { display: flex; align-items: center; gap: .75rem; padding: .8rem; border-radius: var(--radius); background: var(--paper-2); text-decoration: none; min-width: 0; }
.rival .label { font-size: .72rem; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); }

.tabs { display: flex; gap: .35rem; border-bottom: 3px solid var(--paper-line); margin-bottom: 1.1rem; overflow-x: auto; }
.tabs button { background: none; border: 0; font: inherit; font-weight: 900; color: var(--ink-soft); padding: .6rem 1rem; border-radius: var(--radius-sm) var(--radius-sm) 0 0; cursor: pointer; white-space: nowrap; margin-bottom: -3px; border-bottom: 3px solid transparent; }
.tabs button.active { color: var(--ink); border-bottom-color: var(--red); background: var(--paper-2); }
[data-tab-panel] { display: none; }
[data-tab-panel].active { display: block; animation: fade .2s; }

/* ---------- Tarjetas de jugadores ---------- */
.player-card { text-align: center; padding: 1.5rem 1rem 1.1rem; height: 100%; }
.player-card .avatar { margin: 0 auto .75rem; }
.player-card h3 { margin: 0; }
.player-card .pos { position: absolute; top: 12px; left: 12px; }
.player-card .mini-stats { display: flex; justify-content: center; gap: 1rem; margin-top: .9rem; padding-top: .9rem; border-top: 2px dashed var(--paper-line); }
.player-card .mini-stats div { display: flex; flex-direction: column; font-size: .74rem; font-weight: 800; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .05em; }
.player-card .mini-stats b { font-family: var(--font-display); font-weight: 400; font-size: 1.3rem; color: var(--ink); letter-spacing: 0; }

/* ---------- Formularios ---------- */
.form { display: grid; gap: 1.1rem; }
.form-row { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); }
.field { display: grid; gap: .35rem; min-width: 0; }
.field label, .label { font-weight: 900; font-size: .9rem; color: var(--ink); }
.field .help { font-size: .8rem; color: var(--ink-faint); }
.input, .textarea, .select {
    width: 100%; font: inherit; color: var(--ink);
    background: #fff; border: 2px solid var(--paper-line); border-radius: var(--radius-sm);
    padding: .65rem .8rem; transition: border-color .15s, box-shadow .15s;
}
.input:focus, .textarea:focus, .select:focus { outline: 0; border-color: var(--blue); box-shadow: 0 0 0 4px rgba(46, 134, 171, .2); }
.textarea { min-height: 110px; resize: vertical; }
.input-color { padding: 4px; height: 44px; cursor: pointer; }
.check { display: inline-flex; align-items: center; gap: .55rem; font-weight: 800; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--red); }
.form-actions { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; padding-top: .5rem; }

.swatches { display: flex; flex-wrap: wrap; gap: .5rem; }
.swatches label { position: relative; cursor: pointer; }
.swatches input { position: absolute; opacity: 0; }
.swatches span { display: block; width: 36px; height: 36px; border-radius: 50%; background: var(--c); box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .2); transition: transform .12s; }
.swatches input:checked + span { transform: scale(1.12); box-shadow: 0 0 0 3px var(--paper), 0 0 0 6px var(--ink); }
.swatches input:focus-visible + span { outline: 3px solid var(--yellow); outline-offset: 3px; }

.dropzone { border: 3px dashed var(--paper-line); border-radius: var(--radius); padding: 1rem; display: flex; align-items: center; gap: 1rem; cursor: pointer; transition: border-color .15s, background .15s; }
.dropzone.dragover { border-color: var(--blue); background: rgba(46, 134, 171, .06); }
.dropzone input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; }
.dropzone .preview { width: 72px; height: 72px; border-radius: 50%; overflow: hidden; background: var(--paper-2); display: grid; place-items: center; font-size: 1.8rem; flex-shrink: 0; }
.dropzone .preview img { width: 100%; height: 100%; object-fit: cover; }
.dropzone.square .preview { border-radius: var(--radius-sm); width: 110px; }

/* Selector de jugadores para partidas */
.picker { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr)); }
.pick {
    display: flex; align-items: center; gap: .6rem; padding: .55rem .7rem;
    border: 2px solid var(--paper-line); border-radius: 999px; background: #fff;
    cursor: pointer; user-select: none; transition: border-color .12s, background .12s, transform .12s;
    min-width: 0;
}
.pick:hover { border-color: var(--wood-300); }
.pick .name { flex: 1; font-weight: 800; }
.pick .crown { width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--paper-2); font-size: 1.1rem; cursor: pointer; filter: grayscale(1); opacity: .45; transition: all .15s; flex-shrink: 0; display: none; }
.pick.selected { border-color: var(--blue); background: rgba(46, 134, 171, .07); }
.pick.selected .crown { display: grid; place-items: center; }
.pick.winner { border-color: var(--oro); background: #fff8dc; }
.pick.winner .crown { filter: none; opacity: 1; background: var(--oro); transform: rotate(-12deg) scale(1.1); }
.picker-summary { display: flex; flex-wrap: wrap; gap: .5rem 1rem; font-weight: 800; font-size: .9rem; color: var(--ink-soft); }

.game-options { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr)); }
.game-option { position: relative; cursor: pointer; }
.game-option input { position: absolute; opacity: 0; }
.game-option .box { display: flex; flex-direction: column; align-items: center; gap: .25rem; padding: .8rem .5rem; border: 2px solid var(--paper-line); border-radius: var(--radius); background: #fff; text-align: center; font-weight: 800; font-size: .9rem; transition: all .12s; height: 100%; }
.game-option .box .ico { font-size: 1.9rem; }
.game-option .box small { color: var(--ink-faint); font-weight: 700; }
.game-option input:checked + .box { border-color: var(--gc); background: color-mix(in srgb, var(--gc) 12%, white); box-shadow: 0 4px 0 var(--gc); transform: translateY(-2px); }
.game-option input:focus-visible + .box { outline: 3px solid var(--yellow); outline-offset: 2px; }

/* ---------- Auth ---------- */
.auth-wrap { max-width: 440px; margin: 2rem auto; }
.auth-card { padding: 2rem; }
.auth-card .dice-row { display: flex; justify-content: center; gap: .5rem; font-size: 2rem; margin-bottom: .5rem; }

/* ---------- Toasts / flash ---------- */
.toasts { position: fixed; z-index: 90; right: 16px; bottom: 16px; left: 16px; display: flex; flex-direction: column; align-items: flex-end; gap: .6rem; pointer-events: none; }
.toast {
    pointer-events: auto; max-width: 420px; width: 100%;
    display: flex; gap: .75rem; align-items: flex-start;
    background: var(--paper); color: var(--ink); border-radius: var(--radius);
    padding: .85rem 1rem; box-shadow: 0 14px 30px -8px rgba(0, 0, 0, .55);
    border-left: 7px solid var(--blue);
    animation: slide-in .35s cubic-bezier(.2, 1.4, .4, 1);
}
.toast .t-icon { font-size: 1.35rem; line-height: 1.2; }
.toast .t-body { flex: 1; font-weight: 700; word-break: break-word; }
.toast button { background: none; border: 0; font-size: 1.2rem; cursor: pointer; color: var(--ink-faint); line-height: 1; padding: 0 .25rem; }
.toast-success { border-color: var(--green); }
.toast-danger { border-color: var(--red); }
.toast-warning { border-color: var(--yellow); }
.toast-achievement { border-color: var(--oro); background: linear-gradient(135deg, #fff8dc, var(--paper)); }
.toast-achievement .t-title { font-family: var(--font-display); font-size: .8rem; letter-spacing: .1em; text-transform: uppercase; color: #8a5a00; }
.toast.leaving { animation: slide-out .25s forwards; }

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 95; overflow: hidden; }
.confetti i { position: absolute; top: -20px; width: 10px; height: 14px; border-radius: 2px; animation: fall linear forwards; }

/* ---------- Paginación ---------- */
.pagination { display: flex; justify-content: center; flex-wrap: wrap; gap: .4rem; margin-top: 1.5rem; }
.pagination a, .pagination span { min-width: 40px; height: 40px; display: grid; place-items: center; border-radius: 10px; font-weight: 900; text-decoration: none; background: rgba(0, 0, 0, .22); color: var(--paper); padding: 0 .6rem; }
.pagination .current { background: var(--paper); color: var(--ink); }

/* ---------- Estado vacío ---------- */
.empty { text-align: center; padding: 2.5rem 1rem; }
.empty .big { font-size: 3.4rem; display: block; margin-bottom: .5rem; animation: bob 3s ease-in-out infinite; }
.empty h3 { margin-bottom: .3rem; }

/* ---------- Admin ---------- */
.admin-layout { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 1.5rem; align-items: start; }
.admin-nav { position: sticky; top: 90px; padding: .75rem; }
.admin-nav a { display: flex; align-items: center; gap: .6rem; padding: .6rem .8rem; border-radius: var(--radius-sm); text-decoration: none; font-weight: 800; color: var(--ink); }
.admin-nav a:hover { background: var(--paper-2); }
.admin-nav a.active { background: var(--felt-700); color: var(--paper); }
@media (max-width: 860px) {
    .admin-layout { grid-template-columns: 1fr; }
    .admin-nav { position: static; display: flex; overflow-x: auto; gap: .25rem; }
    .admin-nav a { white-space: nowrap; }
}
.kpis { display: grid; gap: .9rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 160px), 1fr)); }
.row-msg { font-size: .78rem; font-weight: 800; display: block; margin-top: .2rem; }
.row-msg.ok { color: #1a7d0b; } .row-msg.err { color: #b42318; }
.inline-form { display: inline; }
.actions-cell { display: flex; flex-wrap: wrap; gap: .35rem; justify-content: flex-end; }
.select-sm { padding: .35rem .5rem; font-size: .88rem; width: auto; }

/* ---------- Footer ---------- */
.site-footer { padding: 1.75rem 0; color: rgba(251, 245, 230, .6); font-size: .9rem; border-top: 2px dashed rgba(255, 255, 255, .12); }
.site-footer .container { display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; justify-content: space-between; align-items: center; }

/* ---------- Error ---------- */
.error-page { text-align: center; padding: 3rem 1rem; }
.error-page .code { font-family: var(--font-display); font-size: clamp(5rem, 18vw, 9rem); line-height: 1; color: var(--yellow); text-shadow: 0 8px 0 rgba(0, 0, 0, .3); }

/* ---------- Dado decorativo ---------- */
.die { width: 46px; height: 46px; border-radius: 10px; background: var(--paper); display: inline-grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); padding: 7px; box-shadow: inset 0 -4px 0 var(--paper-line), 0 4px 10px rgba(0, 0, 0, .3); cursor: pointer; border: 0; vertical-align: middle; }
.die i { width: 8px; height: 8px; border-radius: 50%; background: var(--ink); place-self: center; visibility: hidden; }
.die.rolling { animation: roll .6s ease-out; }

/* ---------- Animaciones ---------- */
@keyframes pop { from { opacity: 0; transform: translateY(-6px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes roll { 0% { transform: rotate(0) scale(1); } 50% { transform: rotate(200deg) scale(1.2); } 100% { transform: rotate(360deg) scale(1); } }
@keyframes slide-in { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: none; } }
@keyframes slide-out { to { opacity: 0; transform: translateX(40px); } }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

.htmx-indicator { opacity: 0; transition: opacity .2s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }
.htmx-swapping { opacity: .4; transition: opacity .15s; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
