@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0
}

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #000;
    font-family: 'Press Start 2P', monospace;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none
}

#shell {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #000
}

#game-canvas {
    display: block;
    width: 100%;
    flex: 1;
    min-height: 0;
    image-rendering: pixelated;
    cursor: none
}

#hud {
    flex-shrink: 0;
    width: 100%;
    background: #0d0000;
    border-top: 3px solid #600;
    display: flex;
    align-items: stretch;
    height: clamp(52px, 11vh, 80px)
}

.hud-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3px 8px;
    border-right: 2px solid #400;
    gap: 1px;
    flex-shrink: 0
}

.hud-panel:last-child {
    border-right: none
}

.hl {
    font-size: clamp(4px, 1.1vw, 7px);
    color: #844;
    letter-spacing: 1px;
    white-space: nowrap
}

.hv {
    font-size: clamp(8px, 2.3vw, 16px);
    color: #f44;
    text-shadow: 0 0 8px #f004;
    white-space: nowrap
}

.hv.g {
    color: #4f4;
    text-shadow: 0 0 8px #0f04
}

.hv.y {
    color: #ff4;
    text-shadow: 0 0 8px #ff04
}

.hv.b {
    color: #4af;
    text-shadow: 0 0 8px #0af4
}

#portrait-wrap {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3px;
    border-right: 2px solid #400
}

#portrait {
    image-rendering: pixelated
}

#health-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    padding: 4px 8px;
    gap: 3px;
    min-width: 0
}

#hbg {
    width: 100%;
    height: clamp(6px, 1.3vh, 11px);
    background: #300;
    border: 1px solid #600;
    border-radius: 2px;
    overflow: hidden
}

#hbar {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #c00, #f44);
    border-radius: 2px;
    transition: width .2s, background .3s
}

#minimap-canvas {
    flex-shrink: 0;
    image-rendering: pixelated;
    border-left: 2px solid #400;
    cursor: default
}

#overlay {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, .9);
    z-index: 50;
    gap: 13px;
    padding: 20px;
    text-align: center
}

#overlay.hidden {
    display: none
}

#ov-title {
    font-size: clamp(20px, 5.5vw, 42px);
    color: #f00;
    text-shadow: 0 0 20px #f00, 0 0 40px #800;
    letter-spacing: 3px;
    animation: hp 1.6s ease-in-out infinite alternate
}

@keyframes hp {
    from {
        text-shadow: 0 0 10px #f00
    }

    to {
        text-shadow: 0 0 40px #f00, 0 0 80px #f44
    }
}

#ov-sub {
    font-size: clamp(8px, 2.2vw, 14px);
    color: #f84
}

#ov-body {
    font-size: clamp(5px, 1.4vw, 8px);
    color: #a66;
    line-height: 2.3;
    max-width: 380px
}

#ov-level {
    font-size: clamp(6px, 1.8vw, 10px);
    color: #f84;
    min-height: 1.4em
}

.hbtn {
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(7px, 2vw, 11px);
    color: #000;
    background: #c00;
    border: none;
    padding: 10px 26px;
    cursor: pointer;
    letter-spacing: 1px;
    box-shadow: 0 4px 0 #500, 0 0 18px #f004;
    transition: transform .08s, box-shadow .08s
}

.hbtn:hover {
    background: #f00
}

.hbtn:active {
    transform: translateY(3px);
    box-shadow: 0 1px 0 #500
}

#announce {
    position: fixed;
    top: 18%;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    pointer-events: none;
    z-index: 40;
    opacity: 0;
    transition: opacity .4s
}

#announce.show {
    opacity: 1
}

#ann-name {
    font-size: clamp(11px, 3.5vw, 24px);
    color: #f44;
    text-shadow: 0 0 20px #f00
}

#ann-sub {
    font-size: clamp(5px, 1.6vw, 9px);
    color: #a44;
    margin-top: 6px
}

#flash {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 35;
    background: transparent;
    transition: background .05s
}

#flash.red {
    background: rgba(255, 0, 0, .35)
}

#flash.white {
    background: rgba(255, 230, 200, .22)
}

