html, body {
    margin: 0;
    padding: 0;
    background: #111;
    overflow: hidden;
    font-family: sans-serif;
    width: 100%;
    height: 100%;
    overscroll-behavior: none;
    -webkit-text-size-adjust: 100%;
}

html,
body,
canvas,
button {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
}

#game,
#controls,
#attackWrapper,
#cooldownWrapper,
#dashWrapper,
#spellControls {
    touch-action: manipulation;
}

#joystick,
#stick {
    touch-action: none;
}

*, *::before, *::after {
    box-sizing: border-box;
}

canvas {
    display: block;
    background: #222;
}

#game {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    height: 100svh;
    height: 100dvh;
}

.menuOverlay {
    position: fixed;
    inset: 0;
    align-items: center;
    justify-content: center;
    padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
    color: white;
    text-align: center;
    background: radial-gradient(circle at 50% 38%, rgba(87, 51, 20, .96), rgba(7, 7, 12, .985) 68%);
    z-index: 20;
    overflow-y: auto;
}

#titleScreen { display: flex; }
#pauseScreen {
    display: none;
    z-index: 19;
    background: rgba(5, 5, 10, .86);
    backdrop-filter: blur(5px);
}

.menuPanel {
    display: grid;
    justify-items: center;
    gap: 15px;
    width: min(480px, 100%);
    padding: clamp(24px, 6vw, 48px);
    border: 2px solid #dba94f;
    background: linear-gradient(145deg, rgba(69, 43, 20, .95), rgba(18, 14, 13, .97));
    box-shadow: 0 0 34px rgba(255, 153, 44, .28), inset 0 0 28px rgba(255, 204, 102, .08);
    clip-path: polygon(5% 0, 95% 0, 100% 8%, 100% 92%, 95% 100%, 5% 100%, 0 92%, 0 8%);
}

.menuPanel h1, .menuPanel h2, .menuPanel p { margin: 0; }
.menuPanel h1 {
    color: #ffd66b;
    font-size: clamp(28px, 7vw, 52px);
    letter-spacing: .09em;
}
.titleSigil {
    color: #fff1a1;
    font-size: 52px;
    filter: drop-shadow(0 0 12px #ffb62e);
}
.menuPanel button {
    min-width: 190px;
    min-height: 50px;
    padding: 12px 20px;
    color: white;
    font-weight: 900;
    border: 2px solid #e6b653;
    background: linear-gradient(#6f4820, #2c1b0e);
    cursor: pointer;
}
.menuPanel small { color: #d8c49b; }

#pauseButton {
    position: fixed;
    top: max(12px, env(safe-area-inset-top));
    right: max(12px, env(safe-area-inset-right));
    z-index: 6;
    display: none;
    width: 46px;
    height: 46px;
    color: white;
    font-size: 20px;
    font-weight: 900;
    border: 2px solid rgba(255,255,255,.55);
    border-radius: 50%;
    background: rgba(20, 17, 20, .72);
    touch-action: manipulation;
}

#ui {
    position: absolute;
    top: max(10px, env(safe-area-inset-top));
    left: max(10px, env(safe-area-inset-left));
    color: white;
    font-size: 16px;
    pointer-events: none;
    text-shadow: 0 1px 3px #000;
    z-index: 2;
}

#gameTitle {
    color: #ffd66b;
    font-weight: 900;
    letter-spacing: .12em;
    margin-bottom: 7px;
}

.health-frame {
    position: relative;
    width: clamp(180px, 55vw, 300px);
    height: 22px;
    overflow: hidden;
    border: 2px solid #e8d8a5;
    background: #35151a;
    box-shadow: 0 0 0 2px #1b1012, 0 3px 10px #000;
    margin-bottom: 7px;
}

#playerHealthFill {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #a51525, #f04b45);
    transition: width .15s ease-out;
}

.health-frame > span {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font-size: 13px;
    font-weight: 900;
    color: #fff;
    z-index: 2;
    text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000, 0 2px 3px #000;
}

#bossHud {
    position: fixed;
    left: 50%;
    bottom: max(38px, calc(env(safe-area-inset-bottom) + 22px));
    width: min(660px, calc(100vw - 300px));
    transform: translateX(-50%);
    color: white;
    text-align: center;
    pointer-events: none;
    z-index: 2;
    display: none;
}

#bossName {
    color: #ffc45b;
    font-weight: 900;
    letter-spacing: .24em;
    text-transform: uppercase;
    text-shadow: 0 2px 4px #000;
    margin-bottom: 4px;
}

#bossHealthFrame {
    position: relative;
    height: 29px;
    overflow: hidden;
    clip-path: polygon(4% 0, 96% 0, 100% 42%, 97% 100%, 3% 100%, 0 42%);
    background: linear-gradient(180deg, #fff0a0, #b96720 55%, #ffcb5e);
    filter: drop-shadow(0 0 8px rgba(255,128,30,.75));
}

