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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #0d0d14;
    color: #f0e6d2;
    overflow: hidden;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

#canvas-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 0;
}

#canvas-container canvas {
    display: block;
}

#ui-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 20px;
}

#header {
    text-align: center;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
}

#header h1 {
    font-size: 2.2rem;
    letter-spacing: 0.15em;
    color: #d4af37;
    margin-bottom: 4px;
}

#level-name {
    font-size: 1rem;
    color: #b0a080;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

#controls-hint {
    position: absolute;
    bottom: 100px;
    left: 20px;
    background: rgba(10, 10, 18, 0.75);
    border: 1px solid rgba(212, 175, 55, 0.3);
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 0.85rem;
    line-height: 1.6;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

#controls-hint p {
    margin: 4px 0;
}

#character-panel {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.character-indicator {
    background: rgba(10, 10, 18, 0.75);
    border: 1px solid rgba(212, 175, 55, 0.3);
    border-radius: 8px;
    padding: 10px 14px;
    min-width: 160px;
    transition: border-color 0.3s, background 0.3s;
}

.character-indicator.active {
    border-color: #d4af37;
    background: rgba(212, 175, 55, 0.15);
    box-shadow: 0 0 12px rgba(212, 175, 55, 0.25);
}

.character-indicator .name {
    display: block;
    font-weight: bold;
    font-size: 1rem;
    color: #d4af37;
}

.character-indicator .desc {
    display: block;
    font-size: 0.75rem;
    color: #a09080;
    margin-top: 2px;
}

#message-panel {
    position: absolute;
    bottom: 140px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(10, 10, 18, 0.85);
    border: 1px solid rgba(212, 175, 55, 0.4);
    border-radius: 8px;
    padding: 12px 24px;
    max-width: 600px;
    text-align: center;
    font-size: 1rem;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

#level-progress {
    position: absolute;
    bottom: 20px;
    right: 20px;
    font-size: 0.9rem;
    color: #b0a080;
    background: rgba(10, 10, 18, 0.75);
    border: 1px solid rgba(212, 175, 55, 0.3);
    border-radius: 8px;
    padding: 8px 12px;
}

#level-number {
    color: #d4af37;
    font-weight: bold;
}

#touch-controls {
    display: none;
    pointer-events: auto;
}

.touch-btn {
    min-width: 52px;
    min-height: 52px;
    border: 1px solid rgba(244, 210, 139, 0.45);
    border-radius: 8px;
    background: rgba(12, 12, 18, 0.72);
    color: #f4d28b;
    font: inherit;
    font-weight: 700;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
    touch-action: none;
}

.touch-btn.pressed,
.touch-btn:active {
    background: rgba(184, 115, 51, 0.72);
    border-color: rgba(244, 210, 139, 0.85);
    transform: translateY(1px);
}

.hidden {
    display: none !important;
}

@media (max-width: 800px), (pointer: coarse) {
    #ui-container {
        padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    }

    #controls-hint {
        display: none;
    }

    #header {
        text-align: left;
        max-width: 48vw;
    }

    #header h1 {
        font-size: 1.45rem;
        letter-spacing: 0.08em;
    }

    #level-name {
        font-size: 0.75rem;
        letter-spacing: 0.04em;
    }

    #character-panel {
        top: max(10px, env(safe-area-inset-top));
        right: max(12px, env(safe-area-inset-right));
        gap: 6px;
    }

    .character-indicator {
        min-width: 116px;
        padding: 7px 9px;
    }

    .character-indicator .name {
        font-size: 0.85rem;
    }

    .character-indicator .desc {
        display: none;
    }

    #message-panel {
        bottom: calc(104px + env(safe-area-inset-bottom));
        width: min(92vw, 460px);
        padding: 9px 12px;
        font-size: 0.82rem;
    }

    #level-progress {
        top: calc(78px + env(safe-area-inset-top));
        right: max(12px, env(safe-area-inset-right));
        bottom: auto;
        font-size: 0.78rem;
        padding: 6px 9px;
    }

    #touch-controls {
        position: absolute;
        inset: auto max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
        display: flex;
        align-items: flex-end;
        justify-content: space-between;
        gap: 16px;
    }

    #touch-stick {
        position: relative;
        width: 164px;
        height: 164px;
        flex: 0 0 164px;
    }

    #touch-stick .touch-btn {
        position: absolute;
        width: 54px;
        height: 54px;
        padding: 0;
    }

    .touch-up {
        top: 0;
        left: 55px;
    }

    .touch-left {
        top: 55px;
        left: 0;
    }

    .touch-down {
        top: 110px;
        left: 55px;
    }

    .touch-right {
        top: 55px;
        left: 110px;
    }

    #touch-actions {
        display: flex;
        align-items: flex-end;
        gap: 8px;
        padding-bottom: 2px;
    }

    .touch-action {
        width: 58px;
        height: 58px;
        font-size: 0.78rem;
    }

    .touch-action.primary {
        width: 68px;
        height: 68px;
        color: #14110d;
        background: rgba(244, 210, 139, 0.88);
        border-color: rgba(244, 210, 139, 1);
    }
}

@media (max-width: 380px) {
    #touch-stick {
        width: 146px;
        height: 146px;
        flex-basis: 146px;
    }

    #touch-stick .touch-btn {
        width: 48px;
        height: 48px;
    }

    .touch-up,
    .touch-down {
        left: 49px;
    }

    .touch-left,
    .touch-right {
        top: 49px;
    }

    .touch-down {
        top: 98px;
    }

    .touch-right {
        left: 98px;
    }

    .touch-action {
        width: 52px;
        height: 52px;
        font-size: 0.72rem;
    }

    .touch-action.primary {
        width: 60px;
        height: 60px;
    }
}
