/* ============================
   Loopix Play - Main Stylesheet
   ============================ */

:root {
    --primary: #667eea;
    --primary-dark: #5a6fd6;
    --secondary: #764ba2;
    --bg: #0f0f1a;
    --bg-card: #1a1a2e;
    --bg-card-hover: #222240;
    --bg-surface: #16162a;
    --text: #e0e0e0;
    --text-muted: #888;
    --text-heading: #fff;
    --border: #2a2a4a;
    --discord: #5865F2;
    --gold: #ffd700;
    --silver: #c0c0c0;
    --bronze: #cd7f32;
    --success: #4caf50;
    --error: #ef5350;
    --radius: 10px;
    --radius-sm: 6px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

.container { max-width: 1200px; margin: 0 auto; padding: 0 1rem; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }

/* ---- Header ---- */
.site-header {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 100;
}

.navbar {
    max-width: 1200px; margin: 0 auto;
    display: flex; align-items: center;
    padding: 0.75rem 1rem; gap: 1.5rem;
}

.nav-logo {
    display: flex; align-items: center; gap: 0.5rem;
    font-size: 1.3rem; font-weight: 700;
    color: var(--text-heading);
    text-decoration: none;
}
.logo-icon { font-size: 1.5rem; }
.logo-img { display: block; width: 36px; height: 36px; border-radius: 8px; }
.hero-logo {
    display: block;
    max-width: 420px; width: 80%; height: auto;
    margin: 0 auto 1rem;
    filter: drop-shadow(0 8px 32px rgba(102, 126, 234, 0.35));
}
.sr-only {
    position: absolute; width: 1px; height: 1px;
    padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

.nav-links { display: flex; gap: 1rem; }
.nav-link {
    color: var(--text-muted); font-weight: 500;
    padding: 0.4rem 0.8rem; border-radius: var(--radius-sm);
    transition: all 0.2s;
}
.nav-link:hover { color: var(--text-heading); background: var(--bg-card); }

.nav-user { margin-left: auto; display: flex; align-items: center; gap: 0.75rem; }
.user-info { display: flex; align-items: center; gap: 0.5rem; color: var(--text); }
.nav-avatar { width: 32px; height: 32px; border-radius: 50%; }
.nav-username { font-weight: 500; }

/* ---- Buttons ---- */
.btn {
    display: inline-flex; align-items: center; gap: 0.5rem;
    padding: 0.6rem 1.2rem; font-size: 0.95rem;
    border: none; border-radius: var(--radius-sm);
    cursor: pointer; font-weight: 600;
    transition: all 0.2s; text-decoration: none;
    color: #fff;
}
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.85rem; }
.btn-lg { padding: 0.8rem 2rem; font-size: 1.1rem; }
.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
}
.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }
.btn-outline {
    background: transparent; border: 1px solid var(--border);
    color: var(--text);
}
.btn-outline:hover { background: var(--bg-card); border-color: var(--primary); color: var(--primary); }
.btn-discord { background: var(--discord); }
.btn-discord:hover { background: #4752c4; }

/* ---- Hero ---- */
.hero {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    padding: 4rem 1rem; text-align: center; color: #fff;
}
.hero h1 { font-size: 3rem; margin-bottom: 0.5rem; }
.hero-subtitle { font-size: 1.2rem; opacity: 0.9; margin-bottom: 1.5rem; }

/* ---- Sections ---- */
.section { margin-bottom: 2rem; }
.section-title {
    font-size: 1.4rem; color: var(--text-heading);
    margin-bottom: 1rem; padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--border);
}
.page-title { font-size: 1.8rem; color: var(--text-heading); margin-bottom: 1.5rem; }

/* ---- Categories Grid ---- */
.categories-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
}
.category-card {
    display: flex; flex-direction: column; align-items: center;
    padding: 1rem; background: var(--bg-card);
    border: 1px solid var(--border); border-radius: var(--radius);
    text-decoration: none; color: var(--text);
    transition: all 0.2s; text-align: center;
}
.category-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--primary); transform: translateY(-2px);
}
.category-icon { font-size: 2rem; margin-bottom: 0.3rem; }
.category-name { font-weight: 600; font-size: 0.9rem; }
.category-count { font-size: 0.8rem; color: var(--text-muted); }

