body, html {
    margin: 0;
    overflow: hidden;
    background: #000;
    color: #fff;
    font-family: sans-serif;
    touch-action: none;
    user-select: none;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

#U {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 9;
    font-size: clamp(12px, 2.5vw, 15px);
    text-shadow: 2px 2px 0 #000;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 5px;
    background: rgba(0,0,0,0.28);
    padding: 8px 15px;
    border-radius: 0 12px 12px 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    backdrop-filter: blur(5px);
    max-width: calc(100% - 60px);
    box-sizing: border-box;
}

b {
    color: #0fc;
    margin-right: 10px;
}

#L {
    color: #f44;
}

#W {
    color: #f0f;
}

.barC {
    width: 100px;
    height: 10px;
    border: 2px solid #fff;
    display: inline-block;
    vertical-align: middle;
    background: rgba(0,0,0,0.5);
    margin-right: 10px;
}

.barF {
    height: 100%;
    background: #0f0;
    transition: width 0.2s;
}

#C {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 9;
    color: #0fc;
    font-size: 30px;
    opacity: .5;
}

#O {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 16;
    display: none;
    background: rgba(0,0,0,0.9);
    padding: 30px;
    border: 3px solid #f00;
    text-align: center;
    border-radius: 15px;
    box-shadow: 0 0 30px #f00;
    width: 80%;
    max-width: 400px;
    max-height: 90vh;
    overflow-y: auto;
    box-sizing: border-box;
}

#SM {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0,0,0,.95);
    border: 3px solid #0fc;
    padding: 20px;
    display: none;
    z-index: 16;
    text-align: center;
    font-size: 20px;
    box-shadow: 0 0 30px #0fc;
    border-radius: 15px;
    width: 80%;
    max-width: 450px;
    max-height: 90vh;
    overflow-y: auto;
    box-sizing: border-box;
    line-height: 1.4;
}

#FW {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0,0,0,.95);
    border: 3px solid #0fc;
    padding: 20px;
    display: none;
    z-index: 16;
    text-align: center;
    font-size: 16px;
    box-shadow: 0 0 30px #0fc;
    border-radius: 15px;
    width: 80%;
    max-width: 450px;
    line-height: 1.4;
    max-height: 90vh;
    overflow-y: auto;
    box-sizing: border-box;
}

#jA {
    position: absolute;
    bottom: 30px;
    left: 30px;
    width: 130px;
    height: 130px;
    background: rgba(255,255,255,.1);
    border-radius: 50%;
    z-index: 9;
    border: 2px solid #fff;
}

#jS {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 50px;
    height: 50px;
    background: rgba(255,255,255,.5);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

#fB {
    position: absolute;
    bottom: 40px;
    right: 30px;
    width: 90px;
    height: 90px;
    background: rgba(255,0,0,.3);
    border-radius: 50%;
    z-index: 9;
    border: 3px solid #f00;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 700;
}

#fB:active {
    background: rgba(255,0,0,.8);
}

#dmg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, transparent 40%, rgba(255,0,0,0.8) 120%);
    opacity: 0;
    transition: opacity .1s;
    pointer-events: none;
    z-index: 8;
}

#arw {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 7;
}

.db {
    border: 2px solid #444;
    padding: 10px;
    border-radius: 10px;
    cursor: pointer;
    text-align: center;
    color: #888;
    font-size: 14px;
    width: 90px;
    transition: .2s;
    background: rgba(0,0,0,0.5);
}

.db:hover {
    border-color: #888;
}

.db.sel {
    /* visual hierarchy via .btn-* classes */
}

#ST {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,10,0.52);
    z-index: 30;
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: auto;
}

#ST-inner {
    width: 100%;
    box-sizing: border-box;
}

#LNC {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 24px;
    color: #0fc;
    display: none;
    z-index: 10;
    text-shadow: 0 0 10px #0fc, 2px 2px 4px #000, -1px -1px 4px #000, 1px -1px 4px #000, -1px 1px 4px #000;
    font-weight: bold;
    text-align: center;
    width: 100%;
}

#BUI {
    display: none;
    position: absolute;
    top: 80px;
    width: 100%;
    text-align: center;
    font-size: 24px;
    color: #f44;
    font-weight: bold;
    text-shadow: 0 0 10px #f00;
    z-index: 9;
    letter-spacing: 2px;
}

.bBarC {
    width: 300px;
    height: 10px;
    border: 2px solid #600;
    margin: 10px auto 0;
    background: #000;
    box-sizing: border-box;
    padding: 1px;
    box-shadow: 0 0 10px #600;
}

