@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;600;700;900&display=swap');

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

body {
    background: #06060e;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    font-family: 'Outfit', sans-serif;
    overflow: hidden;
}

/* ── Game Wrapper ── */
#game-wrapper {
    position: relative;
    width: min(100vw, 1024px);
    aspect-ratio: 16 / 10;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 10px;
    overflow: hidden;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    transform: translateZ(0);
    box-shadow:
        0 0 40px rgba(0,0,0,0.85),
        0 0 80px rgba(254,240,138,0.06),
        0 0 80px rgba(168,85,247,0.06);
}

body.touch-device #game-wrapper {
    box-shadow: 0 0 20px rgba(0,0,0,0.9);
}

#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #0a0a14;
    transform: translateZ(0);
}

/* ── HUD ── */
#hud {
    position: absolute;
    top: 0; left: 0; right: 0;
    padding: 10px 18px;
    display: none;
    justify-content: space-between;
    align-items: center;
    pointer-events: none;
    z-index: 10;
}
#hud.visible { display: flex; }

#timer {
    font-size: 22px;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 2px 10px rgba(0,0,0,0.8);
    background: rgba(0,0,0,0.55);
    padding: 5px 18px;
    border-radius: 20px;
    backdrop-filter: blur(6px);
    border: 1px solid rgba(255,255,255,0.08);
}

.gem-count {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    text-shadow: 0 2px 6px rgba(0,0,0,0.8);
    background: rgba(0,0,0,0.55);
    padding: 5px 14px;
    border-radius: 16px;
    backdrop-filter: blur(6px);
    border: 1px solid rgba(255,255,255,0.08);
}

#deaths-badge {
    font-size: 15px;
    font-weight: 700;
    color: #ff6666;
    background: rgba(40, 10, 10, 0.65);
    padding: 5px 14px;
    border-radius: 16px;
    backdrop-filter: blur(6px);
    border: 1px solid rgba(255, 80, 80, 0.25);
    display: flex;
    align-items: center;
    gap: 5px;
    text-shadow: 0 1px 4px rgba(0,0,0,0.8);
}

