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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans SC', sans-serif;
    background: #1a1a2e;
    color: #eee;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

/* === Game Container === */
#game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100vh;
    height: 100dvh;
    max-width: 1050px;
    margin: 0 auto;
    position: relative;
}

/* === HUD === */
#hud {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 8px 16px;
    background: linear-gradient(180deg, #16213e, #0f3460);
    border-bottom: 2px solid #e94560;
    width: 100%;
    flex-shrink: 0;
    min-height: 44px;
    flex-wrap: wrap;
}

.hud-item {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 16px;
    font-weight: bold;
}

.hud-icon {
    font-size: 20px;
}

.hud-label {
    color: #aaa;
    font-size: 13px;
}

/* Castle HP bar */
.castle-hp-item {
    gap: 6px;
}

.castle-hp-bar-wrap {
    width: 80px;
    height: 10px;
    background: #333;
    border-radius: 5px;
    overflow: hidden;
    border: 1px solid #555;
}

.castle-hp-bar {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #e74c3c, #e94560);
    border-radius: 5px;
    transition: width 0.3s ease;
}

/* Quiz Button */
.quiz-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: #e94560;
    color: #fff;
    border: none;
    border-radius: 20px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.quiz-btn:hover {
    background: #c0392b;
    transform: scale(1.05);
}

.quiz-btn:not(.ready) {
    background: #555;
    cursor: not-allowed;
}

.quiz-btn:not(.ready):hover {
    transform: none;
}

/* Speed Button */
.speed-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    background: #243b6b;
    color: #fff;
    border: 1px solid #4f75c9;
    border-radius: 20px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
    flex-shrink: 0;
}

.speed-btn:hover {
    background: #31508e;
    border-color: #7aa2ff;
    transform: scale(1.05);
}

/* Audio control buttons */
.audio-btn {
    background: #1a1a3e;
    border: 1px solid #444;
    border-radius: 50%;
    width: 34px;
    height: 34px;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    flex-shrink: 0;
}

.audio-btn:hover {
    border-color: #e94560;
    background: #22224e;
}

.audio-btn.muted {
    opacity: 0.5;
}

/* === Game Area (canvas + sidebar) === */
#game-area {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    flex-shrink: 0;
    gap: 0;
    max-width: 100vw;
    overflow: hidden;
}

/* === Canvas === */
#game-canvas {
    display: block;
    flex-shrink: 0;
    image-rendering: auto;
}

/* === Wrong Words Sidebar === */
#wrong-words-sidebar {
    width: 135px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
}

#wrong-words-panel {
    background: #0d1b2e;
    border-left: 2px solid #0f3460;
    min-height: 200px;
    max-height: 420px;
    overflow-y: auto;
    padding: 6px 8px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-size: 12px;
}

.wrong-words-header {
    color: #ffd700;
    font-weight: bold;
    font-size: 13px;
    text-align: center;
    padding-bottom: 6px;
    border-bottom: 1px solid #1a3a5a;
    margin-bottom: 4px;
    flex-shrink: 0;
}

.wrong-words-empty {
    color: #555;
    text-align: center;
    font-size: 11px;
    padding-top: 20px;
}

.wrong-word-item {
    display: block;
    padding: 5px 8px;
    color: #e94560;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.15s;
    font-weight: bold;
    border: 1px solid transparent;
    flex-shrink: 0;
}

.wrong-word-item:hover {
    background: #1a1a3e;
    border-color: #e94560;
}

.wrong-word-item.selected {
    background: #2a1a3e;
    border-color: #ffd700;
    color: #ffd700;
}

