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

:root {
    --bg:           #0d0a07;
    --panel:        #1a1208;
    --panel-alt:    #221a0c;
    --border-hi:    #7a5c2a;
    --border-lo:    #1a0e04;
    --border-mid:   #3a2810;
    --accent:       #d4a843;
    --accent-dim:   #8a6a30;
    --text:         #e8d5a3;
    --text-dim:     #7a6040;
    --text-faint:   #3a2c18;
    --btn-bg:       #3a2810;
    --btn-hover:    #4a3818;
    --btn-active:   #251a08;
    --input-bg:     #0f0a05;
    --red:          #8a2a1a;
    --red-hi:       #cc3322;
    --green:        #2a5a2a;
    --blue:         #1a2a5a;
}

body {
    background: var(--bg) url('../assets/sky.jpg') center / cover no-repeat fixed;
    overflow: hidden;
    font-family: 'Press Start 2P', 'Courier New', monospace;
}

#game-canvas {
    display: block;
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
}

.hidden { display: none !important; }

/* Minecraft border mixin */
.mc-border {
    border: 3px solid;
    border-color: var(--border-hi) var(--border-lo) var(--border-lo) var(--border-hi);
}

/* BUTTONS — Desert Minecraft style */

.mc-btn {
    font-family: 'Press Start 2P', monospace;
    font-size: 9px;
    background: var(--btn-bg);
    border-top:    3px solid var(--border-hi);
    border-left:   3px solid var(--border-hi);
    border-bottom: 3px solid var(--border-lo);
    border-right:  3px solid var(--border-lo);
    color: var(--text);
    padding: 12px 24px;
    cursor: pointer;
    text-align: center;
    letter-spacing: 1px;
    width: 100%;
    text-shadow: 1px 1px 0 #000;
    transition: background 0.05s;
    image-rendering: pixelated;
}
.mc-btn:hover:not(:disabled) {
    background: var(--btn-hover);
    border-top-color:  #9a7c3a;
    border-left-color: #9a7c3a;
}
.mc-btn:active:not(:disabled) {
    background: var(--btn-active);
    border-top-color:    var(--border-lo);
    border-left-color:   var(--border-lo);
    border-bottom-color: var(--border-hi);
    border-right-color:  var(--border-hi);
    padding-top: 13px;
    padding-bottom: 11px;
}
.mc-btn:disabled {
    background: #1a1208;
    border-top-color:    #2a1e0c;
    border-left-color:   #2a1e0c;
    border-bottom-color: #0a0804;
    border-right-color:  #0a0804;
    color: var(--text-faint);
    cursor: not-allowed;
    text-shadow: none;
}

.mc-btn-sm {
    width: auto;
    padding: 8px 14px;
    font-size: 8px;
}

.mc-btn-cancel {
    color: #cc7755;
}
.mc-btn-cancel:hover:not(:disabled) {
    background: #3a1808;
    border-top-color:  #8a4422;
    border-left-color: #8a4422;
}

.mc-btn-gold {
    background: #3a2a08;
    border-top-color:  var(--accent);
    border-left-color: var(--accent);
    color: var(--accent);
}
.mc-btn-gold:hover:not(:disabled) {
    background: #4a3810;
    border-top-color:  #f0cc60;
    border-left-color: #f0cc60;
    color: #f0d860;
}

/* Inputs */

.mc-input {
    background: var(--input-bg);
    border-top:    2px solid #1a1208;
    border-left:   2px solid #1a1208;
    border-bottom: 2px solid var(--border-hi);
    border-right:  2px solid var(--border-hi);
    color: var(--text);
    padding: 10px 12px;
    font-family: 'Press Start 2P', monospace;
    font-size: 9px;
    outline: none;
    width: 100%;
    transition: border-color 0.1s;
}
.mc-input::placeholder { color: var(--text-faint); }
.mc-input:focus {
    border-top-color:    #0a0804;
    border-left-color:   #0a0804;
    border-bottom-color: var(--accent);
    border-right-color:  var(--accent);
}
.mc-input-code {
    width: 120px;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 4px;
    font-size: 11px;
}

/* HOME SCREEN */

#home-screen {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg) url('../assets/fond_soulgate.png') center / cover no-repeat;
}

/* Top-right gear */
.home-top-bar {
    position: absolute;
    top: 16px;
    right: 16px;
}

