/* === Font === */
@font-face {
    font-family: 'ABeeZee';
    src: url('fonts/ABeeZee-Regular.otf') format('opentype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Grundschrift';
    src: url('fonts/Grundschrift-Bold.otf') format('opentype');
    font-weight: bold;
    font-style: normal;
    font-display: swap;
}

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

html, body {
    height: 100%;
    overflow: hidden;
    -webkit-user-select: none;
    user-select: none;
}

body {
    font-family: 'ABeeZee', -apple-system, BlinkMacSystemFont, sans-serif;
    background: #f5f0eb;
    color: #333;
    display: flex;
    justify-content: center;
    align-items: center;
}


/* === App Layout === */
#app {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 10px 8px 20px;
    padding-top: max(10px, env(safe-area-inset-top));
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
    position: relative;
}

/* === Top Bar (Settings left, Progress right) === */
#top-bar {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0;
}

#progress-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 4px;
    border-radius: 20px;
    transition: opacity 0.3s;
    color: inherit;
    touch-action: manipulation;
}

#progress-btn.empty {
    opacity: 0.25;
}

#progress-stars {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-wrap: wrap;
}

.progress-chest {
    height: clamp(1.5rem, 4vw, 2.6rem);
    margin-right: 2px;
}

.progress-coin {
    height: clamp(1.2rem, 3.5vw, 2.2rem);
}

/* Pop-in animation for newly added items */
.progress-chest, .progress-coin {
    display: inline-block;
    vertical-align: middle;
    animation: coinPop 0.4s ease-out;
}

@keyframes coinPop {
    0% { transform: scale(0); opacity: 0; }
    60% { transform: scale(1.3); }
    100% { transform: scale(1); opacity: 1; }
}

#progress-count {
    font-size: clamp(1.4rem, 4vw, 2.4rem);
    font-weight: bold;
    font-family: 'Grundschrift', 'ABeeZee', sans-serif;
    position: relative;
    top: 0.1em;
}

/* === Word Container === */
#word-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    position: relative;
    min-height: 0;
}

#word-display {
    font-family: 'ABeeZee', sans-serif;
    font-size: clamp(3rem, 14vw, 10rem);
    text-align: center;
    line-height: 1.2;
    transition: opacity 0.8s ease-in-out;
    padding: 0;
    white-space: nowrap;
    max-width: 100%;
    overflow: hidden;
    text-overflow: clip;
}

#word-display.fade-in {
    animation: fadeIn 0.8s ease-in-out;
}

#word-display.correct {
    animation: correctPulse 0.6s ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes correctPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.08); }
    100% { transform: scale(1); }
}

.syllable {
    display: inline;
    transition: color 0.3s, background 0.4s, text-decoration-color 0.4s, border-color 0.4s;
    border-radius: 6px;
    padding: 0 2px 4px;
    text-decoration: none;
    border-bottom: 8px solid transparent;
}

.syllable.syl-speaking {
    background: rgba(26, 71, 102, 0.1);
    transition: background 0.15s;
}

.syllable.syl-correct {
    border-bottom-color: #2a7d4f;
}

.syllable.syl-incorrect {
    background: rgba(220, 80, 60, 0.15);
    border-bottom-color: #c44;
    animation: syllableNudge 0.5s ease-in-out;
}

@keyframes syllableNudge {
    0%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
    60% { transform: translateY(2px); }
}

/* === Lesefinger === */
#finger {
    position: absolute;
    height: 220px;
    width: auto;
    left: 0;
    opacity: 0;
    transition: left 1s ease-in-out, opacity 0.5s ease-in-out;
    pointer-events: none;
}

#finger.visible {
    opacity: 1;
}

#finger.slide-right {
    transition: left 1s ease-in-out;
}

#finger.slide-syllable {
    transition: left 0.6s ease-in-out;
}

/* === Feedback === */
#feedback-area {
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 10px;
}

#feedback-text {
    font-size: clamp(1rem, 3vw, 1.4rem);
    text-align: center;
    color: #666;
    transition: color 0.3s;
    width: 100%;
}

