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

:root {
    --primary: #FF6B6B;
    --primary-dark: #EE5A5A;
    --secondary: #4ECDC4;
    --secondary-dark: #3DBDB5;
    --accent: #FFE66D;
    --accent-dark: #F0D85E;
    --success: #51CF66;
    --warning: #FF922B;
    --purple: #845EF7;
    --pink: #F06595;
    --bg: #F8F9FA;
    --card: #FFFFFF;
    --text: #2D3436;
    --text-light: #636E72;
    --shadow: 0 4px 20px rgba(0,0,0,0.08);
    --radius: 16px;
}

html, body {
    height: 100%;
    font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 16px;
    overflow-x: hidden;
}

/* Page Structure */
.page {
    display: none;
    min-height: 100vh;
    padding: 20px 16px 80px;
    max-width: 480px;
    margin: 0 auto;
}
.page.active { display: block; }

/* Header */
.header {
    text-align: center;
    padding: 20px 0;
    position: relative;
}
.header h1 {
    font-size: 24px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), var(--purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Top Bar */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 8px;
}
.stat-item {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 14px;
    font-weight: 600;
}
.stat-item .icon { font-size: 20px; }
.stat-item .num { color: var(--primary); }

/* Cards */
.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 16px;
    transition: transform 0.2s;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 28px;
    border: none;
    border-radius: 50px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    user-select: none;
    -webkit-user-select: none;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: white; }