.gem-icon {
    width: 14px; height: 14px;
    border-radius: 2px;
    transform: rotate(45deg);
}
.gem-icon.fire, .gem-icon.light  { background: linear-gradient(135deg, #ffffff 0%, #fef08a 40%, #eab308 100%); box-shadow: 0 0 8px rgba(254,240,138,0.8); }
.gem-icon.water, .gem-icon.shadow { background: linear-gradient(135deg, #ffffff 0%, #c084fc 45%, #6b21a8 100%); box-shadow: 0 0 8px rgba(192,132,252,0.8); }

/* ── Character Overcharge Meters ── */
.hud-character-meter {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0, 0, 0, 0.6);
    padding: 5px 12px;
    border-radius: 16px;
    backdrop-filter: blur(6px);
    border: 1px solid rgba(255, 255, 255, 0.08);
}
.lux-meter { border-color: rgba(254, 240, 138, 0.35); }
.umbra-meter { border-color: rgba(192, 132, 252, 0.35); }

.meter-icon { font-size: 14px; }

.meter-bar-container {
    width: 70px;
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.meter-bar {
    height: 100%;
    width: 0%;
    border-radius: 4px;
    transition: width 0.15s ease-out;
}

.lux-meter .meter-bar {
    background: linear-gradient(90deg, #fef08a, #f59e0b, #ffffff);
    box-shadow: 0 0 8px rgba(254, 240, 138, 0.8);
}

.umbra-meter .meter-bar {
    background: linear-gradient(90deg, #c084fc, #7c3aed, #ffffff);
    box-shadow: 0 0 8px rgba(192, 132, 252, 0.8);
}

.meter-val {
    font-size: 12px;
    font-weight: 700;
    min-width: 28px;
    text-align: right;
}
.lux-meter .meter-val { color: #fef08a; }
.umbra-meter .meter-val { color: #e9d5ff; }

#pause-btn {
    position: absolute;
    top: 10px; right: 18px;
    background: rgba(0,0,0,0.55);
    border: 1px solid rgba(255,255,255,0.15);
    color: #ccc;
    font-size: 20px;
    cursor: pointer;
    padding: 4px 12px;
    border-radius: 10px;
    display: none;
    z-index: 30;
    backdrop-filter: blur(6px);
    transition: all 0.2s;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
#pause-btn:hover { background: rgba(255,255,255,0.2); color: #fff; }
#pause-btn.visible { display: block; }

#fullscreen-btn {
    position: absolute;
    top: 10px; right: 66px;
    background: rgba(0,0,0,0.55);
    border: 1px solid rgba(255,255,255,0.15);
    color: #ccc;
    font-size: 18px;
    cursor: pointer;
    padding: 4px 11px;
    border-radius: 10px;
    display: block; /* Always accessible */
    z-index: 30;
    backdrop-filter: blur(6px);
    transition: all 0.2s;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
#fullscreen-btn:hover, #fullscreen-btn:active {
    background: rgba(255,255,255,0.25);
    color: #fff;
    border-color: #38bdf8;
    transform: scale(1.05);
}

/* ── Screen Overlays ── */
.screen-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 20;
    transition: opacity 0.3s;
}
.hidden { display: none !important; }
.screen-overlay.hidden { display: none !important; }

/* ── Title Screen ── */
#title-screen {
    background: linear-gradient(170deg, #161009 0%, #0b0814 45%, #05020c 100%);
}

/* ── Title Emblem & Brand Headers ── */
.title-emblem-wrap {
    margin-bottom: 12px;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

.title-emblem {
    width: 78px;
    height: 78px;
    border-radius: 50%;
    filter: drop-shadow(0 0 20px rgba(168, 85, 247, 0.45)) drop-shadow(0 0 35px rgba(254, 240, 138, 0.35));
    animation: emblemPulse 4s ease-in-out infinite alternate;
}

@keyframes emblemPulse {
    0% {
        transform: scale(0.97) rotate(-2deg);
        filter: drop-shadow(0 0 16px rgba(168, 85, 247, 0.4)) drop-shadow(0 0 24px rgba(254, 240, 138, 0.3));
    }
    100% {
        transform: scale(1.03) rotate(2deg);
        filter: drop-shadow(0 0 24px rgba(168, 85, 247, 0.6)) drop-shadow(0 0 38px rgba(254, 240, 138, 0.5));
    }
}

.screen-brand-header {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.85);
    background: rgba(255, 255, 255, 0.06);
    padding: 5px 14px 5px 8px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    margin-bottom: 12px;
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.screen-brand-icon {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: block;
    filter: drop-shadow(0 0 6px rgba(254, 240, 138, 0.5));
}

.hud-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.45);
    padding: 4px 8px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(6px);
}

.hud-brand-icon {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: block;
    filter: drop-shadow(0 0 6px rgba(254, 240, 138, 0.6)) drop-shadow(0 0 6px rgba(168, 85, 247, 0.6));
}

.title-chars {
    display: flex;
    gap: 30px;
    margin-bottom: 10px;
    font-size: 14px;
    opacity: 0.8;
}

#title-screen h1 {
    font-size: 52px;
    font-weight: 900;
    letter-spacing: 2px;
    margin-bottom: 4px;
    line-height: 1.1;
}

.fire-text, .light-title-text {
    background: linear-gradient(180deg, #ffffff 0%, #fef08a 40%, #eab308 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    filter: drop-shadow(0 0 16px rgba(254,240,138,0.6));
}

.amp {
    color: #666;
    font-size: 36px;
    font-weight: 400;
    margin: 0 4px;
}

.water-text, .shadow-title-text {
    background: linear-gradient(180deg, #f8fafc 0%, #c084fc 45%, #6b21a8 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    filter: drop-shadow(0 0 16px rgba(168,85,247,0.6));
}

.subtitle {
    color: #999;
    font-size: 15px;
    margin-bottom: 34px;
    font-weight: 500;
    letter-spacing: 4px;
    text-transform: uppercase;
}

/* ── Controls Info ── */
.controls-info {
    display: flex;
    gap: 40px;
    margin-top: 30px;
    padding: 18px 28px;
    background: rgba(255,255,255,0.03);
    border-radius: 14px;
    border: 1px solid rgba(255,255,255,0.08);
}

.control-set {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.player-name { font-weight: 700; font-size: 15px; }
.player-name.fire, .player-name.light   { color: #fef08a; text-shadow: 0 0 8px rgba(254,240,138,0.4); }
.player-name.water, .player-name.shadow { color: #c084fc; text-shadow: 0 0 8px rgba(192,132,252,0.4); }

.keys {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 130px;
}

.key-cap {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 6px;
    padding: 3px 9px;
    font-size: 12px;
    color: #ccc;
    font-weight: 600;
    min-width: 28px;
    text-align: center;
}

.character-quote {
    font-size: 12px;
    font-style: italic;
    color: #ffd280;
    margin-bottom: 4px;
    opacity: 0.9;
}
.control-set:nth-child(2) .character-quote {
    color: #d8b4fe;
}

.character-lore {
    font-size: 11px;
    color: #888;
    margin-top: 4px;
    max-width: 185px;
    text-align: center;
    line-height: 1.3;
}

.troll-warning {
    margin-top: 22px;
    font-size: 13px;
    color: #ffaa55;
    letter-spacing: 0.5px;
    opacity: 0.95;
    background: rgba(40, 20, 10, 0.4);
    padding: 6px 16px;
    border-radius: 20px;
    border: 1px solid rgba(255, 170, 85, 0.2);
}

/* ── Level Select ── */
#level-select {
    background: rgba(8, 8, 18, 0.96);
    backdrop-filter: blur(12px);
}

#level-select h2 {
    color: #fff;
    font-size: 28px;
    margin-bottom: 14px;
    font-weight: 700;
}

.level-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    max-width: 900px;
    margin: 0 auto 16px auto;
    justify-content: center;
}

.level-card {
    height: 94px;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    border: 2px solid rgba(255,255,255,0.08);
    background: linear-gradient(145deg, rgba(255,215,0,0.05), rgba(147,51,234,0.05));
    transition: all 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    color: white;
    position: relative;
    overflow: hidden;
    padding: 6px 4px;
}

.level-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 50% 120%, rgba(255,215,0,0.15), transparent 70%);
    opacity: 0;
    transition: opacity 0.3s;
}

.level-card:hover {
    border-color: rgba(255,215,0,0.4);
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 8px 24px rgba(255,180,0,0.2), 0 0 12px rgba(168,85,247,0.2);
}
.level-card:hover::before { opacity: 1; }

.level-num {
    font-size: 24px;
    font-weight: 900;
    background: linear-gradient(180deg, #fffbeb, #ffd700);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1;
    position: relative;
}

.level-name {
    font-size: 11.5px;
    font-weight: 600;
    color: #e2e8f0;
    margin-top: 2px;
    position: relative;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.level-diff {
    font-size: 9.5px;
    color: #ffd700;
    font-weight: 700;
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: rgba(255, 215, 0, 0.1);
    padding: 2px 8px;
    border-radius: 8px;
    border: 1px solid rgba(255, 215, 0, 0.25);
    position: relative;
}

/* ── Buttons ── */
.game-btn {
    padding: 13px 38px;
    font-family: 'Outfit', sans-serif;
    font-size: 16px;
    font-weight: 700;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    text-transform: uppercase;
    letter-spacing: 2px;
    position: relative;
    overflow: hidden;
}

.game-btn.primary {
    background: linear-gradient(135deg, #ff6600, #ff3300);
    color: white;
    box-shadow: 0 4px 24px rgba(255, 70, 0, 0.35);
}
.game-btn.primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 36px rgba(255, 70, 0, 0.5);
}

.game-btn.secondary {
    background: rgba(255,255,255,0.08);
    color: #ccc;
    border: 1px solid rgba(255,255,255,0.15);
}
.game-btn.secondary:hover {
    background: rgba(255,255,255,0.15);
    color: #fff;
    transform: translateY(-2px);
}

.btn-group {
    display: flex;
    gap: 14px;
}

/* ── Pause Screen ── */
#pause-screen {
    background: rgba(0, 0, 0, 0.82);
    backdrop-filter: blur(10px);
}
#pause-screen h2 {
    color: #fff;
    font-size: 44px;
    margin-bottom: 28px;
    font-weight: 700;
}
#pause-screen .btn-group {
    flex-direction: column;
    gap: 10px;
}

/* ── Win Screen ── */
#win-screen {
    background: rgba(0, 18, 0, 0.88);
    backdrop-filter: blur(10px);
}
#win-screen h2 {
    color: #00ff88;
    font-size: 46px;
    margin-bottom: 14px;
    font-weight: 900;
    text-shadow: 0 0 40px rgba(0,255,100,0.4);
}
.win-stats {
    color: #bbb;
    font-size: 18px;
    margin-bottom: 28px;
    text-align: center;
    line-height: 1.9;
}
.win-stats span {
    color: #fff;
    font-weight: 700;
}

/* ── Lose Screen ── */
#lose-screen {
    background: rgba(25, 0, 0, 0.88);
    backdrop-filter: blur(10px);
}
#lose-screen h2 {
    color: #ff4444;
    font-size: 46px;
    margin-bottom: 10px;
    font-weight: 900;
    text-shadow: 0 0 40px rgba(255,50,50,0.4);
}
#lose-msg {
    color: #bbb;
    font-size: 17px;
    margin-bottom: 28px;
}