.bBarF {
    height: 100%;
    background: #f00;
    transition: width 0.1s;
}

#SWC {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    perspective: 600px;
    display: none;
    z-index: 5;
    pointer-events: none;
    overflow: hidden;
    -webkit-mask-image: linear-gradient(to top, black 68%, transparent 94%);
    mask-image: linear-gradient(to top, black 68%, transparent 94%);
}

#SWT {
    position: absolute;
    bottom: -20%;
    left: 10%;
    width: 80%;
    transform: rotateX(40deg);
    color: #ffdd00;
    font-size: clamp(18px, 4vw, 28px);
    font-weight: bold;
    text-align: center;
    text-shadow: 0 0 10px #ff0;
    animation: sw 7s linear forwards;
}

@keyframes sw {
    0%   { bottom: -20%; transform: rotateX(40deg) scale(1.0); }
    100% { bottom: 120%; transform: rotateX(40deg) scale(0.15); }
}

#QBtn {
    position: absolute;
    top: 0;
    right: 0;
    width: 45px;
    height: 45px;
    background: rgba(255,255,255,0.12);
    border: 2px solid rgba(255,255,255,0.55);
    border-top: none;
    border-right: none;
    border-radius: 0 0 0 10px;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 45;
    box-shadow: 0 0 10px rgba(255,255,255,0.2);
    transition: 0.2s;
}

#QBtn:hover {
    background: rgba(255,255,255,0.3);
    transform: scale(1.05);
}

@media (hover: hover) and (pointer: fine) {
    #QBtn {
        display: none !important;
    }
}

#HSM {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0,0,0,0.95);
    border: 3px solid #0fc;
    padding: 15px;
    z-index: 50;
    width: 90%;
    max-width: 650px;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 0 30px #0fc;
    max-height: 90vh;
    flex-direction: column;
    box-sizing: border-box;
    overflow: hidden;
}

#hsTb th {
    color: #ff0;
    padding: 8px;
    border-bottom: 2px solid #0fc;
    font-size: 14px;
}

#hsTb td {
    padding: 6px;
    border-bottom: 1px solid #444;
    font-size: 14px;
}

#QM {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    z-index: 60;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
}

.qmBox {
    background: rgba(0,0,0,0.95);
    border: 3px solid #f00;
    padding: 25px;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 0 30px #f00;
    width: 80%;
    max-width: 400px;
    box-sizing: border-box;
}

#rotOverlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    z-index: 9999;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    color: #0fc;
    font-family: sans-serif;
}

@keyframes wpnUnlock {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.92); }
    12% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    80% { opacity: 1; }
    100% { opacity: 0; }
}

#wpnMsg {
    display: none;
    position: absolute;
    top: 38%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 20;
    pointer-events: none;
    text-align: center;
    font-size: clamp(13px, 3vw, 19px);
    font-weight: bold;
    letter-spacing: 1px;
    color: #0af;
    text-shadow: 0 0 10px #08f;
    background: rgba(0,10,30,0.55);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding: 9px 20px;
    border-radius: 8px;
    white-space: nowrap;
}

@keyframes gFade {
    0% { opacity: 0.5; }
    70% { opacity: 0.5; }
    100% { opacity: 0; }
}

@keyframes gFadeOpaque {
    0% { opacity: 1; }
    65% { opacity: 1; }
    100% { opacity: 0; }
}

