:root {
    --bg-top: #1b1640;
    --bg-bottom: #0c0a1f;
    --track: #f4f2ff;
    --edge: #8b7bff;
    --obstacle: #ff4d6d;
    --player: #3ee0ff;
    --muted: #b7b0e6;
}

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

body {
    font-family: 'Arial', sans-serif;
    background:
        radial-gradient(circle at 20% 10%, rgba(139, 123, 255, 0.18), transparent 45%),
        radial-gradient(circle at 85% 90%, rgba(62, 224, 255, 0.10), transparent 45%),
        linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
    color: var(--track);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden;
}

.space-bg {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}

.game-container {
    z-index: 1;
    background: rgba(12, 10, 31, 0.7);
    border: 1px solid rgba(139, 123, 255, 0.35);
    border-radius: 20px;
    padding: 20px;
    box-shadow: 0 0 40px rgba(139, 123, 255, 0.2), 0 20px 60px rgba(0, 0, 0, 0.5);
    max-width: 800px;
    width: 90%;
    position: relative;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}

h1 {
    color: var(--track);
    font-size: 2.1em;
    letter-spacing: 1px;
    white-space: nowrap;
    text-shadow: 0 0 12px rgba(139, 123, 255, 0.9), 0 0 30px rgba(139, 123, 255, 0.5);
}

/* ---------- Zone de jeu + HUD ---------- */

.playfield {
    position: relative;
}

.hud {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: stretch;
    background: rgba(12, 10, 31, 0.55);
    border: 1px solid rgba(139, 123, 255, 0.3);
    border-radius: 12px;
    pointer-events: none;
    user-select: none;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.hud > div {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 5px 16px 6px;
    min-width: 76px;
}

.hud-best,
.hud-coins {
    border-left: 1px solid rgba(139, 123, 255, 0.3);
}

.hud-label {
    font-size: 0.65em;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--muted);
}

#score {
    font-size: 1.5em;
    font-weight: bold;
    color: var(--player);
    text-shadow: 0 0 8px rgba(62, 224, 255, 0.7);
    font-variant-numeric: tabular-nums;
}

#best {
    font-size: 1.5em;
    font-weight: bold;
    color: var(--track);
    opacity: 0.85;
    font-variant-numeric: tabular-nums;
}

#coins {
    font-size: 1.5em;
    font-weight: bold;
    color: #ffd23e;
    text-shadow: 0 0 8px rgba(255, 210, 62, 0.6);
    font-variant-numeric: tabular-nums;
}

#gameCanvas {
    width: 100%;
    aspect-ratio: 760 / 500;
    background: #0c0a1f;
    border-radius: 15px;
    display: block;
    cursor: crosshair;
    touch-action: none;
    user-select: none;
}

/* ---------- Menus ---------- */

.game-over, .start-screen {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(420px, calc(100% - 32px));
    background: linear-gradient(180deg, rgba(27, 22, 64, 0.92), rgba(12, 10, 31, 0.95));
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border: 2px solid var(--edge);
    padding: 36px 32px;
    border-radius: 20px;
    text-align: center;
    box-shadow:
        0 0 0 8px rgba(139, 123, 255, 0.12),
        0 0 40px rgba(139, 123, 255, 0.45),
        0 20px 60px rgba(0, 0, 0, 0.6);
    max-height: calc(100% - 40px);
    overflow-y: auto;
    display: none;
}

.game-over.active, .start-screen.active {
    display: block;
    animation: pop 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
}

@keyframes pop {
    from { opacity: 0; transform: translate(-50%, -50%) scale(0.9); }
    to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.game-over h2, .start-screen h2 {
    color: var(--track);
    font-size: 2.4em;
    margin-bottom: 14px;
    text-shadow: 0 0 12px rgba(139, 123, 255, 0.9), 0 0 30px rgba(139, 123, 255, 0.5);
}

.game-over h2 {
    text-shadow: 0 0 12px rgba(255, 77, 109, 0.9), 0 0 30px rgba(255, 77, 109, 0.5);
}

.game-over p, .start-screen p {
    font-size: 1.1em;
    color: var(--muted);
    margin-bottom: 10px;
}

#gameOverReason {
    color: var(--obstacle);
    font-weight: bold;
}