/* ── Back Link ── */
.back-link {
    margin-top: 20px;
    color: #666;
    font-size: 14px;
    cursor: pointer;
    transition: color 0.2s;
    border: none;
    background: none;
    font-family: 'Outfit', sans-serif;
}
.back-link:hover { color: #aaa; }

/* ── Online Co-op & Multiplayer Styles ── */
.title-btn-row {
    display: flex;
    gap: 14px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 24px;
}

.coop-btn {
    background: linear-gradient(135deg, #059669, #0d9488) !important;
    color: #ffffff !important;
    border: 1px solid rgba(52, 211, 153, 0.4) !important;
    box-shadow: 0 4px 20px rgba(13, 148, 136, 0.35) !important;
    transition: all 0.25s ease !important;
}
.coop-btn:hover {
    transform: translateY(-2px) scale(1.03);
    box-shadow: 0 6px 28px rgba(16, 185, 129, 0.55) !important;
    border-color: #6ee7b7 !important;
}

/* ── Co-op Modal Overlay ── */
#coop-modal {
    background: rgba(10, 8, 20, 0.94);
    backdrop-filter: blur(14px);
    z-index: 60;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 20px 16px;
}

#coop-modal h2 {
    font-size: 38px;
    font-weight: 900;
    margin-bottom: 6px;
    background: linear-gradient(135deg, #38bdf8, #818cf8, #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.mp-tabs {
    display: flex;
    gap: 12px;
    margin: 20px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 12px;
}

.mp-tab {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #94a3b8;
    padding: 10px 22px;
    border-radius: 10px;
    font-family: 'Outfit', sans-serif;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}
.mp-tab:hover {
    color: #f8fafc;
    background: rgba(255, 255, 255, 0.08);
}
.mp-tab.active {
    background: linear-gradient(135deg, rgba(56, 189, 248, 0.2), rgba(129, 140, 248, 0.25));
    border-color: #818cf8;
    color: #ffffff;
    box-shadow: 0 0 16px rgba(129, 140, 248, 0.3);
}

.mp-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 480px;
}

