:root {
    /* Colorful Palette */
    --primary-color: #6366F1; /* Indigo */
    --bg-color: #F0F4FF;      /* Light Blue/White */
    --card-bg: #FFFFFF;
    --text-color: #1F2937;    /* Dark Gray */
    --success-color: #10B981; /* Emerald */
    --error-color: #EF4444;   /* Red */
    --secondary-bg: #E0E7FF;  /* Light Indigo */
    --input-bg: #F9FAFB;
    --border-color: #E5E7EB;
    
    --accent-yellow: #F59E0B; /* Amber */
    --accent-purple: #8B5CF6; /* Violet */
    --accent-pink: #EC4899;   /* Pink */
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
    background-color: var(--bg-color);
    background-image: linear-gradient(135deg, #F0F4FF 0%, #E0E7FF 100%);
    color: var(--text-color);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 16px; /* Base size */
}

#app {
    width: 100%;
    max-width: 600px;
    height: 100vh;
    background-color: var(--card-bg);
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

/* Header */
header {
    padding: 1rem;
    background-color: white;
    color: var(--text-color);
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}

.header-left {
    justify-self: start;
}

.header-center {
    justify-self: center;
    text-align: center;
}

.header-right {
    justify-self: end;
}

#header-title {
    font-size: 1.25rem; /* 20px */
    font-weight: 700;
    color: var(--text-color);
}

/* Old level-info removed */

/* Navigation */
.nav-bar {
    display: flex;
    justify-content: space-around;
    padding: 1rem;
    background: white;
    border-top: 1px solid var(--border-color);
}

.nav-item {
    text-align: center;
    cursor: pointer;
    color: #6B7280;
    font-size: 0.9rem;
    transition: color 0.2s;
}

.nav-item.active {
    color: var(--primary-color);
    font-weight: 600;
}

/* Pages */
.page {
    flex: 1;
    overflow-y: auto;
    display: none; /* Managed by JS */
    flex-direction: column;
    position: relative;
}

.page.active {
    display: flex;
}

/* Home Page */
#home-page {
    justify-content: center;
    align-items: center;
    padding: 2rem;
    text-align: center;
    background: linear-gradient(to bottom right, #EEF2FF, #FFFFFF);
}

.home-illustration {
    width: 200px;
    height: 200px;
    background-color: #E0E7FF;
    border-radius: 50%;
    margin-bottom: 2rem;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 4rem;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

.home-title {
    font-size: 2rem; /* 32px */
    font-weight: 800;
    background: linear-gradient(to right, var(--primary-color), var(--accent-purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.5rem;
}

.home-subtitle {
    color: #6B7280;
    margin-bottom: 3rem;
    font-size: 1rem; /* 16px */
}

/* Progress Page */
#progress-page {
    padding: 2rem;
}

.stat-card {
    background: white;
    padding: 1.5rem;
    border-radius: 1rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
    text-align: center;
}

.stat-value {
    font-size: 2rem; /* 32px */
    font-weight: 700;
    color: var(--primary-color);
}

.stat-label {
    color: #6B7280;
    font-size: 0.875rem; /* 14px */
}

/* Level Grid */
.level-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.5rem;
    padding: 1rem;
}

.level-item {
    aspect-ratio: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 0.5rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    background: white;
    border: 1px solid var(--border-color);
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
}

.level-item:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.level-item.completed {
    background-color: var(--success-color);
    color: white;
    border-color: var(--success-color);
}

.level-item.current {
    background-color: white;
    border: 2px solid var(--primary-color);
    color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

.level-item.failed {
    background-color: var(--error-color);
    color: white;
    border-color: var(--error-color);
}

.level-item.locked {
    background-color: #F3F4F6;
    color: #9CA3AF;
}

/* Game Board */
#game-board {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem;
}

.progress-bar {
    width: 100%;
    height: 4px;
    background-color: #E5E7EB;
    margin-bottom: 1rem;
}

.progress-fill {
    height: 100%;
    background-color: var(--primary-color);
    width: 0%;
    transition: width 0.3s;
}

#display-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 100%;
    min-height: 200px;
}

.display-item {
    font-size: 5rem;
    font-weight: bold;
    color: var(--primary-color);
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
    from { transform: scale(0.5); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.message {
    font-size: 1.5rem; /* 24px */
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--text-color);
}

/* Answer Slots */
.answer-slots-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
    margin: 1rem 0;
    min-height: 60px;
}

.answer-slot {
    width: 40px;
    height: 40px;
    border: 2px solid var(--border-color);
    border-radius: 0.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
    background: white;
    cursor: pointer;
}

