* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #000;
    font-family: 'Courier New', monospace;
    color: #fff;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

#gameCanvas {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1;
    touch-action: none;
    outline: none;
}

#gameCanvas:focus {
    outline: none;
}

.screen-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    display: none;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    pointer-events: none;
    background: rgba(0, 0, 0, 0.7);
    padding: 10px;
}

.screen-overlay.active {
    display: flex;
    pointer-events: auto;
}

.screen-panel {
    background: rgba(5, 5, 20, 0.92);
    border: 2px solid rgba(0, 255, 255, 0.3);
    border-radius: 8px;
    padding: clamp(15px, 4vw, 40px) clamp(15px, 5vw, 40px);
    text-align: center;
    max-width: min(95vw, 520px);
    width: 90%;
    max-height: min(92vh, 90vh);
    overflow-y: auto;
    box-shadow: 0 0 40px rgba(0, 255, 255, 0.1), inset 0 0 30px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.screen-panel::-webkit-scrollbar {
    width: 4px;
}

.screen-panel::-webkit-scrollbar-thumb {
    background: #0ff3;
    border-radius: 2px;
}

.game-title {
    font-size: clamp(24px, 7vw, 56px);
    font-weight: bold;
    color: #0ff;
    text-shadow: 0 0 20px rgba(0, 255, 255, 0.5), 0 0 40px rgba(0, 255, 255, 0.2);
    margin-bottom: 5px;
    letter-spacing: 4px;
    white-space: nowrap;
}

.game-subtitle {
    font-size: clamp(9px, 2.5vw, 16px);
    color: #f80;
    letter-spacing: 6px;
    margin-bottom: clamp(10px, 2vw, 25px);
    text-shadow: 0 0 10px rgba(255, 136, 0, 0.4);
    white-space: nowrap;
}

.menu-best-score {
    font-size: clamp(10px, 2vw, 15px);
    color: #ff0;
    margin-bottom: clamp(10px, 2vw, 20px);
    text-shadow: 0 0 8px rgba(255, 255, 0, 0.3);
}

.btn {
    display: block;
    width: 100%;
    max-width: min(90vw, 280px);
    margin: clamp(4px, 1vw, 8px) auto;
    padding: clamp(10px, 2.5vw, 14px) clamp(15px, 3vw, 20px);
    background: rgba(0, 255, 255, 0.08);
    border: 1px solid rgba(0, 255, 255, 0.3);
    border-radius: 4px;
    color: #0ff;
    font-family: 'Courier New', monospace;
    font-size: clamp(12px, 2.5vw, 16px);
    font-weight: bold;
    cursor: pointer;
    transition: all 0.15s;
    letter-spacing: 2px;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    min-height: 44px;
    touch-action: manipulation;
}

.btn:hover, .btn:focus {
    background: rgba(0, 255, 255, 0.15);
    border-color: #0ff;
    box-shadow: 0 0 15px rgba(0, 255, 255, 0.2);
    transform: scale(1.02);
}

.btn:active {
    background: rgba(0, 255, 255, 0.25);
    transform: scale(0.98);
}

button:focus-visible {
    outline: 2px solid #0ff;
    outline-offset: 2px;
}

.btn-primary {
    background: rgba(0, 255, 255, 0.15);
    border-color: #0ff;
    font-size: clamp(14px, 2.8vw, 20px);
    padding: clamp(12px, 2.5vw, 16px) clamp(15px, 3vw, 24px);
    min-height: 48px;
}

.btn-primary:hover, .btn-primary:focus {
    background: rgba(0, 255, 255, 0.3);
    box-shadow: 0 0 25px rgba(0, 255, 255, 0.3);
}

.btn-danger {
    border-color: rgba(255, 50, 50, 0.4);
    color: #f55;
}

.btn-danger:hover, .btn-danger:focus {
    background: rgba(255, 50, 50, 0.15);
    border-color: #f55;
}

.howto-content {
    text-align: left;
    max-height: min(55vh, 500px);
    overflow-y: auto;
    padding-right: 10px;
    font-size: clamp(11px, 1.8vw, 14px);
    line-height: 1.6;
    width: 100%;
}

.howto-content::-webkit-scrollbar {
    width: 4px;
}

.howto-content::-webkit-scrollbar-thumb {
    background: #0ff3;
    border-radius: 2px;
}

.howto-content h3 {
    color: #0ff;
    margin: clamp(10px, 2vw, 15px) 0 clamp(4px, 1vw, 8px) 0;
    font-size: clamp(12px, 2vw, 16px);
}

.howto-content h3:first-child {
    margin-top: 0;
}

.howto-content .control-row {
    display: flex;
    justify-content: space-between;
    padding: 3px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    min-height: 30px;
    align-items: center;
}

.howto-content .control-key {
    color: #ff0;
    font-weight: bold;
    text-align: center;
    min-width: 70px;
    flex-shrink: 0;
}

.howto-content .control-desc {
    color: #ccc;
    text-align: right;
}

.howto-content .note {
    color: #f80;
    font-style: italic;
    margin-top: 10px;
    font-size: clamp(10px, 1.5vw, 13px);
}

.go-score {
    font-size: clamp(24px, 7vw, 48px);
    color: #ff0;
    font-weight: bold;
    text-shadow: 0 0 20px rgba(255, 255, 0, 0.3);
    margin: 10px 0;
    word-break: break-all;
}

.go-label {
    font-size: clamp(9px, 1.8vw, 13px);
    color: #888;
    letter-spacing: 2px;
}

.go-value {
    font-size: clamp(14px, 3vw, 22px);
    color: #fff;
    margin: 5px 0 clamp(8px, 1.5vw, 12px) 0;
}

.go-new-record {
    color: #f0f;
    font-size: clamp(12px, 2.5vw, 20px);
    font-weight: bold;
    text-shadow: 0 0 15px rgba(255, 0, 255, 0.5);
    animation: pulse 0.8s ease-in-out infinite alternate;
    margin: 10px 0;
}

@keyframes pulse {
    from { opacity: 0.7; transform: scale(1); }
    to { opacity: 1; transform: scale(1.05); }
}

.countdown-text {
    font-size: 80px;
    font-weight: bold;
    color: #fff;
    text-shadow: 0 0 30px #0ff;
}

.section-title {
    color: #0ff;
    font-size: clamp(14px, 3vw, 22px);
    margin-bottom: clamp(10px, 2vw, 15px);
    white-space: nowrap;
}

.countdown-overlay-text {
    font-size: clamp(40px, 15vw, 80px);
    font-weight: bold;
    color: #fff;
    text-shadow: 0 0 30px #0ff;
    text-align: center;
}

.touch-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 20;
    display: none;
    padding: 8px 10px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    pointer-events: none;
    background: linear-gradient(transparent, rgba(0,0,0,0.5) 30%);
}

