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

:root {
    --primary: #1a237e;
    --primary-light: #534bae;
    --secondary: #c62828;
    --accent: #ffd600;
    --success: #2e7d32;
    --error: #c62828;
    --bg: #f5f5f5;
    --card-bg: #ffffff;
    --text: #212121;
    --text-light: #757575;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    min-height: 100vh;
    color: var(--text);
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    text-align: center;
    padding: 30px 0;
    color: white;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
}

main {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.screen {
    display: none;
    animation: fadeIn 0.3s ease;
}

.screen.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Menu Screen */
.menu-section {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

.menu-section h2 {
    color: var(--primary);
    margin-bottom: 20px;
    font-size: 1.3rem;
}

.mode-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.mode-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    background: white;
    cursor: pointer;
    transition: all 0.2s ease;
}

.mode-btn:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.mode-btn.selected {
    border-color: var(--primary);
    background: rgba(26, 35, 126, 0.05);
}

.mode-icon {
    font-size: 2rem;
    margin-bottom: 10px;
}

.mode-name {
    font-weight: 600;
    color: var(--text);
    margin-bottom: 5px;
}

.mode-desc {
    font-size: 0.85rem;
    color: var(--text-light);
    text-align: center;
}

.difficulty-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}

.diff-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 15px 20px;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    background: white;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.95rem;
}

.diff-btn:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
}

.diff-btn.selected {
    border-color: var(--primary);
    background: rgba(26, 35, 126, 0.05);
}

.belt {
    width: 30px;
    height: 12px;
    border-radius: 2px;
    border: 1px solid #ccc;
}