.start-screen ul {
    list-style: none;
    text-align: left;
    margin: 22px auto 26px;
    max-width: 320px;
}

.start-screen li {
    position: relative;
    margin: 12px 0;
    padding-left: 26px;
    color: var(--track);
    line-height: 1.35;
}

.start-screen li::before {
    content: '';
    position: absolute;
    left: 4px;
    top: 0.4em;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--player);
    box-shadow: 0 0 8px var(--player);
}

.start-screen li:nth-child(2)::before {
    background: var(--edge);
    box-shadow: 0 0 8px var(--edge);
}

.start-screen li:nth-child(3)::before {
    background: var(--obstacle);
    box-shadow: 0 0 8px var(--obstacle);
}

.final-score {
    font-size: 1.6em;
    font-weight: bold;
    margin: 20px 0 24px;
}

.game-over .final-score {
    color: var(--track);
}

.final-coins {
    margin: -14px 0 20px;
    color: var(--muted);
}

.final-coins span {
    color: #ffd23e;
    font-weight: bold;
}

.tip-shield { color: #4dffb5; font-weight: bold; }
.tip-slow { color: #c58bff; font-weight: bold; }

.final-score span {
    color: var(--player);
    text-shadow: 0 0 10px rgba(62, 224, 255, 0.8);
}

button {
    background: var(--player);
    color: var(--bg-bottom);
    border: none;
    padding: 15px 44px;
    font-size: 1.2em;
    border-radius: 999px;
    cursor: pointer;
    font-weight: bold;
    letter-spacing: 0.5px;
    box-shadow: 0 0 18px rgba(62, 224, 255, 0.6), 0 0 0 4px rgba(62, 224, 255, 0.15);
    transition: transform 0.2s, box-shadow 0.2s;
}

button:hover {
    transform: translateY(-2px) scale(1.03);
    box-shadow: 0 0 28px rgba(62, 224, 255, 0.9), 0 0 0 6px rgba(62, 224, 255, 0.2);
}

button:active {
    transform: translateY(0) scale(0.98);
}

button:focus-visible {
    outline: 2px solid var(--track);
    outline-offset: 4px;
}

/* ---------- Compte (en-tête) ---------- */

.account {
    display: flex;
    align-items: center;
    gap: 8px;
}

.profile {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px;
    border: 1px solid rgba(139, 123, 255, 0.4);
    border-radius: 999px;
    background: rgba(139, 123, 255, 0.08);
}

.avatar {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--edge), var(--player));
    color: var(--bg-bottom);
    font-weight: bold;
}

