:root {
    color-scheme: dark;
    color: white;
    background: black;
    font-family: "Songti SC", SimSun, serif;
}

body {
    margin: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
}

#playfield { position: relative; flex: 1; min-width: 0; min-height: 0 }

#gameGroup, #touchControls, dialog button {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

#gameGroup {
    width: 570px;
    height: 410px;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) scale(var(--scale, 1));
    background: #9695bc url(images/classic/frame.png) repeat;
    overflow: hidden;
    image-rendering: pixelated;
}

#startPanel, #startTop {
    position: absolute;
    inset: 0;
    z-index: 15;
    display: grid;
    place-content: center;
    background: black;
    text-align: center;
}
#startTop { z-index: 2 }
#startTopProgressBar { width: 140px; height: 3px; background: #222; margin: auto }
#startTopProgress { height: 100%; background: #eee }
#startTopLoadTips, #mainTips { font-size: 14px }
#mainTips { position: absolute; left: 16px; bottom: 4px; z-index: 25 }
#startBackground, #startLogo, #levelChooseButtons { display: none }
.classic-title {
    position: absolute;
    left: 172px;
    top: 65px;
    width: 226px;
    height: 131px;
    background: url(images/classic/title.png) no-repeat;
    pointer-events: none;
}
#startButtonGroup { position: absolute; top: 209px; left: 0; right: 0 }
.startButton {
    display: block;
    width: 135px;
    height: 37px;
    margin: 0 auto 17px;
    border: 0;
    background: transparent;
    color: white;
    cursor: pointer;
    font: bold 26px "Kaiti SC", KaiTi, serif;
}
.startButton:hover, .startButton:focus-visible { color: #f5c46f }

#statusBar { position: absolute; top: 28px; left: 28px; width: 132px; z-index: 1 }
.stats, .keys, #floor, .shortcuts, .map-border {
    box-sizing: border-box;
    border: 3px solid #b8773b;
    box-shadow: inset 0 0 0 1px #704725;
}
.stats, .keys, #floor, .shortcuts { background: #46433e url(images/classic/stone.png) repeat }
.stats { height: 178px; padding: 6px 9px 4px }
.level { height: 45px; display: grid; grid-template-columns: 1fr 1fr auto; align-items: center }
.level img { width: 35px; height: 35px }
.level #lv { font: 27px Arial, sans-serif; padding-left: 8px }
.level span:last-child { font-size: 15px }
.stats dl { margin: 4px 0 0 }
.stats dl div { display: grid; grid-template-columns: 1fr 53px; height: 23px; align-items: center }
.stats dd, .keys b { margin: 0; text-align: center; font: bold italic 19px Arial, sans-serif }
.keys { margin-top: 2px; padding: 1px 8px; height: 104px }
.keys div { display: grid; grid-template-columns: 1fr 44px auto; align-items: center; height: 32px }
.keys img { width: 29px; height: 29px }
.keys b { font-size: 23px }
.keys span { font-size: 13px }
#floor { height: 33px; line-height: 26px; margin: 0; text-align: center; letter-spacing: 3px }
.shortcuts {
    margin-top: 3px;
    padding: 4px 3px;
    height: 51px;
    display: grid;
    grid-template-columns: 42% 58%;
    align-items: center;
}
.shortcuts button {
    padding: 0;
    border: 0;
    background: transparent;
    color: white;
    text-align: left;
    font: bold 13px "Kaiti SC", KaiTi, serif;
    white-space: nowrap;
    cursor: pointer;
}
.shortcuts button:hover, .shortcuts button:focus-visible { color: #f5c46f }

.map-border { position: absolute; left: 187px; top: 28px; width: 358px; height: 358px; z-index: 1; pointer-events: none }
.gameCanvas {
    position: absolute;
    left: 158px;
    top: 0;
    width: 416px;
    height: 416px;
    touch-action: none;
    clip-path: inset(32px);
}
#bg { z-index: 2 }
#event { z-index: 3 }
#fg { z-index: 4 }
#hero { z-index: 5 }
#animate, #weather { z-index: 6 }
#ui { z-index: 7; pointer-events: none }
#data { z-index: 8 }
#ui, #data { clip-path: none }
#curtain, #floorMsgGroup { position: absolute; left: 190px; top: 32px; width: 352px; height: 352px; pointer-events: none }
#curtain { z-index: 6 }
#floorMsgGroup { display: none; z-index: 10; text-align: center; padding-top: 85px; box-sizing: border-box; background: black }
#logoLabel { font: bold 38px "Kaiti SC", KaiTi, serif; margin: 0 }
#versionLabel, #floorNameLabel { margin: 12px 0 }

dialog {
    color: white;
    max-height: 90dvh;
    overflow: auto;
    width: min(460px, calc(100vw - 54px));
    box-sizing: border-box;
    border: 3px solid #b8773b;
    padding: 18px;
    background: #151413;
    font: 15px/1.5 system-ui, sans-serif;
}
dialog::backdrop { background: #000a }
dialog h2 { font-size: 21px; margin: 0 0 7px }
dialog p { margin: 7px 0 12px }
dialog button {
    cursor: pointer;
    color: white;
    background: #2c2824;
    border: 1px solid #71604a;
    padding: 7px 11px;
    font: inherit;
}
dialog button:hover, dialog button:focus-visible { border-color: #f5c46f }
dialog button:disabled { cursor: default; color: #89837c; border-color: #45403a }
#slotList { display: grid; gap: 6px; margin: 12px 0 }
#slotList[hidden] { display: none }
.slot { display: grid; grid-template-columns: 3.5em 1fr; text-align: left; gap: 8px }
.slot span { font-size: 13px }
#slotConfirm { margin-bottom: 14px }
#slotConfirm button { margin-right: 8px }
kbd { font: inherit; color: #d7c7aa }

#battle { position: absolute; inset: 0; z-index: 12; pointer-events: none }
.classic-title { height: 135px }

#touchControls { display: none }

@media (any-pointer: coarse), (max-width: 570px) {
    #touchControls:not([hidden]) {
        box-sizing: border-box;
        width: 100%;
        max-width: 570px;
        align-self: center;
        display: grid;
        grid-template-columns: minmax(140px, 2fr) 3fr;
        align-items: center;
        gap: 12px;
        padding: 8px 10px max(10px, env(safe-area-inset-bottom));
    }
    .touch-directions, .touch-actions {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 4px;
    }
    .touch-up { grid-column: 2; grid-row: 1 }
    .touch-directions button:not(.touch-up) { grid-row: 2 }
    #touchControls button {
        min-height: 44px;
        padding: 0;
        border: 1px solid #9f723e;
        border-radius: 5px;
        color: white;
        background: #29241e;
        font: 15px system-ui, sans-serif;
        touch-action: none;
    }
    #touchControls .touch-directions button { font-size: 22px }
    #touchControls button:active { background: #674829 }
}

@media (any-pointer: coarse) and (orientation: landscape) and (max-height: 500px) {
    body { flex-direction: row }
    #touchControls:not([hidden]) {
        width: 164px;
        grid-template-columns: 1fr;
        padding-right: max(10px, env(safe-area-inset-right));
    }
}