/* ---- Games Grid ---- */
.games-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}
.game-card {
    display: flex; flex-direction: column;
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); overflow: hidden;
    text-decoration: none; color: var(--text);
    transition: all 0.2s;
}
.game-card:hover {
    border-color: var(--primary); transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.15);
}
.game-card-preview {
    height: 140px; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #1a1a3e, #2a2a4e);
    position: relative; overflow: hidden;
}
.game-card-icon { font-size: 3rem; opacity: 0.6; }
.game-card-thumb {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    object-fit: cover; z-index: 1;
}
.game-card-letter {
    font-size: 3rem; font-weight: 900; color: rgba(255,255,255,0.85);
    text-shadow: 0 2px 8px rgba(0,0,0,0.3);
    user-select: none;
}
.game-card-placeholder {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 0.4rem; padding: 0.5rem; text-align: center;
    user-select: none;
}
.game-card-emoji {
    font-size: 2.6rem;
    filter: drop-shadow(0 2px 6px rgba(0,0,0,0.35));
}
.game-card-name {
    font-size: 0.85rem; font-weight: 700; color: #fff;
    text-shadow: 0 1px 4px rgba(0,0,0,0.5);
    line-height: 1.2; max-width: 90%;
    overflow: hidden; display: -webkit-box;
    -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
/* Hide placeholder when thumbnail image is present (img is z-index 1) */
.game-card-thumb:not([style*="display: none"]) ~ .game-card-placeholder { display: none; }
.game-card-info { padding: 0.75rem; }
.game-card-title { font-size: 0.95rem; font-weight: 600; color: var(--text-heading); margin-bottom: 0.3rem; }
.game-card-meta { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.game-card-plays { font-size: 0.75rem; color: var(--text-muted); }

/* ---- Badges ---- */
.badge {
    display: inline-block; padding: 0.15rem 0.5rem;
    font-size: 0.7rem; font-weight: 600;
    border-radius: 20px; text-transform: uppercase;
}
.badge-category { background: var(--primary); color: #fff; opacity: 0.8; }

/* ---- Filters ---- */
.filters-bar { margin-bottom: 1.5rem; }
.category-tabs, .sort-tabs {
    display: flex; gap: 0.3rem; flex-wrap: wrap;
    margin-bottom: 1rem;
}
.tab {
    padding: 0.4rem 0.8rem; font-size: 0.85rem;
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text-muted);
    text-decoration: none; white-space: nowrap;
    transition: all 0.2s;
}
.tab:hover { border-color: var(--primary); color: var(--text); }
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.search-bar input {
    width: 100%; max-width: 400px; padding: 0.5rem 1rem;
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text);
    font-size: 0.9rem;
}
.search-bar input:focus { outline: none; border-color: var(--primary); }

/* ---- Pagination ---- */
.pagination {
    display: flex; align-items: center; justify-content: center;
    gap: 1rem; margin-top: 2rem;
}
.pagination-info { color: var(--text-muted); font-size: 0.9rem; }

/* ---- Leaderboard Table ---- */
.leaderboard-table {
    width: 100%; border-collapse: collapse;
    background: var(--bg-card); border-radius: var(--radius);
    overflow: hidden;
}
.leaderboard-table th {
    background: var(--bg-surface); padding: 0.75rem;
    text-align: left; font-size: 0.85rem;
    color: var(--text-muted); text-transform: uppercase;
    border-bottom: 1px solid var(--border);
}
.leaderboard-table td {
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--border);
}
.leaderboard-table tr:last-child td { border-bottom: none; }
.leaderboard-table .rank { width: 50px; text-align: center; font-weight: 700; font-size: 1.1rem; }
.leaderboard-table .player { display: flex; align-items: center; gap: 0.5rem; }
.player-avatar { width: 28px; height: 28px; border-radius: 50%; }
.leaderboard-table .score { font-weight: 700; color: var(--primary); }
.leaderboard-table .date { color: var(--text-muted); font-size: 0.85rem; }
.top-1 { background: rgba(255, 215, 0, 0.08); }
.top-2 { background: rgba(192, 192, 192, 0.06); }
.top-3 { background: rgba(205, 127, 50, 0.06); }