.touch-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    gap: 4px;
}

.touch-row:last-child {
    margin-bottom: 0;
}

.touch-btn {
    pointer-events: auto;
    border-radius: 50%;
    border: 2px solid rgba(0, 255, 255, 0.4);
    background: rgba(0, 20, 30, 0.75);
    color: #0ff;
    font-family: 'Courier New', monospace;
    font-size: clamp(8px, 2.2vw, 11px);
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    transition: background 0.1s, transform 0.1s;
    flex-shrink: 1;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
}

.touch-btn:active, .touch-btn.pressed {
    background: rgba(0, 255, 255, 0.3);
    border-color: #0ff;
    box-shadow: 0 0 12px rgba(0, 255, 255, 0.4);
    transform: scale(0.95);
}

.touch-btn-large {
    font-size: clamp(9px, 2vw, 12px);
}

.touch-btn-special {
    border-color: rgba(255, 0, 255, 0.4);
    color: #f0f;
}

.touch-btn-special.pressed {
    background: rgba(255, 0, 255, 0.3);
    border-color: #f0f;
    box-shadow: 0 0 12px rgba(255, 0, 255, 0.4);
}

.touch-dpad {
    display: flex;
    gap: 6px;
    align-items: center;
}

.touch-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.touch-row-top {
    justify-content: flex-start;
    gap: 8px;
}

.touch-row-mid {
    justify-content: space-between;
    align-items: center;
}

.touch-row-bot {
    justify-content: center;
}

.touch-row-bot > div:first-child {
    width: 50px;
}

.touch-row-bot > div:last-child {
    width: 50px;
}

@media (orientation: portrait) {
    .touch-controls {
        padding: 6px 8px;
        padding-bottom: max(6px, env(safe-area-inset-bottom));
    }

    .touch-row-top {
        gap: 6px;
    }

    .touch-row-mid {
        gap: 4px;
    }

    .touch-btn {
        min-width: 44px;
        min-height: 44px;
    }

    .howto-content {
        max-height: 45vh;
    }
}