#feedback-text.correct {
    color: #2a7d4f;
}

#feedback-text.incorrect {
    color: #c44;
}

/* Manual evaluation fallback */
.manual-hint {
    font-size: clamp(0.85rem, 2.5vw, 1.1rem);
    color: #888;
    margin-bottom: 10px;
    text-align: center;
}

.manual-buttons {
    display: flex;
    justify-content: space-between;
    width: 100%;
    padding: 0 12px;
}

.manual-btn {
    padding: 12px 24px;
    border: none;
    border-radius: 12px;
    font-size: clamp(0.9rem, 2.5vw, 1.1rem);
    font-weight: 600;
    cursor: pointer;
    color: white;
    transition: transform 0.1s;
    touch-action: manipulation;
}

.manual-btn:active {
    transform: scale(0.93);
}

.manual-btn.correct {
    background: #2a7d4f;
}

.manual-btn.wrong {
    background: #c44;
}

/* Loading dots */
#loading-dots {
    display: flex;
    gap: 8px;
    align-items: center;
}

#loading-dots.hidden {
    display: none;
}

#loading-dots span {
    width: 12px;
    height: 12px;
    background: #888;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

#loading-dots span:nth-child(1) { animation-delay: -0.32s; }
#loading-dots span:nth-child(2) { animation-delay: -0.16s; }
#loading-dots span:nth-child(3) { animation-delay: 0s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* === Action Buttons === */
#action-buttons {
    display: flex;
    gap: 16px;
    padding: 20px 0;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
}

.action-btn {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: none;
    background: #e8e0d8;
    color: #555;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s, background 0.2s, box-shadow 0.2s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.action-btn:active {
    transform: scale(0.92);
}

.action-btn:disabled {
    opacity: 0.35;
    cursor: default;
}

.action-btn:disabled:active {
    transform: none;
}

#mic-btn {
    width: 90px;
    height: 90px;
    background: #d4e8d4;
    color: #3a7d3a;
}

#mic-btn.recording {
    background: #ff6b6b;
    color: #fff;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(255, 107, 107, 0.6); }
    70% { box-shadow: 0 0 0 20px rgba(255, 107, 107, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 107, 107, 0); }
}

.settings-toggle {
    width: 48px;
    height: 48px;
    background: transparent;
    color: #999;
}

/* === Modal === */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: #fff;
    border-radius: 20px;
    width: 100%;
    max-width: 500px;
    max-height: 85vh;
    overflow-y: auto;
    padding: 24px;
    -webkit-overflow-scrolling: touch;
}

.modal-small {
    max-width: 320px;
    text-align: center;
    padding: 30px;
}