/* ---- Game Player Page ---- */
.game-page-header {
    display: flex; align-items: center; gap: 1rem;
    margin-bottom: 1.5rem; flex-wrap: wrap;
}

.game-layout {
    display: grid; grid-template-columns: 1fr 300px;
    gap: 1.5rem;
}

.game-player-container {
    background: #000; border-radius: var(--radius);
    overflow: hidden; aspect-ratio: 4/3;
    display: flex; align-items: center; justify-content: center;
}

.ruffle-container {
    width: 100%; height: 100%;
}

.game-controls {
    display: flex; gap: 0.5rem; margin-top: 0.75rem;
}

.score-panel {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1rem;
    margin-top: 1rem;
}
.score-panel h3 { font-size: 1rem; margin-bottom: 0.75rem; color: var(--text-heading); }
.score-display { text-align: center; margin-bottom: 0.75rem; }
.score-value {
    font-size: 2rem; font-weight: 700;
    color: var(--primary); font-variant-numeric: tabular-nums;
}
.score-value.score-captured { color: var(--success); }
.score-form { display: flex; gap: 0.5rem; }
.score-form input {
    flex: 1; padding: 0.5rem; background: var(--bg-surface);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    color: var(--text); font-size: 0.9rem;
}
.score-form input:focus { outline: none; border-color: var(--primary); }
.score-status { font-size: 0.85rem; margin-top: 0.5rem; }
.score-status.success { color: var(--success); }
.score-status.error { color: var(--error); }
.score-status.auto { color: var(--gold); }

.login-prompt {
    text-align: center; padding: 1rem;
}
.login-prompt p { margin-bottom: 0.75rem; color: var(--text-muted); }

.game-sidebar {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1rem;
    height: fit-content;
}
.game-sidebar h3 { font-size: 1rem; margin-bottom: 0.75rem; color: var(--text-heading); }

/* ---- Two Columns ---- */
.two-columns {
    display: grid; grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

/* ---- Activity Feed ---- */
.activity-feed { display: flex; flex-direction: column; gap: 0.5rem; }
.activity-item {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.5rem; background: var(--bg-surface);
    border-radius: var(--radius-sm);
}
.activity-avatar { width: 28px; height: 28px; border-radius: 50%; }
.activity-text { font-size: 0.85rem; }

/* ---- Stats Grid ---- */
.stats-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.75rem;
}
.stat-card {
    display: flex; flex-direction: column; align-items: center;
    padding: 1rem; background: var(--bg-card);
    border: 1px solid var(--border); border-radius: var(--radius);
}
.stat-value { font-size: 1.8rem; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; }

/* ---- Profile ---- */
.profile-header {
    display: flex; align-items: center; gap: 1.5rem;
    margin-bottom: 2rem;
}
.profile-avatar { width: 80px; height: 80px; border-radius: 50%; border: 3px solid var(--primary); }

.score-list { display: flex; flex-direction: column; gap: 0.3rem; }
.score-list-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0.5rem 0.75rem; background: var(--bg-surface);
    border-radius: var(--radius-sm);
}
.score-list-item .score { font-weight: 600; color: var(--primary); }

/* ---- Error Page ---- */
.error-code { font-size: 5rem; color: var(--primary); opacity: 0.5; }
.error-message { font-size: 1.2rem; color: var(--text-muted); margin: 1rem 0 2rem; }

/* ---- Footer ---- */
.site-footer {
    margin-top: 3rem; padding: 1.5rem;
    text-align: center; color: var(--text-muted);
    font-size: 0.85rem; border-top: 1px solid var(--border);
}
.site-footer a { color: var(--primary); }

