/* 全局样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Hiragino Kaku Gothic Pro', 'Yu Gothic', 'Meiryo', sans-serif;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* 深色模式 */
.dark {
    color-scheme: dark;
}

.light {
    color-scheme: light;
}

/* 按钮样式 */
.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-weight: 600;
    border: none;
    border-radius: 0.75rem;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: white;
    color: #667eea;
    font-weight: 600;
    border: 2px solid #667eea;
    border-radius: 0.75rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.dark .btn-secondary {
    background: #374151;
    color: #a78bfa;
    border-color: #a78bfa;
}

.btn-secondary:hover {
    background: #667eea;
    color: white;
    transform: translateY(-2px);
}

.dark .btn-secondary:hover {
    background: #a78bfa;
    color: white;
}

.btn-icon {
    background: transparent;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 0.5rem;
    transition: all 0.3s ease;
}

.btn-icon:hover {
    background: rgba(0, 0, 0, 0.05);
}

.dark .btn-icon:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* 卡片样式 */
.card {
    background: white;
    border-radius: 1rem;
    padding: 2rem;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.dark .card {
    background: #1f2937;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

/* 选项按钮 */
.option-btn {
    background: white;
    border: 2px solid #e5e7eb;
    border-radius: 0.75rem;
    padding: 1.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 120px;
}

.dark .option-btn {
    background: #374151;
    border-color: #4b5563;
}

.option-btn:hover {
    border-color: #667eea;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
}

.option-btn.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: transparent;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.option-btn.active .text-gray-500,
.option-btn.active .text-gray-400 {
    color: rgba(255, 255, 255, 0.8) !important;
}

/* 统计卡片 */
.stat-card {
    background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
    border-radius: 0.75rem;
    padding: 1.5rem;
    text-align: center;
    transition: all 0.3s ease;
}

.dark .stat-card {
    background: linear-gradient(135deg, #374151 0%, #4b5563 100%);
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}

/* 进度条样式 */
.progress-bar {
    background: linear-gradient(90deg, rgb(236, 72, 153) 0%, rgb(168, 85, 247) 100%);
    height: 0.5rem;
    border-radius: 9999px;
    transition: all 0.3s ease;
    width: 0%;
}

/* 进度条动画 */
@keyframes progressGlow {
    0%, 100% {
        box-shadow: 0 0 8px rgba(102, 126, 234, 0.5);
    }
    50% {
        box-shadow: 0 0 20px rgba(102, 126, 234, 0.8);
    }
}

.progress-bar {
    animation: progressGlow 2s infinite;
}

/* 反馈动画 */
@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-20px);
    }
}

.feedback-correct {
    animation: bounce 0.6s ease;
    color: #10b981;
}

.feedback-wrong {
    animation: shake 0.6s ease;
    color: #ef4444;
}

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

/* 输入框样式 */
input[type="text"]:focus {
    transform: scale(1.02);
}

/* 选项按钮（听音辨字） */
.choice-btn {
    background: white;
    border: 2px solid #e5e7eb;
    border-radius: 0.75rem;
    padding: 1.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 2rem;
    font-weight: bold;
}

.dark .choice-btn {
    background: #374151;
    border-color: #4b5563;
    color: white;
}

.choice-btn:hover {
    border-color: #667eea;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
}

.choice-btn.selected {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: transparent;
}

.choice-btn.correct {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    border-color: transparent;
}

.choice-btn.wrong {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
    border-color: transparent;
}

/* 统计条 */
.stat-bar {
    background: #e5e7eb;
    border-radius: 0.5rem;
    height: 2rem;
    overflow: hidden;
    position: relative;
}

.dark .stat-bar {
    background: #4b5563;
}

.stat-bar-fill {
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    height: 100%;
    transition: width 0.5s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.875rem;
    font-weight: 600;
}

/* 响应式调整 */
@media (max-width: 768px) {
    .card {
        padding: 1.5rem;
    }

    #questionText {
        font-size: 3rem !important;
    }

    #answerInput {
        font-size: 1.5rem !important;
    }
}

/* 平滑过渡 */
.fade-in {
    animation: fadeIn 0.5s ease;
}

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

/* 隐藏滚动条但保持功能 */
.hide-scrollbar::-webkit-scrollbar {
    display: none;
}

.hide-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* 日式设计元素 */
.japanese-pattern {
    background-image: 
        repeating-linear-gradient(45deg, transparent, transparent 10px, rgba(255,255,255,.05) 10px, rgba(255,255,255,.05) 20px),
        repeating-linear-gradient(-45deg, transparent, transparent 10px, rgba(255,255,255,.05) 10px, rgba(255,255,255,.05) 20px);
}

/* 加载动画 */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255,255,255,.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Tooltip */
.tooltip {
    position: relative;
}

.tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: 0.5rem 1rem;
    background: #1f2937;
    color: white;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    margin-bottom: 0.5rem;
}

.tooltip:hover::after {
    opacity: 1;
}

/* 虚拟键盘浮动按钮 */
.virtual-keyboard-float-btn {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.6);
    transition: all 0.3s ease;
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.virtual-keyboard-float-btn:hover {
    transform: translateY(-4px) scale(1.05);
    box-shadow: 0 8px 30px rgba(102, 126, 234, 0.8);
}