@media (orientation: landscape) {
    .touch-controls {
        padding: 4px 10px;
        padding-bottom: max(4px, env(safe-area-inset-bottom));
    }

    .touch-row-top {
        margin-bottom: 4px;
    }

    .touch-row-mid {
        margin-bottom: 4px;
    }

    .touch-btn {
        min-width: 40px;
        min-height: 40px;
    }

    .screen-panel {
        max-height: 95vh;
        padding: clamp(10px, 3vw, 25px) clamp(10px, 4vw, 30px);
    }

    .howto-content {
        max-height: 70vh;
    }
}

@media (max-width: 480px) {
    .screen-panel {
        padding: 12px 15px;
        width: 95%;
    }

    .game-title {
        letter-spacing: 2px;
    }

    .game-subtitle {
        letter-spacing: 3px;
    }

    .btn {
        max-width: 95vw;
        padding: 10px 12px;
        font-size: clamp(12px, 4vw, 14px);
        min-height: 44px;
    }

    .btn-primary {
        min-height: 48px;
    }

    .howto-content {
        font-size: clamp(10px, 3vw, 12px);
        max-height: 45vh;
    }

    .howto-content .control-row {
        min-height: 26px;
        padding: 2px 0;
    }

    .touch-btn {
        min-width: 44px;
        min-height: 44px;
    }

    .touch-btn-large {
        min-width: 50px;
        min-height: 50px;
    }

    .go-score {
        font-size: clamp(22px, 8vw, 36px);
    }
}

@media (min-width: 481px) and (max-width: 768px) {
    .screen-panel {
        padding: 15px 20px;
        max-width: 90vw;
    }

    .btn {
        max-width: min(85vw, 260px);
        min-height: 44px;
    }

    .touch-btn {
        min-width: 46px;
        min-height: 46px;
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .screen-panel {
        padding: 20px 30px;
        max-width: 85vw;
    }

    .btn {
        max-width: min(60vw, 280px);
        min-height: 48px;
    }

    .howto-content {
        max-height: 60vh;
        font-size: clamp(12px, 1.6vw, 14px);
    }
}

@media (min-width: 1025px) {
    .screen-panel {
        padding: 25px 40px;
        max-width: 520px;
    }

    .btn {
        max-width: 280px;
        min-height: 48px;
    }

    .howto-content {
        max-height: 65vh;
    }
}

@media (max-height: 500px) and (orientation: landscape) {
    .screen-panel {
        padding: 10px 15px;
        max-height: 95vh;
    }

    .game-title {
        font-size: clamp(18px, 5vw, 32px);
    }

    .game-subtitle {
        font-size: clamp(8px, 1.8vw, 12px);
        margin-bottom: 8px;
    }

    .btn {
        margin: 3px auto;
        padding: 8px 12px;
        font-size: clamp(11px, 2vw, 13px);
        min-height: 36px;
    }

    .btn-primary {
        padding: 10px 16px;
        min-height: 40px;
    }

    .touch-controls {
        padding: 4px 8px;
    }

    .touch-row {
        margin-bottom: 3px;
    }

    .touch-btn {
        min-width: 36px;
        min-height: 36px;
        font-size: clamp(8px, 1.5vw, 10px);
    }

    .touch-btn-large {
        min-width: 44px;
        min-height: 44px;
    }

    .howto-content {
        max-height: 75vh;
    }
}

@media (max-height: 350px) and (orientation: landscape) {
    .screen-panel {
        padding: 8px 12px;
    }

    .game-title {
        font-size: clamp(16px, 4vw, 24px);
    }

    .btn {
        margin: 2px auto;
        padding: 6px 10px;
        font-size: clamp(10px, 1.8vw, 12px);
        min-height: 32px;
    }

    .btn-primary {
        min-height: 36px;
    }

    .howto-content {
        max-height: 80vh;
        font-size: 10px;
    }
}

@media (max-width: 768px) {
    .screen-panel {
        padding: 15px 20px;
        max-height: 92vh;
    }
}

@media (min-aspect-ratio: 16/9) and (max-width: 1200px) {
    .touch-controls {
        bottom: 0;
    }
}

@media (min-aspect-ratio: 21/9) {
    .touch-controls {
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }

    .touch-btn {
        min-width: 38px;
        min-height: 38px;
    }

    .touch-btn-large {
        min-width: 50px;
        min-height: 50px;
    }
}

.hidden {
    display: none !important;
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition-duration: 0s !important;
    }
}