.account-name {
    color: var(--track);
    font-weight: bold;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

button.chip-btn {
    background: transparent;
    color: var(--track);
    border: 1px solid var(--edge);
    padding: 9px 14px;
    font-size: 0.95em;
    border-radius: 10px;
    box-shadow: none;
}

button.chip-btn:hover {
    background: rgba(139, 123, 255, 0.18);
    box-shadow: 0 0 14px rgba(139, 123, 255, 0.5);
    transform: none;
}

button.icon-btn {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border-radius: 50%;
    background: transparent;
    box-shadow: none;
    color: var(--muted);
}

button.icon-btn svg {
    width: 17px;
    height: 17px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

button.icon-btn:hover {
    background: rgba(255, 77, 109, 0.18);
    color: var(--obstacle);
    box-shadow: none;
    transform: none;
}

/* ---------- Tuiles secondaires des menus ---------- */

.menu-tiles {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid rgba(139, 123, 255, 0.25);
}

button.menu-tile {
    --accent: 139, 123, 255;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 14px 6px 12px;
    font-size: 0.9em;
    letter-spacing: 0.3px;
    border-radius: 14px;
    color: var(--track);
    background: rgba(var(--accent), 0.08);
    border: 1px solid rgba(var(--accent), 0.4);
    box-shadow: none;
}

button.menu-tile.tile-rank     { --accent: 255, 210, 62; }
button.menu-tile.tile-missions { --accent: 139, 123, 255; }
button.menu-tile.tile-shop     { --accent: 62, 224, 255; }

button.menu-tile svg {
    width: 28px;
    height: 28px;
    fill: none;
    stroke: rgb(var(--accent));
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    filter: drop-shadow(0 0 6px rgba(var(--accent), 0.6));
    transition: transform 0.2s;
}

button.menu-tile:hover {
    background: rgba(var(--accent), 0.18);
    border-color: rgb(var(--accent));
    box-shadow: 0 0 18px rgba(var(--accent), 0.35);
    transform: translateY(-2px);
}

button.menu-tile:hover svg {
    transform: scale(1.12);
}

button.menu-tile .badge {
    position: absolute;
    top: -7px;
    right: -7px;
    margin: 0;
}

button.link-btn {
    background: none;
    border: none;
    box-shadow: none;
    padding: 6px 10px;
    color: var(--edge);
    font-size: 1em;
    text-decoration: underline;
    text-underline-offset: 4px;
}

button.link-btn:hover {
    color: var(--track);
    transform: none;
    box-shadow: none;
}

button.link-btn.inline {
    padding: 0;
    font-size: inherit;
    color: var(--player);
}

.save-status {
    min-height: 1.4em;
    font-size: 0.95em !important;
    margin-bottom: 18px !important;
}

.save-status.good {
    color: var(--player) !important;
}

.save-status.bad {
    color: var(--obstacle) !important;
}

/* ---------- Panneaux (classement, compte) ---------- */

.panel {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(12, 10, 31, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    border-radius: 20px;
    z-index: 10;
}

.panel.active {
    display: flex;
}

.panel-card {
    position: relative;
    width: min(400px, 100%);
    max-height: 100%;
    overflow-y: auto;
    background: linear-gradient(180deg, rgba(27, 22, 64, 0.97), rgba(12, 10, 31, 0.98));
    border: 2px solid var(--edge);
    border-radius: 20px;
    padding: 30px 28px;
    text-align: center;
    box-shadow:
        0 0 0 8px rgba(139, 123, 255, 0.12),
        0 0 40px rgba(139, 123, 255, 0.45),
        0 20px 60px rgba(0, 0, 0, 0.6);
    animation: panel-pop 0.3s cubic-bezier(0.2, 1.4, 0.4, 1);
}

@keyframes panel-pop {
    from { opacity: 0; transform: scale(0.92); }
    to   { opacity: 1; transform: scale(1); }
}

.panel-card h2 {
    color: var(--track);
    font-size: 2em;
    margin-bottom: 6px;
    text-shadow: 0 0 12px rgba(139, 123, 255, 0.9), 0 0 30px rgba(139, 123, 255, 0.5);
}

.panel-sub {
    color: var(--muted);
    margin-bottom: 18px;
}

button.close-btn {
    position: absolute;
    top: 10px;
    right: 12px;
    width: 34px;
    height: 34px;
    padding: 0;
    font-size: 1.5em;
    line-height: 1;
    border-radius: 50%;
    background: transparent;
    color: var(--muted);
    box-shadow: none;
}

button.close-btn:hover {
    color: var(--track);
    background: rgba(139, 123, 255, 0.18);
    transform: none;
    box-shadow: none;
}

/* Classement */

.leaderboard {
    list-style: none;
    text-align: left;
}

.leaderboard li {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 12px;
    margin: 6px 0;
    border-radius: 10px;
    background: rgba(139, 123, 255, 0.08);
    border: 1px solid rgba(139, 123, 255, 0.2);
}

.leaderboard li.empty {
    justify-content: center;
    color: var(--muted);
    background: none;
    border: none;
}

.leaderboard .rank {
    width: 26px;
    height: 26px;
    flex-shrink: 0;
    display: grid;
    place-items: center;
    border-radius: 50%;
    font-weight: bold;
    font-size: 0.9em;
    color: var(--muted);
    border: 1px solid rgba(139, 123, 255, 0.4);
}

.leaderboard .name {
    flex: 1;
    color: var(--track);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.leaderboard .pts {
    font-weight: bold;
    color: var(--player);
    font-variant-numeric: tabular-nums;
}

.leaderboard li.top1 .rank {
    background: var(--player);
    border-color: var(--player);
    color: var(--bg-bottom);
    box-shadow: 0 0 10px var(--player);
}

.leaderboard li.top2 .rank {
    background: var(--edge);
    border-color: var(--edge);
    color: var(--bg-bottom);
}

.leaderboard li.top3 .rank {
    border-color: var(--edge);
    color: var(--track);
}

.leaderboard li.me {
    border-color: var(--player);
    box-shadow: 0 0 12px rgba(62, 224, 255, 0.35);
}

/* Formulaire de compte */

.tabs {
    display: flex;
    gap: 6px;
    margin: 14px 0 20px;
    padding: 4px;
    border-radius: 999px;
    background: rgba(139, 123, 255, 0.1);
    border: 1px solid rgba(139, 123, 255, 0.3);
}

button.tab {
    flex: 1;
    padding: 9px 10px;
    font-size: 0.95em;
    background: transparent;
    color: var(--muted);
    box-shadow: none;
}

button.tab:hover {
    color: var(--track);
    transform: none;
    box-shadow: none;
}

button.tab.active {
    background: var(--edge);
    color: var(--track);
    box-shadow: 0 0 12px rgba(139, 123, 255, 0.6);
}

#authForm label {
    display: block;
    text-align: left;
    color: var(--muted);
    font-size: 0.9em;
    font-weight: bold;
    margin-bottom: 14px;
}

#authForm input {
    display: block;
    width: 100%;
    margin-top: 6px;
    padding: 12px 14px;
    font-size: 1rem;
    color: var(--track);
    background: rgba(12, 10, 31, 0.8);
    border: 1px solid rgba(139, 123, 255, 0.5);
    border-radius: 10px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#authForm input:focus {
    border-color: var(--player);
    box-shadow: 0 0 12px rgba(62, 224, 255, 0.4);
}

.form-error {
    min-height: 1.3em;
    color: var(--obstacle);
    font-size: 0.9em;
    margin-bottom: 12px;
}

#authForm button[type="submit"] {
    width: 100%;
}

button:disabled {
    opacity: 0.6;
    cursor: wait;
}

/* ---------- Gold ---------- */

.coin {
    display: inline-block;
    width: 0.95em;
    height: 0.95em;
    margin-right: 6px;
    vertical-align: -0.12em;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #fff3b0, #ffd23e 45%, #e09b00 100%);
    box-shadow: 0 0 8px rgba(255, 210, 62, 0.7), inset 0 0 0 1.5px rgba(160, 100, 0, 0.6);
}

button.gold-chip {
    display: inline-flex;
    align-items: center;
    background: rgba(255, 210, 62, 0.1);
    border: 1px solid rgba(255, 210, 62, 0.55);
    color: #ffe066;
    padding: 9px 14px;
    font-size: 1em;
    border-radius: 10px;
    box-shadow: none;
}

button.gold-chip:hover {
    background: rgba(255, 210, 62, 0.2);
    box-shadow: 0 0 14px rgba(255, 210, 62, 0.45);
    transform: none;
}

.gold-text {
    color: #ffe066;
}

.badge {
    display: inline-grid;
    place-items: center;
    min-width: 18px;
    height: 18px;
    margin-left: 6px;
    padding: 0 5px;
    border-radius: 999px;
    background: var(--obstacle);
    color: #fff;
    font-size: 0.75em;
    text-decoration: none;
    vertical-align: 2px;
    box-shadow: 0 0 8px var(--obstacle);
}

.badge[hidden] {
    display: none;
}

.mission-done {
    display: block;
    margin-top: 6px;
    color: #ffe066;
}

/* ---------- Missions ---------- */

.missions {
    list-style: none;
    text-align: left;
}

.mission {
    padding: 12px 14px;
    margin: 8px 0;
    border-radius: 12px;
    background: rgba(139, 123, 255, 0.08);
    border: 1px solid rgba(139, 123, 255, 0.25);
}

.mission.done {
    border-color: rgba(255, 210, 62, 0.7);
    box-shadow: 0 0 14px rgba(255, 210, 62, 0.25);
}

.mission.claimed {
    opacity: 0.55;
}

.mission-top,
.mission-bottom {
    display: flex;
    align-items: center;
    gap: 12px;
}

.mission-top {
    justify-content: space-between;
    margin-bottom: 10px;
}

.mission-label {
    color: var(--track);
    line-height: 1.3;
}

.mission-reward {
    flex-shrink: 0;
    color: #ffe066;
    font-weight: bold;
}

.progress {
    flex: 1;
    height: 8px;
    border-radius: 999px;
    background: rgba(12, 10, 31, 0.8);
    border: 1px solid rgba(139, 123, 255, 0.3);
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--edge), var(--player));
    box-shadow: 0 0 8px var(--player);
    transition: width 0.4s;
}