#bossHealthTrack {
    position: absolute;
    inset: 4px;
    clip-path: polygon(4% 0, 96% 0, 100% 42%, 97% 100%, 3% 100%, 0 42%);
    background: #170b0b;
    overflow: hidden;
}

#bossHealthFill {
    width: 100%;
    height: 100%;
    background: linear-gradient(180deg, #ff694a 0%, #aa151b 55%, #5d0711 100%);
    transition: width .12s linear;
}

#bossHealthText {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font-weight: 900;
    text-shadow: 0 1px 3px #000;
    z-index: 2;
}

#upgradeScreen {
    position: fixed;
    inset: 0;
    display: none;
    place-content: center;
    justify-items: center;
    gap: 12px;
    padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
    color: white;
    text-align: center;
    background: radial-gradient(circle, rgba(55,35,16,.94), rgba(5,5,8,.97));
    z-index: 9;
    overflow-y: auto;
}

#upgradeScreen h2, #upgradeScreen p { margin: 0; }

#upgradeChoices {
    display: grid;
    grid-template-columns: repeat(3, minmax(130px, 190px));
    gap: 10px;
    width: min(100%, 590px);
}

#upgradeChoices button, #continueButton, #endScreen button {
    padding: 13px 16px;
    color: white;
    background: linear-gradient(#49351d, #21170d);
    border: 2px solid #dba94f;
    font-weight: 800;
    cursor: pointer;
    min-height: 48px;
}

#upgradeChoices button.controller-selected {
    outline: 3px solid #fff2aa;
    box-shadow: 0 0 18px #e89a2e;
}

#upgradeChoices small {
    display: block;
    color: #e8cf9d;
    margin-top: 4px;
}

.upgradeNumbers {
    display: block;
    margin-top: 6px;
    color: #fff4b8;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

#upgradeChoices button:disabled {
    opacity: .5;
    cursor: default;
}

#upgradeChoices button.capped {
    border-color: #8d7b58;
}

#continueButton:disabled {
    opacity: .4;
    cursor: default;
}

#playAgainButton:disabled {
    opacity: .45;
    cursor: default;
    filter: grayscale(0.35);
}

#endScreen {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.85);
    color: white;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    font-size: 18px;
    padding: 20px;
    z-index: 10;
    text-align: center;
    overflow-y: auto;
}

#joystick {
    position: fixed;
    bottom: max(24px, calc(env(safe-area-inset-bottom) + 14px));
    left: max(20px, calc(env(safe-area-inset-left) + 14px));
    width: clamp(86px, 14vmin, 110px);
    height: clamp(86px, 14vmin, 110px);
    background: rgba(255,255,255,0.1);
    border-radius: 50%;
    touch-action: none;
    z-index: 3;
    border: 2px solid rgba(255,255,255,0.2);
}

#stick {
    width: clamp(26px, 4vmin, 30px);
    height: clamp(26px, 4vmin, 30px);
    background: rgba(0,255,0,0.5);
    border-radius: 50%;
    position: absolute;
    left: 40px;
    top: 40px;
}

#dashWrapper {
    position: fixed;
    left: max(30px, calc(env(safe-area-inset-left) + 24px));
    bottom: max(148px, calc(env(safe-area-inset-bottom) + 138px));
    width: 90px;
    height: 90px;
    z-index: 3;
}

#dashCanvas {
    position: absolute;
    inset: 0;
    width: 90px;
    height: 90px;
    background: transparent;
}

#dashButton {
    position: absolute;
    left: 8px;
    top: 8px;
    width: 74px;
    height: 74px;
    border-radius: 50%;
    border: 2px solid rgba(171, 225, 255, .85);
    color: white;
    font-weight: 900;
    background: rgba(40, 155, 220, .82);
    box-shadow: 0 0 13px rgba(84, 196, 255, .4);
    touch-action: manipulation;
    user-select: none;
}

#dashButton.disabled {
    color: rgba(255,255,255,.55);
    background: rgba(85, 91, 100, .5);
    box-shadow: none;
}

#controls {
    position: absolute;
    bottom: 50px;
    right: 50px;
    display: flex;
    justify-content: flex-end;
    width: 150px; /* Enough space for a large button */
    z-index: 3;
}

#attackWrapper {
    position: fixed;
    bottom: max(19px, calc(env(safe-area-inset-bottom) + 9px));
    right: max(15px, calc(env(safe-area-inset-right) + 9px));
    width: 110px;
    height: 110px;
    z-index: 3;
}

#attackCooldownCanvas {
    position: absolute;
    inset: 0;
    width: 110px;
    height: 110px;
    background: transparent;
}