/* ---- Game Modal ---- */
.game-modal {
    display: none; position: fixed; inset: 0;
    z-index: 10000;
}
.game-modal.active { display: flex; align-items: center; justify-content: center; }

.game-modal-overlay {
    position: absolute; inset: 0;
    background: rgba(0,0,0,0.85);
    backdrop-filter: blur(4px);
}

.game-modal-content {
    position: relative; z-index: 1;
    width: 95vw; max-width: 1300px;
    height: 90vh; max-height: 800px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex; flex-direction: column;
    overflow: hidden;
    box-shadow: 0 25px 60px rgba(0,0,0,0.5);
}

.game-modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.game-modal-header h2 {
    font-size: 1.1rem; color: var(--text-heading);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    margin-right: 1rem;
}
.game-modal-header-actions {
    display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0;
}
.game-modal-close {
    background: none; border: none; color: var(--text-muted);
    font-size: 1.8rem; cursor: pointer; padding: 0 0.3rem;
    line-height: 1; transition: color 0.2s;
}
.game-modal-close:hover { color: var(--error); }

.game-modal-body {
    display: grid; grid-template-columns: 1fr 280px;
    flex: 1; overflow: hidden;
}

.game-modal-player {
    position: relative;
    background: #000;
    display: flex; align-items: center; justify-content: center;
    overflow: hidden;
}
.game-modal-player .ruffle-container {
    width: 100%; height: 100%;
}

.game-modal-loading {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-muted); font-size: 1.1rem;
    background: rgba(0,0,0,0.8);
    z-index: 2;
}

.game-modal-sidebar {
    display: flex; flex-direction: column;
    overflow-y: auto;
    border-left: 1px solid var(--border);
    background: var(--bg-card);
}

.game-modal-score {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border);
}
.game-modal-score h3 {
    font-size: 0.9rem; color: var(--text-heading);
    margin-bottom: 0.5rem;
}

.game-modal-leaderboard {
    padding: 0.75rem; flex: 1;
}
.game-modal-leaderboard h3 {
    font-size: 0.9rem; color: var(--text-heading);
    margin-bottom: 0.5rem;
}

.leaderboard-mini { font-size: 0.8rem; }
.leaderboard-mini td { padding: 0.35rem 0.5rem; }
.leaderboard-mini .rank { width: 35px; font-size: 0.9rem; }
.leaderboard-mini .player-avatar { width: 22px; height: 22px; }

/* Game card thumbnail image */
.game-card-thumb {
    width: 100%; height: 100%;
    object-fit: cover;
}

/* ---- Admin page ---- */
.admin-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin: 1.5rem 0 2rem;
}
.admin-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    text-align: center;
}
.admin-card-value {
    font-size: 2rem; font-weight: 800;
    color: var(--primary);
    line-height: 1.1;
}
.admin-card-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.4rem;
}
.admin-section {
    margin: 2rem 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}
.admin-section h2 {
    color: var(--text-heading);
    margin-bottom: 1rem;
    font-size: 1.3rem;
}
.disabled-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 0.5rem;
}
.disabled-item {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
    display: flex; flex-direction: column; gap: 0.3rem;
}
.btn.btn-sm {
    padding: 0.35rem 0.7rem;
    font-size: 0.85rem;
}

/* ---- Manual score input (fallback) ---- */
.manual-score-label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin: 0.5rem 0 0.25rem;
}
.score-panel input#score-input {
    width: 100%;
    margin-bottom: 0.5rem;
}