.mp-desc {
    color: #cbd5e1;
    font-size: 15px;
    margin-bottom: 16px;
    text-align: center;
    line-height: 1.5;
}

.code-display-box {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(15, 23, 42, 0.85);
    border: 2px dashed rgba(129, 140, 248, 0.5);
    padding: 12px 20px;
    border-radius: 12px;
    margin-bottom: 16px;
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.5);
}

.room-code-text {
    font-family: monospace;
    font-size: 32px;
    font-weight: 900;
    letter-spacing: 6px;
    color: #38bdf8;
    text-shadow: 0 0 12px rgba(56, 189, 248, 0.6);
    user-select: all;
}

.mp-mini-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #f8fafc;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 13px;
    font-family: 'Outfit', sans-serif;
    cursor: pointer;
    transition: all 0.2s;
}
.mp-mini-btn:hover {
    background: rgba(255, 255, 255, 0.18);
    border-color: #38bdf8;
    transform: translateY(-1px);
}

.mp-status-box {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 18px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.04);
    font-size: 14px;
    color: #94a3b8;
    margin-bottom: 20px;
    border: 1px solid rgba(255, 255, 255, 0.08);
}
.mp-status-box.waiting {
    color: #fbbf24;
    border-color: rgba(251, 191, 36, 0.3);
}
.mp-status-box.connected {
    color: #34d399;
    border-color: rgba(52, 211, 153, 0.4);
    background: rgba(52, 211, 153, 0.1);
}

.join-input-group {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    width: 100%;
    max-width: 400px;
}

#mp-join-code {
    flex: 1;
    background: rgba(15, 23, 42, 0.85);
    border: 2px solid rgba(129, 140, 248, 0.4);
    color: #ffffff;
    font-family: monospace;
    font-size: 22px;
    font-weight: 800;
    text-align: center;
    letter-spacing: 4px;
    padding: 10px;
    border-radius: 10px;
    outline: none;
    transition: border-color 0.2s;
}
#mp-join-code:focus {
    border-color: #38bdf8;
    box-shadow: 0 0 16px rgba(56, 189, 248, 0.4);
}