#attackButton {
    width: clamp(76px, 13vmin, 100px);
    height: clamp(76px, 13vmin, 100px);
    border-radius: 50%;
    background: rgba(0, 255, 0, 0.82);
    border: none;
    color: white;
    font-size: 18px;
    font-weight: bold;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

#attackButton.dash-cooldown {
    background: rgba(71, 91, 104, .58);
    box-shadow: inset 0 0 0 3px rgba(111, 221, 255, .45);
}

    #attackButton:not(.dash-cooldown):hover {
        background-color: rgba(255, 0, 0, 1); /* Hover effect */
    }

#cooldownWrapper {
    position: fixed;
    bottom: max(150px, calc(env(safe-area-inset-bottom) + 140px));
    right: max(10px, env(safe-area-inset-right));
    width: 120px;
    height: 120px;
    /* pointer-events: none; <-- REMOVE THIS LINE */
}

#cooldownCanvas {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 0;
    background: transparent;
}

#cooldownButton {
    position: absolute;
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: rgba(255, 165, 0, 0.82);
    border: none;
    color: white;
    font-size: 14px;
    font-weight: bold;
    left: 10px;
    top: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    transition: background 0.3s;
}

button:focus-visible {
    outline: 4px solid white;
    outline-offset: 3px;
}

#controlHint {
    position: fixed;
    left: 50%;
    bottom: max(8px, env(safe-area-inset-bottom));
    transform: translateX(-50%);
    color: rgba(255,255,255,.75);
    font-size: 13px;
    white-space: nowrap;
    pointer-events: none;
    text-shadow: 0 1px 3px #000;
}

    #cooldownButton.disabled {
        background: rgba(100, 100, 100, 0.4);
        cursor: default;
    }

    #cooldownButton.slyth-ready {
        background: radial-gradient(circle at 35% 30%, #eaa9ff, #7a209f 65%, #32103f);
        box-shadow: 0 0 23px rgba(213, 86, 255, .9);
    }

    #cooldownButton::after {
        content: '';
        position: absolute;
        width: 110px;
        height: 110px;
        border-radius: 50%;
        border: 4px solid rgba(255, 165, 0, 0.7);
        box-sizing: border-box;
        top: -5px;
        left: -5px;
        clip-path: inset(0 0 0 0 round 50%);
        transform: rotate(-90deg);
        transform-origin: center;
        pointer-events: none;
        animation-play-state: paused;
    }

@keyframes cooldownTimer {
    from {
        stroke-dasharray: 0 100;
    }

    to {
        stroke-dasharray: 100 0;
    }
}

.no-touch #joystick {
    opacity: .28;
}

#slythMeter { display: flex; align-items: center; gap: 6px; }
#slythMeter > div {
    position: relative; width: 112px; height: 13px; overflow: hidden;
    border: 1px solid rgba(221,159,255,.9); background: rgba(20,7,29,.86); border-radius: 7px;
}
#slythFill {
    position: absolute; inset: 0 auto 0 0; width: 0;
    background: linear-gradient(90deg, #5a168a, #d067ff, #f2c6ff); box-shadow: 0 0 10px #d067ff;
}
#slythMeter b {
    position: absolute; inset: 0; display: grid; place-items: center;
    font-size: 9px; line-height: 13px; text-shadow: 0 1px 2px #000;
}
#spellControls {
    position: fixed; left: 50%; top: max(10px, env(safe-area-inset-top)); bottom: auto;
    transform: translateX(-50%); z-index: 4; display: flex; align-items: center; gap: 8px;
}
#spellChoices {
    display: grid; grid-template-columns: repeat(6, 48px); gap: 4px; padding: 5px;
    border: 1px solid rgba(210,146,255,.45); border-radius: 12px;
    background: rgba(15,6,22,.72); backdrop-filter: blur(3px);
}
#spellChoices button {
    height: 45px; padding: 3px 1px; border: 1px solid rgba(214,173,241,.42);
    border-radius: 8px; color: #e9d8f5; background: rgba(77,38,98,.66);
    font-weight: 800; line-height: 12px; touch-action: manipulation;
}
#spellChoices button span { font-size: 8px; }
#spellChoices button.selected {
    color: white; border-color: #f2c4ff; background: #8f35bd;
    box-shadow: 0 0 12px rgba(211,102,255,.8);
}
#spellChoices button.unaffordable { opacity: .45; }
#spellChoices button.locked { display: none; }
#castButton {
    width: 62px; height: 62px; border-radius: 50%; border: 2px solid #edc4ff;
    color: white; background: radial-gradient(circle at 35% 30%, #b85be7, #4e146d);
    box-shadow: 0 0 14px rgba(197,83,255,.65); font-weight: 900; touch-action: manipulation;
}
#castButton small { display: block; font-size: 9px; }
#castButton.unaffordable { filter: grayscale(.8); opacity: .55; }