.answer-slot.active {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.answer-slot.correct {
    border-color: var(--success-color);
    background-color: #ECFDF5;
    color: var(--success-color);
}

.answer-slot.incorrect {
    border-color: var(--error-color);
    background-color: #FEF2F2;
    color: var(--error-color);
}

/* Input Area & Keyboard */
#input-area {
    background: white;
    padding: 1rem;
    border-top: 1px solid var(--border-color);
    display: none; /* Managed by JS */
}

.keyboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    gap: 0.5rem;
    max-height: 200px;
    overflow-y: auto;
}

.key-btn {
    height: 40px;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 0.25rem;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    font-size: 1.2rem;
    transition: background 0.1s;
}

.key-btn:active {
    background: var(--secondary-bg);
}

/* Tabs for Icons */
.tabs-container {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    overflow-x: auto;
    padding-bottom: 0.5rem;
}

.tab-btn {
    padding: 0.25rem 0.75rem;
    border: 1px solid var(--border-color);
    background: white;
    border-radius: 1rem;
    cursor: pointer;
    white-space: nowrap;
    font-size: 0.8rem;
}

.tab-btn.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* Controls */
.controls {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
}

.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 0.5rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.95rem; /* ~15px */
}

.btn-primary {
    background: linear-gradient(to right, var(--primary-color), var(--accent-purple));
    color: white;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.btn:active, .btn-active-mode {
    transform: translateY(2px);
    filter: brightness(0.9);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

.btn:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
}

.btn-secondary {
    background: white;
    border: 1px solid var(--border-color);
    color: var(--text-color);
}

.btn-secondary:hover {
    background: var(--input-bg);
}

.btn-danger {
    background: var(--error-color);
    color: white;
}

/* Config Page Styles */
#config-page {
    padding: 1rem;
}

.config-container {
    padding-bottom: 2rem;
}

.config-section {
    background: white;
    padding: 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.config-section h3 {
    margin-bottom: 0.75rem;
    color: var(--primary-color);
    font-size: 1.1rem;
    border-bottom: 1px solid #f3f4f6;
    padding-bottom: 0.5rem;
}

.form-row {
    display: flex;
    gap: 0.5rem;
}

.form-group {
    margin-bottom: 0.5rem;
    flex: 1;
}

.form-group label {
    display: block;
    font-size: 0.9rem; /* 14.4px */
    color: #6B7280;
    margin-bottom: 0.25rem;
}

.form-input {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 0.25rem;
    font-size: 0.9rem;
    background-color: var(--input-bg);
}

.form-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.1);
}

/* Achievements */
.badges-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr); /* Force 3 columns for alignment */
    gap: 1rem;
    padding: 1rem;
    /* justify-content: center; Remove to align left/grid */
    /* text-align: center; */
}

.badge-item {
    background: white;
    border: 2px solid var(--success-color);
    border-radius: 0.5rem;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    height: 100%; /* Ensure equal height */
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.badge-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.badge-title {
    font-weight: bold;
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
    color: var(--text-color);
}

.badge-desc {
    font-size: 0.75rem;
    color: #6B7280;
}

/* Practice Grid */
.practice-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    padding: 1rem;
}

.practice-item {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.practice-item:hover {
    transform: translateY(-2px);
    border-color: var(--primary-color);
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
}

.practice-item .icon {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.practice-item .title {
    font-weight: 600;
    color: var(--text-color);
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.3s;
}

.modal-content {
    background: white;
    padding: 1.5rem;
    border-radius: 1rem;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    animation: slideUp 0.3s;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    margin: 0;
    color: var(--text-color);
}

.close-modal {
    font-size: 1.5rem;
    color: #9CA3AF;
    cursor: pointer;
    line-height: 1;
}

.close-modal:hover {
    color: var(--error-color);
}

.share-text {
    text-align: center;
    margin-bottom: 1.5rem;
    color: var(--text-color);
    line-height: 1.5;
}

.share-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-bottom: 1.5rem;
}

.share-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border: none;
    border-radius: 0.5rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s;
    color: white;
}

.share-btn:hover {
    transform: translateY(-2px);
    filter: brightness(1.1);
}

.share-btn.wechat {
    background-color: #07C160; /* WeChat Green */
}

.share-btn.qq {
    background-color: #12B7F5; /* QQ Blue */
}

.share-footer {
    text-align: center;
    font-size: 0.9rem;
    color: #6B7280;
    border-top: 1px solid var(--border-color);
    padding-top: 1rem;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* Role Restricted - Hidden by default until JS authorizes */
.role-restricted {
    display: none !important;
}