/* ── HUD Multiplayer Status & Quick Emotes ── */
.mp-hud-badge {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(15, 23, 42, 0.85);
    border: 1px solid rgba(129, 140, 248, 0.4);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 13px;
    color: #e2e8f0;
}

#mp-hud-role {
    font-weight: 700;
}

#mp-ping-badge {
    font-family: monospace;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 6px;
}
.ping-good { background: rgba(34, 197, 94, 0.2); color: #4ade80; border: 1px solid rgba(74, 222, 128, 0.4); }
.ping-ok   { background: rgba(234, 179, 8, 0.2); color: #facc15; border: 1px solid rgba(250, 204, 21, 0.4); }
.ping-lag  { background: rgba(239, 68, 68, 0.2); color: #f87171; border: 1px solid rgba(248, 113, 113, 0.4); }

.mp-quick-emotes {
    display: flex;
    gap: 4px;
}
.mp-emote-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    padding: 2px 6px;
    font-size: 13px;
    cursor: pointer;
    transition: transform 0.15s, background 0.15s;
}
.mp-emote-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.18);
}

/* ── Virtual On-Screen Touch Controls (Phones / Touch Devices Only) ── */
#touch-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 140px;
    display: none; /* Hidden on PC / mouse by default */
    justify-content: space-between;
    align-items: flex-end;
    padding: 12px 20px env(safe-area-inset-bottom, 14px) 20px;
    pointer-events: none;
    z-index: 25;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

/* Display touch controls ONLY on touch-enabled devices when HUD is visible (playing) */
body.touch-device #hud.visible ~ #touch-controls {
    display: flex;
}

.touch-cluster {
    display: flex;
    align-items: center;
    gap: 12px;
    pointer-events: auto;
}

.touch-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.28);
    border: 1.5px solid rgba(255, 255, 255, 0.22);
    border-radius: 50%;
    color: rgba(248, 250, 252, 0.85);
    font-family: 'Outfit', sans-serif;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
    opacity: 0.65;
    transition: transform 0.08s ease, background 0.08s ease, opacity 0.12s ease, border-color 0.08s ease, box-shadow 0.08s ease;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.touch-btn:active,
.touch-btn.pressed {
    opacity: 1 !important;
}

/* Directional Buttons (Left & Right) */
.touch-left-cluster .touch-btn {
    width: 64px;
    height: 64px;
    font-size: 22px;
}

.touch-left-cluster .touch-btn:active,
.touch-left-cluster .touch-btn.pressed {
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.5), rgba(245, 158, 11, 0.7));
    border-color: #fbbf24;
    box-shadow: 0 0 24px rgba(251, 191, 36, 0.8);
    transform: scale(0.92);
}

/* Jump Button */
.touch-jump-btn {
    width: 78px;
    height: 78px;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.25), rgba(168, 85, 247, 0.35));
    border-color: rgba(192, 132, 252, 0.45);
}

.touch-jump-btn .touch-icon {
    font-size: 24px;
    margin-bottom: -3px;
}

.touch-jump-btn .touch-label {
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 1px;
    color: #e2e8f0;
}

.touch-jump-btn:active,
.touch-jump-btn.pressed {
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.7), rgba(217, 70, 239, 0.85));
    border-color: #c084fc;
    box-shadow: 0 0 30px rgba(192, 132, 252, 0.85);
    transform: scale(0.92);
}

/* Character Swap Button in Solo Mode */
.touch-swap-btn {
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
    background: rgba(30, 41, 59, 0.35);
    border: 1px solid rgba(148, 163, 184, 0.3);
    min-width: 90px;
    opacity: 0.7;
}

.touch-swap-btn:active,
.touch-swap-btn.pressed {
    opacity: 1 !important;
    background: rgba(56, 189, 248, 0.4);
    border-color: #38bdf8;
    box-shadow: 0 0 16px rgba(56, 189, 248, 0.5);
}

.touch-swap-hint {
    font-size: 9px;
    opacity: 0.7;
    font-weight: 400;
    margin-top: 1px;
}

/* ── Orientation Prompt (Portrait warning on Phones) ── */
#orientation-prompt {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(6, 6, 14, 0.96);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    padding: 24px;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    text-align: center;
}

@media (orientation: portrait) and (max-width: 900px) {
    body.touch-device #orientation-prompt {
        display: flex;
    }
}

.orient-card {
    background: rgba(15, 23, 42, 0.85);
    border: 1px solid rgba(129, 140, 248, 0.35);
    padding: 32px 24px;
    border-radius: 24px;
    max-width: 320px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.85);
}

