/* ═══════════════════════════════════════════════════════════
   BUST-A-QUIZZ — Responsive UI/UX optimisé multi-plateforme
   Mobile-first, touch targets 48px+, dvh, safe-area, performance
   ═══════════════════════════════════════════════════════════ */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overscroll-behavior: none; }
body {
    background: radial-gradient(ellipse at 50% 30%, #3a3450 0%, #1a1628 55%, #0c0a14 100%);
    color: #fff;
    font-family: 'Press Start 2P', 'Courier New', monospace;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    min-height: 100dvh; /* dvh = dynamic viewport height (mobile address bar safe) */
    padding: 8px;
    padding: env(safe-area-inset-top, 8px) env(safe-area-inset-right, 8px) env(safe-area-inset-bottom, 8px) env(safe-area-inset-left, 8px);
    overflow: hidden;
    image-rendering: pixelated;
    user-select: none; -webkit-user-select: none;
}

.page-title {
    font-size: clamp(10px, 3vw, 18px); letter-spacing: 2px; margin-bottom: 6px;
    text-shadow: 2px 2px 0 #000; color: #f8d020; text-align: center;
}

/* ─── Game container (flex layout) ─── */
.game-container {
    display: flex; align-items: flex-start; justify-content: center; gap: 12px;
    max-width: 100%; max-height: calc(100dvh - 60px);
}
.game-container.battle-mode { gap: 12px; }

/* ─── Coque GBC ─── */
.gbc-shell {
    position: relative;
    width: min(94vw, 440px);
    max-height: calc(100dvh - 80px);
    background: linear-gradient(160deg, #7a5fc8 0%, #5d3fa8 45%, #4a2f8f 100%);
    border-radius: 16px 16px 40px 40px; padding: 14px 12px 16px;
    box-shadow: inset 0 2px 0 rgba(255,255,255,0.3), inset 0 -3px 8px rgba(0,0,0,0.3), 0 12px 28px rgba(0,0,0,0.5);
    border: 1px solid #2a1a55;
}
.gbc-label {
    text-align: center; font-size: 11px; color: #f8f0ff; margin: 12px 0 4px; letter-spacing: 1px;
    text-shadow: 2px 2px 0 rgba(0,0,0,0.6);
}
.gbc-label .color-word {
    background: linear-gradient(90deg, #f83838, #f8d020, #38c838, #38c8f8, #a838f8);
    -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; font-weight: bold;
}
.gbc-sub {
    text-align: center; font-size: 5px; letter-spacing: 1px;
    color: rgba(255,255,255,0.6); text-shadow: 1px 1px 0 rgba(0,0,0,0.6);
    margin-bottom: 4px;
}

/* ─── Contrôles décoratifs ─── */
.controls {
    display: flex; justify-content: space-between; align-items: flex-end;
    margin-top: 12px; padding: 0 6px;
}
.dpad {
    width: 64px; height: 64px; position: relative;
    filter: drop-shadow(0 3px 2px rgba(0,0,0,0.5));
}
.dpad::before, .dpad::after {
    content: ''; position: absolute;
    background: linear-gradient(180deg, #2c2c38, #14141c);
    border-radius: 4px; border: 1px solid #0a0a10;
}
.dpad::before { left: 25px; top: 0; width: 14px; height: 64px; }
.dpad::after  { left: 0; top: 25px; width: 64px; height: 14px; }
.dpad-center {
    position: absolute; left: 25px; top: 25px;
    width: 14px; height: 14px; background: #1a1a24;
    border-radius: 3px; border: 1px solid #0a0a10;
}
.abuttons { display: flex; gap: 12px; margin-bottom: 4px; }
.abtn {
    width: 30px; height: 30px; border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #b8485c, #7a2034 70%);
    color: #f8e0e8; display: flex; align-items: center; justify-content: center;
    font-size: 10px; font-family: 'Press Start 2P', monospace;
    box-shadow: inset 0 2px 3px rgba(255,255,255,0.35), 0 3px 4px rgba(0,0,0,0.5);
    border: 1px solid #4a1220;
}
.abtn.b {
    background: radial-gradient(circle at 35% 30%, #b858b8, #7a207a 70%);
    color: #f8e0f8; border-color: #4a124a;
}
.power-led {
    position: absolute; top: 22px; right: 26px;
    width: 7px; height: 7px; border-radius: 50%;
    background: radial-gradient(circle at 40% 35%, #ff9090, #e03030 60%, #801010);
    box-shadow: 0 0 6px #ff4040;
    animation: ledPulse 2s ease-in-out infinite alternate;
}
@keyframes ledPulse { 0% { opacity: 0.8; } 100% { opacity: 1; } }

/* ─── Écran ─── */
.gbc-screen {
    position: relative; background: #2a2a34; border-radius: 6px; padding: 8px;
    box-shadow: inset 0 2px 6px rgba(0,0,0,0.8), 0 1px 0 rgba(255,255,255,0.1); border: 2px solid #14141c;
}
.screen-wrap {
    position: relative; width: 100%; aspect-ratio: 160 / 144;
    background: #08080e; border-radius: 3px; overflow: hidden; box-shadow: inset 0 0 0 2px #101018;
}
canvas#gameCanvas {
    display: block; width: 100%; height: 100%;
    image-rendering: pixelated; image-rendering: crisp-edges;
    background: #08080e; touch-action: none; cursor: crosshair;
}
/* Scanlines/LCD — désactivés sur mobile pour performance GPU */
.scanlines {
    position: absolute; inset: 0; pointer-events: none;
    background: repeating-linear-gradient(0deg, rgba(0,0,0,0.12) 0px, rgba(0,0,0,0.12) 1px, transparent 1px, transparent 3px);
    mix-blend-mode: multiply; z-index: 5;
}
.lcd-grid {
    position: absolute; inset: 0; pointer-events: none;
    background: repeating-linear-gradient(90deg, rgba(120,180,255,0.03) 0px, rgba(120,180,255,0.03) 1px, transparent 1px, transparent 2px);
    z-index: 5;
}
.glass {
    position: absolute; inset: 0; pointer-events: none;
    background: linear-gradient(160deg, rgba(255,255,255,0.06) 0%, transparent 35%); z-index: 6;
}

/* ─── Overlays (menus, quiz) ─── */
.overlay {
    position: absolute; inset: 0; z-index: 20;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    background: rgba(4,4,10,0.92); padding: 6px;
    font-family: 'Press Start 2P', monospace;
    overflow-y: auto; /* Scroll si contenu dépasse sur petit écran */
}
.overlay.hidden { display: none; }
.dialog {
    width: 96%; max-width: 310px; background: #1a1a28;
    border: 2px solid #f8f8f8; outline: 2px solid #101018;
    box-shadow: 0 3px 0 #888, inset 0 0 0 2px #0a0a14;
    padding: 10px 8px; text-align: center; color: #f8f8f8;
}
.dialog-title { font-size: 7px; color: #f8d020; margin-bottom: 6px; letter-spacing: 1px; }
.dialog-text { font-size: 6px; line-height: 1.8; margin-bottom: 6px; }

/* ─── Boutons (min-height 44px pour touch) ─── */
.btn {
    font-family: 'Press Start 2P', monospace; font-size: 7px; padding: 10px 12px;
    min-height: 44px; /* Touch target minimum Apple/Google */
    background: #2a2a3c; color: #f8d020; border: 2px solid #f8d020; border-radius: 4px;
    cursor: pointer; box-shadow: 2px 2px 0 #000; text-transform: uppercase; transition: transform 0.05s;
    display: flex; align-items: center; justify-content: center; width: 100%;
}
.btn:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 #000; }
.btn:hover { background: #3a3a50; }
.btn-small { display: inline-flex; width: auto; font-size: 7px; padding: 8px 12px; min-height: 36px; }

/* ─── Quiz (adapté touch) ─── */
.quiz-dialog { max-width: 320px; }
.quiz-timer-bar {
    width: 100%; height: 5px; background: #333; border-radius: 3px; margin-bottom: 8px; overflow: hidden;
}
.quiz-timer-fill {
    height: 100%; background: #38c838; transition: width 0.1s linear; width: 100%;
}
.quiz-timer-fill.warning { background: #f87820; }
.quiz-timer-fill.danger { background: #f83838; }

.options { display: flex; flex-direction: column; gap: 5px; }
.opt-btn {
    font-family: 'Press Start 2P', monospace; font-size: 6px; padding: 10px 8px;
    min-height: 40px; /* Touch-friendly */
    background: #2a2a3c; color: #f8f8f8; border: 2px solid #555; border-radius: 4px;
    cursor: pointer; text-align: left; transition: all 0.1s;
    display: flex; align-items: center;
}
.opt-btn:hover { border-color: #f8d020; background: #3a3a50; }
.opt-btn.correct { background: #1c6c30; border-color: #38c838; color: #b8ffc8; }
.opt-btn.wrong { background: #6c1c20; border-color: #f83838; color: #ffb8b8; }
.opt-btn:disabled { cursor: default; opacity: 0.8; }

.feedback { font-size: 6px; margin-top: 6px; min-height: 14px; }
.feedback.ok { color: #38c838; }
.feedback.ko { color: #f83838; }

/* ─── Session code ─── */
.session-code {
    font-size: 14px; color: #f8d020; letter-spacing: 4px; margin: 6px 0;
    background: #0a0a14; padding: 8px; border-radius: 4px;
}
.session-input {
    font-family: 'Press Start 2P', monospace; font-size: 10px; width: 100%; padding: 10px;
    min-height: 44px;
    background: #0a0a14; color: #f8f8f8; border: 2px solid #555; border-radius: 4px;
    text-align: center; letter-spacing: 3px; text-transform: uppercase;
}
.session-input:focus { border-color: #f8d020; outline: none; }

/* ─── Subject list ─── */
.subject-list { display: flex; flex-direction: column; gap: 4px; }
.subject-btn {
    font-family: 'Press Start 2P', monospace; font-size: 6px; padding: 10px 8px;
    min-height: 40px;
    background: #2a2a3c; color: #38c8f8; border: 2px solid #38c8f8; border-radius: 4px;
    cursor: pointer; text-align: center; display: flex; align-items: center; justify-content: center;
}
.subject-btn:hover { background: #1c3c6c; }

/* ─── Screen shake ─── */
.screen-wrap.shake { animation: screenShake 0.35s ease-in-out; }
@keyframes screenShake {
    0%, 100% { transform: translate(0, 0); }
    15% { transform: translate(-2px, 1px); }
    30% { transform: translate(2px, -1px); }
    45% { transform: translate(-1px, 2px); }
    60% { transform: translate(1px, -1px); }
    75% { transform: translate(-1px, 0px); }
    90% { transform: translate(1px, 1px); }
}

/* ─── Action bar ─── */
.action-bar { margin-top: 6px; display: flex; gap: 8px; }
.hint {
    margin-top: 6px; font-size: 5px; line-height: 1.8; color: rgba(255,255,255,0.4);
    text-align: center; max-width: 400px; text-shadow: 1px 1px 0 #000;
}
.hint b { color: #f8d020; }

/* ─── Panneau adversaires (Battle Royale) ─── */
.opponents-panel {
    width: 130px; max-height: calc(100dvh - 100px); overflow-y: auto;
    background: rgba(20,20,40,0.95); border: 2px solid #3c3c50;
    border-radius: 10px; padding: 6px 5px;
    font-family: 'Press Start 2P', monospace;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
.opponents-panel.hidden { display: none; }
.opponents-title { font-size: 5px; color: #f8d020; text-align: center; margin-bottom: 5px; letter-spacing: 1px; }
.opponents-list { display: flex; flex-direction: column; gap: 5px; }
.opponent-card {
    background: #1a1a28; border: 2px solid #3c3c50; border-radius: 5px;
    padding: 5px; transition: border-color 0.3s;
}
.opponent-card.dead { opacity: 0.35; border-color: #f83838; }
.opponent-card.leader { border-color: #f8d020; }
.opponent-card .opp-name { font-size: 4px; color: #f8f8f8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 2px; }
.opponent-card .opp-score { font-size: 6px; color: #f8d020; }
.opponent-card .opp-streak { font-size: 4px; color: #a838f8; margin-top: 2px; }
.opponent-card .opp-bar { height: 3px; background: #333; border-radius: 2px; margin-top: 3px; overflow: hidden; }
.opponent-card .opp-bar-fill { height: 100%; background: #38c838; transition: width 0.3s; }

/* ─── Character grid (40 personnages, 8×5 scrollable) ─── */
.character-grid {
    display: grid; grid-template-columns: repeat(8, 1fr); gap: 3px; margin-top: 5px;
    max-height: 110px; overflow-y: auto;
}
.char-btn {
    padding: 4px 2px !important; text-align: center; min-width: 0; height: 54px;
    display: flex !important; flex-direction: column; align-items: center; justify-content: center;
    overflow: hidden; transition: transform 0.1s, border-color 0.1s;
}
.char-btn:hover { transform: scale(1.06); }
.char-avatar {
    width: 22px; height: 22px; object-fit: contain; image-rendering: pixelated;
    display: block; flex-shrink: 0; margin: 0 auto 1px;
}

/* ─── Back button ─── */
.btn-back { background: transparent !important; border-color: #555 !important; color: #888 !important; font-size: 6px !important; min-height: 36px !important; }
.btn-back:hover { border-color: #f8f8f8 !important; color: #f8f8f8 !important; }

/* ─── Animations ─── */
@keyframes blink { 0% { opacity: 1; } 100% { opacity: 0.3; } }
@keyframes notifPulse { 0% { transform: translate(-50%, -50%) scale(1); } 100% { transform: translate(-50%, -50%) scale(1.06); } }

/* ─── Music menu ─── */
.music-list { display: flex; flex-direction: column; gap: 3px; max-height: 90px; overflow-y: auto; }
.music-track-btn { font-size: 5px !important; padding: 6px !important; text-align: left !important; min-height: 30px !important; }
.music-track-btn.active-track { border-color: #38c838 !important; background: #1c3c20 !important; }

/* ─── Notifications ─── */
.brainstorm-notif, .special-notif {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    z-index: 30; font-family: 'Press Start 2P', monospace; font-size: 7px;
    text-align: center; padding: 10px 12px; border-radius: 6px;
    animation: notifPulse 0.4s ease-in-out 4 alternate;
    pointer-events: none;
}
.brainstorm-notif { background: rgba(248,208,32,0.95); color: #1a1a28; border: 2px solid #f87820; box-shadow: 0 0 16px rgba(248,208,32,0.5); }
.special-notif { background: rgba(168,56,200,0.95); color: #fff; border: 2px solid #f8f8f8; box-shadow: 0 0 16px rgba(168,56,200,0.5); }

/* ─── Vrai/Faux ─── */
.vf-btn { font-size: 8px !important; padding: 12px !important; text-align: center !important; min-height: 48px !important; }

/* ─── Pairing ─── */
.pairing-term { background: #1a1a28; border: 1px solid #f8d020; border-radius: 3px; padding: 6px; margin-bottom: 5px; text-align: center; }

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE BREAKPOINTS
   ═══════════════════════════════════════════════════════════ */

/* ─── MOBILE PETIT (≤ 380px) — iPhone SE, petits Android ─── */
@media (max-width: 380px) {
    body { padding: 4px; }
    .page-title { font-size: 9px; margin-bottom: 3px; }
    .gbc-shell { width: 100vw; padding: 8px 6px 12px; border-radius: 0; }
    .gbc-screen { padding: 5px; }
    .btn { font-size: 6px; padding: 8px 8px; min-height: 40px; }
    .opt-btn { font-size: 5px; padding: 8px 6px; min-height: 36px; }
    .dialog { padding: 8px 6px; }
    .character-grid { grid-template-columns: repeat(4, 1fr); }
    .char-avatar { width: 20px; height: 20px; }
    .hint { display: none; }
    .controls { display: none; }
    .gbc-sub { display: none; }
    .gbc-label { font-size: 8px; margin: 6px 0 2px; }
}

/* ─── MOBILE STANDARD (≤ 480px) ─── */
@media (max-width: 480px) {
    .gbc-shell { width: 98vw; padding: 10px 8px 14px; }
    .hint { font-size: 5px; }
    .btn { font-size: 7px; }
    .action-bar { margin-top: 4px; }
}

/* ─── MOBILE LANDSCAPE ─── */
@media (max-height: 500px) and (orientation: landscape) {
    body { padding: 2px; flex-direction: row; }
    .page-title { display: none; }
    .gbc-shell { width: auto; height: calc(100dvh - 8px); padding: 6px; border-radius: 8px; }
    .gbc-screen { padding: 4px; }
    .gbc-label { display: none; }
    .gbc-sub { display: none; }
    .controls { display: none; }
    .action-bar { flex-direction: column; margin-top: 0; margin-left: 6px; }
    .hint { display: none; }
    .game-container { gap: 6px; }
    /* Scanlines trop lourds en landscape mobile */
    .scanlines, .lcd-grid { display: none; }
}

/* ─── TABLETTE (481px - 768px) ─── */
@media (min-width: 481px) and (max-width: 768px) {
    .gbc-shell { width: min(85vw, 440px); }
    .character-grid { grid-template-columns: repeat(5, 1fr); max-height: 120px; }
}

/* ─── PETIT DESKTOP / LAPTOP (≤ 700px de hauteur) ─── */
@media (max-height: 700px) and (min-width: 481px) {
    .page-title { margin-bottom: 3px; font-size: 12px; }
    .gbc-shell { padding: 10px 10px 14px; }
    .hint { display: none; }
    .controls { margin-top: 6px; }
    .dpad { width: 50px; height: 50px; }
    .dpad::before { left: 19px; width: 12px; height: 50px; }
    .dpad::after  { top: 19px; width: 50px; height: 12px; }
    .dpad-center { left: 19px; top: 19px; width: 12px; height: 12px; }
    .abtn { width: 24px; height: 24px; font-size: 8px; }
}

/* ─── GRAND ÉCRAN (≥ 1024px) ─── */
@media (min-width: 1024px) {
    .gbc-shell { width: 460px; }
    .character-grid { max-height: 130px; }
    .char-avatar { width: 30px; height: 30px; }
}

/* ─── BATTLE MODE: panneau passe en bas sur mobile ─── */
@media (max-width: 640px) {
    .game-container.battle-mode { flex-direction: column; align-items: center; }
    .opponents-panel {
        width: 96vw; max-width: 440px; max-height: 70px;
        display: flex; gap: 4px; padding: 4px; order: 1;
    }
    .opponents-panel .opponents-title { display: none; }
    .opponents-list { flex-direction: row; overflow-x: auto; gap: 4px; }
    .opponent-card { min-width: 75px; flex-shrink: 0; }
}

/* ─── PERFORMANCE: désactiver les effets visuels lourds sur mobile ─── */
@media (hover: none) and (pointer: coarse) {
    /* Mobile touch device — alleger les composites GPU */
    .scanlines { opacity: 0.5; }
    .lcd-grid { display: none; }
    .glass { display: none; }
    /* Disable hover effects (pas pertinent sur touch) */
    .btn:hover { background: #2a2a3c; }
    .opt-btn:hover { border-color: #555; background: #2a2a3c; }
}

/* ─── PREFERS-REDUCED-MOTION (accessibilité) ─── */
@media (prefers-reduced-motion: reduce) {
    .screen-wrap.shake { animation: none; }
    .brainstorm-notif, .special-notif { animation: none; }
    @keyframes blink { 0%, 100% { opacity: 1; } }
}
