:root {
    --purple: #9C27B0;
    --purple-light: #CE93D8;
    --orange: #FF9800;
    --orange-light: #FFCC80;
    --blue: #2196F3;
    --blue-light: #90CAF9;
    --green: #4CAF50;
    --green-light: #A5D6A7;
    --red: #F44336;
    --bg: #F3E5F5;
    --bg-card: #FFFFFF;
    --text: #212121;
    --text-dim: #757575;
    --radius: 16px;
    --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

/* Pages */
.page {
    display: none;
    flex: 1;
    flex-direction: column;
    overflow-y: auto;
    padding: 16px;
    padding-bottom: 80px;
}
.page.active { display: flex; }

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0 16px;
}
.page-header h1 {
    font-size: 1.4rem;
    color: var(--purple);
}
.page-body { flex: 1; }
.page-footer {
    padding: 16px 0;
    text-align: center;
}
.center-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
}

/* Bottom Nav */
#bottom-nav {
    display: flex;
    background: var(--bg-card);
    border-top: 1px solid #E0E0E0;
    padding: 4px 0;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 50;
}
.nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 6px 0;
    border: none;
    background: none;
    color: var(--text-dim);
    font-size: 0.75rem;
    cursor: pointer;
}
.nav-btn .nav-icon { font-size: 1.4rem; }
.nav-btn.active { color: var(--purple); }
.nav-btn.active .nav-icon { transform: scale(1.1); }

/* Buttons */
.btn-primary {
    background: var(--purple);
    color: white;
    border: none;
    border-radius: var(--radius);
    padding: 14px 32px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s;
}
.btn-primary:active { transform: scale(0.95); }

.btn-secondary {
    background: var(--orange);
    color: white;
    border: none;
    border-radius: var(--radius);
    padding: 12px 24px;
    font-size: 1rem;
    cursor: pointer;
}
.btn-secondary:active { transform: scale(0.95); }

.btn-danger {
    background: var(--red);
    color: white;
    border: none;
    border-radius: var(--radius);
    padding: 12px 24px;
    font-size: 1rem;
    cursor: pointer;
    margin-top: 24px;
}

.btn-back {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: var(--purple);
    cursor: pointer;
    padding: 4px 8px;
}

.btn-play-large {
    background: var(--blue);
    color: white;
    border: none;
    border-radius: 50%;
    width: 80px;
    height: 80px;
    font-size: 1.8rem;
    cursor: pointer;
    transition: transform 0.1s;
    align-self: center;
}
.btn-play-large:active { transform: scale(0.9); }

.btn-record {
    background: var(--red);
    color: white;
    border: none;
    border-radius: var(--radius);
    padding: 16px 32px;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.1s;
}
.btn-record.recording {
    background: #D32F2F;
    transform: scale(1.05);
    box-shadow: 0 0 20px rgba(244,67,54,0.5);
}

.btn-mode {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    background: var(--bg-card);
    border: 2px solid var(--purple-light);
    border-radius: var(--radius);
    padding: 24px 32px;
    cursor: pointer;
    transition: transform 0.1s;
}
.btn-mode:active { transform: scale(0.95); }
.mode-icon { font-size: 2.5rem; }
.mode-label { font-size: 1.1rem; color: var(--purple); font-weight: 600; }

/* Tone Cards */
.tone-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 8px 0;
}
.tone-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px 16px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    cursor: pointer;
    transition: transform 0.15s;
}
.tone-card:active { transform: scale(0.95); }
.tone-card.active { border: 2px solid var(--purple); }
.tone-symbol { font-size: 3rem; font-weight: 700; }
.tone-name { font-size: 1rem; color: var(--text-dim); margin-top: 4px; }
.tone-desc { font-size: 0.85rem; color: var(--text-dim); margin-top: 4px; }
.tone-indicators {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 16px;
}
.tone-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    background: #E0E0E0;
}
.tone-dot.active { background: var(--purple); }

