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

html, body {
    background: #0a0a1a;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    font-family: 'Segoe UI', sans-serif;
    overflow: hidden;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
    position: fixed;
    width: 100%;
    height: 100%;
}

#game-wrapper {
    position: relative;
    width: 960px;
    height: 540px;
    border: 2px solid #2a2a4a;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 0 40px rgba(100, 100, 255, 0.15);
}

canvas {
    display: block;
    background: #1a1a2e;
}

#hud {
    position: absolute;
    top: 0; left: 0; right: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    background: linear-gradient(to bottom, rgba(0,0,0,0.6), transparent);
    color: #fff;
    font-size: 16px;
    font-weight: bold;
    pointer-events: none;
    z-index: 2;
}

.heart { color: #ff4466; font-size: 20px; margin-left: 3px; }
.heart.lost { color: #333; }

/* Modal */
#modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 50;
    backdrop-filter: blur(4px);
    overflow-y: auto;
    padding: 16px;
}

#modal-content {
    background: linear-gradient(135deg, #1e1e3a, #2a2a50);
    border: 2px solid #4a4a8a;
    border-radius: 16px;
    padding: 24px 28px;
    max-width: 520px;
    width: 100%;
    text-align: center;
    color: #e0e0ff;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    margin: auto;
}

#modal-icon {
    font-size: 40px;
    margin-bottom: 10px;
}

#modal-title {
    font-size: 20px;
    margin-bottom: 12px;
    color: #8888ff;
}

#modal-question {
    font-size: 17px;
    margin-bottom: 20px;
    line-height: 1.5;
}

#modal-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#modal-options button {
    padding: 10px 16px;
    background: #2a2a5a;
    color: #d0d0ff;
    border: 1px solid #4a4a8a;
    border-radius: 8px;
    font-size: 15px;
    cursor: pointer;
    transition: all 0.15s;
}

#modal-options button:hover {
    background: #3a3a7a;
    border-color: #6a6aff;
    transform: translateX(4px);
}

#modal-options button.correct {
    background: #1a5a2a;
    border-color: #2a8a3a;
    color: #aaffaa;
}

#modal-options button.wrong {
    background: #5a1a1a;
    border-color: #8a2a2a;
    color: #ffaaaa;
}

#modal-input-wrap {
    display: flex;
    gap: 8px;
    justify-content: center;
}

#modal-input {
    padding: 10px 16px;
    background: #1a1a3a;
    color: #e0e0ff;
    border: 1px solid #4a4a8a;
    border-radius: 8px;
    font-size: 16px;
    width: 200px;
    outline: none;
}

#modal-input:focus { border-color: #6a6aff; }

#modal-submit, #next-level-btn {
    padding: 10px 24px;
    background: linear-gradient(135deg, #4a4aaa, #6a6aff);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
}

#modal-submit:hover, #next-level-btn:hover {
    background: linear-gradient(135deg, #5a5abb, #7a7aff);
    transform: scale(1.05);
}

#start-btn {
    padding: 18px 60px;
    background: linear-gradient(135deg, #4a4aaa, #7a5aff);
    color: #fff;
    border: 2px solid rgba(150, 150, 255, 0.3);
    border-radius: 12px;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 2px;
    box-shadow: 0 4px 20px rgba(100, 100, 255, 0.3);
    animation: pulse-btn 2s ease-in-out infinite;
}

#start-btn:hover, #start-btn:focus {
    background: linear-gradient(135deg, #5a5abb, #8a6aff);
    transform: scale(1.08);
    box-shadow: 0 6px 30px rgba(120, 120, 255, 0.5);
    outline: none;
}

@keyframes pulse-btn {
    0%, 100% { box-shadow: 0 4px 20px rgba(100, 100, 255, 0.3); }
    50% { box-shadow: 0 4px 30px rgba(130, 130, 255, 0.5); }
}

#modal-feedback {
    margin-top: 14px;
    font-size: 15px;
    font-weight: bold;
}

#modal-feedback.correct { color: #66ff88; }
#modal-feedback.wrong { color: #ff6666; }

#modal-hint {
    margin-top: 14px;
    padding: 10px 16px;
    background: rgba(255, 200, 50, 0.1);
    border: 1px solid #6a6a30;
    border-radius: 8px;
    color: #ddcc66;
    font-size: 15px;
}

#modal-skip-wrap {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid #3a3a6a;
    display: flex;
    gap: 10px;
    justify-content: center;
}

#modal-hint-btn {
    padding: 8px 18px;
    background: #3a3a20;
    color: #cccc77;
    border: 1px solid #6a6a30;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s;
}

#modal-hint-btn:hover {
    background: #4a4a2a;
    border-color: #8a8a44;
}

#modal-skip-btn {
    padding: 8px 18px;
    background: #4a2a2a;
    color: #dd9999;
    border: 1px solid #8a4444;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s;
}

#modal-skip-btn:hover {
    background: #5a3333;
    border-color: #aa5555;
}

/* Start screen */
#start-screen {
    position: absolute;
    inset: 0;
    z-index: 20;
}

#start-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

#start-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: radial-gradient(ellipse at center, rgba(10,10,40,0.3) 0%, rgba(10,10,40,0.85) 70%);
    color: #e0e0ff;
    z-index: 1;
}