.btn-secondary { background: linear-gradient(135deg, var(--secondary), var(--secondary-dark)); color: white; }
.btn-accent { background: linear-gradient(135deg, var(--accent), var(--accent-dark)); color: #5F4B00; }
.btn-success { background: var(--success); color: white; }
.btn-purple { background: linear-gradient(135deg, var(--purple), #6C3CE0); color: white; }
.btn-pink { background: linear-gradient(135deg, var(--pink), #D6336C); color: white; }
.btn-lg { padding: 18px 36px; font-size: 20px; width: 100%; }
.btn-sm { padding: 8px 16px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-outline {
    background: transparent;
    border: 2px solid var(--primary);
    color: var(--primary);
}

/* Grade Selector */
.grade-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin: 16px 0;
}
.grade-btn {
    padding: 20px 12px;
    border: 3px solid #E8E8E8;
    border-radius: var(--radius);
    background: var(--card);
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}
.grade-btn:hover { border-color: var(--secondary); }
.grade-btn:active { transform: scale(0.95); }
.grade-btn.selected { border-color: var(--secondary); background: #E8F8F6; }
.grade-btn .sub {
    font-size: 12px;
    color: var(--text-light);
    font-weight: 400;
    margin-top: 4px;
}

/* Practice Area */
.practice-header {
    text-align: center;
    margin-bottom: 20px;
}
.practice-header .progress-text {
    font-size: 14px;
    color: var(--text-light);
    margin-bottom: 8px;
}
.progress-bar {
    height: 8px;
    background: #E8E8E8;
    border-radius: 4px;
    overflow: hidden;
}
.progress-bar .fill {
    height: 100%;
    background: linear-gradient(90deg, var(--secondary), var(--success));
    border-radius: 4px;
    transition: width 0.3s;
}

.word-card {
    text-align: center;
    padding: 40px 20px;
    margin-bottom: 20px;
    position: relative;
    overflow: hidden;
}
.word-card .pinyin {
    font-size: 28px;
    color: var(--secondary);
    margin-bottom: 12px;
    font-weight: 700;
}
.word-card .hint {
    font-size: 16px;
    color: var(--text-light);
    line-height: 1.6;
}
.word-card .hint .blank {
    display: inline-block;
    width: 3em;
    border-bottom: 2px solid var(--primary);
    margin: 0 2px;
}

.practice-input-area {
    text-align: center;
}
.practice-input-area input {
    width: 100%;
    max-width: 320px;
    padding: 16px 20px;
    font-size: 28px;
    border: 3px solid #E8E8E8;
    border-radius: 12px;
    text-align: center;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
}
.practice-input-area input:focus {
    border-color: var(--secondary);
}
.practice-input-area input.correct {
    border-color: var(--success);
    background: #EBFBEE;
}
.practice-input-area input.wrong {
    border-color: var(--primary);
    background: #FFF5F5;
    animation: shake 0.4s;
}
.practice-input-area .input-hint {
    font-size: 13px;
    color: var(--text-light);
    margin-top: 8px;
}

.action-buttons {
    display: flex;
    gap: 12px;
    margin-top: 20px;
    justify-content: center;
    flex-wrap: wrap;
}
.action-buttons .btn { min-width: 120px; }

/* Result overlay */
.result-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
}
.result-overlay.show { display: flex; }
.result-overlay .card {
    max-width: 360px;
    width: 90%;
    text-align: center;
    padding: 32px 24px;
    animation: popIn 0.3s;
}
.result-overlay .big-icon { font-size: 64px; margin-bottom: 12px; }
.result-overlay h2 { font-size: 22px; margin-bottom: 8px; }
.result-overlay p { color: var(--text-light); margin-bottom: 16px; font-size: 15px; }
.stars-row { font-size: 40px; margin: 12px 0; letter-spacing: 8px; }

/* Wrong Words */
.wrong-list { list-style: none; }
.wrong-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 0;
    border-bottom: 1px solid #F0F0F0;
    gap: 12px;
}
.wrong-item:last-child { border-bottom: none; }
.wrong-item .word-info { flex: 1; }
.wrong-item .word { font-size: 22px; font-weight: 700; }
.wrong-item .pinyin-sm { font-size: 13px; color: var(--text-light); }
.wrong-item .wrong-count {
    background: #FFF5F5;
    color: var(--primary);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}
.wrong-item .mastered {
    background: #EBFBEE;
    color: var(--success);
}

/* Stats Page */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}
.stat-card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    text-align: center;
}
.stat-card .num {
    font-size: 32px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), var(--purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.stat-card .label { font-size: 13px; color: var(--text-light); margin-top: 4px; }

/* Level badge */
.level-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 20px;
    border-radius: 50px;
    font-weight: 700;
    font-size: 18px;
}
.level-badge.level-1 { background: #E8E8E8; color: #666; }
.level-badge.level-2 { background: #FEF3C7; color: #92400E; }
.level-badge.level-3 { background: #E0E7FF; color: #3730A3; }
.level-badge.level-4 { background: #F3E8FF; color: #6B21A8; }
.level-badge.level-5 { background: linear-gradient(135deg, #FEF3C7, #FDE68A); color: #78350F; }
.level-badge.level-5 .star { animation: spin 3s linear infinite; display: inline-block; }

/* Bottom Nav */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--card);
    display: flex;
    justify-content: space-around;
    padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
    box-shadow: 0 -2px 20px rgba(0,0,0,0.06);
    z-index: 100;
    max-width: 480px;
    margin: 0 auto;
}
.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 16px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 11px;
    color: var(--text-light);
    transition: color 0.2s;
}
.nav-item .nav-icon { font-size: 24px; }
.nav-item.active { color: var(--primary); }
.nav-item.active .nav-icon { transform: scale(1.1); }

/* Animations */
@keyframes popIn {
    0% { transform: scale(0.5); opacity: 0; }
    70% { transform: scale(1.05); }
    100% { transform: scale(1); opacity: 1; }
}
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-8px); }
    75% { transform: translateX(8px); }
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}
@keyframes confetti-fall {
    0% { transform: translateY(-100px) rotate(0deg); opacity: 1; }
    100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}
@keyframes bounceIn {
    0% { transform: scale(0); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}
@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}
@keyframes slideUp {
    0% { transform: translateY(30px); opacity: 0; }
    100% { transform: translateY(0); opacity: 1; }
}

.star-animate {
    display: inline-block;
    animation: bounceIn 0.4s ease-out;
}

/* Confetti */
.confetti-container {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    pointer-events: none;
    z-index: 999;
    overflow: hidden;
}
.confetti-piece {
    position: absolute;
    width: 10px;
    height: 10px;
    animation: confetti-fall 2s ease-out forwards;
}

/* Session Summary */
.session-summary {
    text-align: center;
    padding: 20px 0;
}
.session-summary .big-score {
    font-size: 56px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--accent), var(--warning));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.session-summary .summary-stars { font-size: 32px; margin: 12px 0; letter-spacing: 4px; }

/* Badge System */
.badge-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin: 16px 0;
}
.badge {
    text-align: center;
    padding: 12px 8px;
    border-radius: 12px;
    background: var(--card);
    box-shadow: var(--shadow);
}
.badge .badge-icon { font-size: 36px; display: block; margin-bottom: 4px; }
.badge .badge-name { font-size: 11px; color: var(--text-light); }
.badge.locked { opacity: 0.4; filter: grayscale(1); }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-light);
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }

/* Quick actions */
.quick-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin: 16px 0;
}
.quick-action {
    padding: 20px;
    border-radius: var(--radius);
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    font-family: inherit;
    font-weight: 700;
}
.quick-action:active { transform: scale(0.96); }
.quick-action .qa-icon { font-size: 36px; display: block; margin-bottom: 8px; }
.quick-action .qa-label { font-size: 15px; }

/* Speech button */
.speak-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 2px solid var(--secondary);
    border-radius: 20px;
    background: transparent;
    color: var(--secondary);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 8px;
}
.speak-btn:active { background: var(--secondary); color: white; }

/* Review mode label */
.review-badge {
    display: inline-block;
    padding: 4px 12px;
    background: #FFF5F5;
    color: var(--primary);
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 8px;
}

/* Responsive */
@media (max-width: 360px) {
    .grade-grid { grid-template-columns: repeat(2, 1fr); }
    .stats-grid { grid-template-columns: 1fr; }
    .quick-actions { grid-template-columns: 1fr; }
    .badge-grid { grid-template-columns: repeat(3, 1fr); }
}

/* Streak fire */
.fire-icon { display: inline-block; }
.streak-active .fire-icon { animation: pulse 0.6s infinite; }

/* Today's target */
.target-progress {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 8px 0;
}
.target-bar {
    flex: 1;
    height: 10px;
    background: #E8E8E8;
    border-radius: 5px;
    overflow: hidden;
}
.target-bar .fill {
    height: 100%;
    background: linear-gradient(90deg, var(--warning), var(--primary));
    border-radius: 5px;
    transition: width 0.5s;
}

/* Responsive for tablets */
@media (min-width: 768px) {
    .page { max-width: 600px; }
    .word-card .pinyin { font-size: 36px; }
    .practice-input-area input { max-width: 400px; font-size: 32px; }
}