.virtual-keyboard-float-btn:active {
    transform: translateY(-2px) scale(1.02);
}

/* 虚拟键盘面板 */
.virtual-keyboard {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 90%;
    max-width: 600px;
    max-height: 500px;
    background: white;
    border-radius: 1rem;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    transition: all 0.3s ease;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.dark .virtual-keyboard {
    background: #1f2937;
}

.virtual-keyboard-header {
    padding: 1rem 1.5rem;
    border-bottom: 2px solid #e5e7eb;
    background: linear-gradient(135deg, #f9fafb 0%, #f3f4f6 100%);
}

.dark .virtual-keyboard-header {
    border-bottom-color: #374151;
    background: linear-gradient(135deg, #374151 0%, #4b5563 100%);
}

.keyboard-tab-btn {
    padding: 0.5rem 1rem;
    border: 2px solid #e5e7eb;
    background: white;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
    color: #6b7280;
}

.dark .keyboard-tab-btn {
    background: #1f2937;
    border-color: #4b5563;
    color: #9ca3af;
}

.keyboard-tab-btn:hover {
    border-color: #667eea;
    color: #667eea;
}

.keyboard-tab-btn.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: transparent;
}

.virtual-keyboard-content {
    padding: 1rem;
    overflow-y: auto;
    flex: 1;
}

.kana-keyboard {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
    gap: 0.5rem;
}

.kana-key {
    aspect-ratio: 1;
    border: 2px solid #e5e7eb;
    background: white;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    font-weight: 600;
    color: #1f2937;
    min-height: 50px;
}

.dark .kana-key {
    background: #374151;
    border-color: #4b5563;
    color: white;
}

.kana-key:hover {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: transparent;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.kana-key:active {
    transform: translateY(0);
}

.kana-key-romaji {
    font-size: 0.6rem;
    color: #9ca3af;
    margin-top: 0.15rem;
    display: none; /* 默认隐藏罗马音 */
}

.virtual-keyboard.show-romaji .kana-key-romaji {
    display: block; /* 当开启显示时才显示 */
}

.kana-key:hover .kana-key-romaji {
    color: rgba(255, 255, 255, 0.8);
}

/* 罗马音切换按钮 */
.keyboard-toggle-btn {
    padding: 0.4rem 0.75rem;
    border: 2px solid #e5e7eb;
    background: white;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
    color: #6b7280;
}

.dark .keyboard-toggle-btn {
    background: #1f2937;
    border-color: #4b5563;
    color: #9ca3af;
}

.keyboard-toggle-btn:hover {
    border-color: #667eea;
    color: #667eea;
}

.keyboard-toggle-btn.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: transparent;
}

/* 键盘动画 */
@keyframes slideUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.virtual-keyboard:not(.hidden) {
    animation: slideUp 0.3s ease;
}

/* 响应式调整 */
@media (max-width: 768px) {
    .virtual-keyboard {
        width: 95%;
        max-width: none;
        bottom: 1rem;
        right: 2.5%;
        max-height: 400px;
    }

    .virtual-keyboard-float-btn {
        width: 50px;
        height: 50px;
        bottom: 1rem;
        right: 1rem;
    }

    .kana-keyboard {
        grid-template-columns: repeat(auto-fill, minmax(45px, 1fr));
        gap: 0.4rem;
    }

    .kana-key {
        font-size: 1rem;
        min-height: 45px;
    }

    .kana-key-romaji {
        font-size: 0.55rem;
    }
}

/* 自动适配系统深色模式偏好 */
@media (prefers-color-scheme: dark) {
    /* 只在没有明确设置 dark/light 类时生效 */
    html:not(.dark):not(.light) {
        color-scheme: dark;
    }
    
    html:not(.dark):not(.light) .btn-secondary {
        background: #374151;
        color: #a78bfa;
        border-color: #a78bfa;
    }
    
    html:not(.dark):not(.light) .btn-secondary:hover {
        background: #a78bfa;
        color: white;
    }
    
    html:not(.dark):not(.light) .btn-icon:hover {
        background: rgba(255, 255, 255, 0.1);
    }
    
    html:not(.dark):not(.light) .card {
        background: #1f2937;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    }
    
    html:not(.dark):not(.light) .option-btn {
        background: #374151;
        border-color: #4b5563;
    }
    
    html:not(.dark):not(.light) .stat-card {
        background: linear-gradient(135deg, #374151 0%, #4b5563 100%);
    }
    
    html:not(.dark):not(.light) .choice-btn {
        background: #374151;
        border-color: #4b5563;
        color: white;
    }
    
    html:not(.dark):not(.light) .stat-bar {
        background: #4b5563;
    }

    html:not(.dark):not(.light) .virtual-keyboard {
        background: #1f2937;
    }

    html:not(.dark):not(.light) .virtual-keyboard-header {
        border-bottom-color: #374151;
        background: linear-gradient(135deg, #374151 0%, #4b5563 100%);
    }

    html:not(.dark):not(.light) .keyboard-tab-btn {
        background: #1f2937;
        border-color: #4b5563;
        color: #9ca3af;
    }

    html:not(.dark):not(.light) .kana-key {
        background: #374151;
        border-color: #4b5563;
        color: white;
    }
}