/* ---- CSS pseudo-fullscreen (marche sur iOS Safari) ---- */
.css-fullscreen {
    position: fixed !important;
    top: 0; left: 0; right: 0; bottom: 0;
    width: 100vw !important; height: 100vh !important;
    z-index: 9990;
    background: #000;
    margin: 0; padding: 0;
    display: flex; align-items: center; justify-content: center;
}
.css-fullscreen ruffle-player,
.css-fullscreen ruffle-embed,
.css-fullscreen embed,
.css-fullscreen iframe,
.css-fullscreen canvas {
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw; max-height: 100vh;
}
body.css-fullscreen-active {
    overflow: hidden;
    /* Pas de position:fixed sur body : casserait le viewport des
       position:fixed enfants (notamment #touch-controls et #tc-toggle)
       sur certains mobiles. */
}
html.css-fullscreen-active, body.css-fullscreen-active {
    /* Empeche scroll sans casser le containing block fixed */
    touch-action: none;
}
body.css-fullscreen-active .site-header,
body.css-fullscreen-active .site-footer,
body.css-fullscreen-active .game-sidebar,
body.css-fullscreen-active .game-controls,
body.css-fullscreen-active .score-panel,
body.css-fullscreen-active .game-page-header,
body.css-fullscreen-active .main-content > :not(:has(.css-fullscreen)) {
    display: none !important;
}
#css-fs-exit {
    position: fixed;
    top: env(safe-area-inset-top, 12px);
    right: env(safe-area-inset-right, 12px);
    z-index: 9999;
    width: 44px; height: 44px;
    background: rgba(20, 20, 40, 0.85);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}

/* ---- Touch controls overlay (mobile/tablet) ---- */
/* Par defaut cache. Affiche uniquement sur device sans hover et pointer coarse
   (= mobile / tablette tactile / MuMu / Fire TV). */
#touch-controls { display: none; }
@media (hover: none), (pointer: coarse), (max-width: 1023px) {
    #touch-controls {
        display: flex;
    }
}
#touch-controls {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    justify-content: space-between;
    align-items: flex-end;
    padding: 1rem;
    pointer-events: none;
    z-index: 10000;     /* AU-DESSUS du pseudo-fullscreen (z-index 9990) */
    transition: transform 0.25s ease, opacity 0.25s ease;
}
#touch-controls.tc-hidden {
    transform: translateY(110%);
    opacity: 0;
}
#touch-controls > * { pointer-events: auto; }

.tc-dpad {
    display: grid;
    grid-template-columns: repeat(3, 52px);
    grid-template-rows: repeat(3, 52px);
    gap: 4px;
}
.tc-dpad .tc-up    { grid-column: 2; grid-row: 1; }
.tc-dpad .tc-left  { grid-column: 1; grid-row: 2; }
.tc-dpad .tc-right { grid-column: 3; grid-row: 2; }
.tc-dpad .tc-down  { grid-column: 2; grid-row: 3; }

.tc-actions {
    display: flex; flex-direction: column;
    gap: 10px;
    align-items: flex-end;
}

.tc-btn {
    width: 52px; height: 52px;
    border-radius: 50%;
    background: rgba(20, 20, 40, 0.78);
    border: 2px solid rgba(255, 255, 255, 0.28);
    color: #fff;
    font-size: 1.4rem;
    font-weight: bold;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    touch-action: manipulation;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    display: flex; align-items: center; justify-content: center;
    transition: background 0.05s, transform 0.05s;
}
.tc-btn:active, .tc-btn.active {
    background: var(--primary);
    transform: scale(0.93);
}
.tc-btn-action {
    width: 60px; height: 60px;
    font-size: 1.5rem;
    background: rgba(102, 126, 234, 0.78);
}

/* Toggle = HORS du #touch-controls, toujours visible sur mobile
   (pas affecte par le transform parent) */
#tc-toggle {
    display: none;
    position: fixed;
    right: 12px;
    top: 12px;          /* TOP au lieu de bottom -> pas de chevauchement avec bouton B */
    z-index: 10001;     /* AU-DESSUS du fullscreen + des controles */
    width: 40px; height: 40px;
    background: rgba(102, 126, 234, 0.85);
    border: 2px solid rgba(255,255,255,0.4);
    color: #fff;
    border-radius: 50%;
    font-size: 1.1rem;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}
