/* === Base Reset === */
* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    width: 100%; height: 100dvh;
    overflow: hidden;
    background: #87CEEB;
    font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    position: fixed;
    top: 0; left: 0;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: none;
}

/* === Game Container === */
#game-container {
    position: relative;
    width: 100vw; height: 100dvh;
    max-height: -webkit-fill-available;
    overflow: hidden;
}

#game-canvas {
    display: block;
    width: 100%; height: 100%;
    image-rendering: pixelated;
}

/* === HUD === */
#hud {
    position: absolute;
    top: 0; left: 0; right: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    pointer-events: none;
    z-index: 10;
}

#hud > div {
    display: flex;
    align-items: center;
    gap: 12px;
}

#hud span {
    color: #fff;
    font-size: 18px;
    font-weight: 700;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
}

.hud-btn {
    pointer-events: all;
    background: rgba(255,255,255,0.25);
    border: 2px solid rgba(255,255,255,0.5);
    border-radius: 50%;
    width: 40px; height: 40px;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.hud-btn:hover, .hud-btn:active {
    background: rgba(255,255,255,0.45);
}

/* === Progress Bar === */
#progress-bar-container {
    position: absolute;
    top: 50px; left: 16px; right: 16px;
    height: 8px;
    background: rgba(0,0,0,0.2);
    border-radius: 4px;
    z-index: 10;
    overflow: visible;
}

#progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #FFD700, #FF6B35);
    border-radius: 4px;
    width: 0%;
    transition: width 0.3s ease;
}

#progress-label {
    position: absolute;
    right: 0;
    top: -18px;
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}

/* === Overlays === */
.overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.45);
    z-index: 50;
    animation: fadeIn 0.3s ease;
}

.overlay.hidden { display: none; }