/* Wrong word detail (below word list) */
.wrong-word-detail {
    background: #0f1a2e;
    border: 1px solid #ffd700;
    border-top: none;
    border-radius: 0 0 8px 8px;
    padding: 10px;
    font-size: 12px;
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.wrong-word-detail .wwd-word {
    font-size: 18px;
    font-weight: bold;
    color: #ffd700;
    text-align: center;
}

.wrong-word-detail .wwd-ipa {
    color: #5db8d8;
    font-family: 'Segoe UI', 'Lucida Sans Unicode', serif;
    font-size: 13px;
    text-align: center;
}

.wrong-word-detail .wwd-def {
    color: #ccc;
    font-size: 13px;
}

.wrong-word-detail .wwd-example {
    color: #999;
    font-style: italic;
}

.wwd-speak-btn {
    margin-top: 6px;
    padding: 5px 12px;
    background: #1a3e5a;
    border: 1px solid #5db8d8;
    border-radius: 12px;
    color: #5db8d8;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
    align-self: center;
}

.wwd-speak-btn:hover {
    background: #1e4a6a;
    border-color: #ffd700;
    color: #ffd700;
}

.wwd-speak-btn:active {
    transform: scale(0.95);
}

/* === Tower Palette === */
#tower-palette {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    background: #16213e;
    border-top: 2px solid #0f3460;
    width: 100%;
    justify-content: center;
    flex-shrink: 0;
    flex-wrap: wrap;
}

.tower-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 12px;
    min-width: 64px;
    background: #1a1a3e;
    border: 2px solid #333;
    border-radius: 10px;
    color: #ccc;
    cursor: pointer;
    transition: all 0.15s;
    position: relative;
}

.tower-btn:hover {
    border-color: #e94560;
    background: #22224e;
}

.tower-btn.selected {
    border-color: #e94560;
    background: #2a1a3e;
    box-shadow: 0 0 10px rgba(233, 69, 96, 0.5);
}

.tower-btn:active {
    transform: scale(0.95);
}

.tower-icon {
    font-size: 22px;
}

.tower-name {
    font-size: 12px;
    font-weight: bold;
}

.tower-cost {
    font-size: 11px;
    color: #ffd700;
}

.tower-key {
    position: absolute;
    top: 2px;
    right: 4px;
    font-size: 9px;
    color: #666;
    background: #111;
    padding: 1px 4px;
    border-radius: 3px;
}

/* === Upgrade Panel === */
#upgrade-panel {
    position: absolute;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: #16213e;
    border: 2px solid #e94560;
    border-radius: 10px;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 10;
    white-space: nowrap;
}

#upgrade-info {
    font-size: 13px;
    color: #ccc;
}

#upgrade-btn {
    padding: 6px 16px;
    background: #ffd700;
    color: #1a1a2e;
    border: none;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
    font-size: 14px;
}

#upgrade-btn:disabled {
    background: #555;
    color: #999;
    cursor: not-allowed;
}

#upgrade-btn:not(:disabled):hover {
    background: #ffed4a;
}

/* === Overlays === */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.75);
    z-index: 20;
    backdrop-filter: blur(3px);
}

.overlay-content {
    background: linear-gradient(135deg, #16213e, #1a1a3e);
    border: 2px solid #e94560;
    border-radius: 16px;
    padding: 32px 40px;
    text-align: center;
    max-width: 420px;
    width: 90%;
}

.overlay-content h1 {
    font-size: 36px;
    margin-bottom: 4px;
}

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

.subtitle {
    color: #aaa;
    font-size: 14px;
    margin-bottom: 20px;
}

.instructions {
    text-align: left;
    margin-bottom: 16px;
    line-height: 1.8;
    font-size: 14px;
}

.instructions p {
    margin: 4px 0;
}

.controls-info {
    font-size: 11px;
    color: #888;
    margin-bottom: 16px;
    line-height: 1.6;
}

.hint {
    font-size: 12px;
    color: #888;
    margin: 8px 0;
}

.reward-text {
    font-size: 22px;
    color: #ffd700;
    font-weight: bold;
    margin: 8px 0;
}

/* Hell mode button (menu) */
.hellmode-btn {
    padding: 10px 24px;
    background: #1a1a2e;
    color: #ff6030;
    border: 2px solid #ff6030;
    border-radius: 25px;
    font-size: 15px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 8px;
    display: block;
    margin-left: auto;
    margin-right: auto;
}

.hellmode-btn:hover:not(:disabled) {
    background: #2a1a1a;
    border-color: #ff0000;
    color: #ff0000;
    box-shadow: 0 0 15px rgba(255, 50, 0, 0.4);
    transform: scale(1.03);
}

.hellmode-btn.active {
    background: #2a0a0a;
    border-color: #ff0000;
    color: #ff4444;
    box-shadow: 0 0 20px rgba(255, 0, 0, 0.6), inset 0 0 10px rgba(255, 0, 0, 0.1);
    animation: hellmode-pulse 1.5s ease-in-out infinite;
}

.hellmode-btn:disabled {
    cursor: default;
}

@keyframes hellmode-pulse {
    0%, 100% { box-shadow: 0 0 20px rgba(255, 0, 0, 0.6); }
    50% { box-shadow: 0 0 35px rgba(255, 0, 0, 0.9); }
}

/* Hell mode HUD indicator */
.hellmode-indicator {
    font-size: 12px;
    font-weight: bold;
    color: #ff4444;
    background: #1a0000;
    border: 1px solid #ff0000;
    border-radius: 10px;
    padding: 2px 8px;
    animation: hellmode-pulse 1.5s ease-in-out infinite;
    white-space: nowrap;
}

.primary-btn {
    padding: 12px 36px;
    background: #e94560;
    color: #fff;
    border: none;
    border-radius: 25px;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 8px;
}

.primary-btn:hover {
    background: #c0392b;
    transform: scale(1.05);
}

.primary-btn:active {
    transform: scale(0.97);
}

/* === Quiz Modal === */
#quiz-modal {
    z-index: 25;
}