/* World Map */
.world-map {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px 0;
}
.level-node {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    cursor: pointer;
    transition: transform 0.15s;
}
.level-node:active { transform: scale(0.95); }
.level-island {
    width: 80px; height: 80px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: 700;
    color: white;
    position: relative;
}
.level-island.green { background: var(--green); }
.level-island.orange { background: var(--orange); }
.level-island.blue { background: var(--blue); }
.level-island.locked { opacity: 0.4; }
.level-stars {
    display: flex;
    gap: 2px;
    margin-top: 4px;
    font-size: 0.9rem;
}
.level-name {
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-top: 2px;
    text-align: center;
    max-width: 120px;
}
.level-lock {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.5rem;
}
.level-current {
    position: absolute;
    top: -4px; right: -4px;
    width: 16px; height: 16px;
    border-radius: 50%;
    background: var(--orange);
    animation: pulse 1.5s infinite;
}
@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.3); opacity: 0.7; }
}
.path-connector {
    width: 4px; height: 24px;
    background: var(--purple-light);
    border-radius: 2px;
}
.total-stars { font-size: 1.1rem; }

/* Practice */
.practice-header {
    padding: 8px 0;
}
.practice-stats {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.stat-lives { font-size: 1rem; letter-spacing: 2px; }
.stat-combo { font-size: 0.9rem; color: var(--orange); font-weight: 600; }
.stat-score { font-size: 1rem; font-weight: 600; }
.practice-progress {
    height: 6px;
    background: #E0E0E0;
    border-radius: 3px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: var(--purple);
    border-radius: 3px;
    transition: width 0.3s;
    width: 0%;
}
.practice-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
}
.practice-prompt { font-size: 1.2rem; color: var(--text-dim); }
.practice-choices {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    width: 100%;
    max-width: 300px;
}
.tone-choice-btn {
    padding: 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 1.5rem;
    font-weight: 700;
    color: white;
    cursor: pointer;
    transition: transform 0.1s;
}
.tone-choice-btn:active { transform: scale(0.95); }
.tone-choice-btn.t1 { background: var(--green); }
.tone-choice-btn.t2 { background: var(--blue); }
.tone-choice-btn.t3 { background: var(--orange); }
.tone-choice-btn.t4 { background: var(--red); }
.tone-choice-btn.correct { box-shadow: 0 0 0 4px var(--green); }
.tone-choice-btn.wrong { box-shadow: 0 0 0 4px var(--red); opacity: 0.6; }

.pinyin-large {
    font-size: 5rem;
    font-weight: 700;
    color: var(--purple);
    line-height: 1;
}
.pinyin-hint {
    font-size: 2rem;
    color: var(--text-dim);
    text-align: center;
}

.record-result {
    text-align: center;
    font-size: 1.1rem;
    padding: 12px;
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    width: 100%;
    max-width: 300px;
}

/* Writing Canvas */
.writing-canvas {
    border: 3px solid var(--purple-light);
    border-radius: var(--radius);
    background: white;
    touch-action: none;
    width: 100%;
    max-width: 320px;
    aspect-ratio: 1;
}
.writing-controls {
    display: flex;
    gap: 12px;
    width: 100%;
    max-width: 320px;
}
.writing-controls .btn-secondary,
.writing-controls .btn-primary {
    flex: 1;
    text-align: center;
}

/* Profile */
.avatar { font-size: 4rem; }
.profile-name { font-size: 1.3rem; font-weight: 600; }
.profile-level { font-size: 1rem; color: var(--text-dim); }
.profile-stars { font-size: 1.5rem; margin-top: 8px; }
.profile-combo { font-size: 0.9rem; color: var(--text-dim); }

/* Modal */
#modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 100;
}

/* Result card */
.result-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    width: 100%;
    max-width: 300px;
}
.result-card h2 { font-size: 1.5rem; margin-bottom: 8px; }
.result-card .result-stars { font-size: 2rem; margin: 8px 0; }
.result-card .result-detail { font-size: 0.9rem; color: var(--text-dim); margin: 4px 0; }

/* Responsive */
@media (min-width: 600px) {
    .page { max-width: 480px; margin: 0 auto; }
    #bottom-nav { max-width: 480px; margin: 0 auto; left: 50%; transform: translateX(-50%); }
}
