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

:root {
    --bg: #1a1a2e;
    --panel: #16213e;
    --accent: #e94560;
    --gold: #ffd700;
    --text: #eeeeee;
    --muted: #a7a7b8;
}

html,
body {
    min-height: 100%;
    background: radial-gradient(circle at top, #202044 0%, var(--bg) 55%, #0f1022 100%);
    color: var(--text);
    font-family: "Courier New", monospace;
    overflow: hidden;
    touch-action: none;
    overscroll-behavior: none;
}

body {
    min-height: 100svh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
}

#game-shell {
    width: min(100vw - 16px, 980px);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

#title {
    font-size: clamp(1.05rem, 4vw, 1.65rem);
    line-height: 1;
    color: var(--accent);
    text-shadow: 2px 2px 0 var(--panel), 0 0 18px rgba(233, 69, 96, 0.25);
    text-align: center;
    user-select: none;
}

canvas {
    display: block;
    width: min(100%, calc((100svh - 156px) * 1.7857));
    max-width: 800px;
    height: auto;
    aspect-ratio: 800 / 448;
    image-rendering: pixelated;
    border: clamp(2px, 0.7vw, 3px) solid var(--accent);
    border-radius: 6px;
    background: #87ceeb;
    box-shadow: 0 0 28px rgba(233, 69, 96, 0.2);
}

#ui {
    width: min(100%, 800px);
    display: grid;
    grid-template-columns: repeat(4, auto);
    justify-content: center;
    gap: clamp(8px, 3vw, 20px);
    font-size: clamp(0.68rem, 2.4vw, 0.9rem);
    text-align: center;
    user-select: none;
}

.stat { color: var(--accent); font-weight: 700; }

#controls {
    color: var(--muted);
    font-size: clamp(0.62rem, 2.4vw, 0.78rem);
    text-align: center;
    user-select: none;
}

#touch-controls {
    width: min(100%, 800px);
    display: none;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    padding-top: 2px;
    user-select: none;
}

.touch-cluster {
    display: flex;
    gap: 10px;
    align-items: center;
}

.touch-btn {
    border: 2px solid rgba(233, 69, 96, 0.85);
    border-radius: 999px;
    min-width: 64px;
    min-height: 54px;
    padding: 0 18px;
    background: rgba(22, 33, 62, 0.88);
    color: var(--text);
    font: 800 1rem "Courier New", monospace;
    box-shadow: 0 5px 0 rgba(0, 0, 0, 0.35), inset 0 0 16px rgba(233, 69, 96, 0.12);
    cursor: pointer;
    touch-action: none;
}

.touch-btn.jump {
    min-width: 92px;
    color: #111;
    background: linear-gradient(180deg, #ffe16b, var(--gold));
    border-color: #f7c83b;
}

.touch-btn.small {
    min-width: 48px;
    min-height: 44px;
    padding: 0 12px;
    font-size: 0.9rem;
}

.touch-btn:active,
.touch-btn.active {
    transform: translateY(3px);
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35), inset 0 0 18px rgba(255, 255, 255, 0.2);
}

@media (hover: none), (pointer: coarse), (max-width: 760px) {
    #touch-controls { display: flex; }
    #controls { font-size: 0.68rem; }
    canvas { width: min(100%, calc((100svh - 208px) * 1.7857)); }
}

@media (max-width: 520px) {
    body { align-items: flex-start; }
    #game-shell { gap: 6px; }
    #ui { grid-template-columns: repeat(2, auto); row-gap: 3px; }
    #touch-controls { gap: 8px; }
    .touch-cluster { gap: 7px; }
    .touch-btn { min-width: 56px; min-height: 50px; padding: 0 14px; }
    .touch-btn.jump { min-width: 82px; }
    .touch-btn.small { min-width: 44px; min-height: 40px; padding: 0 10px; }
}

@media (max-height: 500px) and (orientation: landscape) {
    body { align-items: center; padding: 4px max(6px, env(safe-area-inset-right)) 4px max(6px, env(safe-area-inset-left)); }
    #game-shell { display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto auto; column-gap: 10px; align-items: center; width: 100%; }
    #title { grid-column: 1; font-size: 0.95rem; }
    canvas { grid-column: 1; width: min(calc(100vw - 172px), calc(100svh - 70px) * 1.7857); }
    #ui { grid-column: 1; font-size: 0.62rem; gap: 7px; }
    #controls { display: none; }
    #touch-controls { grid-column: 2; grid-row: 1 / span 3; width: auto; flex-direction: column; justify-content: center; }
    .move-cluster { flex-direction: row; }
    .action-cluster { flex-direction: column; }
    .touch-btn { min-width: 52px; min-height: 46px; padding: 0 10px; }
    .touch-btn.jump { min-width: 68px; min-height: 54px; }
}