.overlay-content {
    background: linear-gradient(135deg, #fff8e1, #fff);
    border-radius: 24px;
    padding: 36px 48px;
    text-align: center;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 12px 40px rgba(0,0,0,0.3);
    animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.overlay-content h1 {
    font-size: 36px;
    color: #E91E63;
    margin-bottom: 8px;
}

.overlay-content h2 {
    font-size: 28px;
    color: #4CAF50;
    margin-bottom: 12px;
}

.subtitle {
    font-size: 18px;
    color: #795548;
    margin-bottom: 16px;
}

.demo-badge {
    display: inline-block;
    background: #FF9800;
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    padding: 4px 16px;
    border-radius: 20px;
    margin-bottom: 16px;
    animation: pulse 2s infinite;
}

.prompt-text {
    font-size: 16px;
    color: #888;
    margin-top: 16px;
    animation: blink 1.5s infinite;
}

.title-features {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    margin-top: 16px;
}

.title-features span {
    background: #E8F5E9;
    padding: 6px 14px;
    border-radius: 16px;
    font-size: 14px;
    color: #2E7D32;
}

/* === Settings === */
.settings-content {
    text-align: left;
}

.settings-content h2 {
    text-align: center;
    margin-bottom: 20px;
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid #eee;
}

.setting-row label {
    font-size: 16px;
    color: #333;
    font-weight: 600;
}

.setting-row input[type="range"] {
    width: 120px;
    accent-color: #4CAF50;
}

.setting-row select {
    font-size: 14px;
    padding: 4px 8px;
    border-radius: 8px;
    border: 2px solid #4CAF50;
}

.setting-row input[type="checkbox"] {
    width: 22px; height: 22px;
    accent-color: #4CAF50;
}

.voice-control-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-voice-test {
    background: #FF9800;
    color: #fff;
    border: none;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 700;
    border-radius: 8px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s, transform 0.1s;
}

.btn-voice-test:hover { background: #F57C00; }
.btn-voice-test:active { transform: scale(0.93); }

.voice-test-status {
    font-size: 11px;
    color: #666;
    font-style: italic;
    white-space: nowrap;
}
.voice-test-status.hidden { display: none; }

.voice-debug-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}
.voice-debug-info {
    font-size: 11px;
    color: #888;
    font-family: monospace;
    word-break: break-all;
    line-height: 1.4;
}

.btn-primary {
    display: block;
    margin: 20px auto 0;
    background: #4CAF50;
    color: #fff;
    border: none;
    padding: 12px 32px;
    font-size: 18px;
    font-weight: 700;
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.1s, background 0.2s;
}

.btn-primary:hover { background: #388E3C; }
.btn-primary:active { transform: scale(0.95); }

/* === Touch Controls === */
#touch-controls {
    position: absolute;
    bottom: max(12px, env(safe-area-inset-bottom, 0px));
    left: 0; right: 0;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 0 max(16px, env(safe-area-inset-left, 0px)) 0 max(16px, env(safe-area-inset-right, 0px));
    z-index: 20;
    pointer-events: none;
}

#touch-controls.hidden { display: none; }

.touch-btn {
    pointer-events: all;
    width: 72px; height: 72px;
    border-radius: 50%;
    border: 3px solid rgba(255,255,255,0.7);
    background: rgba(255,255,255,0.3);
    color: #fff;
    font-size: 28px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
    -webkit-tap-highlight-color: transparent;
    transition: background 0.05s, transform 0.05s;
}

.touch-btn.pressed {
    background: rgba(255,255,255,0.55);
    transform: scale(0.9);
}

.touch-left-group {
    display: flex;
    gap: 12px;
    pointer-events: none;
}

.touch-right-group {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    pointer-events: none;
}

.touch-jump {
    width: 84px; height: 84px;
    font-size: 34px;
}

/* === Level Stars === */
#level-stars {
    font-size: 42px;
    margin: 12px 0;
}

/* === Animations === */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes popIn {
    from { opacity: 0; transform: scale(0.7); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* === Large text mode === */
body.large-text #hud span { font-size: 24px; }
body.large-text .overlay-content h1 { font-size: 44px; }
body.large-text .overlay-content h2 { font-size: 34px; }
body.large-text .prompt-text { font-size: 20px; }
body.large-text .setting-row label { font-size: 20px; }
body.large-text .touch-btn { width: 88px; height: 88px; font-size: 36px; }
body.large-text .touch-jump { width: 100px; height: 100px; font-size: 42px; }

/* === High contrast === */
body.high-contrast .overlay-content {
    background: #000;
    color: #fff;
    border: 3px solid #FFD700;
}
body.high-contrast .overlay-content h1,
body.high-contrast .overlay-content h2 { color: #FFD700; }
body.high-contrast .subtitle,
body.high-contrast .prompt-text,
body.high-contrast .setting-row label { color: #fff; }
body.high-contrast .title-features span {
    background: #333;
    color: #FFD700;
}
body.high-contrast .touch-btn {
    background: rgba(0,0,0,0.7);
    border-color: #FFD700;
    color: #FFD700;
}

/* === Responsive === */
@media (max-width: 600px) {
    .overlay-content {
        padding: 24px 20px;
        border-radius: 16px;
    }
    .overlay-content h1 { font-size: 26px; }
    .overlay-content h2 { font-size: 22px; }
    #hud { padding: 8px 10px; }
    #hud span { font-size: 14px; }
    .hud-btn { width: 40px; height: 40px; font-size: 18px; }
    .title-features span { font-size: 12px; padding: 4px 10px; }
    .touch-btn { width: 64px; height: 64px; font-size: 24px; }
    .touch-jump { width: 76px; height: 76px; font-size: 30px; }
    .touch-left-group { gap: 8px; }
    .touch-right-group { gap: 8px; }
}

@media (max-height: 500px) {
    .touch-btn { width: 52px; height: 52px; font-size: 20px; }
    .touch-jump { width: 62px; height: 62px; font-size: 26px; }
    .touch-left-group { gap: 6px; }
    .touch-right-group { gap: 6px; }
    #progress-bar-container { top: 40px; }
}