.orient-icon-anim {
    font-size: 52px;
    margin-bottom: 16px;
    animation: rotatePhone 2.2s infinite ease-in-out;
}

@keyframes rotatePhone {
    0% { transform: rotate(0deg); }
    40% { transform: rotate(-90deg); }
    70% { transform: rotate(-90deg); }
    100% { transform: rotate(0deg); }
}

.orient-card h3 {
    font-size: 20px;
    font-weight: 800;
    color: #f8fafc;
    margin-bottom: 8px;
}

.orient-card p {
    font-size: 13px;
    color: #94a3b8;
    line-height: 1.5;
}

/* ── Fullscreen and Mobile Expansion ── */
:fullscreen #game-wrapper,
:-webkit-full-screen #game-wrapper,
body.is-fullscreen #game-wrapper,
body.touch-device #game-wrapper {
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    max-height: 100dvh !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    aspect-ratio: auto !important;
}

:fullscreen #game-canvas,
:-webkit-full-screen #game-canvas,
body.is-fullscreen #game-canvas,
body.touch-device #game-canvas {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain !important;
}

/* ══════════════════════════════════════════════════════════════
   MOBILE PHONE — ENLARGED UI FOR TOUCH SCREENS
   All buttons, text, and controls scaled up for finger-friendly use
   ══════════════════════════════════════════════════════════════ */

/* ── General mobile (max-width 800px) ── */
@media (max-width: 800px) {

    /* ── Title Screen ── */
    #title-screen h1 { font-size: 36px; margin-bottom: 4px; }
    .subtitle { font-size: 12px; margin-bottom: 16px; letter-spacing: 2px; }
    .controls-info { display: none; }
    .troll-warning { font-size: 13px; margin-top: 12px; max-width: 92%; padding: 8px 14px; }

    /* ── Buttons — BIG finger-friendly targets ── */
    .title-btn-row {
        flex-direction: column;
        width: 92%;
        max-width: 340px;
        gap: 12px;
    }
    .game-btn {
        width: 100%;
        padding: 16px 20px;
        font-size: 17px;
        letter-spacing: 1.5px;
        border-radius: 14px;
        min-height: 54px;
    }
    .game-btn.primary {
        box-shadow: 0 4px 20px rgba(255, 70, 0, 0.4);
    }
    .coop-btn {
        box-shadow: 0 4px 20px rgba(13, 148, 136, 0.4) !important;
    }

    /* ── Level Select ── */
    #level-select h2 { font-size: 26px; margin-bottom: 16px; }
    .level-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
        max-width: 95%;
        padding: 0 8px;
    }
    .level-card {
        height: 90px;
        padding: 8px 4px;
        border-radius: 10px;
    }
    .level-card .level-num { font-size: 22px; }
    .level-card .level-name { font-size: 12px; }
    .level-card .level-diff { font-size: 9px; }
    .back-link { font-size: 16px; padding: 10px 16px; min-height: 44px; }

    /* ── Co-op Modal — Scrollable, fits phone screen ── */
    #coop-modal {
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        padding: 16px 12px;
        padding-top: env(safe-area-inset-top, 16px);
        padding-bottom: env(safe-area-inset-bottom, 16px);
        justify-content: flex-start;
    }
    #coop-modal h2 {
        font-size: 28px;
        margin-bottom: 4px;
        margin-top: 8px;
    }
    #coop-modal .subtitle {
        font-size: 11px;
        margin-bottom: 10px;
    }
    .mp-tabs {
        gap: 8px;
        margin: 12px 0;
        padding-bottom: 10px;
        flex-wrap: nowrap;
        width: 100%;
        max-width: 340px;
    }
    .mp-tab {
        padding: 12px 16px;
        font-size: 14px;
        border-radius: 12px;
        flex: 1;
        text-align: center;
        min-height: 48px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .mp-panel {
        max-width: 100%;
        padding: 0 4px;
    }
    .mp-desc {
        font-size: 14px;
        margin-bottom: 12px;
        padding: 0 8px;
    }
    .code-display-box {
        flex-wrap: wrap;
        justify-content: center;
        padding: 12px 14px;
        gap: 8px;
        width: 100%;
        max-width: 340px;
    }
    .room-code-text {
        font-size: 28px;
        letter-spacing: 5px;
        width: 100%;
        text-align: center;
        margin-bottom: 4px;
    }
    .mp-mini-btn {
        padding: 10px 16px;
        font-size: 14px;
        border-radius: 10px;
        min-height: 44px;
        flex: 1;
    }
    .mp-status-box {
        font-size: 14px;
        padding: 10px 14px;
        width: 100%;
        max-width: 340px;
    }
    .join-input-group {
        max-width: 340px;
        width: 100%;
        gap: 8px;
    }
    #mp-join-code {
        font-size: 20px;
        padding: 12px 10px;
        letter-spacing: 4px;
        min-height: 50px;
    }
    .join-input-group .game-btn {
        min-width: 100px;
        padding: 12px 16px;
    }
    #btn-coop-back {
        margin-top: 16px;
        margin-bottom: 16px;
    }
    #btn-host-start {
        min-height: 50px;
        font-size: 16px;
    }

    /* ── Pause / Win / Lose screens ── */
    #pause-screen h2 { font-size: 34px; margin-bottom: 20px; }
    #win-screen h2 { font-size: 34px; }
    #lose-screen h2 { font-size: 34px; }
    #lose-msg { font-size: 15px; }
    .win-stats { font-size: 16px; }
    .btn-group {
        gap: 10px;
        width: 85%;
        max-width: 300px;
    }
    .btn-group .game-btn {
        min-height: 50px;
        font-size: 16px;
    }

    /* ── HUD — Slightly larger for readability ── */
    #hud {
        padding: 6px 10px;
        gap: 4px;
        flex-wrap: nowrap;
    }
    #timer {
        font-size: 16px;
        padding: 4px 12px;
        border-radius: 14px;
    }
    .gem-count {
        font-size: 13px;
        gap: 4px;
        padding: 4px 10px;
    }
    #deaths-badge {
        font-size: 13px;
        padding: 4px 10px;
    }
    .hud-character-meter {
        padding: 4px 8px;
        gap: 4px;
    }
    .meter-bar-container { width: 50px; }
    .meter-val { font-size: 11px; min-width: 24px; }
    .meter-icon { font-size: 12px; }
    #pause-btn {
        top: 6px; right: 8px;
        width: 36px; height: 36px;
        font-size: 16px;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: 36px;
    }
    #fullscreen-btn {
        top: 6px; right: 50px;
        width: 36px; height: 36px;
        font-size: 16px;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: 36px;
    }
    .mp-hud-badge { padding: 3px 8px; font-size: 11px; }
    .mp-emote-btn { font-size: 12px; padding: 2px 5px; }

    /* ── Touch Controls — BIGGER for phones ── */
    #touch-controls {
        height: 120px;
        padding: 8px 16px env(safe-area-inset-bottom, 10px) 16px;
    }
    .touch-left-cluster .touch-btn {
        width: 66px;
        height: 66px;
        font-size: 24px;
    }
    .touch-jump-btn {
        width: 82px;
        height: 82px;
    }
    .touch-jump-btn .touch-icon { font-size: 26px; }
    .touch-jump-btn .touch-label { font-size: 11px; letter-spacing: 1.5px; }
    .touch-swap-btn {
        padding: 8px 16px;
        font-size: 13px;
        min-width: 100px;
        min-height: 40px;
    }
    .touch-cluster { gap: 14px; }
}

