:root {
    --bg-dark: #0f111a;
    --card-bg: rgba(25, 28, 41, 0.65);
    --card-border: rgba(255, 255, 255, 0.1);
    --text-main: #f8f9fa;
    --text-muted: #a0a4b8;
    --primary: #6b4cff;
    --primary-hover: #8367ff;
    --success: #20c997;
    --error: #ff4b72;
    --font-main: 'Outfit', sans-serif;
    --aurora-1: #6b4cff;
    --aurora-2: #00d2ff;
    --aurora-3: #ff4b72;
}

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

body {
    font-family: var(--font-main);
    background-color: var(--bg-dark);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    position: relative;
}

.background-aurora {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: -1;
    overflow: hidden;
    background: var(--bg-dark);
}

.background-aurora::before,
.background-aurora::after {
    content: '';
    position: absolute;
    width: 600px;
    height: 600px;
    border-radius: 50%;
    filter: blur(100px);
    opacity: 0.5;
    animation: drift 20s infinite ease-in-out alternate;
}

.background-aurora::before {
    background: radial-gradient(circle, var(--aurora-1), transparent 70%);
    top: -100px; left: -100px;
}
.background-aurora::after {
    background: radial-gradient(circle, var(--aurora-2), transparent 70%);
    bottom: -100px; right: -100px;
    animation-delay: -10s;
}

@keyframes drift {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(100px, 150px) scale(1.2); }
}

.app-container {
    width: 90%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    z-index: 10;
    max-height: 95vh;
}

.hidden { display: none !important; }

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 10px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.3s ease, transform 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    color: var(--text-main);
    transform: rotate(15deg) scale(1.1);
}

h1 {
    font-size: 1.6rem;
    font-weight: 800;
    background: linear-gradient(135deg, #fff, #a0a4b8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.5px;
}

.card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 20px;
    padding: 25px 30px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.4);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.stats-panel {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding: 15px 25px;
    gap: 15px;
}

.stat-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.stat-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    font-weight: 600;
}

.stat-value {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--text-main);
}
.stat-value.success { color: var(--success); }
.stat-value.error { color: var(--error); }

.global-stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-top: 10px;
}
.global-stats-grid .stat-box {
    background: rgba(0,0,0,0.2);
    border-radius: 12px;
    padding: 20px;
    border: 1px solid var(--card-border);
}

.challenge-info {
    display: flex;
    gap: 12px;
    width: 100%;
    justify-content: center;
    margin-bottom: 15px;
    flex-wrap: wrap;
    align-items: center;
}

.pronoun-badge {
    padding: 10px 24px;
    border-radius: 16px;
    font-size: 1.8rem;
    font-weight: 800;
    color: #fff;
    background: rgba(107, 76, 255, 0.3);
    border: 2px solid var(--primary);
    box-shadow: 0 4px 15px rgba(107, 76, 255, 0.4);
    text-transform: lowercase;
}

.tense-badge {
    padding: 6px 16px;
    border-radius: 30px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--card-border);
}

.verb-display {
    font-size: 3rem;
    font-weight: 800;
    margin-bottom: 30px;
    color: #fff;
    text-shadow: 0 0 20px rgba(255,255,255,0.2);
    text-align: center;
}

.input-wrapper {
    width: 100%;
    position: relative;
    margin-bottom: 20px;
}

input[type="text"] {
    width: 100%;
    padding: 18px 24px;
    background: rgba(0, 0, 0, 0.2);
    border: 2px solid var(--card-border);
    border-radius: 16px;
    color: #fff;
    font-size: 1.2rem;
    font-family: var(--font-main);
    transition: all 0.3s ease;
    outline: none;
}
input[type="text"]:focus {
    border-color: var(--primary);
    background: rgba(0, 0, 0, 0.4);
    box-shadow: 0 0 15px rgba(107, 76, 255, 0.3);
}

.feedback-icon {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%) scale(0);
    font-size: 1.5rem;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.feedback-icon.show { transform: translateY(-50%) scale(1); }

.feedback-message {
    text-align: center;
    min-height: 24px;
    font-weight: 600;
    font-size: 1rem;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
}
.feedback-message.show { opacity: 1; transform: translateY(0); }
.feedback-message.success { color: var(--success); }
.feedback-message.error { color: var(--error); }

.btn {
    width: 100%;
    padding: 16px;
    border: none;
    border-radius: 16px;
    font-family: var(--font-main);
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
}

.primary-btn {
    background: linear-gradient(135deg, var(--primary), #5235cc);
    color: white;
    box-shadow: 0 8px 20px rgba(107, 76, 255, 0.3);
}
.primary-btn:hover { transform: translateY(-2px); box-shadow: 0 12px 25px rgba(107, 76, 255, 0.4); }
.primary-btn:active { transform: translateY(1px); }

.danger-btn {
    background: rgba(255, 75, 114, 0.15);
    color: var(--error);
    border: 1px solid var(--error);
    box-shadow: 0 4px 10px rgba(255, 75, 114, 0.2);
}
.danger-btn:hover { background: var(--error); color: white; }

.small-btn {
    padding: 6px 12px;
    font-size: 0.85rem;
    border-radius: 8px;
    width: auto;
}

/* Modals */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}
.modal.show { opacity: 1; pointer-events: all; }

.modal-content {
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    padding: 30px;
    align-items: stretch;
    transform: translateY(20px);
}
.modal.show .modal-content { transform: translateY(0); }

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}
.modal-header h2 { font-size: 1.5rem; color: #fff; }
.modal-header .icon-btn { font-size: 2rem; line-height: 1; margin:0;}

/* Scrollbars */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: rgba(255,255,255,0.05); border-radius: 4px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 4px; }

