* { margin: 0; padding: 0; box-sizing: border-box; }
body { overflow: hidden; background: #1a1a2e; font-family: 'Segoe UI', Tahoma, sans-serif; }
canvas { display: block; }

#ui {
    position: fixed; top: 0; left: 0; width: 100%;
    padding: 18px 28px; display: flex; justify-content: space-between; align-items: flex-start;
    pointer-events: none; z-index: 10;
}
#score {
    color: #fff; font-size: 26px; font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.6);
    letter-spacing: 1px;
}
#coin-display {
    color: #ffd700; font-size: 20px; font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.6);
}
#health {
    font-size: 30px; text-shadow: 2px 2px 4px rgba(0,0,0,0.6);
    display: flex; align-items: center; gap: 6px;
}
.hearts-wrap {
    position: relative;
    display: inline-block;
    vertical-align: middle;
}
.hearts-empty, .hearts-full {
    display: block;
    white-space: nowrap;
    letter-spacing: 1px;
    font-size: 22px;
    line-height: 1;
}
.hearts-empty {
    opacity: 1;
}
.hearts-full {
    position: absolute;
    top: 0; left: 0;
    overflow: hidden;
    white-space: nowrap;
}
#speed-indicator {
    color: rgba(255,255,255,0.5); font-size: 14px;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.6);
}

.overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    background: rgba(0,0,0,0.75); z-index: 20;
    backdrop-filter: blur(4px);
}
.overlay h1 {
    color: #fff; font-size: 60px; margin-bottom: 10px;
    text-shadow:
        0 0 10px rgba(255,215,0,0.4),
        0 0 30px rgba(255,150,0,0.2),
        3px 3px 0 rgba(0,0,0,0.6),
        5px 5px 10px rgba(0,0,0,0.5);
    letter-spacing: 3px;
    background: linear-gradient(180deg, #fff 0%, #ffd700 50%, #cc8800 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    filter: drop-shadow(3px 4px 6px rgba(0,0,0,0.7));
}

@keyframes game-title-float {
    0%, 100% { transform: translateY(0) rotate(-0.6deg) scale(1); }
    20% { transform: translateY(-5px) rotate(0.5deg) scale(1.01); }
    40% { transform: translateY(-2px) rotate(-0.3deg) scale(1); }
    60% { transform: translateY(-6px) rotate(0.7deg) scale(1.02); }
    80% { transform: translateY(-3px) rotate(-0.4deg) scale(1.01); }
}

@keyframes game-title-glow {
    0%, 100% {
        filter:
            drop-shadow(0 0 6px rgba(255, 215, 0, 0.45))
            drop-shadow(0 0 14px rgba(255, 180, 80, 0.25))
            drop-shadow(3px 4px 6px rgba(0, 0, 0, 0.75));
    }
    33% {
        filter:
            drop-shadow(0 0 16px rgba(255, 230, 140, 0.85))
            drop-shadow(0 0 28px rgba(255, 160, 60, 0.5))
            drop-shadow(0 0 42px rgba(200, 120, 255, 0.2))
            drop-shadow(3px 4px 8px rgba(0, 0, 0, 0.7));
    }
    66% {
        filter:
            drop-shadow(0 0 12px rgba(255, 200, 100, 0.7))
            drop-shadow(0 0 22px rgba(120, 200, 255, 0.35))
            drop-shadow(3px 5px 7px rgba(0, 0, 0, 0.72));
    }
}

.overlay h1.game-title {
    display: inline-block;
    transform-origin: 50% 60%;
    animation:
        game-title-float 3.4s ease-in-out infinite,
        game-title-glow 2.8s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
    .overlay h1.game-title {
        animation: none;
    }
}
.overlay h2 {
    color: #e63946; font-size: 50px; margin-bottom: 15px;
}
.overlay p {
    color: #ccc; font-size: 20px; margin: 4px 0;
}
.overlay .gold { color: #ffd700; }
.overlay .gold-sm { color: #ffd700; font-size: 16px; }
.overlay .pink { color: #ff88ff; font-size: 18px; margin-top: 12px; }
.overlay .win-subtitle { font-size: 24px; }
.overlay .sub { color: #999; font-size: 15px; margin-top: 14px; text-align: center; line-height: 1.9; }
.overlay .sub strong { color: #bbb; }

.coop-stats { display: none; margin: 12px auto; max-width: 400px; }
.coop-stats table { width: 100%; border-collapse: collapse; text-align: center; font-size: 14px; color: #ccc; }
.coop-stats th, .coop-stats td { padding: 3px 4px; }
.coop-stats .label { text-align: left; }
.coop-stats .hdr { border-bottom: 1px solid rgba(255,255,255,0.2); }
.coop-stats .best { color: #ffd700; font-weight: bold; }

#new-best-popup h2 { color: #ffd700; margin-bottom: 4px; }
#new-best-popup .lb-name-input { margin-top: 12px; margin-bottom: 16px; }
.lb-name-input {
    display: block; margin: 6px auto 0; padding: 6px 12px;
    font-size: 16px; text-align: center; border-radius: 6px;
    border: 2px solid #ffd700; background: rgba(0,0,0,0.5); color: #fff;
    outline: none; width: 180px; font-family: inherit;
}
.lb-name-input::placeholder { color: #777; }

.lb-tabs { display: flex; justify-content: center; gap: 8px; margin: 6px 0; }
.lb-tab {
    padding: 5px 16px; font-size: 14px; border-radius: 6px; cursor: pointer;
    border: 1px solid #555; background: rgba(255,255,255,0.05); color: #aaa;
    font-family: inherit; transition: background 0.15s, color 0.15s;
}
.lb-tab:hover { background: rgba(255,255,255,0.1); color: #ddd; }
.lb-tab.active { background: rgba(255,215,0,0.15); color: #ffd700; border-color: #ffd700; }

#lb-table-wrap {
    width: 90%; max-width: 500px; margin: 10px auto; max-height: 340px;
    overflow-y: auto; color: #ccc;
}
.lb-table { width: 100%; border-collapse: collapse; font-size: 14px; color: #ccc; }
.lb-table th { padding: 5px 6px; border-bottom: 1px solid rgba(255,255,255,0.2); color: #999; font-weight: normal; text-align: center; }
.lb-table td { padding: 4px 6px; text-align: center; }
.lb-table .rank { width: 30px; color: #888; }
.lb-table .name { text-align: left; color: #eee; max-width: 100px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-table .highlight td { color: #ffd700; }
.lb-empty { text-align: center; color: #666; margin-top: 30px; font-size: 16px; }
.coop-stats .p1 { color: #44aaff; }
.coop-stats .p2 { color: #ff6644; }

.controls-grid {
    display: grid; grid-template-columns: auto auto; column-gap: 20px; row-gap: 4px;
    margin: 12px 0 8px; color: #ccc; font-size: 14px;
    background: rgba(255,255,255,0.05); border-radius: 8px; padding: 10px 18px;
}
.controls-grid span:nth-child(odd) { text-align: right; color: #bbb; }
.controls-grid span:nth-child(even) { text-align: left; color: #888; }
.controls-grid strong { color: #ddd; }

.vol-row {
    display: flex; align-items: center; gap: 10px;
    margin: 5px 0; width: 280px;
}
.vol-row label { color: #ccc; font-size: 14px; width: 80px; text-align: right; }
.vol-row input[type=range] { flex: 1; accent-color: #c0392b; cursor: pointer; }
.vol-row span { color: #aaa; font-size: 13px; width: 38px; text-align: left; }
.overlay button {
    margin-top: 14px; padding: 14px 44px; font-size: 21px;
    background: #c0392b; color: white; border: none; border-radius: 8px;
    cursor: pointer; transition: transform 0.1s, background 0.15s;
    font-weight: 600; letter-spacing: 0.5px;
}
.overlay button:hover { background: #e74c3c; transform: scale(1.04); }
.overlay button.alt-btn { background: #2980b9; }
.overlay button.alt-btn:hover { background: #3498db; }
#btn-continue { background: #27ae60; font-size: 19px; }
#btn-continue:hover { background: #2ecc71; }
#btn-continue-run { background: #2980b9; font-size: 20px; border: 2px solid #5dade2; }
#btn-continue-run:hover { background: #3498db; }
.overlay button.back-btn { background: #555; }
.overlay button.back-btn:hover { background: #777; }
#start-screen { display: flex; }
#game-over-screen { display: none; }
#shop-screen { display: none; }

/* Settings cog button */
#btn-settings-cog {
    position: fixed; top: 14px; right: 14px; z-index: 30;
    background: rgba(0,0,0,0.5); color: #ccc; border: 1px solid rgba(255,255,255,0.15);
    border-radius: 50%; width: 40px; height: 40px; font-size: 22px;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: background 0.15s, color 0.15s;
    padding: 0; margin: 0; line-height: 1;
}
#btn-settings-cog:hover { background: rgba(255,255,255,0.15); color: #fff; }

#settings-screen { z-index: 25; }

/* Settings panel */
.settings-panel {
    max-width: 520px; width: 90%; max-height: 65vh; overflow-y: auto;
    background: rgba(0,0,0,0.4); border-radius: 10px;
    padding: 16px 24px; margin: 8px 0;
}
.settings-section { margin-bottom: 16px; }
.settings-section-title {
    color: #ffd700; font-size: 16px; font-weight: 700;
    letter-spacing: 2px; text-transform: uppercase;
    border-bottom: 1px solid rgba(255,215,0,0.2);
    padding-bottom: 4px; margin-bottom: 10px;
}

/* Binding rows */
.bind-player-title {
    color: #88bbff; font-size: 13px; font-weight: 600;
    margin: 10px 0 4px; letter-spacing: 1px;
}
.bind-row {
    display: flex; align-items: center; gap: 8px;
    margin: 3px 0; color: #ccc; font-size: 13px;
}
.bind-label { width: 90px; text-align: right; color: #999; }
.bind-keys { display: flex; gap: 4px; flex-wrap: wrap; }
.bind-key {
    display: inline-block; background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.25); border-radius: 4px;
    padding: 3px 10px; font-size: 12px; color: #eee;
    cursor: pointer; transition: background 0.15s, border-color 0.15s;
    min-width: 30px; text-align: center; font-family: monospace;
}
.bind-key:hover { background: rgba(255,255,255,0.25); border-color: #ffd700; }
.bind-key.listening {
    background: rgba(255,215,0,0.2); border-color: #ffd700;
    animation: bind-pulse 0.6s ease-in-out infinite alternate;
    color: #ffd700;
}
.bind-key-add {
    display: inline-block; background: rgba(255,255,255,0.06);
    border: 1px dashed rgba(255,255,255,0.2); border-radius: 4px;
    padding: 3px 8px; font-size: 11px; color: #666; cursor: pointer;
}
.bind-key-add:hover { color: #aaa; border-color: rgba(255,255,255,0.4); }
@keyframes bind-pulse {
    from { box-shadow: 0 0 4px rgba(255,215,0,0.3); }
    to   { box-shadow: 0 0 10px rgba(255,215,0,0.6); }
}
.bind-note { color: #666; font-size: 11px; margin-top: 8px; font-style: italic; }

.shop-overlay {
    padding: 0 !important;
    justify-content: stretch !important;
}
.shop-header {
    flex-shrink: 0; text-align: center;
    padding: 14px 20px 8px; border-bottom: 1px solid rgba(255,255,255,0.1);
}
.shop-body {
    flex: 1; display: flex; overflow: hidden; min-height: 0;
}
.shop-preview-col {
    flex-shrink: 0; width: 210px; display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    border-right: 1px solid rgba(255,255,255,0.1);
    background: rgba(0,0,0,0.25); overflow-y: auto;
}
#shop-preview-canvas { display: block; }
.shop-grid {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px;
    overflow-y: auto; padding: 10px 16px;
}
.shop-footer {
    flex-shrink: 0; display: flex; gap: 12px; justify-content: center;
    padding: 10px 20px 14px; border-top: 1px solid rgba(255,255,255,0.1);
}
.shop-footer button { margin-top: 0; }

.shop-card {
    background: rgba(255,255,255,0.08);
    border: 2px solid rgba(255,255,255,0.15);
    border-radius: 8px; padding: 10px 12px; width: 140px; text-align: center;
}
.shop-card.maxed { border-color: #ffd700; }
.shop-card.coop-bought { opacity: 0.7; }
.shop-card.equipped { border-color: #44ff44; }
.shop-card.staged { border-color: #ffaa00; box-shadow: 0 0 6px rgba(255,170,0,0.3); }
.shop-card.active-eq { border-color: #88ccff; box-shadow: 0 0 8px rgba(136,204,255,0.3); }
.shop-card.sale { border-color: #ff4444; box-shadow: 0 0 12px rgba(255,68,68,0.4); position: relative; }
.sale-badge {
    display: inline-block; background: #ff4444; color: #fff; font-size: 10px; font-weight: 800;
    padding: 2px 8px; border-radius: 4px; letter-spacing: 1px;
    animation: sale-pulse 0.8s ease-in-out infinite alternate;
    margin-bottom: 4px;
}
@keyframes sale-pulse {
    from { transform: scale(1); box-shadow: 0 0 4px rgba(255,68,68,0.4); }
    to   { transform: scale(1.08); box-shadow: 0 0 10px rgba(255,68,68,0.7); }
}
.shop-card h3 { color: #fff; font-size: 13px; margin-bottom: 4px; white-space: nowrap; }
.shop-card .desc { color: #aaa; font-size: 11px; margin: 2px 0; }
.shop-card .lvl { color: #7ec8e3; font-size: 11px; margin: 4px 0; }
.shop-card button {
    margin-top: 6px; padding: 5px 10px; font-size: 12px;
    background: #27ae60; color: white; border: none; border-radius: 5px;
    cursor: pointer; font-weight: 600;
}
.shop-card button:hover { background: #2ecc71; }
.shop-card button:disabled { background: #555; opacity: 0.5; cursor: not-allowed; }

.shop-section-title {
    color: #999; font-size: 12px; text-transform: uppercase;
    letter-spacing: 2px; margin: 6px 0 2px; text-align: center;
}
.shop-slot-title {
    color: #ccc; font-size: 13px; font-weight: 600;
    margin: 8px 0 2px; text-align: center;
}
.shop-row {
    display: flex; gap: 8px; flex-wrap: wrap; justify-content: center;
    margin-bottom: 4px;
}

#equipment-display {
    position: fixed; top: 10px; left: 50%; transform: translateX(-50%);
    display: flex; gap: 4px; flex-wrap: wrap;
    justify-content: center; align-items: flex-start;
    max-width: 80vw;
    pointer-events: none; z-index: 11;
}
.eq-badge {
    position: relative;
    display: inline-flex; align-items: center; gap: 3px;
    background: rgba(0,0,0,0.55); border: 1px solid rgba(255,255,255,0.2);
    border-radius: 5px; padding: 1px 6px 1px 3px;
    backdrop-filter: blur(2px); cursor: default;
    pointer-events: auto;
}
.eq-badge .eq-tip {
    display: none; position: absolute; top: 100%; left: 50%;
    transform: translateX(-50%); margin-top: 6px;
    background: rgba(0,0,0,0.92); border: 1px solid rgba(255,255,255,0.25);
    border-radius: 6px; padding: 6px 10px;
    width: max-content; max-width: 220px;
    z-index: 100; pointer-events: none;
    text-align: center;
}
.eq-badge:hover .eq-tip { display: block; }
.eq-tip-name {
    color: #ffd700; font-size: 12px; font-weight: 700;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.9);
}
.eq-tip-desc {
    color: #ccc; font-size: 11px; margin-top: 2px;
    line-height: 1.3;
}
.eq-icon {
    font-size: 14px; line-height: 1;
}
.eq-label {
    color: #ccffdd; font-size: 11px; font-weight: 600;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
    white-space: nowrap;
}
.eq-badge.eq-cooldown {
    opacity: 0.45; border-color: rgba(255,80,80,0.4);
}
.eq-cd {
    color: #ff8888; font-size: 11px; font-weight: 700;
    margin-left: 3px;
}
.buff-badge {
    border-color: rgba(255,220,100,0.35);
    background: rgba(40,30,0,0.55);
}
.buff-badge .eq-label {
    color: #ffe088;
}
.buff-spent {
    opacity: 0.4;
}
.buff-spent .eq-icon {
    filter: grayscale(1);
}
.buff-spent .eq-label {
    text-decoration: line-through;
    color: #998866;
}
.eq-spent {
    font-size: 9px; font-weight: 800; color: #ff6666;
    text-decoration: none; display: inline-block;
    margin-left: 3px;
}

#buff-announce {
    position: fixed; top: 25%; left: 50%; transform: translate(-50%, -50%) scale(0.5);
    z-index: 50; pointer-events: none;
    display: flex; flex-direction: column; align-items: center;
    opacity: 0; transition: none;
}
#buff-announce.ba-show {
    animation: buffPopIn 1.8s ease-out forwards;
}
.ba-icon {
    font-size: 64px; line-height: 1;
    filter: drop-shadow(0 0 12px currentColor);
}
.ba-text {
    font-size: 42px; font-weight: 900;
    letter-spacing: 2px; text-transform: uppercase;
    text-shadow: 0 0 20px currentColor, 0 2px 6px rgba(0,0,0,0.7);
    margin-top: 4px;
}
.ba-desc {
    font-size: 20px; font-weight: 600; color: #fff;
    text-shadow: 0 0 8px rgba(0,0,0,0.8);
    margin-top: 2px; opacity: 0.85;
}

@keyframes buffPopIn {
    0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.3); }
    15%  { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
    30%  { transform: translate(-50%, -50%) scale(1.0); }
    75%  { opacity: 1; transform: translate(-50%, -60%) scale(1.0); }
    100% { opacity: 0; transform: translate(-50%, -80%) scale(0.9); }
}

#secondwind-announce {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    z-index: 60; pointer-events: none;
    display: none; flex-direction: column;
    align-items: center; justify-content: center;
    background: radial-gradient(ellipse at center, rgba(150,220,255,0.25) 0%, rgba(0,0,0,0.5) 70%);
    opacity: 1; transition: opacity 0.4s ease-out;
    font-family: inherit;
}
.sw-icon {
    font-size: 80px; line-height: 1;
    filter: drop-shadow(0 0 24px rgba(150,220,255,0.9));
    animation: swPulse 0.6s ease-in-out infinite alternate;
}
.sw-text {
    font-size: 52px; font-weight: 900;
    color: #ccefff;
    letter-spacing: 3px; text-transform: uppercase;
    text-shadow: 0 0 30px rgba(150,220,255,0.9), 0 0 60px rgba(100,180,255,0.5), 0 2px 6px rgba(0,0,0,0.7);
    margin-top: 8px;
}
.sw-desc {
    font-size: 22px; font-weight: 600; color: #fff;
    text-shadow: 0 0 12px rgba(150,220,255,0.6), 0 0 4px rgba(0,0,0,0.8);
    margin-top: 4px; opacity: 0.85;
}
@keyframes swPulse {
    0%   { transform: scale(1); filter: drop-shadow(0 0 24px rgba(150,220,255,0.9)); }
    100% { transform: scale(1.15); filter: drop-shadow(0 0 36px rgba(200,240,255,1)); }
}

#boss-hp-bar {
    position: fixed; bottom: 40px; left: 50%; transform: translateX(-50%);
    width: 400px; max-width: 80vw; height: 28px;
    background: #222; border: 2px solid #ff4444; border-radius: 6px;
    z-index: 15; overflow: hidden;
}
.bhp-fill {
    height: 100%; width: 100%; background: linear-gradient(90deg, #cc2200, #ff4400);
    transition: width 0.3s; border-radius: 4px;
}
.bhp-text {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: bold; font-size: 14px;
    text-shadow: 1px 1px 3px #000; letter-spacing: 2px;
}
#win-screen h1 { color: #ffd700; text-shadow: 0 0 30px rgba(255,215,0,0.5); }

#buff-pick-grid {
    display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
    max-width: 600px; margin: 0 auto;
}
.buff-pick-card {
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    background: rgba(30,25,10,0.85); border: 2px solid rgba(255,220,100,0.3);
    border-radius: 10px; padding: 10px 14px; cursor: pointer;
    transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
    min-width: 100px; max-width: 140px;
}
.buff-pick-card:hover {
    border-color: #ffd700; transform: scale(1.08);
    box-shadow: 0 0 16px rgba(255,215,0,0.4);
}
.buff-pick-card .bp-icon { font-size: 28px; }
.buff-pick-card .bp-name { color: #ffe088; font-size: 13px; font-weight: bold; text-align: center; }
.buff-pick-card .bp-stacks { color: #aaa; font-size: 11px; }
.buff-pick-card .bp-desc { color: #999; font-size: 10px; text-align: center; }

#game-over-screen p, #win-screen p {
    color: #fff; font-size: 20px; margin: 4px 0;
    text-shadow: 1px 1px 4px rgba(0,0,0,0.8);
}
#game-over-screen, #win-screen {
    gap: 2px;
}
#game-over-screen > p, #win-screen > p,
#game-over-screen > button, #win-screen > button,
#game-over-screen > h2, #win-screen > h1,
#game-over-screen > div, #win-screen > div {
    position: relative; z-index: 1;
}
#game-over-screen::after, #win-screen::after {
    content: '';
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 420px; max-width: 90%;
    height: 85%; max-height: 500px;
    background: rgba(0, 0, 0, 0.55);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 0;
}
#pause-screen { display: none; gap: 0; }
#pause-screen h2 { color: #fff; font-size: 42px; margin-bottom: 10px; }
#btn-resume { background: #27ae60; }
#btn-resume:hover { background: #2ecc71; }
#btn-to-menu { background: #555; }
#btn-to-menu:hover { background: #777; }

.char-select-difficulty {
    width: 100%;
    max-width: 520px;
}
.char-select-difficulty label {
    vertical-align: middle;
}

.char-panel {
    background: rgba(0,0,0,0.4); border-radius: 12px; padding: 16px 24px;
    min-width: 200px; text-align: center;
}
.char-panel h3 { color: #fff; margin: 0 0 10px; font-size: 18px; }
.char-panel canvas { margin: 0 auto; }
.char-type-row {
    display: flex; gap: 6px; justify-content: center; margin-bottom: 8px;
}
.char-type-btn {
    padding: 4px 10px; border-radius: 8px; font-size: 20px; cursor: pointer;
    background: rgba(255,255,255,0.08); border: 2px solid rgba(255,255,255,0.2);
    transition: all 0.1s; user-select: none;
}
.char-type-btn.selected { background: rgba(255,200,50,0.25); border-color: #ffd700; }
.char-type-btn.locked { opacity: 0.35; cursor: pointer; }
.char-type-btn.locked:hover { opacity: 0.55; }
.char-type-btn.locked.selected { opacity: 0.65; border-color: #888; background: rgba(128,128,128,0.2); }
.colour-grid {
    display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
}
.colour-swatch {
    width: 36px; height: 36px; border-radius: 50%; border: 3px solid rgba(255,255,255,0.2);
    cursor: pointer; transition: transform 0.15s, border-color 0.15s;
}
.colour-swatch:hover { transform: scale(1.15); }
.colour-swatch.selected { border-color: #ffd700; transform: scale(1.2); box-shadow: 0 0 10px rgba(255,215,0,0.5); }
#btn-coop { background: #8e44ad; }
#btn-coop:hover { background: #a569bd; }

/* Fullscreen button */
#btn-fullscreen {
    position: fixed; top: 14px; right: 60px; z-index: 30;
    background: rgba(0,0,0,0.5); color: #ccc;
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 50%; width: 40px; height: 40px;
    font-size: 18px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.15s, color 0.15s;
    padding: 0; margin: 0; line-height: 1;
}
#btn-fullscreen:hover { background: rgba(255,255,255,0.15); color: #fff; }

/* ─── TOUCH CONTROLS ─────────────────────────────────── */
body.touch-device { touch-action: none; -webkit-touch-callout: none; }
body.touch-device canvas { touch-action: none; }
body.touch-device * { -webkit-tap-highlight-color: transparent; }

#touch-controls {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none; z-index: 18;
}
#touch-controls > * { pointer-events: auto; }

#touch-joy-base {
    display: none; position: fixed;
    width: 110px; height: 110px;
    border-radius: 50%;
    background: rgba(255,255,255,0.08);
    border: 2px solid rgba(255,255,255,0.2);
}
#touch-joy-thumb {
    position: absolute; left: 50%; top: 50%;
    width: 50px; height: 50px;
    margin: -25px 0 0 -25px;
    border-radius: 50%;
    background: rgba(255,255,255,0.3);
    border: 2px solid rgba(255,255,255,0.45);
}

#touch-btn-jump,
#touch-btn-attack {
    position: fixed; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: bold; user-select: none;
    -webkit-user-select: none; -webkit-touch-callout: none;
    transition: background 0.08s;
}
#touch-btn-jump {
    bottom: 28px; right: 28px;
    width: 76px; height: 76px;
    background: rgba(46,204,113,0.3);
    border: 2.5px solid rgba(46,204,113,0.55);
    color: rgba(255,255,255,0.8); font-size: 32px;
}
#touch-btn-attack {
    bottom: 115px; right: 110px;
    width: 66px; height: 66px;
    background: rgba(231,76,60,0.3);
    border: 2.5px solid rgba(231,76,60,0.55);
    color: rgba(255,255,255,0.8); font-size: 26px;
}
#touch-btn-jump.active  { background: rgba(46,204,113,0.55); transform: scale(0.93); }
#touch-btn-attack.active { background: rgba(231,76,60,0.55); transform: scale(0.93); }

/* ── P2 touch controls (co-op mobile) ── */
#touch-joy-base-p2 {
    display: none; position: fixed;
    width: 110px; height: 110px;
    border-radius: 50%;
    background: rgba(68,170,255,0.08);
    border: 2px solid rgba(68,170,255,0.25);
}
#touch-joy-thumb-p2 {
    position: absolute; left: 50%; top: 50%;
    width: 50px; height: 50px;
    margin: -25px 0 0 -25px;
    border-radius: 50%;
    background: rgba(68,170,255,0.3);
    border: 2px solid rgba(68,170,255,0.5);
}
#touch-btn-jump-p2,
#touch-btn-attack-p2 {
    position: fixed; border-radius: 50%;
    display: none; align-items: center; justify-content: center;
    font-weight: bold; user-select: none;
    -webkit-user-select: none; -webkit-touch-callout: none;
    transition: background 0.08s;
}
#touch-btn-jump-p2 {
    bottom: 28px; left: 28px;
    width: 76px; height: 76px;
    background: rgba(46,204,113,0.3);
    border: 2.5px solid rgba(46,204,113,0.55);
    color: rgba(255,255,255,0.8); font-size: 32px;
}
#touch-btn-attack-p2 {
    bottom: 115px; left: 110px;
    width: 66px; height: 66px;
    background: rgba(231,76,60,0.3);
    border: 2.5px solid rgba(231,76,60,0.55);
    color: rgba(255,255,255,0.8); font-size: 26px;
}
#touch-btn-jump-p2.active   { background: rgba(46,204,113,0.55); transform: scale(0.93); }
#touch-btn-attack-p2.active { background: rgba(231,76,60,0.55);  transform: scale(0.93); }
/* Show P2 buttons when coop-touch class is on body */
body.coop-touch #touch-btn-jump-p2,
body.coop-touch #touch-btn-attack-p2 { display: flex; }

/* Player labels on touch buttons in co-op */
body.coop-touch #touch-btn-jump::after    { content: 'P1'; position: absolute; top: -18px; font-size: 10px; color: rgba(255,255,255,0.5); }
body.coop-touch #touch-btn-jump-p2::after { content: 'P2'; position: absolute; top: -18px; font-size: 10px; color: rgba(68,170,255,0.7); }

#touch-btn-pause {
    position: fixed; top: 14px; right: 106px; z-index: 30;
    width: 40px; height: 40px; border-radius: 50%;
    background: rgba(0,0,0,0.5);
    border: 1px solid rgba(255,255,255,0.15);
    color: rgba(255,255,255,0.7); font-size: 14px; letter-spacing: 2px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: background 0.15s, color 0.15s;
    user-select: none; -webkit-user-select: none;
}
#touch-btn-pause:hover { background: rgba(255,255,255,0.15); color: #fff; }
#touch-btn-pause:active { background: rgba(255,255,255,0.15); }

/* ─── MOBILE RESPONSIVE ──────────────────────────────── */
@media (max-width: 700px) {
    .overlay button { padding: 12px 30px; font-size: 18px; }
    .overlay h1 { font-size: 36px; }
    .overlay h2 { font-size: 30px; }
    .overlay p { font-size: 15px; }
    #score { font-size: 18px; }
    #ui { padding: 8px 12px; }
    .vol-row { width: 210px; }
    .vol-row label { font-size: 12px; width: 60px; }
    .settings-panel { padding: 10px 12px; max-height: 55vh; }
    .shop-preview-col { width: 100px; }
    #shop-preview-canvas { width: 90px !important; height: 130px !important; }
    .shop-card { width: 110px; padding: 4px 6px; }
    .shop-card h3 { font-size: 11px; }
    .shop-card .desc { font-size: 10px; }
    .shop-footer button { padding: 10px 20px; font-size: 16px; }
    .char-panel { padding: 10px 14px; min-width: 140px; }
    .char-panel h3 { font-size: 14px; }
    .colour-swatch { width: 28px; height: 28px; }
    #btn-settings-cog { top: 10px; right: 10px; width: 34px; height: 34px; font-size: 18px; }
    #btn-fullscreen { top: 10px; right: 48px; width: 34px; height: 34px; font-size: 15px; }
    #touch-btn-pause { top: 10px; right: 86px; width: 34px; height: 34px; font-size: 12px; }
}
@media (max-height: 600px) {
    /* Medium-short screens: horizontal char panel layout, smaller heading */
    #char-select-screen { gap: 0; }
    #char-select-screen > h2 { font-size: 26px; margin-bottom: 4px; }
    .char-panel {
        padding: 6px 10px; min-width: auto;
        display: flex; flex-direction: row; align-items: center; gap: 10px;
    }
    .char-panel h3 { display: none; }
    .char-panel canvas { width: 100px !important; height: 140px !important; flex-shrink: 0; }
    .char-panel-options { display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 0; }
    .char-type-row { margin-bottom: 3px; }
    .colour-swatch { width: 26px; height: 26px; }
    #char-select-buttons { margin-top: 4px; }
    #char-select-buttons button { padding: 6px 20px; font-size: 15px; margin-top: 0; }
    #btn-char-ready-0, #btn-char-ready-1 { padding: 4px 14px !important; font-size: 13px !important; margin-top: 3px !important; }
}
@media (max-height: 450px) {
    .overlay { padding: 4px; gap: 1px; }
    .overlay button { padding: 6px 16px; font-size: 14px; margin-top: 4px; }
    .overlay h1 { font-size: 24px; margin-bottom: 2px; }
    .overlay h2 { font-size: 18px; margin-bottom: 4px; letter-spacing: 1px; }
    .overlay p { font-size: 12px; margin: 2px 0; }

    /* Character select — horizontal layout: preview left, options right */
    #char-select-screen { gap: 0; }
    .char-panel {
        padding: 4px 8px; min-width: auto;
        display: flex; flex-direction: row; align-items: center; gap: 8px;
    }
    .char-panel h3 { display: none; }
    .char-panel canvas { width: 80px !important; height: 110px !important; flex-shrink: 0; }
    .char-type-row { margin-bottom: 2px; }
    .char-type-btn { padding: 2px 6px; font-size: 16px; }
    .colour-grid { gap: 4px; }
    .colour-swatch { width: 22px; height: 22px; }
    #char-select-buttons { margin-top: 2px; gap: 6px; }
    #char-select-buttons button { padding: 4px 14px; font-size: 12px; margin-top: 0; }
    #btn-char-ready-0, #btn-char-ready-1 { padding: 3px 12px !important; font-size: 11px !important; margin-top: 2px !important; }
    #char-select-hint { font-size: 10px; margin: 2px 0; }

    /* Wrap char-panel internals in a column for the right side */
    .char-panel-options { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0; }

    /* Shop layout tweaks */
    .shop-header { padding: 6px 10px 4px; }
    .shop-header h1 { font-size: 22px !important; }
    .shop-grid { padding: 4px 8px; gap: 2px; }
    .shop-card { padding: 4px 6px; width: 100px; }
    .shop-card h3 { font-size: 10px; }
    .shop-card .desc { font-size: 9px; }
    .shop-card button { padding: 4px 10px; font-size: 12px; }
    .shop-footer { padding: 4px 10px 6px; }
    .shop-footer button { padding: 6px 14px; font-size: 14px; }
    .shop-section-title { font-size: 12px; }
    .shop-row { gap: 4px; }
    .shop-preview-col { width: 80px; }
    #shop-preview-canvas { width: 70px !important; height: 100px !important; }
}

#tutorial-tip {
    position: fixed;
    bottom: 18%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.82);
    color: #fff;
    font-size: 22px;
    font-weight: bold;
    padding: 14px 32px;
    border-radius: 12px;
    border: 2px solid rgba(255,255,255,0.25);
    text-align: center;
    pointer-events: none;
    z-index: 60;
    text-shadow: 1px 1px 4px rgba(0,0,0,0.9);
    animation: tutPulse 1.8s ease-in-out infinite;
    max-width: 90vw;
    white-space: nowrap;
    opacity: 1;
    transition: opacity 1s ease-out;
}
#tutorial-tip.tut-fade { opacity: 0; }
body.touch-device #tutorial-tip { bottom: 10px; font-size: 18px; padding: 10px 22px; }
#tutorial-tip .tut-key {
    display: inline-block;
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.4);
    border-radius: 5px;
    padding: 2px 8px;
    margin: 0 3px;
    font-family: monospace;
}
@keyframes tutPulse {
    0%, 100% { opacity: 1; transform: translateX(-50%) scale(1); }
    50% { opacity: 0.85; transform: translateX(-50%) scale(1.03); }
}
