* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    min-height: -webkit-fill-available;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* Header */
.header {
    background: white;
    padding: 12px 16px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    position: relative;
    z-index: 100;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

h1 {
    font-size: 18px;
    color: #333;
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.title-japanese {
    font-size: 20px;
    font-weight: bold;
}

.title-english {
    font-size: 11px;
    color: #666;
    font-weight: normal;
}

/* Language Setup Modal */
.language-setup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 3000;
    padding: 20px;
}

.language-setup.hidden {
    display: none !important;
}

.language-setup-content {
    background: white;
    border-radius: 20px;
    padding: 30px;
    max-width: 400px;
    width: 100%;
    text-align: center;
}

.language-setup h2 {
    margin-bottom: 10px;
    color: #333;
}

.language-setup p {
    color: #666;
    margin-bottom: 25px;
    font-size: 14px;
}

.language-options {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.language-option {
    flex: 1;
    padding: 15px;
    border: 2px solid #667eea;
    background: white;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s;
    font-family: inherit;
    font-size: inherit;
}

.language-option:hover {
    background: #667eea;
    color: white;
    transform: scale(1.05);
}

.language-option:active {
    transform: scale(0.98);
}

.language-option .flag {
    font-size: 30px;
    margin-bottom: 8px;
}

.language-option .lang-name {
    font-weight: 600;
}

/* Hamburger Menu */
.hamburger {
    width: 32px;
    height: 32px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    padding: 6px;
    border-radius: 6px;
    transition: background 0.3s;
}

.hamburger:active {
    background: rgba(102, 126, 234, 0.1);
}

.hamburger span {
    display: block;
    height: 2px;
    background: #667eea;
    border-radius: 2px;
    transition: all 0.3s;
}

.hamburger.active span:nth-child(1) {
    transform: rotate(45deg) translateY(5px);
}

.hamburger.active span:nth-child(2) {
    opacity: 0;
}

.hamburger.active span:nth-child(3) {
    transform: rotate(-45deg) translateY(-5px);
}

/* Dropdown Menu */
.dropdown-menu {
    position: absolute;
    top: calc(100% + 5px);
    right: 16px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.2);
    padding: 8px 0;
    min-width: 250px;
    max-width: 90vw;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.3s;
    z-index: 1000;
    max-height: 80vh;
    overflow-y: auto;
}

.dropdown-menu.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.menu-section {
    padding: 8px 0;
}

.menu-section-title {
    padding: 8px 16px;
    font-size: 12px;
    font-weight: 600;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.menu-item {
    padding: 12px 16px;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 10px;
    color: #333;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-size: 14px;
}

.menu-item:active, .menu-item:hover {
    background: #f0f0f0;
}

.menu-item.mode-item {
    justify-content: space-between;
}

.mode-indicator {
    color: #48bb78;
    font-weight: bold;
    font-size: 16px;
    width: 20px;
    text-align: center;
}

.menu-item.language-item {
    justify-content: space-between;
}

.language-indicator {
    font-size: 12px;
    color: #667eea;
    font-weight: 600;
}

.menu-stats {
    padding: 0 16px;
}

.menu-stat-item {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 14px;
}

.menu-stat-value {
    font-weight: bold;
    color: #667eea;
}

.menu-divider {
    height: 1px;
    background: #e0e0e0;
    margin: 4px 0;
}

/* Main Content */
.main-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 12px;
    max-width: 600px;
    width: 100%;
    margin: 0 auto;
}

/* Mode Selector */
.mode-selector {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.mode-btn {
    padding: 6px 14px;
    border: 2px solid white;
    background: rgba(255,255,255,0.2);
    color: white;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: 600;
    font-size: 13px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

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

.mode-btn.active {
    background: white;
    color: #667eea;
}

/* Card Container */
.card-container {
    flex: 1;
    background: white;
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 300px;
}

.question-card {
    text-align: center;
}

.character {
    font-size: min(40vw, 120px);
    margin: 20px 0;
    color: #333;
    font-weight: bold;
    line-height: 1.2;
}

.question-text {
    font-size: 16px;
    color: #666;
    margin-bottom: 25px;
    padding: 0 10px;
    font-weight: 500;
}

.choices {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 20px;
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
}

.choice-btn {
    padding: 20px 15px;
    border: 3px solid #e0e0e0;
    background: white;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 20px;
    font-weight: 600;
    min-height: 70px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

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

.choice-btn.correct {
    background: #48bb78;
    color: white;
    border-color: #48bb78;
}

.choice-btn.incorrect {
    background: #f56565;
    color: white;
    border-color: #f56565;
}

.choice-btn.disabled {
    pointer-events: none;
    opacity: 0.6;
}

.feedback {
    text-align: center;
    padding: 12px;
    border-radius: 8px;
    margin-top: 15px;
    font-size: 14px;
    font-weight: 600;
}

.feedback.correct {
    background: #c6f6d5;
    color: #22543d;
}

.feedback.incorrect {
    background: #fed7d7;
    color: #742a2a;
}

.next-btn {
    display: block;
    margin: 15px auto 0;
    padding: 10px 24px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s;
    min-height: 44px;
}

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

/* Stats Bar (Bottom) */
.stats-bar {
    background: rgba(255,255,255,0.98);
    padding: 8px 4px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    position: sticky;
    bottom: 0;
    z-index: 50;
}

.stat {
    text-align: center;
    flex: 1;
    padding: 4px;
}

.stat-value {
    font-size: 18px;
    font-weight: bold;
    color: #667eea;
    line-height: 1.2;
}

.stat-label {
    font-size: 10px;
    color: #666;
    margin-top: 2px;
}

/* Welcome Screen */
.welcome {
    text-align: center;
    padding: 20px;
    color: #666;
}

.welcome h2 {
    color: #333;
    margin-bottom: 15px;
    font-size: 22px;
}

.welcome p {
    font-size: 14px;
    line-height: 1.5;
    margin-bottom: 10px;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 2000;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.modal.active {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 20px;
}

.modal-content {
    background: white;
    border-radius: 16px;
    padding: 20px;
    width: 100%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    margin-top: 20px;
}

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

.modal-title {
    font-size: 20px;
    color: #333;
}

.close-btn {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: #999;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:active {
    color: #333;
}

.kana-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(45px, 1fr));
    gap: 6px;
    margin-bottom: 20px;
}

.kana-cell {
    position: relative;
    aspect-ratio: 1;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: white;
    transition: all 0.3s;
}

.kana-cell:active {
    transform: scale(0.95);
}

.kana-main {
    font-size: 18px;
    font-weight: bold;
    line-height: 1;
}

.kana-sub {
    font-size: 8px;
    color: #999;
    margin-top: 2px;
}

.status-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 6px;
    font-size: 16px;
    font-weight: bold;
    pointer-events: none;
}

.status-overlay.mastered {
    background: rgba(72, 187, 120, 0.9);
    color: white;
}

.status-overlay.learning {
    background: rgba(237, 137, 54, 0.9);
    color: white;
}

.status-overlay.struggling {
    background: rgba(245, 101, 101, 0.9);
    color: white;
}

.legend {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
}

.legend-box {
    width: 16px;
    height: 16px;
    border-radius: 4px;
}

.legend-box.mastered {
    background: rgba(72, 187, 120, 0.9);
}

.legend-box.learning {
    background: rgba(237, 137, 54, 0.9);
}

.legend-box.struggling {
    background: rgba(245, 101, 101, 0.9);
}

.legend-box.unseen {
    background: #f0f0f0;
    border: 1px solid #ccc;
}

.file-input {
    display: none;
}

/* Section headers in modal */
h3 {
    font-size: 16px;
    color: #333;
    margin: 16px 0 8px 0;
    padding-top: 8px;
    border-top: 1px solid #e0e0e0;
}

h3:first-of-type {
    border-top: none;
    margin-top: 0;
    padding-top: 0;
}

.hidden {
    display: none !important;
}

/* Responsive adjustments */
@media (max-width: 360px) {
    .mode-btn {
        font-size: 12px;
        padding: 5px 12px;
    }
    
    .character {
        font-size: min(50vw, 100px);
    }
    
    .choice-btn {
        font-size: 18px;
        min-height: 65px;
    }
    
    .stat-value {
        font-size: 16px;
    }
    
    .kana-grid {
        grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    }
}

@media (min-width: 768px) {
    .header {
        padding: 15px 20px;
    }
    
    h1 {
        font-size: 20px;
    }

    .title-japanese {
        font-size: 24px;
    }

    .title-english {
        font-size: 12px;
    }
    
    .main-container {
        padding: 20px;
    }
    
    .card-container {
        padding: 30px;
    }
    
    .character {
        font-size: 100px;
    }
    
    .question-text {
        font-size: 18px;
    }
    
    .choices {
        gap: 16px;
        max-width: 500px;
    }
    
    .choice-btn {
        padding: 25px;
        font-size: 22px;
        min-height: 80px;
    }
    
    .stats-bar {
        padding: 12px;
    }
    
    .stat-value {
        font-size: 22px;
    }
    
    .stat-label {
        font-size: 11px;
    }
}