.quiz-content {
    background: linear-gradient(135deg, #16213e, #1a1a3e);
    border: 2px solid #ffd700;
    border-radius: 16px;
    padding: 24px 32px;
    text-align: center;
    max-width: 450px;
    width: 90%;
}

.quiz-content h2 {
    font-size: 22px;
    margin-bottom: 4px;
}

#quiz-progress {
    font-size: 12px;
    color: #888;
    margin-bottom: 12px;
}

.quiz-word {
    font-size: 36px;
    font-weight: bold;
    color: #ffd700;
    margin: 12px 0;
    letter-spacing: 2px;
}

.quiz-hint {
    font-size: 13px;
    color: #aaa;
    margin-bottom: 12px;
}

.quiz-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 12px;
}

.quiz-option-btn {
    padding: 14px 20px;
    background: #1a1a3e;
    border: 2px solid #444;
    border-radius: 10px;
    color: #eee;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.15s;
    text-align: center;
}

.quiz-option-btn:hover:not(:disabled) {
    border-color: #e94560;
    background: #22224e;
}

.quiz-option-btn:disabled {
    cursor: default;
}

.quiz-option-btn.correct-answer {
    border-color: #2ecc71;
    background: #1a3e2a;
    color: #2ecc71;
}

.quiz-option-btn.wrong-answer {
    border-color: #e74c3c;
    background: #3e1a1a;
    color: #e74c3c;
}

.quiz-feedback {
    font-size: 16px;
    font-weight: bold;
    min-height: 24px;
    line-height: 24px;
}

.quiz-feedback.correct {
    color: #2ecc71;
}

.quiz-feedback.incorrect {
    color: #e74c3c;
}

/* Quiz continue button (shown after wrong answer) */
.quiz-continue-btn {
    display: block;
    margin: 14px auto 0;
    padding: 10px 28px;
    background: #e94560;
    color: #fff;
    border: none;
    border-radius: 20px;
    font-size: 15px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
}

.quiz-continue-btn:hover {
    background: #c0392b;
    transform: scale(1.05);
}

.quiz-continue-btn:disabled {
    background: #555;
    color: #bbb;
    cursor: not-allowed;
    transform: none;
}

.quiz-continue-btn:disabled:hover {
    background: #555;
    transform: none;
}

.quiz-continue-btn:active {
    transform: scale(0.97);
}

/* Quiz speak (pronunciation) button */
.quiz-speak-btn {
    display: inline-block;
    margin-top: 8px;
    padding: 6px 16px;
    background: #1a3e5a;
    border: 1px solid #5db8d8;
    border-radius: 15px;
    color: #5db8d8;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
}

.quiz-speak-btn:hover {
    background: #1e4a6a;
}

.quiz-speak-btn:active {
    transform: scale(0.96);
}