.white-belt { background: #fafafa; }
.orange-belt { background: linear-gradient(90deg, #ff9800 50%, #4caf50 50%); }
.blue-belt { background: linear-gradient(90deg, #2196f3 50%, #795548 50%); }
.black-belt { background: #212121; }

.start-btn {
    display: block;
    width: 100%;
    padding: 18px;
    font-size: 1.2rem;
    font-weight: 600;
    color: white;
    background: var(--secondary);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.start-btn:hover:not(:disabled) {
    background: #a31f1f;
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(198, 40, 40, 0.4);
}

.start-btn:disabled {
    background: #bdbdbd;
    cursor: not-allowed;
}

.study-link {
    display: block;
    text-align: center;
    margin-top: 20px;
    padding: 14px;
    color: white;
    text-decoration: none;
    font-weight: 500;
    font-size: 1.05rem;
    background: var(--primary);
    border-radius: 10px;
    transition: all 0.2s ease;
}

.study-link:hover {
    background: var(--primary-light);
    color: white;
}

/* Quiz Screen */
.quiz-header {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.progress-info {
    display: flex;
    justify-content: space-between;
    margin-bottom: 12px;
    font-weight: 500;
}

.progress-bar {
    height: 8px;
    background: #e0e0e0;
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--primary-light));
    border-radius: 4px;
    transition: width 0.3s ease;
    width: 0%;
}

.question-container {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 30px;
    margin-bottom: 20px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    min-height: 300px;
}

.question-text {
    font-size: 1.4rem;
    color: var(--primary);
    margin-bottom: 25px;
    text-align: center;
}

.question-term {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary);
    text-align: center;
    margin-bottom: 30px;
    padding: 20px;
    background: rgba(26, 35, 126, 0.05);
    border-radius: 12px;
}

/* Multiple Choice Options */
.options-container {
    display: grid;
    gap: 12px;
}

.option-btn {
    padding: 18px 25px;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    background: white;
    cursor: pointer;
    text-align: left;
    font-size: 1.1rem;
    transition: all 0.2s ease;
}

.option-btn:hover:not(:disabled) {
    border-color: var(--primary);
    background: rgba(26, 35, 126, 0.03);
}

.option-btn.correct {
    border-color: #4caf50;
    border-width: 3px;
    background: #e8f5e9;
    color: #1b5e20;
    font-weight: 600;
    box-shadow: 0 0 0 4px rgba(76, 175, 80, 0.2);
}

.option-btn.incorrect {
    border-color: #f44336;
    border-width: 3px;
    background: #ffebee;
    color: #b71c1c;
    font-weight: 600;
    box-shadow: 0 0 0 4px rgba(244, 67, 54, 0.2);
}

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

/* Fill in the Blank */
.fill-blank-container {
    text-align: center;
}

.answer-input {
    width: 100%;
    max-width: 400px;
    padding: 15px 20px;
    font-size: 1.2rem;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    text-align: center;
    margin-bottom: 15px;
    transition: border-color 0.2s ease;
}

.answer-input:focus {
    outline: none;
    border-color: var(--primary);
}

.submit-answer-btn {
    padding: 12px 40px;
    font-size: 1.1rem;
    font-weight: 600;
    color: white;
    background: var(--primary);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.submit-answer-btn:hover {
    background: var(--primary-light);
}

/* Matching Game */
.matching-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.matching-column {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.matching-column h3 {
    text-align: center;
    color: var(--primary);
    margin-bottom: 10px;
    font-size: 1rem;
}

.match-item {
    padding: 15px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s ease;
}

.match-item:hover:not(.matched):not(.selected) {
    border-color: var(--primary);
}

.match-item.selected {
    border-color: var(--primary);
    background: rgba(26, 35, 126, 0.1);
}

.match-item.matched {
    border-color: var(--success);
    background: rgba(46, 125, 50, 0.1);
    cursor: default;
}

.match-item.wrong {
    animation: shake 0.3s ease;
    border-color: var(--error);
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* Feedback */
.feedback {
    padding: 25px;
    border-radius: 12px;
    margin-bottom: 20px;
    text-align: center;
    font-size: 1.3rem;
    font-weight: 600;
    animation: popIn 0.3s ease;
}

@keyframes popIn {
    0% { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.feedback.correct {
    background: #e8f5e9;
    color: #1b5e20;
    border: 3px solid #4caf50;
    box-shadow: 0 4px 20px rgba(76, 175, 80, 0.3);
}

.feedback.correct::before {
    content: "✓ ";
    font-size: 1.4rem;
}

.feedback.incorrect {
    background: #ffebee;
    color: #b71c1c;
    border: 3px solid #f44336;
    box-shadow: 0 4px 20px rgba(244, 67, 54, 0.3);
}

.feedback.incorrect::before {
    content: "✗ ";
    font-size: 1.4rem;
}

.feedback.hidden {
    display: none;
}

.next-btn {
    display: block;
    width: 100%;
    padding: 18px;
    font-size: 1.1rem;
    font-weight: 600;
    color: white;
    background: var(--primary);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.next-btn:hover {
    background: var(--primary-light);
}

.next-btn.hidden {
    display: none;
}

/* Results Screen */
.results-card {
    background: var(--card-bg);
    border-radius: 20px;
    padding: 40px;
    text-align: center;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

.results-card h2 {
    color: var(--primary);
    font-size: 2rem;
    margin-bottom: 30px;
}

.final-score {
    font-size: 4rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 15px;
}

.score-message {
    font-size: 1.3rem;
    color: var(--text-light);
    margin-bottom: 30px;
}

.results-breakdown {
    text-align: left;
    margin-bottom: 30px;
    padding: 20px;
    background: #f5f5f5;
    border-radius: 12px;
}

.results-breakdown h3 {
    margin-bottom: 15px;
    color: var(--primary);
}

.result-item {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid #e0e0e0;
}

.result-item:last-child {
    border-bottom: none;
}

.result-item.correct-result {
    color: var(--success);
}

.result-item.incorrect-result {
    color: var(--error);
}

.results-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.action-btn {
    padding: 15px 35px;
    font-size: 1.1rem;
    font-weight: 600;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.action-btn:not(.secondary) {
    color: white;
    background: var(--secondary);
}

.action-btn:not(.secondary):hover {
    background: #a31f1f;
}

.action-btn.secondary {
    color: var(--primary);
    background: white;
    border: 2px solid var(--primary);
}

.action-btn.secondary:hover {
    background: rgba(26, 35, 126, 0.05);
}

/* Leaderboard */
.leaderboard-prompt {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.leaderboard-prompt.hidden {
    display: none;
}

.leaderboard-prompt input {
    padding: 12px 16px;
    font-size: 1rem;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    width: 200px;
}

.leaderboard-prompt input:focus {
    outline: none;
    border-color: var(--primary);
}

.save-score-btn {
    padding: 12px 20px;
    font-size: 1rem;
    font-weight: 600;
    color: white;
    background: var(--success);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.save-score-btn:hover {
    background: #1b5e20;
}

.leaderboard-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

.leaderboard-card h3 {
    color: var(--primary);
    margin-bottom: 15px;
    text-align: center;
    font-size: 1.3rem;
}

.leaderboard-list {
    margin-bottom: 15px;
}

.leaderboard-entry {
    display: grid;
    grid-template-columns: 40px 1fr 1fr 60px;
    gap: 10px;
    align-items: center;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 8px;
    background: #f5f5f5;
}

.leaderboard-entry.top-1 {
    background: linear-gradient(135deg, #ffd700 0%, #ffed4a 100%);
}

.leaderboard-entry.top-2 {
    background: linear-gradient(135deg, #c0c0c0 0%, #e8e8e8 100%);
}

.leaderboard-entry.top-3 {
    background: linear-gradient(135deg, #cd7f32 0%, #daa06d 100%);
}

.lb-rank {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--primary);
}

.lb-name {
    font-weight: 600;
}

.lb-details {
    font-size: 0.85rem;
    color: var(--text-light);
    text-transform: capitalize;
}

.lb-score {
    font-weight: 700;
    color: var(--primary);
    text-align: right;
}

.no-scores {
    text-align: center;
    color: var(--text-light);
    padding: 20px;
}

/* Stats and Leaderboard Row */
.stats-leaderboard-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-top: 25px;
}

.stats-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

.stats-card h3,
.leaderboard-card h3 {
    color: var(--primary);
    margin-bottom: 15px;
    font-size: 1.1rem;
}

.stats-panel {
    font-size: 0.9rem;
}

.stats-overall {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
}

.stat-item {
    flex: 1;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: white;
    padding: 15px;
    border-radius: 10px;
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 0.8rem;
    opacity: 0.9;
    margin-bottom: 5px;
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
}

.stats-breakdown h4 {
    color: var(--primary);
    font-size: 0.95rem;
    margin-bottom: 10px;
    padding-bottom: 5px;
    border-bottom: 1px solid #e0e0e0;
}

.stats-grid {
    margin-bottom: 15px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid #f0f0f0;
}

.stat-row:last-child {
    border-bottom: none;
}

.stat-name {
    font-weight: 500;
    color: var(--text);
}

.stat-data {
    color: var(--text-light);
    font-size: 0.85rem;
}

footer {
    text-align: center;
    padding: 20px;
    color: rgba(255,255,255,0.8);
    font-size: 0.95rem;
}

/* Responsive */
@media (max-width: 600px) {
    .container {
        padding: 10px;
    }

    header h1 {
        font-size: 1.8rem;
    }

    .menu-section {
        padding: 20px 15px;
    }

    .mode-buttons {
        grid-template-columns: 1fr;
    }

    .difficulty-buttons {
        grid-template-columns: 1fr;
    }

    .question-term {
        font-size: 1.8rem;
    }

    .matching-container {
        grid-template-columns: 1fr;
    }

    .results-actions {
        flex-direction: column;
    }

    .stats-leaderboard-row {
        grid-template-columns: 1fr;
    }

    .stats-overall {
        flex-direction: column;
    }

    .leaderboard-entry {
        grid-template-columns: 30px 1fr 50px;
    }

    .lb-details {
        display: none;
    }
}

/* Audio Pronunciation Speaker Button */
.speaker-btn {
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    font-size: 1.2rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
    vertical-align: middle;
    margin-left: 10px;
}

.speaker-btn:hover {
    background: var(--primary-light);
    transform: scale(1.1);
}

.speaker-btn-sm {
    width: 32px;
    height: 32px;
    font-size: 0.9rem;
    margin-left: 6px;
}

/* Kanji Typography */
.kanji-display {
    font-size: 2.8rem;
    font-weight: bold;
    color: var(--secondary);
    margin-bottom: 5px;
    letter-spacing: 2px;
}

.kanji-sub {
    font-size: 0.95rem;
    color: var(--text-light);
    margin-top: 4px;
}

/* Category Filter Buttons */
.category-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
}

.cat-btn {
    padding: 8px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 20px;
    background: white;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.cat-btn:hover {
    border-color: var(--primary);
}

.cat-btn.selected {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Category Badges */
.category-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.category-badge-nage {
    background: #e3f2fd;
    color: #1565c0;
}

.category-badge-katame {
    background: #fbe9e7;
    color: #d84315;
}

.category-badge-etiquette {
    background: #e8f5e9;
    color: #2e7d32;
}

/* 3D Flashcard Styles */
.flashcard-wrapper {
    perspective: 1000px;
    width: 100%;
    min-height: 280px;
    margin: 20px 0;
}

.flashcard {
    width: 100%;
    height: 100%;
    min-height: 280px;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    border-radius: 16px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.12);
}

.flashcard.flipped {
    transform: rotateY(180deg);
}

.flashcard-front, .flashcard-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 16px;
    padding: 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: white;
    border: 2px solid #e0e0e0;
    text-align: center;
}

.flashcard-back {
    transform: rotateY(180deg);
    background: #f8f9fa;
    border-color: var(--primary-light);
}

.flashcard-hint {
    font-size: 0.85rem;
    color: var(--text-light);
    margin-top: 15px;
    font-style: italic;
}

.flashcard-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    margin-top: 15px;
}

.fc-btn {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.fc-review {
    background: #ffe0b2;
    color: #e65100;
}

.fc-gotit {
    background: #c8e6c9;
    color: #1b5e20;
}

.fc-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

/* 60s Blitz & Survival Mode UI */
.blitz-timer-container {
    width: 100%;
    height: 10px;
    background: #e0e0e0;
    border-radius: 5px;
    overflow: hidden;
    margin: 10px 0;
}

.blitz-timer-fill {
    height: 100%;
    background: linear-gradient(90deg, #4caf50, #ff9800, #f44336);
    width: 100%;
    transition: width 1s linear;
}

.survival-lives {
    display: flex;
    gap: 6px;
    font-size: 1.4rem;
}

/* Belt Achievement Badges Grid */
.belt-badges-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 12px;
    margin-top: 15px;
}

.belt-badge-card {
    background: #f5f5f5;
    border: 2px dashed #bdbdbd;
    border-radius: 12px;
    padding: 15px 10px;
    text-align: center;
    opacity: 0.6;
    transition: all 0.3s ease;
}

.belt-badge-card.unlocked {
    background: #fff;
    border: 2px solid var(--accent);
    box-shadow: 0 4px 15px rgba(255, 214, 0, 0.3);
    opacity: 1;
}

.belt-badge-card .badge-icon {
    font-size: 2rem;
    margin-bottom: 5px;
}

.belt-badge-card .badge-title {
    font-size: 0.85rem;
    font-weight: bold;
    color: var(--text);
}

.belt-badge-card .badge-status {
    font-size: 0.75rem;
    color: var(--text-light);
    margin-top: 2px;
}