/* Grid specific to Tenses/Modals */
.tenses-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
    overflow-y: auto;
    padding-right: 10px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 0.95rem;
    color: var(--text-muted);
    transition: color 0.2s;
    user-select: none;
}
.checkbox-label:hover { color: var(--text-main); }
.checkbox-label input[type="checkbox"] {
    appearance: none;
    width: 20px;
    height: 20px;
    border: 2px solid var(--text-muted);
    border-radius: 6px;
    background: transparent;
    cursor: pointer;
    position: relative;
    transition: all 0.2s;
}
.checkbox-label input[type="checkbox"]:checked {
    background: var(--primary);
    border-color: var(--primary);
}
.checkbox-label input[type="checkbox"]:checked::after {
    content: '✓';
    position: absolute;
    color: white;
    font-size: 14px;
    left: 4px;
    top: -1px;
}

/* Summary Card */
.summary-card { align-items: stretch; max-height: 80vh; overflow: hidden; }
.summary-title { font-size: 1.8rem; text-align: center; margin-bottom: 5px; }
.text-muted { color: var(--text-muted); text-align: center; font-size: 0.95rem; margin-bottom: 20px; }

.mistakes-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-right: 5px;
}
.mistake-item {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.mistake-header { display: flex; align-items: center; gap: 10px; font-size: 0.9rem; color: var(--text-muted); }
.verb-name { color: var(--text-main); font-weight: 600; font-size: 1rem; text-transform: uppercase;}
.mistake-body {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(25, 28, 41, 0.4);
    padding: 8px 12px;
    border-radius: 8px;
}
.user-typed { color: var(--error); text-decoration: line-through; font-weight: 600; }
.correct-ans { color: var(--success); font-weight: 600; }

/* Database Section */
.db-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
    padding-right: 10px;
    max-height: 50vh;
}
.db-item {
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    overflow: hidden;
}
.db-item summary {
    padding: 15px 20px;
    cursor: pointer;
    font-weight: 800;
    font-size: 1.2rem;
    color: var(--text-main);
    list-style: none;
    display: flex;
    justify-content: space-between;
    transition: background 0.2s;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.db-item summary::-webkit-details-marker { display: none; }
.db-item summary:hover { background: rgba(255,255,255,0.05); }
.db-item summary::after { content: '+'; color: var(--primary); font-size: 1.5rem; }
.db-item[open] summary::after { content: '-'; }

.db-details-content {
    padding: 0 20px 20px 20px;
}
.db-tense-section {
    margin-top: 15px;
}
.db-tense-title {
    font-size: 0.85rem;
    color: var(--primary);
    border-bottom: 1px solid var(--card-border);
    padding-bottom: 5px;
    margin-bottom: 10px;
    text-transform: uppercase;
}
.db-pronoun-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.95rem;
    padding: 4px 0;
    border-bottom: 1px dashed rgba(255,255,255,0.05);
}
.db-pronoun { color: var(--text-muted); }
.db-conjugation { color: var(--success); font-weight: 600; }

.success-btn {
    background: rgba(32, 201, 151, 0.15);
    color: var(--success);
    border: 1px solid var(--success);
    box-shadow: 0 4px 10px rgba(32, 201, 151, 0.2);
}
.success-btn:hover { background: var(--success); color: white; }

.chart-bar-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    height: 100%;
}
.chart-bar {
    width: 100%;
    max-width: 25px;
    background: rgba(255,255,255,0.05);
    border-radius: 4px 4px 0 0;
    display: flex;
    flex-direction: column-reverse; /* Builds from bottom */
    overflow: hidden;
    position: relative;
    transition: height 0.3s ease;
}
.chart-bar .correct-segment { background: var(--success); width: 100%; transition: height 0.3s ease;}
.chart-bar .incorrect-segment { background: var(--error); width: 100%; transition: height 0.3s ease;}
.chart-time-label { font-size: 0.6rem; color: #ffb100; font-weight: 800; margin-bottom: 2px; text-align: center; }
.chart-date-label { font-size: 0.65rem; color: var(--text-muted); margin-top: 6px; text-align: center; }

/* Mobile & Short Screen Optimizations */
@media (max-width: 600px), (max-height: 850px) {
    :root {
        --container-padding: 10px;
    }
    header h1 { display: none; } /* Hide big logo to save space */
    header { 
        justify-content: flex-end; 
        padding: 5px 0;
        margin-bottom: 5px;
    }
    .header-actions { width: 100%; justify-content: flex-end; gap: 8px; }
    .btn.small-btn { padding: 4px 10px; font-size: 0.75rem; }
    
    .question-card {
        padding: 15px;
        margin: 5px 0;
    }
    #verb-display { font-size: 2rem; margin-bottom: 2px; }
    .badge-container { margin-bottom: 8px; gap: 5px; }
    .badge { padding: 3px 8px; font-size: 0.7rem; }
    
    #answer-input { 
        padding: 10px; 
        font-size: 1rem; 
        margin-bottom: 10px; 
    }
    
    /* Flatten stats bar on mobile */
    .stats-panel-grid { 
        display: flex; 
        justify-content: space-around; 
        gap: 5px; 
        margin-bottom: 5px;
        padding: 5px;
    }
    .stat-item { padding: 5px; background: none; box-shadow: none; border-bottom: 1px solid rgba(255,255,255,0.1); }
    .stat-item .label { font-size: 0.6rem; opacity: 0.7; }
    .stat-item .value { font-size: 1rem; }

    #daily-chart { height: 80px !important; }
}

@media (max-height: 600px) {
    .stats-panel-grid { display: none; }
}

/* Animations */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}
.shake { animation: shake 0.5s ease-in-out; }
@keyframes popIn {
    0% { transform: scale(0.9); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}
.pop-in { animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