#spellChoiceScreen {
    position: fixed;
    inset: 0;
    z-index: 12;
    display: none;
    place-content: center;
    justify-items: center;
    gap: 14px;
    padding: 24px;
    color: white;
    text-align: center;
    background: radial-gradient(circle, rgba(76,24,99,.94), rgba(5,3,9,.97) 65%);
}

#spellChoiceScreen h2, #spellChoiceScreen p { margin: 0; }
#spellChoiceOptions { display: flex; gap: 18px; }
#spellChoiceOptions button {
    width: min(220px, 40vw);
    min-height: 118px;
    padding: 16px;
    border: 2px solid rgba(227,179,255,.7);
    border-radius: 16px;
    color: white;
    background: linear-gradient(145deg, rgba(141,54,181,.88), rgba(51,17,70,.94));
    box-shadow: 0 0 18px rgba(195,84,246,.28);
    font-size: 18px;
    font-weight: 900;
}
#spellChoiceOptions button small { display: block; margin-top: 9px; font-size: 12px; font-weight: 500; }
#spellChoiceOptions button.controller-selected {
    border-color: white;
    box-shadow: 0 0 25px rgba(224,143,255,.9);
    transform: scale(1.04);
}

.no-touch #joystick:hover {
    opacity: 1;
}

@media (max-width: 700px), (max-height: 520px) {
    #ui {
        font-size: clamp(10px, 2.8vw, 12px);
        max-width: calc(100vw - 20px - env(safe-area-inset-left) - env(safe-area-inset-right));
    }
    #gameTitle { font-size: 12px; margin-bottom: 4px; }
    .health-frame { height: 19px; margin-bottom: 4px; }
    #joystick {
        width: clamp(82px, 22vmin, 96px);
        height: clamp(82px, 22vmin, 96px);
    }
    #attackButton {
        width: clamp(72px, 20vmin, 82px);
        height: clamp(72px, 20vmin, 82px);
        font-size: 15px;
    }
    #attackWrapper {
        width: 90px;
        height: 90px;
        right: max(16px, calc(env(safe-area-inset-right) + 10px));
        bottom: max(20px, calc(env(safe-area-inset-bottom) + 10px));
    }
    #attackCooldownCanvas {
        width: 90px;
        height: 90px;
    }
    #dashWrapper {
        transform: scale(.82);
        transform-origin: bottom left;
        left: max(14px, env(safe-area-inset-left));
        bottom: max(118px, calc(env(safe-area-inset-bottom) + 108px));
    }
    #cooldownWrapper {
        transform: scale(.78);
        transform-origin: bottom right;
        right: max(10px, env(safe-area-inset-right));
        bottom: max(132px, calc(env(safe-area-inset-bottom) + 122px));
    }
    #controlHint { display: none; }
    #spellControls {
        top: max(6px, env(safe-area-inset-top));
        bottom: auto;
        transform: translateX(-50%) scale(.82);
        transform-origin: top center;
    }
    #bossHud {
        width: min(480px, calc(100vw - 32px - env(safe-area-inset-left) - env(safe-area-inset-right)));
        bottom: max(120px, calc(env(safe-area-inset-bottom) + 110px));
    }
    #bossHealthFrame { height: 22px; }
    #bossName { font-size: 11px; }
    #upgradeChoices { grid-template-columns: repeat(3, minmax(95px, 1fr)); }
}

@media (max-width: 520px) and (orientation: portrait) {
    #spellControls { top: max(5px, env(safe-area-inset-top)); bottom: auto; transform: translateX(-50%) scale(.7); }
    #spellChoices { grid-template-columns: repeat(3, 48px); }
    #ui { top: max(86px, calc(env(safe-area-inset-top) + 76px)); }
}

@media (pointer: coarse) {
    #bossHud {
        bottom: max(28px, calc(env(safe-area-inset-bottom) + 18px));
        width: min(660px, calc(100vw - 28px - env(safe-area-inset-left) - env(safe-area-inset-right)));
    }
}

@media (max-width: 380px) and (orientation: portrait) {
    #upgradeChoices {
        grid-template-columns: repeat(2, minmax(120px, 1fr));
    }
    #upgradeScreen { place-content: start center; }
}

@media (max-height: 430px) and (orientation: landscape) {
    #ui > div:not(#gameTitle):not(.health-frame) { display: none; }
    #gameTitle { display: none; }
    #upgradeScreen {
        place-content: start center;
        gap: 7px;
    }
    #upgradeChoices button { padding: 7px 10px; min-height: 42px; }
    #upgradeChoices small { margin-top: 1px; }
    #endScreen { justify-content: flex-start; }
    .menuOverlay { align-items: flex-start; }
    .menuPanel { padding: 18px 28px; gap: 8px; }
    .titleSigil { font-size: 34px; }
}