#msg {
    position: fixed;
    top: 16%;
    left: 50%;
    transform: translateX(-50%);
    font-size: clamp(7px, 2vw, 11px);
    color: #ff4;
    text-shadow: 0 0 10px #ff0;
    pointer-events: none;
    z-index: 42;
    opacity: 0;
    transition: opacity .3s;
    white-space: nowrap
}

#msg.show {
    opacity: 1
}

#crosshair {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 30
}

/* Weapon name HUD badge */
#weap-name {
    position: fixed;
    bottom: calc(clamp(52px, 11vh, 80px) + 2px);
    right: 6px;
    font-size: clamp(5px, 1.2vw, 8px);
    color: #ff4;
    text-shadow: 0 0 8px #ff0;
    pointer-events: none;
    z-index: 29;
    opacity: 0.85;
    letter-spacing: 1px
}

/* Key icons in HUD */
#key-row {
    display: flex;
    gap: 3px;
    align-items: center
}

.key-icon {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    border: 1px solid rgba(255, 255, 255, .4);
    display: none
}

.key-icon.yellow {
    background: #ffcc00;
    box-shadow: 0 0 6px #ff0;
    display: block
}

.key-icon.blue {
    background: #00aaff;
    box-shadow: 0 0 6px #0af;
    display: block
}

/* Score screen */
#score-screen {
    position: fixed;
    inset: 0;
    background: #000;
    z-index: 58;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 28px;
    pointer-events: all
}

#score-screen.hide {
    display: none
}

#ss-title {
    font-size: clamp(12px, 4vw, 26px);
    color: #ff4;
    text-shadow: 0 0 16px #ff0;
    letter-spacing: 3px
}

#ss-table {
    font-size: clamp(6px, 1.6vw, 10px);
    color: #aaa;
    line-height: 2.4;
    text-align: left;
    border: 1px solid #333;
    padding: 14px 24px;
    min-width: 240px
}

#ss-table .ss-val {
    color: #ff4;
    float: right;
    margin-left: 32px
}

#ss-bonus {
    font-size: clamp(7px, 1.8vw, 11px);
    color: #4f4;
    text-shadow: 0 0 8px #0f0
}

#ss-total {
    font-size: clamp(10px, 3vw, 18px);
    color: #f44;
    text-shadow: 0 0 12px #f00;
    letter-spacing: 2px
}

#ss-prompt {
    font-size: clamp(5px, 1.4vw, 8px);
    color: #600;
    letter-spacing: 2px;
    animation: blink 1s step-end infinite
}

/* Cutscene full-screen overlay */
#cutscene {
    position: fixed;
    inset: 0;
    background: #000;
    z-index: 60;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    padding: 30px;
    pointer-events: all
}

#cutscene.hide {
    display: none
}

#cs-level {
    font-size: clamp(10px, 3.5vw, 22px);
    color: #f00;
    letter-spacing: 3px;
    text-shadow: 0 0 20px #f00, 0 0 40px #800;
    animation: hp 1.6s ease-in-out infinite alternate
}

#cs-name {
    font-size: clamp(14px, 5vw, 34px);
    color: #f44;
    letter-spacing: 2px;
    text-shadow: 0 0 16px #f44;
    margin-bottom: 8px
}

#cs-text {
    font-size: clamp(6px, 1.8vw, 11px);
    color: #a88;
    line-height: 2.2;
    max-width: 480px;
    text-align: center;
    min-height: 4em
}

#cs-prompt {
    font-size: clamp(5px, 1.4vw, 8px);
    color: #600;
    letter-spacing: 2px;
    animation: blink 1s step-end infinite
}

@keyframes blink {
    50% {
        opacity: 0
    }
}

#weapon-canvas {
    position: fixed;
    bottom: 0;
    left: 0;
    pointer-events: none;
    z-index: 28;
    image-rendering: pixelated
}

/* ── Look swipe zone (right half) ── */
#tz-look {
    position: fixed;
    top: 0;
    right: 0;
    width: 50%;
    height: 80%;
    pointer-events: all;
    z-index: 20;
    display: none
}