.mission.done .progress-fill {
    background: linear-gradient(90deg, #ffb703, #ffe066);
    box-shadow: 0 0 8px #ffd23e;
}

.mission-state {
    flex-shrink: 0;
    min-width: 76px;
    text-align: right;
    color: var(--muted);
    font-size: 0.9em;
    font-variant-numeric: tabular-nums;
}

button.claim-btn {
    flex-shrink: 0;
    padding: 7px 14px;
    font-size: 0.9em;
    background: #ffd23e;
    color: var(--bg-bottom);
    box-shadow: 0 0 14px rgba(255, 210, 62, 0.6);
}

button.claim-btn:hover {
    box-shadow: 0 0 22px rgba(255, 210, 62, 0.9);
}

/* ---------- Boutique ---------- */

.panel-card.wide {
    width: min(560px, 100%);
}

.skin-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 10px;
}

.skin-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 16px 8px 12px;
    border-radius: 14px;
    background: rgba(139, 123, 255, 0.08);
    border: 1px solid rgba(139, 123, 255, 0.25);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.skin-card:hover {
    border-color: rgba(139, 123, 255, 0.6);
}

.skin-card.equipped {
    border-color: var(--player);
    box-shadow: 0 0 16px rgba(62, 224, 255, 0.35);
}

.skin-name {
    color: var(--track);
    font-weight: bold;
    font-size: 0.95em;
}

