@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;600;700;800&display=swap');

* {
box-sizing: border-box;
-webkit-tap-highlight-color: transparent;
}

html,
body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
background: #000;
font-family: "MS Sans Serif", "Space Grotesk", system-ui, sans-serif;
color: #111;
touch-action: none;
}

.window {
height: 100dvh;
display: flex;
flex-direction: column;
padding: max(4px, env(safe-area-inset-top)) 4px max(4px, env(safe-area-inset-bottom));
background:
linear-gradient(90deg, rgba(0,255,80,.28) 1px, transparent 1px),
linear-gradient(0deg, rgba(0,255,80,.18) 1px, transparent 1px),
#00a000;
background-size: 32px 32px;
}

.titlebar {
height: 28px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 6px;
background: linear-gradient(90deg, #000080, #1084d0);
color: #fff;
font-weight: 900;
border-top: 2px solid #dbeafe;
border-left: 2px solid #dbeafe;
border-right: 2px solid #020617;
border-bottom: 2px solid #020617;
}

.win-controls {
display: flex;
gap: 3px;
}

.win-controls b {
width: 20px;
height: 20px;
display: grid;
place-items: center;
background: #c0c0c0;
color: #111;
border-top: 2px solid #fff;
border-left: 2px solid #fff;
border-right: 2px solid #404040;
border-bottom: 2px solid #404040;
font-size: 12px;
}

.menubar {
height: 24px;
display: flex;
align-items: center;
gap: 22px;
padding: 0 9px;
background: #f2f2f2;
border-left: 2px solid #808080;
border-right: 2px solid #808080;
font-size: 13px;
font-weight: 700;
}

.top-controls {
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
gap: 6px;
padding: 6px 0;
}

.win-btn {
height: 34px;
display: flex;
align-items: center;
justify-content: center;
text-decoration: none;
border-radius: 0;
background: #c0c0c0;
color: #111;
border-top: 3px solid #fff;
border-left: 3px solid #fff;
border-right: 3px solid #404040;
border-bottom: 3px solid #404040;
font-family: inherit;
font-weight: 900;
font-size: 12px;
}

.win-btn:active {
border-top: 3px solid #404040;
border-left: 3px solid #404040;
border-right: 3px solid #fff;
border-bottom: 3px solid #fff;
background: #b8b8b8;
transform: translate(1px, 1px);
}

.game-layout {
flex: 1;
min-height: 0;
display: grid;
grid-template-columns: minmax(0, 1fr) 120px;
gap: 8px;
padding: 6px;
background: rgba(0,120,0,.6);
border: 2px solid #008000;
}

.board-wrap {
min-height: 0;
display: flex;
align-items: center;
justify-content: center;
}

#board {
display: grid;
aspect-ratio: 1 / 1;
width: min(100%, 700px);
max-height: 100%;
background: #c0c0c0;
border-top: 4px solid #fff;
border-left: 4px solid #fff;
border-right: 4px solid #404040;
border-bottom: 4px solid #404040;
}

.tile {
display: grid;
place-items: center;
min-width: 0;
min-height: 0;
aspect-ratio: 1 / 1;
font-size: clamp(10px, 2.6vw, 22px);
line-height: 1;
border: 1px solid #9a9a9a;
user-select: none;
}

.floor { background: #c9c9c9; }
.wall { background: linear-gradient(135deg, #d8d8d8, #868686); }
.chip { background: #c9c9c9; color: #00f; }
.exit { background: #0044ff; color: #fff; }
.socket { background: #111; color: #0f0; }
.water { background: repeating-linear-gradient(45deg, #8ff 0 4px, #2dd 4px 8px); }
.fire { background: #ffb000; }
.block { background: linear-gradient(135deg, #efefef, #777); }
.key-red { background: #c9c9c9; color: #f00; }
.key-blue { background: #c9c9c9; color: #00f; }
.key-yellow { background: #c9c9c9; color: #dd0; }
.door-red { background: #7f0000; color: #fff; }
.door-blue { background: #00007f; color: #fff; }
.door-yellow { background: #7f7f00; color: #fff; }
.enemy { background: #c9c9c9; color: #800080; }
.player { background: #c9c9c9; color: #008000; }

.sidebar {
display: grid;
align-content: start;
gap: 12px;
padding: 8px;
background: #c0c0c0;
border-top: 3px solid #fff;
border-left: 3px solid #fff;
border-right: 3px solid #404040;
border-bottom: 3px solid #404040;
}

.panel {
display: grid;
gap: 5px;
text-align: center;
}

.panel label {
font-size: 16px;
font-weight: 900;
color: #f00;
text-shadow: 1px 1px #fff;
}

.panel div {
background: #111;
color: #00ff00;
font-size: 25px;
font-weight: 900;
font-family: monospace;
padding: 4px;
border: 2px inset #808080;
}

.mobile-dpad {
display: none;
}

.overlay {
position: fixed;
inset: 0;
display: none;
align-items: center;
justify-content: center;
background: rgba(0,0,0,.72);
backdrop-filter: blur(12px);
z-index: 30;
padding: 18px;
}

.overlay.show {
display: flex;
}

.panel-modal {
position: relative;
width: min(92vw, 520px);
max-height: 82dvh;
overflow: auto;
padding: 24px;
border-radius: 0;
background: #c0c0c0;
color: #111;
border-top: 4px solid #fff;
border-left: 4px solid #fff;
border-right: 4px solid #404040;
border-bottom: 4px solid #404040;
}

.panel-modal p {
font-size: 16px;
line-height: 1.45;
}

.close {
position: absolute;
right: 10px;
top: 10px;
width: 36px;
height: 36px;
border-radius: 0;
background: #c0c0c0;
border-top: 3px solid #fff;
border-left: 3px solid #fff;
border-right: 3px solid #404040;
border-bottom: 3px solid #404040;
font-size: 22px;
}

@media (hover: none), (pointer: coarse), (max-width: 700px) {
.game-layout {
grid-template-columns: 1fr;
}

.sidebar {
grid-template-columns: 1fr 1fr 1fr;
padding: 5px;
gap: 6px;
}

.panel label {
font-size: 11px;
}

.panel div {
font-size: 18px;
}

.mobile-dpad {
display: grid;
grid-template-columns: 58px 58px 58px;
grid-template-rows: 46px 46px;
gap: 6px;
justify-content: center;
padding: 6px 0 0;
}

.mobile-dpad button {
height: 46px;
border-radius: 0;
background: #c0c0c0;
color: #111;
border-top: 3px solid #fff;
border-left: 3px solid #fff;
border-right: 3px solid #404040;
border-bottom: 3px solid #404040;
font-family: inherit;
font-weight: 900;
font-size: 22px;
}

.mobile-dpad [data-dir="up"] { grid-column: 2; grid-row: 1; }
.mobile-dpad [data-dir="left"] { grid-column: 1; grid-row: 2; }
.mobile-dpad [data-dir="right"] { grid-column: 3; grid-row: 2; }
.mobile-dpad [data-dir="down"] { grid-column: 2; grid-row: 2; }
}

.player {
font-size: clamp(22px, 5.4vw, 44px) !important;
}