#level-complete {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #0a0a2a, #1a1a4a);
    z-index: 20;
    color: #e0e0ff;
}

#start-overlay h1 {
    font-size: 56px;
    margin-bottom: 4px;
    background: linear-gradient(135deg, #88aaff, #cc88ff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: none;
    letter-spacing: 2px;
}

#start-overlay p { font-size: 18px; color: #9999cc; margin-bottom: 30px; }
#new-game-btn {
    padding: 10px 30px;
    background: transparent;
    color: #8888bb;
    border: 1px solid #4a4a7a;
    border-radius: 8px;
    font-size: 15px;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 10px;
}

#new-game-btn:hover, #new-game-btn:focus {
    background: rgba(80, 40, 40, 0.5);
    border-color: #8a5555;
    color: #cc8888;
    outline: none;
}

#sound-toggle {
    margin-top: 14px;
    background: transparent;
    border: 1px solid #4a4a7a;
    border-radius: 50%;
    width: 42px;
    height: 42px;
    font-size: 20px;
    cursor: pointer;
    color: #aaaacc;
    transition: all 0.2s;
    line-height: 1;
}

#sound-toggle:hover, #sound-toggle:focus {
    border-color: #7a7aff;
    color: #ddddff;
    outline: none;
}

#sound-toggle.muted {
    color: #666688;
    border-color: #333355;
}

#save-info { font-size: 14px; color: #88aa88; margin-top: 12px; margin-bottom: 0; }

.controls-info {
    display: flex;
    gap: 20px;
    margin-bottom: 30px;
    color: #6666aa;
    font-size: 14px;
}

kbd {
    background: #2a2a5a;
    padding: 2px 8px;
    border-radius: 4px;
    border: 1px solid #4a4a8a;
    font-family: inherit;
    color: #aaaaff;
}

#level-complete h2 {
    font-size: 36px;
    color: #66ff88;
    margin-bottom: 12px;
}

#level-complete p { font-size: 18px; margin-bottom: 24px; color: #aaaacc; }

/* Touch controls */
#touch-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    padding: 10px 16px 20px;
    pointer-events: none;
    z-index: 30;
}

#touch-left, #touch-right {
    display: flex;
    gap: 10px;
    pointer-events: auto;
}

.touch-btn {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: 2px solid rgba(150, 150, 255, 0.4);
    background: rgba(30, 30, 80, 0.7);
    color: rgba(200, 200, 255, 0.9);
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
    backdrop-filter: blur(4px);
}

.touch-btn:active, .touch-btn.pressed {
    background: rgba(80, 80, 180, 0.8);
    border-color: rgba(150, 150, 255, 0.8);
}

.action-btn {
    background: rgba(50, 30, 80, 0.7);
    border-color: rgba(180, 130, 255, 0.4);
}

.action-btn:active, .action-btn.pressed {
    background: rgba(100, 60, 160, 0.8);
    border-color: rgba(180, 130, 255, 0.8);
}

/* Mobile responsive */
@media (max-width: 980px) {
    #game-wrapper {
        width: 100vw;
        height: 56.25vw; /* 16:9 */
        border: none;
        border-radius: 0;
    }
    canvas { width: 100%; height: 100%; }
    #start-canvas { width: 100% !important; height: 100% !important; }
    body { align-items: flex-start; }
}

/* Landscape mobile - fit to height */
@media (max-width: 980px) and (orientation: landscape) {
    #game-wrapper {
        width: 177.78vh; /* 16:9 from height */
        height: 100vh;
        max-width: 100vw;
    }
    body { align-items: center; justify-content: center; }
    #touch-controls {
        padding: 6px 12px 10px;
    }
    .touch-btn { width: 50px; height: 50px; font-size: 18px; }
}

@media (max-width: 600px) {
    #start-overlay h1 { font-size: 36px; }
    #start-overlay p { font-size: 14px; margin-bottom: 16px; }
    .controls-info { display: none; }
    #start-btn { padding: 14px 40px; font-size: 20px; }
    #new-game-btn { padding: 8px 20px; font-size: 13px; }
    #hud { font-size: 13px; padding: 6px 12px; }
    .heart { font-size: 16px; }
    #modal-content { padding: 16px 16px; }
    #modal-icon { font-size: 28px; margin-bottom: 6px; }
    #modal-title { font-size: 16px; margin-bottom: 8px; }
    #modal-question { font-size: 14px; margin-bottom: 14px; }
    #modal-options button { font-size: 13px; padding: 8px 10px; }
    #modal-skip-wrap { margin-top: 10px; padding-top: 8px; gap: 6px; }
    #modal-skip-btn, #modal-hint-btn { font-size: 12px; padding: 6px 12px; }
    #modal-hint { font-size: 13px; padding: 8px 12px; margin-top: 10px; }
    #modal-feedback { font-size: 13px; margin-top: 10px; }
    #modal-input { font-size: 14px; padding: 8px 12px; width: 160px; }
    #modal-submit { font-size: 14px; padding: 8px 16px; }
    #level-complete h2 { font-size: 28px; }
    .touch-btn { width: 56px; height: 56px; font-size: 20px; }
}

.hidden { display: none !important; }