@media (hover: none), (pointer: coarse), (max-width: 1023px) {
    #tc-toggle { display: block; }
}

/* Note : sur grand ecran sans tactile, l'overlay reste cache par defaut
   (geree par la media query au-dessus : display:flex uniquement sur device sans hover). */

/* ---- Downloader code badge (homepage) ---- */
.download-card .code {
    display: inline-block;
    background: #000;
    color: var(--gold);
    font-family: 'Courier New', monospace;
    font-size: 1.6rem;
    font-weight: 900;
    letter-spacing: 0.2rem;
    padding: 0.6rem 1.2rem;
    margin: 0.5rem 0;
    border-radius: var(--radius-sm);
    border: 2px solid var(--gold);
}

/* ---- Download section (homepage Loopix Play) ---- */
.download-section { padding: 2rem 0; }
.download-grid {
    display: grid; gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    margin-top: 1.5rem;
}
.download-card {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    transition: background .2s, border-color .2s;
}
.download-card.available {
    border-color: var(--primary);
    background: linear-gradient(135deg, rgba(102,126,234,0.08), rgba(118,75,162,0.06));
}
.download-card .badge {
    position: absolute; top: 0.75rem; right: 0.75rem;
    background: var(--success); color: white; border: 0;
    text-transform: uppercase; font-size: 0.7rem; letter-spacing: 0.5px;
    padding: 0.2rem 0.55rem;
}
.download-card .badge.soon { background: var(--text-muted); }
.download-card h4 { color: var(--text-heading); margin: 0.5rem 0; padding-right: 80px; }
.download-card p { color: var(--text-muted); font-size: 0.92rem; min-height: 2.8em; }
.download-card .action {
    display: inline-block; margin-top: 0.75rem;
    background: var(--primary); color: white;
    padding: 0.55rem 1rem; border-radius: var(--radius-sm);
    font-weight: 600; text-decoration: none;
}
.download-card.coming .action { background: var(--bg-surface); color: var(--text-muted); }
.download-card .action:hover { filter: brightness(1.1); }

/* ---- Burger toggle (mobile only) ---- */
.nav-toggle {
    display: none;
    background: transparent;
    border: 0;
    cursor: pointer;
    padding: 0.5rem;
    margin-left: auto;
    width: 44px; height: 44px;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
}
.nav-toggle span {
    display: block;
    width: 24px; height: 2px;
    background: var(--text);
    transition: transform .2s, opacity .2s;
}
.nav-toggle[aria-expanded="true"] span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.nav-toggle[aria-expanded="true"] span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ---- Hero secondary actions ---- */
.hero-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; justify-content: center; }