@keyframes critPulse {
    0%   { color: #f00; text-shadow: 0 0 6px #f00, 0 0 16px #f00; }
    50%  { color: #fff; text-shadow: 0 0 5px #fff, 0 0 12px #f55; }
    100% { color: #f00; text-shadow: 0 0 6px #f00, 0 0 16px #f00; }
}

@keyframes warnPulse {
    0%   { color: #ff0; text-shadow: 0 0 6px #ff0, 0 0 16px #fa0; }
    50%  { color: #fff; text-shadow: 0 0 5px #fff, 0 0 12px #ff8; }
    100% { color: #ff0; text-shadow: 0 0 6px #ff0, 0 0 16px #fa0; }
}

@keyframes gJitter {
    0%   { transform: translateX(0px); }
    100% { transform: translateX(9px); }
}

@keyframes gJitter2 {
    0%   { transform: translateX(0px); }
    100% { transform: translateX(-8px); }
}

#glitchWrap {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 8;
    overflow: hidden;
}

/* ── Step panels (slide transition) ── */
.step-panel {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: transform 0.42s cubic-bezier(0.4,0,0.2,1), opacity 0.42s ease;
    padding-bottom: 10px;
    box-sizing: border-box;
}

.step-panel.s-cur {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
}

.step-panel.s-left {
    transform: translateX(-72px);
    opacity: 0;
    pointer-events: none;
}

.step-panel.s-right {
    transform: translateX(72px);
    opacity: 0;
    pointer-events: none;
}

/* ── Difficulty buttons ── */
.diffBtn {
    width: 115px !important;
    aspect-ratio: 1 / 1 !important;
    font-size: 13px !important;
    box-sizing: border-box;
}

.diff-featured {
    box-shadow: 0 0 20px rgba(0,255,204,0.65), 0 0 6px rgba(0,255,204,0.35) !important;
    background: rgba(0,255,204,0.1) !important;
}

.diff-featured b {
    color: #0fc !important;
    text-shadow: 0 0 8px rgba(0,255,204,0.8);
}

/* ── Step1 content wrapper – aligns diffGrid + buttons ── */
#step1Body {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 30px;
    width: 100%;
}

/* ── Step2 content wrapper – constrains sectorGrid + buttons ── */
#step2Body {
    display: flex;
    flex-direction: column;
    align-items: center;
}

#diffGrid {
    display: flex;
    gap: 10px;
    flex-wrap: nowrap;
    justify-content: center;
}

/* ── Shared action buttons (O GRĘ, INSTALL, HIGH SCORES, BACK) ── */
.stepBtn {
    width: 175px;
    font-size: 14px !important;
    padding: 10px !important;
    box-sizing: border-box;
}

/* ── Sector grid ── */
#sectorGrid {
    display: grid;
    grid-template-columns: repeat(3, 60px);
    gap: 6px;
    margin: 4px 0 6px 0;
}

.sectorBtn {
    width: 60px !important;
    height: 52px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 18px !important;
    font-weight: bold !important;
    padding: 0 !important;
    box-sizing: border-box;
    line-height: 1.1;
    transform: none !important;
}

#step2BtnRow {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    margin-top: 30px;
}

.sectorBtnFull {
    grid-column: 1 / -1;
    width: 100% !important;
}

.sectorLocked {
    border-color: #2a2a2a !important;
    color: #3a3a3a !important;
    cursor: not-allowed !important;
    box-shadow: none !important;
    background: rgba(0,0,0,0.2) !important;
    transform: none !important;
}

.sectorLocked:hover {
    border-color: #2a2a2a !important;
}

/* ── Button design system ──────────────────────────────────────────── */

/* Press feedback for all interactive buttons */
.db:not(.sectorLocked):active { transform: scale(0.97) !important; }
.btn-cta:active               { transform: scale(0.97); }

/* Primary – main CTA (#0fc cyan) */
.btn-primary {
    border-color: #0fc !important;
    color: #fff !important;
    box-shadow: 0 0 12px rgba(0,255,204,0.35) !important;
    background: rgba(0,255,204,0.06) !important;
}
.btn-primary:hover {
    box-shadow: 0 0 20px rgba(0,255,204,0.6) !important;
    background: rgba(0,255,204,0.13) !important;
}

/* Secondary – supplementary actions */
.btn-secondary {
    border-color: #efefef !important;
    color: #fcfcfc !important;
    box-shadow: none !important;
    background: rgba(255,255,255,0.03) !important;
}
.btn-secondary:hover {
    border-color: #fff !important;
    color: #fff !important;
    background: rgba(255,255,255,0.07) !important;
}

/* Tertiary – back / cancel */
.btn-tertiary {
    border-color: transparent !important;
    color: #fcfcfc !important;
    box-shadow: none !important;
    background: transparent !important;
}
.btn-tertiary:hover {
    border-color: transparent !important;
    color: #fff !important;
}

/* Accent – special install action (yellow) */
.btn-accent {
    border-color: #ff0 !important;
    color: #ff0 !important;
    font-weight: bold;
    box-shadow: 0 0 10px rgba(255,255,0,0.3) !important;
    background: rgba(255,255,0,0.04) !important;
}
.btn-accent:hover {
    box-shadow: 0 0 16px rgba(255,255,0,0.5) !important;
    background: rgba(255,255,0,0.09) !important;
}

/* Danger – destructive (quit yes, game over) */
.btn-danger {
    border-color: #f00 !important;
    color: #f00 !important;
    box-shadow: none !important;
    background: rgba(255,0,0,0.1) !important;
}
.btn-danger:hover {
    box-shadow: 0 0 12px rgba(255,0,0,0.4) !important;
    background: rgba(255,0,0,0.18) !important;
}