.icon-btn {
    background: var(--btn-hover);
    border-top:    2px solid var(--border-hi);
    border-left:   2px solid var(--border-hi);
    border-bottom: 2px solid var(--border-lo);
    border-right:  2px solid var(--border-lo);
    color: var(--accent);
    font-size: 18px;
    width: 40px;
    height: 40px;
    cursor: pointer;
    font-family: inherit;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Bottom-left social icons */
.home-bottom-bar {
    position: absolute;
    bottom: 16px;
    left: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.social-link {
    width: 36px;
    height: 36px;
    background: var(--btn-hover);
    border-top:    2px solid var(--border-hi);
    border-left:   2px solid var(--border-hi);
    border-bottom: 2px solid var(--border-lo);
    border-right:  2px solid var(--border-lo);
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    cursor: pointer;
    padding: 0;
    flex-shrink: 0;
}
.social-link span {
    font-family: 'Press Start 2P', monospace;
    font-size: 11px;
    color: var(--accent);
    line-height: 1;
}
.social-icon {
    width: 20px;
    height: 20px;
    display: block;
    object-fit: contain;
}
.social-icon-invert {
    filter: invert(1) brightness(1.1);
}

.version-label {
    font-size: 7px;
    color: var(--text-faint);
    letter-spacing: 1px;
    margin-left: 8px;
    line-height: 1;
}

/* Center panel */
.home-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 360px;
}

.home-panel {
    width: 100%;
    background: rgba(26, 18, 8, 0.92);
    border-top:    3px solid var(--border-hi);
    border-left:   3px solid var(--border-hi);
    border-bottom: 3px solid var(--border-lo);
    border-right:  3px solid var(--border-lo);
    padding: 32px 28px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
}

/* Title */
.home-title {
    font-family: 'Press Start 2P', monospace;
    font-size: 28px;
    color: var(--accent);
    letter-spacing: 4px;
    text-align: center;
    margin-bottom: 8px;
    text-shadow: 2px 2px 0 #3a2000;
}

.home-subtitle {
    font-family: 'Press Start 2P', monospace;
    font-size: 7px;
    color: var(--accent-dim);
    letter-spacing: 3px;
    text-align: center;
    margin-bottom: 28px;
    opacity: 0.7;
}

/* Divider */
.home-divider {
    width: 100%;
    height: 1px;
    background: linear-gradient(to right, transparent, var(--border-hi), transparent);
    margin-bottom: 20px;
}

.home-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    width: 100%;
    margin-bottom: 8px;
}

#home-username {
    flex-direction: row;
    gap: 6px;
    margin-bottom: 16px;
}

#join-row {
    flex-direction: row;
    gap: 6px;
}

/* Status */
.home-status {
    font-size: 7px;
    color: var(--text-faint);
    letter-spacing: 1px;
    margin-top: 14px;
    text-align: center;
}
.home-status.ok  { color: #6a9a50; }
.home-status.err { color: var(--red-hi); }

/* LOBBY SCREEN */

#lobby-screen {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg) url('../assets/fond_soulgate.png') center / cover no-repeat;
}

#loading-screen {
    position: fixed;
    inset: 0;
    z-index: 20;
    background: var(--bg) url('../assets/fond_soulgate.png') center / cover no-repeat;
    display: flex;
    align-items: center;
    justify-content: center;
}
.loading-text {
    font-family: 'Press Start 2P', monospace;
    font-size: 18px;
    color: var(--accent);
    letter-spacing: 4px;
    background: rgba(13, 10, 7, 0.85);
    padding: 18px 32px;
    border-top:    3px solid var(--border-hi);
    border-left:   3px solid var(--border-hi);
    border-bottom: 3px solid var(--border-lo);
    border-right:  3px solid var(--border-lo);
    animation: loading-pulse 1.4s ease-in-out infinite;
}
@keyframes loading-pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.5; }
}

.lobby-panel {
    background: rgba(26, 18, 8, 0.94);
    border-top:    3px solid var(--border-hi);
    border-left:   3px solid var(--border-hi);
    border-bottom: 3px solid var(--border-lo);
    border-right:  3px solid var(--border-lo);
    padding: 24px 28px 20px;
    width: 440px;
    color: var(--text);
}

.lobby-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-mid);
}

.lobby-code {
    font-size: 8px;
    color: var(--accent-dim);
    letter-spacing: 1px;
}
.lobby-code strong {
    color: var(--accent);
    letter-spacing: 5px;
    font-size: 11px;
}

.lobby-section-title {
    font-size: 8px;
    color: var(--accent-dim);
    letter-spacing: 2px;
    margin-bottom: 10px;
    text-align: center;
}

/* Class cards */
.class-btns {
    display: flex;
    gap: 6px;
    margin-bottom: 14px;
}