/* ── Extra-small phones (width <= 420px) — even bigger buttons ── */
@media (max-width: 420px) {
    #title-screen h1 { font-size: 30px; }
    .subtitle { font-size: 10px; letter-spacing: 1.5px; }
    .title-btn-row { width: 95%; max-width: 300px; }
    .game-btn {
        padding: 18px 20px;
        font-size: 18px;
        min-height: 58px;
    }
    .level-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
    .level-card { height: 80px; }
    .level-card .level-num { font-size: 20px; }

    #coop-modal h2 { font-size: 24px; }
    .room-code-text { font-size: 24px; letter-spacing: 3px; }
    .mp-tab { font-size: 13px; padding: 10px 12px; }
}

/* ── Landscape phone — tighter vertical spacing ── */
@media (max-height: 450px) and (orientation: landscape) {
    #title-screen {
        padding: 6px 16px;
        justify-content: center;
        gap: 2px;
    }
    .title-emblem-wrap { margin-bottom: 2px; }
    .title-emblem { width: 44px; height: 44px; }
    .screen-brand-header { margin-bottom: 4px; padding: 2px 10px 2px 6px; font-size: 11px; }
    .screen-brand-icon { width: 16px; height: 16px; }
    #title-screen h1 { font-size: 26px; margin-bottom: 1px; }
    .subtitle { font-size: 9px; margin-bottom: 4px; }
    .title-btn-row {
        flex-direction: row;
        width: auto;
        max-width: none;
        gap: 12px;
    }
    .game-btn {
        width: auto;
        padding: 12px 24px;
        font-size: 15px;
        min-height: 46px;
    }
    .troll-warning { margin-top: 6px; font-size: 11px; }

    /* Co-op modal in landscape — less vertical padding */
    #coop-modal {
        padding: 8px 16px;
        justify-content: flex-start;
    }
    #coop-modal h2 { font-size: 22px; margin-top: 4px; margin-bottom: 2px; }
    #coop-modal .subtitle { margin-bottom: 6px; }
    .mp-tabs { margin: 6px 0; }
    .mp-tab { padding: 8px 14px; min-height: 40px; }
    .code-display-box { padding: 8px 12px; }
    .room-code-text { font-size: 24px; }
    .mp-mini-btn { padding: 8px 12px; min-height: 38px; }
    .mp-status-box { padding: 6px 12px; margin-bottom: 10px; }
    #mp-join-code { min-height: 42px; padding: 8px; }
    #btn-host-start { min-height: 42px; }

    /* Level select in landscape */
    #level-select h2 { font-size: 22px; margin-bottom: 10px; }
    .level-grid {
        grid-template-columns: repeat(5, 1fr);
        gap: 6px;
    }
    .level-card { height: 70px; }

    /* Pause/Win/Lose in landscape */
    #pause-screen h2, #win-screen h2, #lose-screen h2 { font-size: 28px; margin-bottom: 12px; }
    .win-stats { margin-bottom: 14px; }
    .btn-group .game-btn { min-height: 42px; font-size: 14px; }

    /* Touch controls in landscape — positioned at edges */
    #touch-controls {
        height: 100px;
        padding: 6px 20px env(safe-area-inset-bottom, 8px) 20px;
    }
    .touch-left-cluster .touch-btn { width: 60px; height: 60px; font-size: 22px; }
    .touch-jump-btn { width: 74px; height: 74px; }
    .touch-jump-btn .touch-icon { font-size: 22px; }
}