/* ===== 选字模式 ===== */
.char-select-area {
    margin: 16px 0;
    padding: 16px;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.char-options {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    min-height: 60px;
}

.char-option-btn {
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    font-weight: 700;
    border: 3px solid #E8E8E8;
    border-radius: 12px;
    background: var(--card);
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    font-family: inherit;
}
.char-option-btn:active {
    transform: scale(0.9);
    background: #F0F0F0;
}
.char-option-btn.selected {
    border-color: var(--secondary);
    background: #E8F8F6;
    transform: scale(1.05);
}
.char-option-btn.used {
    opacity: 0.3;
    pointer-events: none;
    transform: scale(0.85);
}
.char-option-btn.correct-highlight {
    border-color: var(--success);
    background: #EBFBEE;
    animation: bounceIn 0.3s;
}
.char-option-btn.wrong-highlight {
    border-color: var(--primary);
    background: #FFF5F5;
    animation: shake 0.3s;
}

.char-answer {
    text-align: center;
    margin-top: 12px;
    padding: 8px;
    min-height: 40px;
    border-bottom: 2px solid #E8E8E8;
}

/* 描红区域 */
.trace-area {
    margin: 16px 0;
    padding: 16px;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: center;
}

.hanzi-container {
    width: 200px;
    height: 200px;
    margin: 8px auto;
    position: relative;
}

.hanzi-container svg {
    width: 100%;
    height: 100%;
}

/* 选字模式提示 */
.char-hint-row {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-top: 8px;
    flex-wrap: wrap;
}
.char-hint-row .btn { min-width: 80px; }

/* 书写完成提示 */
.trace-complete {
    display: inline-block;
    padding: 8px 16px;
    background: #EBFBEE;
    color: var(--success);
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    animation: bounceIn 0.3s;
}

/* 字符进度指示 */
.char-position {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 14px;
    font-weight: 700;
    margin: 0 4px;
    background: #E8E8E8;
    color: var(--text-light);
    transition: all 0.3s;
}
.char-position.active {
    background: var(--secondary);
    color: white;
    transform: scale(1.15);
}
.char-position.done {
    background: var(--success);
    color: white;
}

/* ===== 模式切换 ===== */
.mode-toggle {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin: 0 0 12px;
    background: var(--card);
    border-radius: 50px;
    padding: 4px;
    box-shadow: var(--shadow);
}
.mode-btn {
    flex: 1;
    padding: 10px 16px;
    border: none;
    border-radius: 50px;
    background: transparent;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-light);
    font-family: inherit;
}
.mode-btn.active {
    background: linear-gradient(135deg, var(--secondary), var(--secondary-dark));
    color: white;
    box-shadow: 0 2px 8px rgba(78,205,196,0.3);
}

/* ===== 手写板 ===== */
.handwrite-area {
    margin: 16px 0;
    padding: 16px;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.handwrite-canvas-wrap {
    position: relative;
    width: 240px;
    height: 240px;
    margin: 0 auto;
}

.handwrite-canvas {
    width: 240px;
    height: 240px;
    border: 3px solid #DDD;
    border-radius: 8px;
    touch-action: none;
    cursor: crosshair;
    display: block;
}

/* 田字格背景 */
.handwrite-grid {
    position: absolute;
    top: 0; left: 0;
    width: 240px;
    height: 240px;
    pointer-events: none;
    border-radius: 8px;
}
.handwrite-grid::before,
.handwrite-grid::after {
    content: '';
    position: absolute;
    background: #E8E8E8;
}
.handwrite-grid::before {
    width: 1px;
    height: 100%;
    left: 50%;
    top: 0;
}
.handwrite-grid::after {
    height: 1px;
    width: 100%;
    top: 50%;
    left: 0;
}

.handwrite-controls {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-top: 8px;
}

@media (max-width: 360px) {
    .handwrite-canvas-wrap,
    .handwrite-canvas {
        width: 200px;
        height: 200px;
    }
    .handwrite-grid {
        width: 200px;
        height: 200px;
    }
}

/* 多字手写区域 */
.handwrite-canvases {
    display: flex;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.handwrite-canvas-item {
    position: relative;
    width: 200px;
    height: 200px;
}

.handwrite-canvas-item canvas {
    width: 100%;
    height: 100%;
    background: #fff;
    border: 2px solid #E8E8E8;
    border-radius: 8px;
    touch-action: none;
}

.handwrite-canvas-item .handwrite-grid {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    border-radius: 8px;
    overflow: hidden;
}

/* ===== 登录 ===== */
#login-overlay .card input:focus {
    border-color: var(--secondary) !important;
}
#login-overlay .card .action-buttons {
    margin-top: 4px;
}
#user-bar .btn-outline {
    border-width: 1px;
    padding: 2px 8px;
    font-size: 11px;
}