/* ---- Forms ---- */
.container-narrow { max-width: 600px; margin: 0 auto; padding: 1.5rem 1rem; }
.form-stack { display: flex; flex-direction: column; gap: 1rem; margin-top: 1rem; }
.form-field { display: flex; flex-direction: column; gap: 0.35rem; }
.form-label { font-weight: 500; color: var(--text-heading); font-size: 0.95rem; }
.form-input {
    background: var(--bg-card);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.75rem 0.9rem;
    font-size: 1rem;
    font-family: inherit;
    width: 100%;
}
.form-input:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
.form-actions { display: flex; gap: 0.75rem; justify-content: flex-end; margin-top: 0.5rem; }
.alert { padding: 0.75rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; }
.alert-error { background: rgba(239, 83, 80, 0.12); border: 1px solid var(--error); color: #ffb4b4; }

/* ---- Page header ---- */
.page-header {
    display: flex; align-items: center; justify-content: space-between;
    gap: 1rem; flex-wrap: wrap;
    margin: 1.5rem 0 1rem;
}

/* ---- Teams ---- */
.my-teams { margin-bottom: 2rem; }
.team-grid {
    display: grid; gap: 0.75rem;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}
.team-card {
    display: block;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    color: var(--text);
    transition: background .2s, transform .2s;
}
.team-card:hover { background: var(--bg-card-hover); transform: translateY(-2px); }
.team-card-mine { border-color: var(--primary); }
.team-card-name { font-weight: 700; color: var(--text-heading); margin-bottom: .25rem; }
.team-card-role { font-size: 0.85rem; color: var(--text-muted); }

.team-header {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 1rem; flex-wrap: wrap;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin: 1.5rem 0;
}
.team-header-main { flex: 1; min-width: 240px; }
.team-header h1 { color: var(--text-heading); margin-bottom: 0.5rem; }
.team-description { color: var(--text-muted); margin-bottom: 0.75rem; }
.team-meta { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.team-header-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.inline-form { margin: 0; }

.badge {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    padding: 0.25rem 0.65rem;
    border-radius: 999px;
    font-size: 0.85rem;
    color: var(--text);
}
.badge-points { background: rgba(102, 126, 234, 0.15); border-color: var(--primary); color: var(--primary); font-weight: 600; }

.members-section { margin-top: 1.5rem; }
.members-grid {
    display: grid; gap: 0.5rem;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    margin-top: 0.75rem;
}
.member-card {
    display: flex; align-items: center; gap: 0.75rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.8rem;
    color: var(--text);
    transition: background .2s;
}
.member-card:hover { background: var(--bg-card-hover); }
.member-avatar { width: 36px; height: 36px; border-radius: 50%; }
.member-name { font-weight: 500; color: var(--text-heading); }
.member-role { font-size: 0.8rem; color: var(--gold); }

.link-back { margin-top: 1.5rem; }
.empty-state { color: var(--text-muted); padding: 1.5rem; text-align: center; }
.btn-disabled { background: var(--bg-card); color: var(--text-muted); cursor: not-allowed; opacity: 0.65; }
.btn-danger { background: var(--error); color: white; }
.btn-danger:hover { filter: brightness(1.1); }

.leaderboard-table-wrapper { overflow-x: auto; }
.team-link { color: var(--text-heading); font-weight: 600; }
.team-link:hover { color: var(--primary); }
.num-col { text-align: right; white-space: nowrap; }
.score { font-weight: 700; color: var(--primary); }

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .hero h1 { font-size: 1.8rem; }
    .hero-actions { flex-direction: column; align-items: stretch; }
    .hero-actions .btn { justify-content: center; }
    .game-layout { grid-template-columns: 1fr; }
    .two-columns { grid-template-columns: 1fr; }
    .games-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
    .category-tabs { overflow-x: auto; flex-wrap: nowrap; }

    /* Header mobile : burger */
    .navbar { flex-wrap: nowrap; gap: 0.5rem; }
    .nav-toggle { display: flex; }
    .nav-links {
        display: none;
        order: 4;
        width: 100%;
        flex-direction: column;
        background: var(--bg-card);
        padding: 0.5rem;
        border-radius: var(--radius-sm);
        border: 1px solid var(--border);
        margin-top: 0.5rem;
    }
    .nav-links.open { display: flex; }
    .nav-link { width: 100%; padding: 0.75rem; }
    .nav-user { margin-left: 0; }
    .nav-username { display: none; }

    /* Teams mobile */
    .team-header-actions { width: 100%; }
    .team-header-actions .btn { flex: 1; justify-content: center; }
    .members-grid { grid-template-columns: 1fr 1fr; }

    /* Game modal mobile */
    .game-modal-content { width: 100vw; height: 100vh; max-height: 100vh; border-radius: 0; }
    .game-modal-body { grid-template-columns: 1fr; }
    .game-modal-sidebar { max-height: 200px; border-left: none; border-top: 1px solid var(--border); }
    .game-modal-header-actions .btn { display: none; }
    .game-modal-header-actions .game-modal-close { display: block; }
}

@media (max-width: 480px) {
    .container { padding: 0 0.75rem; }
    .games-grid { grid-template-columns: repeat(2, 1fr); gap: 0.5rem; }
    .members-grid { grid-template-columns: 1fr; }
    .btn { min-height: 44px; }   /* touch target Apple HIG */
}