/* ══════════════════════════════════════════════════════════════
   GAMEPAD & PROGRESSION STYLES (STEAM READY)
   ══════════════════════════════════════════════════════════════ */

/* Gamepad connection toast */
#gamepad-toast {
    position: absolute;
    top: 54px;
    left: 50%;
    transform: translateX(-50%) translateY(-60px);
    background: linear-gradient(135deg, rgba(20, 15, 35, 0.95), rgba(30, 20, 50, 0.95));
    border: 1px solid rgba(192, 132, 252, 0.4);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.6), 0 0 15px rgba(192, 132, 252, 0.25);
    color: #f8fafc;
    font-size: 13px;
    font-weight: 700;
    padding: 8px 18px;
    border-radius: 20px;
    z-index: 1000;
    pointer-events: none;
    opacity: 0;
    transition: transform 0.35s cubic-bezier(0.18, 0.89, 0.32, 1.28), opacity 0.35s ease;
}

#gamepad-toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* Title screen Gamepad Hint Bar */
.gamepad-hint-bar {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 6px 14px;
    border-radius: 20px;
    margin: 8px auto;
    font-size: 12px;
    color: #cbd5e1;
    max-width: 90%;
}

.gp-pill {
    font-weight: 700;
    color: #fef08a;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.gp-detail kbd {
    background: #1e1b2e;
    border: 1px solid #4c1d95;
    border-bottom: 2px solid #3b0764;
    padding: 1px 6px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 11px;
    color: #f3e8ff;
    font-weight: 700;
}

/* Level Select Lock & Record Badges */
.level-card {
    position: relative;
    transition: transform 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.level-card.locked {
    opacity: 0.45;
    filter: grayscale(0.85);
    cursor: not-allowed;
    border-color: rgba(255, 255, 255, 0.05);
}

.level-card.locked:hover {
    transform: none;
    border-color: rgba(239, 68, 68, 0.3);
}

.level-card.completed {
    border-color: rgba(74, 222, 128, 0.4);
    box-shadow: 0 0 12px rgba(74, 222, 128, 0.12);
}

.level-save-badge {
    margin-top: 4px;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.level-save-badge .lock-icon {
    color: #94a3b8;
    font-size: 11px;
}

.level-save-badge .rec-time {
    color: #fef08a;
    font-weight: 700;
}

.level-save-badge .rec-gems {
    color: #67e8f9;
    font-weight: 600;
}

.level-save-badge .rec-new {
    color: #a855f7;
    font-weight: 700;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