.modal-small p {
    font-size: 1.3rem;
    margin-bottom: 20px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-header h2 {
    font-size: 1.4rem;
}

.close-btn {
    background: none;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    color: #999;
    line-height: 1;
    padding: 4px 8px;
    touch-action: manipulation;
}

/* === Settings Sections === */
.setting-section {
    margin-bottom: 24px;
}

.setting-section h3 {
    font-size: 1.1rem;
    margin-bottom: 10px;
    color: #555;
}


/* Letter Grid */
.letter-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.letter-btn {
    min-width: 48px;
    height: 48px;
    border-radius: 12px;
    border: 2px solid transparent;
    background: #f0ebe6;
    font-family: 'ABeeZee', sans-serif;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, border-color 0.2s;
    touch-action: manipulation;
    padding: 0 12px;
}

.letter-btn.active {
    background: #c8e6c9;
    border-color: #4caf50;
}

/* Preset Buttons */
.preset-buttons {
    display: flex;
    gap: 10px;
}

.preset-btn {
    flex: 1;
    padding: 10px;
    border-radius: 12px;
    border: 2px solid #ddd;
    background: #f8f4f0;
    font-family: 'ABeeZee', sans-serif;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
    touch-action: manipulation;
}

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

/* Range Sliders */
.range-container {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.range-container label {
    font-size: 0.95rem;
    min-width: 60px;
}

.range-container input[type="range"] {
    flex: 1;
    min-width: 80px;
}

/* Radio Group */
.radio-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.radio-option {
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.radio-option input[type="radio"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

.radio-option {
    flex-wrap: wrap;
}

.option-hint {
    width: 100%;
    font-size: 0.8rem;
    color: #999;
    margin-left: 28px;
}

/* Push-to-talk hint */
#ptt-hint {
    font-size: clamp(0.9rem, 2.5vw, 1.2rem);
    color: #999;
    text-align: center;
    padding: 8px;
    animation: pttPulse 2s ease-in-out infinite;
}

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

/* In push-to-talk mode, the word container becomes the touch target */
#word-container.ptt-active {
    cursor: pointer;
    -webkit-touch-callout: none;
}

#word-container.ptt-active.ptt-pressed {
    background: rgba(76, 175, 80, 0.08);
    border-radius: 20px;
}

/* Toggle Switch */
.toggle-switch {
    display: inline-flex;
    align-items: center;
    cursor: pointer;
}

.toggle-switch input {
    display: none;
}

.toggle-slider {
    width: 52px;
    height: 28px;
    background: #ccc;
    border-radius: 14px;
    position: relative;
    transition: background 0.3s;
}

.toggle-slider::after {
    content: '';
    width: 22px;
    height: 22px;
    background: #fff;
    border-radius: 50%;
    position: absolute;
    top: 3px;
    left: 3px;
    transition: left 0.3s;
}

.toggle-switch input:checked + .toggle-slider {
    background: #4caf50;
}

.toggle-switch input:checked + .toggle-slider::after {
    left: 27px;
}

/* Attempts Container */
#attempts-container {
    margin-top: 10px;
    display: flex;
    align-items: center;
    gap: 12px;
}

#attempts-container label {
    font-size: 0.95rem;
    min-width: 90px;
}

#attempts-container input[type="range"] {
    flex: 1;
}

/* API Key */
#api-key-container {
    margin-top: 12px;
}

#api-key-container.hidden {
    display: none;
}

#api-key-container label {
    display: block;
    font-size: 0.95rem;
    margin-bottom: 6px;
}

#google-api-key {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid #ddd;
    border-radius: 12px;
    font-size: 1rem;
    font-family: 'ABeeZee', sans-serif;
}

/* Confirm Buttons */
.confirm-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.confirm-btn {
    padding: 12px 32px;
    border: none;
    border-radius: 14px;
    font-size: 1.1rem;
    font-family: 'ABeeZee', sans-serif;
    cursor: pointer;
    touch-action: manipulation;
}

#confirm-yes {
    background: #e57373;
    color: #fff;
}

#confirm-no {
    background: #e0e0e0;
    color: #555;
}

/* === Success overlay === */
.success-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 50;
    animation: successFade 1.2s ease-out forwards;
}

.success-overlay .checkmark {
    font-size: 8rem;
    color: #4caf50;
    animation: successScale 0.6s ease-out;
}

@keyframes successFade {
    0% { opacity: 1; }
    70% { opacity: 1; }
    100% { opacity: 0; }
}

@keyframes successScale {
    0% { transform: scale(0); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

/* === Responsive === */
@media (max-width: 400px) {
    #action-buttons {
        gap: 10px;
    }

    .action-btn {
        width: 68px;
        height: 68px;
    }

    #mic-btn {
        width: 78px;
        height: 78px;
    }

    .settings-toggle {
        width: 44px;
        height: 44px;
    }
}

@media (orientation: landscape) and (max-height: 500px) {
    #app {
        padding: 10px 20px;
    }

    #word-display {
        font-size: clamp(2.5rem, 8vw, 5rem);
    }

    .action-btn {
        width: 60px;
        height: 60px;
    }

    #mic-btn {
        width: 68px;
        height: 68px;
    }

    #finger {
        height: 150px;
    }

    #feedback-area {
        min-height: 30px;
    }

    #top-bar {
        padding: 0;
    }
}