.quiz-speak-btn.speaking {
    border-color: #ffd700;
    color: #ffd700;
    background: #2a3a1e;
}

/* Quiz detail (IPA, definition, example on wrong answer) */
.quiz-detail {
    margin-top: 10px;
    padding: 10px 14px;
    background: rgba(255,255,255,0.05);
    border-radius: 8px;
    text-align: left;
}

.quiz-detail-row {
    display: flex;
    gap: 8px;
    margin: 4px 0;
    font-size: 14px;
    line-height: 1.5;
}

.quiz-detail-label {
    color: #888;
    min-width: 70px;
    flex-shrink: 0;
}

.quiz-ipa {
    font-family: 'Segoe UI', 'Lucida Sans Unicode', serif;
    color: #5db8d8;
}

.quiz-example {
    color: #aaa;
    font-style: italic;
}

/* === Toast === */
.toast {
    position: absolute;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: #e74c3c;
    color: #fff;
    padding: 8px 20px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: bold;
    z-index: 30;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.toast.show {
    opacity: 1;
}

/* === Utility === */
.hidden {
    display: none !important;
}

/* === Responsive === */
@media (max-width: 768px) {
    #game-container {
        max-width: 100vw;
    }

    #hud {
        gap: 10px;
        padding: 6px 10px;
    }

    #game-area {
        justify-content: center;
        width: 100%;
        flex-direction: column;
        align-items: center;
    }

    #wrong-words-sidebar {
        display: flex;
        width: min(96vw, 520px);
        max-height: 120px;
        margin-top: 6px;
    }

    #wrong-words-panel {
        width: 100%;
        min-height: 44px;
        max-height: 76px;
        border-left: 0;
        border-top: 2px solid #0f3460;
        overflow-x: auto;
        overflow-y: hidden;
        flex-direction: row;
        align-items: center;
        gap: 6px;
        padding: 6px;
    }

    .wrong-words-header {
        border-bottom: 0;
        border-right: 1px solid #1a3a5a;
        margin-bottom: 0;
        padding: 0 8px 0 0;
        white-space: nowrap;
    }

    .wrong-words-empty {
        padding-top: 0;
        white-space: nowrap;
    }

    .wrong-word-item {
        white-space: nowrap;
    }

    .wrong-word-detail {
        max-height: 92px;
        overflow-y: auto;
        border-top: 0;
        border-radius: 0 0 8px 8px;
    }

    .hud-item {
        font-size: 14px;
    }

    .hud-icon {
        font-size: 16px;
    }

    .quiz-btn {
        font-size: 12px;
        padding: 5px 10px;
    }

    .speed-btn {
        font-size: 12px;
        padding: 5px 9px;
    }

    #tower-palette {
        gap: 4px;
        padding: 6px;
    }

    .tower-btn {
        min-width: 50px;
        padding: 4px 8px;
    }

    .tower-icon {
        font-size: 18px;
    }

    .tower-name {
        font-size: 10px;
    }

    .tower-cost {
        font-size: 10px;
    }

    .overlay-content {
        padding: 20px 24px;
    }

    .overlay-content h1 {
        font-size: 28px;
    }

    .overlay-content h2 {
        font-size: 22px;
    }

    .quiz-word {
        font-size: 28px;
    }

    .quiz-option-btn {
        font-size: 16px;
        padding: 12px 16px;
    }

    #upgrade-panel {
        bottom: 80px;
        padding: 8px 12px;
    }
}

@media (max-width: 480px) {
    #hud {
        gap: 6px;
        padding: 4px 6px;
        font-size: 12px;
    }

    .hud-item {
        font-size: 12px;
    }

    .quiz-btn {
        font-size: 11px;
        padding: 4px 8px;
    }

    .speed-btn {
        font-size: 11px;
        padding: 4px 7px;
    }

    .tower-btn {
        min-width: 44px;
        padding: 4px 6px;
    }

    .tower-name {
        font-size: 9px;
    }

    .tower-cost {
        font-size: 9px;
    }

    .tower-key {
        display: none;
    }

    .quiz-option-btn {
        font-size: 15px;
        padding: 10px 14px;
    }
}