/* ── D-Pad controller — 6-button layout ── */
#dpad {
    position: fixed;
    bottom: calc(clamp(52px, 11vh, 80px) + 12px);
    left: 8px;
    z-index: 40;
    display: none;
    width: clamp(170px, 42vw, 230px);
    height: clamp(120px, 30vw, 165px);
    pointer-events: none;
}

/* Individual d-pad buttons */
.dp {
    position: absolute;
    width: 30%;
    height: 46%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(200, 60, 0, 0.28);
    border: 2px solid rgba(255, 100, 30, 0.50);
    border-radius: 7px;
    font-size: clamp(11px, 3.5vw, 18px);
    color: rgba(255, 140, 80, 0.95);
    pointer-events: all;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    touch-action: none;
    box-sizing: border-box;
}

.dp:active {
    background: rgba(255, 80, 20, 0.55);
}

/*
  Layout — 3 columns, 2 rows:
  [SL][▲][SR]   top row:    strafe-left | forward | strafe-right
  [◀][▼][▶]    bottom row: turn-left   | back    | turn-right
*/
#dp-strafeL {
    top: 0;
    left: 0;
}

#dp-up {
    top: 0;
    left: 35%;
}

#dp-strafeR {
    top: 0;
    right: 0;
}

#dp-left {
    bottom: 0;
    left: 0;
}

#dp-down {
    bottom: 0;
    left: 35%;
}

#dp-right {
    bottom: 0;
    right: 0;
}

/* Strafe buttons slightly different tint so player knows they're different */
#dp-strafeL,
#dp-strafeR {
    background: rgba(0, 100, 200, 0.25);
    border-color: rgba(80, 160, 255, 0.45);
    color: rgba(120, 200, 255, 0.95);
    font-size: clamp(9px, 3vw, 15px);
}

/* ── Action buttons (right side) ── */
.tbtn {
    position: fixed;
    pointer-events: all;
    z-index: 40;
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    font-family: 'Press Start 2P', monospace;
    border: 2px solid;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
}

#tb-fire {
    right: clamp(10px, 3vw, 22px);
    bottom: calc(clamp(52px, 11vh, 80px) + 14px);
    width: clamp(60px, 14vw, 80px);
    height: clamp(60px, 14vw, 80px);
    background: rgba(200, 0, 0, 0.45);
    border-color: #c00;
    color: #f44;
    font-size: clamp(7px, 2vw, 10px);
}

#tb-use {
    right: clamp(82px, 18vw, 116px);
    bottom: calc(clamp(52px, 11vh, 80px) + 20px);
    width: clamp(46px, 10vw, 60px);
    height: clamp(46px, 10vw, 60px);
    background: rgba(0, 60, 180, 0.35);
    border-color: #04c;
    color: #4af;
    font-size: clamp(5px, 1.4vw, 8px);
}

/* ── Death screen ── */
#death-screen {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.96);
    z-index: 62;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    pointer-events: all;
}

#death-screen.hide {
    display: none
}

#ds-skull {
    font-size: clamp(48px, 14vw, 100px);
}

#ds-title {
    font-size: clamp(28px, 8vw, 64px);
    color: #f00;
    letter-spacing: 4px;
    text-shadow: 0 0 30px #f00, 0 0 60px #800;
    animation: hp 1.2s ease-in-out infinite alternate;
}

#ds-stats {
    font-size: clamp(7px, 1.8vw, 11px);
    color: #a66;
    line-height: 2.4;
    text-align: center;
}

#ds-prompt {
    font-size: clamp(6px, 1.6vw, 9px);
    color: #844;
    letter-spacing: 2px;
    animation: blink 1s step-end infinite;
}

/* Show touch controls on touch/mobile devices */
@media (pointer:coarse) {
    #tz-look {
        display: block;
    }

    #dpad {
        display: block;
    }

    .tbtn {
        display: flex;
    }
}

/* Also always show on small screens regardless of pointer type */
@media (max-width:768px) {
    #tz-look {
        display: block;
    }

    #dpad {
        display: block;
    }

    .tbtn {
        display: flex;
    }
}