button.skin-btn {
    width: 100%;
    padding: 7px 8px;
    font-size: 0.9em;
    background: var(--edge);
    color: var(--track);
    box-shadow: none;
}

button.skin-btn.buy {
    background: rgba(255, 210, 62, 0.12);
    border: 1px solid rgba(255, 210, 62, 0.6);
    color: #ffe066;
}

button.skin-btn.buy.too-expensive {
    opacity: 0.5;
}

button.skin-btn:hover {
    transform: none;
    box-shadow: 0 0 12px rgba(139, 123, 255, 0.5);
}

button.skin-btn:disabled {
    background: transparent;
    color: var(--player);
    opacity: 1;
    cursor: default;
}

.swatch {
    display: inline-block;
    flex-shrink: 0;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 10px var(--glow, var(--player));
}

.swatch.small {
    width: 11px;
    height: 11px;
    border-width: 1.5px;
    margin-right: 8px;
    vertical-align: -1px;
}

.swatch.large {
    width: 34px;
    height: 34px;
    border-width: 3px;
    box-shadow: 0 0 18px var(--glow, var(--player));
}

.swatch.rainbow {
    background: conic-gradient(#ff6ad5, #ffd23e, #4dffb5, #3ee0ff, #c58bff, #ff6ad5);
    animation: spin 2.5s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
    .swatch.rainbow {
        animation: none;
    }
}

@media (max-width: 768px) {
    h1 {
        font-size: 1.8em;
    }

    .game-over, .start-screen {
        padding: 24px 20px;
    }

    .game-over h2, .start-screen h2 {
        font-size: 1.8em;
    }

    button.menu-tile {
        font-size: 0.8em;
    }

    .account-name {
        display: none;
    }

    .hud {
        top: 8px;
        font-size: 0.85em;
    }
}

/* ---------- Paramètres ---------- */

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

button.settings-btn {
    width: 38px;
    height: 38px;
    border: 1px solid var(--edge);
}

button.settings-btn svg {
    width: 20px;
    height: 20px;
}

button.settings-btn:hover {
    color: var(--track);
    background: rgba(139, 123, 255, 0.18);
    box-shadow: 0 0 14px rgba(139, 123, 255, 0.5);
    transform: none;
}

.volume-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 18px;
    color: var(--track);
    font-weight: bold;
}

.volume-row input[type="range"] {
    flex: 1;
    accent-color: var(--player);
    cursor: pointer;
}

.volume-value {
    min-width: 44px;
    text-align: right;
    color: var(--muted);
    font-weight: normal;
}

button.mute-btn.active {
    border-color: var(--obstacle);
    color: var(--obstacle);
}