.class-btn {
    flex: 1;
    background: var(--panel);
    border-top:    2px solid var(--border-hi);
    border-left:   2px solid var(--border-hi);
    border-bottom: 2px solid var(--border-lo);
    border-right:  2px solid var(--border-lo);
    padding: 12px 6px;
    text-align: center;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-family: 'Press Start 2P', monospace;
    transition: background 0.05s;
}
.class-btn:hover:not(:disabled) {
    background: var(--btn-hover);
    border-top-color:  #9a7c3a;
    border-left-color: #9a7c3a;
}

.class-name { font-size: 9px; color: var(--text); }
.class-role { font-size: 6px; color: var(--text-dim); }

.class-btn.active[data-class="kael"] {
    background: rgba(80, 20, 10, 0.8);
    border-top-color:  #cc4433;
    border-left-color: #cc4433;
}
.class-btn.active[data-class="kael"] .class-name { color: #ff7766; }
.class-btn.active[data-class="kael"] .class-role  { color: #883322; }

.class-btn.active[data-class="seris"] {
    background: rgba(10, 20, 60, 0.8);
    border-top-color:  #4477cc;
    border-left-color: #4477cc;
}
.class-btn.active[data-class="seris"] .class-name { color: #7799ff; }
.class-btn.active[data-class="seris"] .class-role  { color: #334488; }

.class-btn.active[data-class="aldric"] {
    background: rgba(10, 40, 15, 0.8);
    border-top-color:  #44aa66;
    border-left-color: #44aa66;
}
.class-btn.active[data-class="aldric"] .class-name { color: #77cc99; }
.class-btn.active[data-class="aldric"] .class-role  { color: #336644; }

/* Players list */
.players-lobby {
    font-size: 8px;
    color: var(--text-dim);
    min-height: 18px;
    line-height: 2.2;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
    text-align: center;
    padding: 8px 0;
    border-top:    1px solid var(--border-mid);
    border-bottom: 1px solid var(--border-mid);
}

.lobby-actions {
    display: flex;
    gap: 6px;
    margin-top: 12px;
}

.msg {
    margin-top: 8px;
    font-size: 7px;
    color: var(--accent-dim);
    min-height: 12px;
    letter-spacing: 0.5px;
    text-align: center;
}
.msg.err { color: var(--red-hi); }

/* IN-GAME: Barre de vie boss */

#boss-bar {
    position: fixed;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 15;
    min-width: 320px;
}
.boss-bar-box {
    background: rgba(10, 5, 20, 0.88);
    border: 1px solid #6a22aa;
    padding: 8px 16px 10px;
    font-family: 'Courier New', monospace;
    text-align: center;
}
.boss-bar-name { font-size: 11px; letter-spacing: 3px; color: #bb88ff; margin-bottom: 6px; }
.boss-bar-track { background: #1a0a2a; height: 10px; width: 100%; margin-bottom: 4px; border: 1px solid #3a1a5a; }
.boss-bar-fill { height: 100%; width: 100%; background: linear-gradient(to right, #7722cc, #aa44ff); transition: width 0.1s linear; }
.boss-bar-hp { font-size: 10px; color: #8855bb; }

/* IN-GAME: Panneau d'upgrade */

#upgrade-panel {
    position: fixed;
    inset: 0;
    z-index: 15;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(8, 5, 2, 0.78);   /* backdrop : intercepte les clics, focus sur le menu */
}
.upgrade-box {
    background: #12121e;
    border: 1px solid #4a2a8a;
    padding: 20px 28px;
    min-width: 280px;
    color: #c8c8d8;
    font-size: 13px;
    font-family: 'Courier New', monospace;
}
.upgrade-title { font-size: 14px; color: #9977cc; letter-spacing: 2px; margin-bottom: 10px; text-align: center; }
.upgrade-souls { text-align: center; margin-bottom: 14px; font-size: 12px; color: #aaa; }
.upgrade-souls strong { color: #f0c040; }
.upgrade-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.upgrade-info { flex: 1; }
.upgrade-name { font-size: 12px; color: #ddd; }
.upgrade-desc { font-size: 10px; color: #666; margin-top: 2px; }
.upgrade-stacks { font-size: 10px; color: #7755aa; white-space: nowrap; }
.upgrade-buy { padding: 4px 10px; font-size: 11px; white-space: nowrap; color: #f0c040; border-color: #8a6a10; background: #0a0a18; border: 1px solid #8a6a10; cursor: pointer; font-family: 'Courier New', monospace; }
.upgrade-buy:disabled { color: #555; border-color: #333; cursor: not-allowed; }

/* IN-GAME: Bouton plein ecran */

.fullscreen-btn {
    position: fixed;
    top: 8px;
    right: 8px;
    z-index: 20;
    padding: 4px 8px;
    font-size: 18px;
    line-height: 1;
    opacity: 0.35;
    border: 1px solid #333;
    background: transparent;
    color: #aaa;
    cursor: pointer;
    font-family: inherit;
}
.fullscreen-btn:hover { opacity: 0.85; }

/* HUD joueur (bas-gauche) */

#player-hud {
    position: fixed;
    bottom: 16px;
    left: 16px;
    z-index: 15;
    background: rgba(8, 8, 20, 0.82);
    border: 1px solid #2a2a4a;
    padding: 10px 12px;
    font-family: 'Courier New', monospace;
    font-size: 11px;
    color: #c8c8d8;
    min-width: 220px;
}
#hud-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 7px; }
#hud-class-name { font-size: 12px; letter-spacing: 2px; color: #9988ff; }
#hud-souls { color: #f0c040; font-size: 10px; }

#hud-hp-wrap { position: relative; height: 14px; background: #1a0808; border: 1px solid #3a1a1a; margin-bottom: 8px; overflow: hidden; }
#hud-hp-fill { position: absolute; inset: 0; background: linear-gradient(to right, #882222, #cc3333); transition: width 0.1s linear; width: 100%; }
#hud-hp-text { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 10px; color: #eee; z-index: 1; }

#hud-skills { display: flex; gap: 5px; margin-bottom: 6px; }
.hud-skill { position: relative; width: 36px; height: 36px; background: #0e0e1e; border: 1px solid #333; overflow: hidden; flex-shrink: 0; }
.hud-skill .cd-fill { position: absolute; bottom: 0; left: 0; width: 100%; height: 0%; background: rgba(100, 60, 220, 0.45); transition: height 0.1s linear; }
.hud-skill .key { position: absolute; bottom: 2px; left: 0; right: 0; text-align: center; font-size: 10px; color: #888; z-index: 1; }
.hud-skill.ready { border-color: #8866ff; }
.hud-skill.locked { opacity: 0.5; }
.hud-skill.divine-ready { border-color: #f0c040; box-shadow: 0 0 6px rgba(240, 192, 64, 0.5); }
#hud-divine-uses { position: absolute; top: 2px; right: 3px; font-size: 8px; color: #f0c040; z-index: 1; letter-spacing: -1px; }

#hud-buffs { display: flex; flex-wrap: wrap; gap: 4px; min-height: 4px; }
.buff-tag { font-size: 9px; padding: 1px 5px; border: 1px solid; font-family: 'Courier New', monospace; }
.buff-tag.invulnerable { color: #f0c040; border-color: #8a6a10; background: rgba(240,192,64,0.12); }
.buff-tag.casting      { color: #44ffff; border-color: #228888; background: rgba(68,255,255,0.10); }
.buff-tag.flying       { color: #88ccff; border-color: #336688; background: rgba(136,204,255,0.10); }
.buff-tag.intangible   { color: #cc88ff; border-color: #553388; background: rgba(204,136,255,0.10); }
.buff-tag.combat_buff  { color: #ff8844; border-color: #883322; background: rgba(255,136,68,0.10); }
.buff-tag.damage_mult  { color: #ff4444; border-color: #882222; background: rgba(255,68,68,0.10); }

/* IN-GAME: Barre Soulgate (haut-centre) */

#soulgate-hud {
    position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 15;
    display: flex; align-items: center; gap: 8px;
    background: rgba(8, 8, 20, 0.82); border: 1px solid #2a2a4a; padding: 6px 12px;
    font-family: 'Courier New', monospace; font-size: 10px; color: #c8c8d8;
}
.sg-label { letter-spacing: 2px; color: #9977cc; font-size: 10px; white-space: nowrap; }
#sg-track { width: 180px; height: 8px; background: #1a0a2a; border: 1px solid #2a1a4a; overflow: hidden; }
#sg-fill { height: 100%; width: 100%; background: linear-gradient(to right, #5522aa, #9944ff); transition: width 0.1s linear; }
#sg-hp-text { white-space: nowrap; color: #8855bb; font-size: 10px; }

/* IN-GAME: Infos vague (haut-droite) */

#wave-hud {
    position: fixed; top: 14px; right: 16px; z-index: 15;
    background: rgba(8, 8, 20, 0.82); border: 1px solid #2a2a4a; padding: 8px 12px;
    font-family: 'Courier New', monospace; text-align: right;
}
#wave-label { font-size: 11px; color: #9977cc; letter-spacing: 1px; margin-bottom: 3px; }
#wave-state-label { font-size: 10px; color: #c8c8d8; margin-bottom: 2px; }
#wave-enemies { font-size: 10px; color: #f0c040; }

/* END GAME OVERLAY */

#endgame-overlay {
    position: fixed; inset: 0;
    background: rgba(8, 5, 2, 0.88);
    display: flex; align-items: center; justify-content: center;
    z-index: 100;
}

#endgame-box {
    background: rgba(26, 18, 8, 0.97);
    border-top:    3px solid var(--border-hi);
    border-left:   3px solid var(--border-hi);
    border-bottom: 3px solid var(--border-lo);
    border-right:  3px solid var(--border-lo);
    padding: 32px 40px;
    text-align: center;
    font-family: 'Press Start 2P', monospace;
    max-height: 90vh;
    overflow-y: auto;
    max-width: 520px;
    width: 92vw;
}

#endgame-title {
    font-size: 28px;
    letter-spacing: 4px;
    margin-bottom: 10px;
}
#endgame-title.victory { color: var(--accent); text-shadow: 2px 2px 0 #3a2000; }
#endgame-title.defeat  { color: #cc3322;        text-shadow: 2px 2px 0 #2a0808; }

#endgame-sub {
    font-size: 8px;
    color: var(--text-dim);
    margin-bottom: 12px;
}

.endgame-stat {
    font-size: 9px;
    color: var(--text);
    margin-bottom: 5px;
}

/* Leaderboard form inside endgame */
#endgame-form { margin-top: 16px; text-align: left; }

.lb-host-only {
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    line-height: 1.6;
    color: var(--accent);
    text-align: center;
    padding: 14px 8px;
    background: var(--panel);
    border-top:    2px solid var(--border-hi);
    border-left:   2px solid var(--border-hi);
    border-bottom: 2px solid var(--border-lo);
    border-right:  2px solid var(--border-lo);
    margin-bottom: 8px;
}

.lb-field { margin-bottom: 10px; }
.lb-field label {
    display: block;
    font-size: 7px;
    color: var(--accent-dim);
    margin-bottom: 4px;
    letter-spacing: 0.5px;
}
.lb-field input {
    width: 100%;
    background: var(--input-bg);
    border-top:    2px solid #1a1208;
    border-left:   2px solid #1a1208;
    border-bottom: 2px solid var(--border-hi);
    border-right:  2px solid var(--border-hi);
    color: var(--text);
    padding: 6px 8px;
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    outline: none;
}
.lb-field input.taken {
    border-bottom-color: var(--red-hi);
    border-right-color:  var(--red-hi);
}
.lb-discord-error {
    display: block;
    font-size: 7px;
    margin-top: 3px;
    min-height: 11px;
    color: #6a9a50;
}
.lb-discord-error.error { color: var(--red-hi); }
#lb-submit-btn { width: 100%; margin-top: 12px; }

/* LEADERBOARD SCREEN */

#leaderboard-screen {
    position: fixed; inset: 0; z-index: 50;
    background: var(--bg) url('../assets/fond_soulgate.png') center / cover no-repeat;
    display: flex; align-items: center; justify-content: center;
}

.lb-panel {
    width: min(860px, 95vw);
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    background: rgba(26, 18, 8, 0.97);
    border-top:    3px solid var(--border-hi);
    border-left:   3px solid var(--border-hi);
    border-bottom: 3px solid var(--border-lo);
    border-right:  3px solid var(--border-lo);
    padding: 24px 28px;
}

.lb-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 18px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border-mid);
}

.lb-title {
    font-family: 'Press Start 2P', monospace;
    font-size: 14px;
    color: var(--accent);
    letter-spacing: 4px;
    flex: 1;
    text-align: center;
    text-shadow: 2px 2px 0 #3a2000;
}

.lb-table-wrap { overflow-y: auto; flex: 1; }

.lb-table {
    width: 100%;
    border-collapse: collapse;
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
}
.lb-table thead {
    position: sticky;
    top: 0;
    background: var(--panel);
}
.lb-table th {
    padding: 10px 12px;
    color: var(--accent-dim);
    border-bottom: 1px solid var(--border-mid);
    text-align: left;
    font-size: 7px;
    letter-spacing: 1px;
}
.lb-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-mid);
    color: var(--text);
    font-size: 8px;
}
.lb-table tr:nth-child(even) td { background: rgba(58, 40, 16, 0.18); }
.lb-table tr:hover td           { background: rgba(212, 168, 67, 0.06); }
.lb-table tr.lb-first td        { color: var(--accent); }

.lb-rank  { color: var(--accent-dim); width: 36px; }
.lb-team  { color: var(--text); }
.lb-score { color: var(--accent); }
.lb-players { color: #8ab4d4; font-size: 7px; }