/* Confirm – keep playing (green) */
.btn-confirm {
    border-color: #0f0 !important;
    color: #0f0 !important;
    box-shadow: none !important;
    background: rgba(0,255,0,0.08) !important;
}
.btn-confirm:hover {
    box-shadow: 0 0 12px rgba(0,255,0,0.4) !important;
    background: rgba(0,255,0,0.15) !important;
}

/* Filled CTA buttons – summary OK, Play Again */
.btn-cta {
    font-weight: bold;
    font-size: 18px;
    padding: 10px;
    border-radius: 10px;
    cursor: pointer;
    text-align: center;
    display: block;
    box-sizing: border-box;
    transition: .2s;
}
.btn-cta-primary {
    background: #0fc;
    color: #000;
    box-shadow: 0 0 15px rgba(0,255,204,0.7);
}
.btn-cta-primary:hover { background: #4fffdd; box-shadow: 0 0 22px rgba(0,255,204,0.9); }
.btn-cta-danger {
    background: #f00;
    color: #000;
    box-shadow: 0 0 15px rgba(255,0,0,0.7);
}
.btn-cta-danger:hover  { background: #ff4444; box-shadow: 0 0 22px rgba(255,0,0,0.9); }

/* LegM box flex layout */
#legBox {
    box-sizing: border-box;
    border-color: #0fc !important;
    box-shadow: 0 0 30px rgba(0,255,204,0.4) !important;
}

@media (orientation: portrait) {
    #step1Body {
        width: 220px;
        max-width: 92vw;
    }
    #diffGrid {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
        width: 100%;
    }
    .diffBtn {
        width: 100% !important;
        aspect-ratio: unset !important;
    }
    .stepBtn {
        width: 100% !important;
    }
    #stepsWrap {
        height: 430px !important;
    }
    #step2Body {
        width: 192px;
        max-width: 92vw;
    }
}

@media (orientation: landscape) {
    #stepsWrap {
        height: 300px;
    }
    #sectorGrid {
        grid-template-columns: repeat(10, 1fr) !important;
        gap: 5px !important;
        width: 600px;
        max-width: 96vw;
    }
    .sectorBtn {
        width: auto !important;
        min-width: 44px !important;
    }
    .sectorBtnFull {
        grid-column: auto !important;
        width: auto !important;
    }
    #step2Body {
        width: 600px;
        max-width: 96vw;
    }
    #step2BtnRow {
        flex-direction: row-reverse;
        justify-content: center;
        gap: 10px;
    }
    #step2BtnRow .stepBtn {
        flex: none;
        width: 192px !important;
    }
}

/* Phone landscape: revert diffBtn to content-driven height (matches portrait) */
@media (orientation: landscape) and (pointer: coarse) {
    .diffBtn {
        aspect-ratio: unset !important;
    }
}

@keyframes starReveal {
    from { color: #7c7c7c; text-shadow: none; }
    to   { color: #ffd700; text-shadow: 0 0 8px #ffa000, 0 0 14px #ff8c00; }
}

@media screen and (display-mode: standalone) and (orientation: portrait),
       screen and (display-mode: fullscreen) and (orientation: portrait) {
    #rotOverlay {
        display: flex !important;
    }
    #ST, #HSM, #O, #SM, #FW, #QM, canvas, #U, #C, #jA, #fB, #fB2, #fB3, #LNC, #BUI, #SWC, #langSel, #QBtn, #LvlM, #popups, #btnLeg, #LegM, #AboutM {
        display: none !important;
    }
}

/* ── Desktop: 1.5× UI scale ──────────────────────────────────────────── */
@media (hover: hover) and (pointer: fine) and (min-width: 1024px) {
    #ST { overflow: hidden; }
    #ST-inner {
        zoom: 1.5;
        width: calc(100% / 1.5) !important;
        max-height: calc(100vh / 1.5) !important;
    }
    #U, #BUI, #LNC, #wpnMsg,
    #O, #SM, #FW, #HSM,
    .qmBox,
    #btnLeg, #langSel, #QBtn,
    #jA, #fB, #fB2, #fB3, #fBsp, #fBsh, #fBbomb {
        zoom: 1.5;
    }
    #SWT {
        font-size: clamp(27px, 6vw, 42px);
    }
    #SWT span:first-child {
        font-size: clamp(39px, 9vw, 66px) !important;
    }
    #desktopHint { display: flex !important; }
}

/* ── Hide cursor during gameplay ─────────────────────────────────────────── */
html.gx-playing,
html.gx-playing *,
body.gx-playing,
body.gx-playing * {
    cursor: none !important;
}