@media (hover: none) {
    .btn:hover {
        transform: none;
    }

    .btn:active {
        transform: scale(0.98);
    }
}

@media (pointer: coarse) {
    .btn {
        min-height: 44px;
    }

    .touch-btn {
        min-width: 44px;
        min-height: 44px;
    }
}

@media (prefers-color-scheme: dark) {
    .screen-panel {
        background: rgba(5, 5, 20, 0.95);
    }
}

@media (prefers-color-scheme: light) {
    .screen-panel {
        background: rgba(240, 240, 255, 0.95);
        border-color: rgba(0, 100, 200, 0.3);
        color: #000;
    }

    .game-title { color: #0066cc; }
    .game-subtitle { color: #cc6600; }
    .menu-best-score { color: #cc9900; }
    .btn { color: #0066cc; background: rgba(0, 100, 200, 0.08); border-color: rgba(0, 100, 200, 0.3); }
    .btn:hover, .btn:focus { background: rgba(0, 100, 200, 0.15); border-color: #0066cc; }
    .btn-primary { background: rgba(0, 100, 200, 0.15); border-color: #0066cc; }
    .btn-danger { border-color: rgba(200, 50, 50, 0.4); color: #c00; }
    .howto-content h3 { color: #0066cc; }
    .howto-content .control-key { color: #cc9900; }
    .howto-content .control-desc { color: #333; }
    .section-title { color: #0066cc; }
    .go-score { color: #cc9900; }
    .go-label { color: #666; }
    .go-value { color: #000; }
    .go-new-record { color: #c0f; }
}

@media (display-mode: standalone) {
    .screen-overlay {
        padding-top: env(safe-area-inset-top);
    }
}

@media (min-width: 1440px) {
    .screen-panel {
        max-width: 560px;
        padding: 30px 50px;
    }

    .game-title {
        font-size: 56px;
    }

    .btn {
        max-width: 300px;
    }
}

@media (min-width: 1920px) {
    .screen-panel {
        max-width: 640px;
        padding: 40px 60px;
    }

    .game-title {
        font-size: 64px;
    }
}

@media (max-width: 360px) {
    .screen-panel {
        padding: 10px 12px;
        width: 98%;
    }

    .game-title {
        font-size: clamp(20px, 8vw, 28px);
    }

    .game-subtitle {
        font-size: clamp(8px, 2.5vw, 12px);
        letter-spacing: 2px;
    }

    .btn {
        font-size: clamp(11px, 3.5vw, 13px);
        padding: 10px 10px;
        min-height: 44px;
    }

    .howto-content {
        font-size: clamp(9px, 3vw, 11px);
    }

    .howto-content .control-key {
        min-width: 55px;
        font-size: 0.9em;
    }
}

    @media (min-height: 900px) and (max-width: 768px) {
    .touch-controls {
        padding: 10px 12px;
    }

    .touch-btn {
        min-width: 50px;
        min-height: 50px;
    }

    .touch-btn-large {
        min-width: 60px;
        min-height: 60px;
    }
}

#countdown-overlay {
    z-index: 15;
    background: transparent;
}

.touch-controls.visible {
    display: flex;
    flex-direction: column;
}

@media (max-height: 350px) and (orientation: landscape) {
    .touch-controls {
        padding-top: 2px;
        padding-bottom: max(2px, env(safe-area-inset-bottom, 0px));
    }

    .touch-row {
        margin-bottom: 2px;
    }

    .touch-btn {
        min-width: 40px;
        min-height: 40px;
        font-size: 8px;
    }

    .touch-btn-large {
        min-width: 44px;
        min-height: 44px;
    }
}

.display-mode-standalone-safe-area .screen-overlay,
.screen-overlay {
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    padding-left: max(10px, env(safe-area-inset-left, 0px));
    padding-right: max(10px, env(safe-area-inset-right, 0px));
}

.display-mode-standalone-safe-area .touch-controls,
.touch-controls {
    padding-left: max(10px, env(safe-area-inset-left, 0px));
    padding-right: max(10px, env(safe-area-inset-right, 0px));
}
