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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
}

body {
    background: linear-gradient(180deg, #ffeef8 0%, #e8f4ff 50%, #fff0f5 100%);
}

#app {
    width: 100%;
    height: 100%;
    position: relative;
}

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
}

.screen.active {
    display: flex;
}

/* ===== Menu Screen ===== */
.menu-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 40px 20px;
    position: relative;
}

.user-panel {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px 8px 16px;
    margin-bottom: 10px;
    border: 2px solid rgba(196, 76, 255, 0.18);
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.78);
    box-shadow: 0 4px 14px rgba(196, 76, 255, 0.12);
    color: #6b4e7a;
    font-size: 0.95rem;
}

.user-label strong {
    color: #8b5cf6;
}

.user-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#current-avatar {
    margin-right: 2px;
    font-size: 1.15rem;
}

.user-switch-btn {
    border: none;
    border-radius: 18px;
    padding: 7px 13px;
    background: linear-gradient(135deg, #c44cff 0%, #8b5cf6 100%);
    color: #fff;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.user-switch-btn:active {
    transform: scale(0.94);
}

.game-title {
    font-size: 3.5rem;
    text-align: center;
    background: linear-gradient(135deg, #ff6b9d 0%, #c44cff 50%, #6eb5ff 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 4px 20px rgba(255, 107, 157, 0.3);
    margin-bottom: 20px;
    font-weight: 800;
    letter-spacing: 4px;
    animation: titleFloat 3s ease-in-out infinite;
}

@keyframes titleFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.pony-decoration {
    width: 200px;
    height: 200px;
    margin: 20px 0;
}

.difficulty-buttons {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
    max-width: 320px;
    margin-bottom: 30px;
}

.difficulty-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 30px;
    border: none;
    border-radius: 25px;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
    position: relative;
    overflow: hidden;
}

.difficulty-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    transition: left 0.5s;
}

.difficulty-btn:hover::before,
.difficulty-btn:active::before {
    left: 100%;
}

.difficulty-btn.easy {
    background: linear-gradient(135deg, #a8e6cf 0%, #7fcdbb 100%);
    color: #2d5a47;
}

.difficulty-btn.medium {
    background: linear-gradient(135deg, #ffd93d 0%, #ffb347 100%);
    color: #6b4e00;
}

.difficulty-btn.hard {
    background: linear-gradient(135deg, #ff6b9d 0%, #ff4757 100%);
    color: #fff;
}

.difficulty-btn.infinite {
    background: linear-gradient(135deg, #6eb5ff 0%, #4facfe 100%);
    color: #fff;
}

.difficulty-btn.hell {
    background: linear-gradient(135deg, #8b0000 0%, #ff4500 50%, #dc143c 100%);
    color: #fff;
    animation: hellGlow 1.5s ease-in-out infinite;
}

@keyframes hellGlow {
    0%, 100% { box-shadow: 0 6px 20px rgba(139, 0, 0, 0.5); }
    50% { box-shadow: 0 6px 30px rgba(255, 69, 0, 0.8), 0 0 40px rgba(255, 69, 0, 0.4); }
}

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

.difficulty-btn .star {
    font-size: 1.5rem;
    margin-bottom: 4px;
}

.difficulty-btn .label {
    font-weight: 700;
    font-size: 1.4rem;
}

.difficulty-btn .desc {
    font-size: 0.9rem;
    opacity: 0.8;
    margin-top: 4px;
}

.collection-btn {
    background: linear-gradient(135deg, #c44cff 0%, #8b5cf6 100%);
    color: white;
    border: none;
    padding: 16px 40px;
    border-radius: 30px;
    font-size: 1.2rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(196, 76, 255, 0.4);
    transition: all 0.3s ease;
}

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

.leaderboard-btn {
    margin-top: 12px;
    border: 2px solid #ffd76a;
    border-radius: 24px;
    padding: 11px 30px;
    background: rgba(255, 255, 255, 0.82);
    color: #9a6b00;
    font-size: 1.05rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(255, 190, 46, 0.2);
    transition: transform 0.2s ease;
}

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

.visual-math-btn,
.parent-btn {
    border: none;
    padding: 13px 32px;
    border-radius: 26px;
    color: #fff;
    font-size: 1.08rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 5px 16px rgba(0, 0, 0, 0.15);
    transition: transform 0.2s ease;
}

.visual-math-btn {
    background: linear-gradient(135deg, #ffb347 0%, #ff7f50 100%);
    margin-bottom: 10px;
}

.visual-math-actions {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    width: min(88vw, 360px);
}

.visual-math-secondary {
    padding: 10px 24px;
    background: linear-gradient(135deg, #f5a6d8 0%, #a982e8 100%);
    font-size: 0.98rem;
}

.parent-btn {
    margin-top: 10px;
    background: linear-gradient(135deg, #5ec6a6 0%, #2d9d84 100%);
}

.visual-math-btn:active,
.parent-btn:active {
    transform: scale(0.95);
}

/* ===== Game Screen ===== */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: linear-gradient(180deg, rgba(255,255,255,0.9) 0%, rgba(255,255,255,0.7) 100%);
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.back-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 100%);
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(255, 154, 158, 0.4);
    transition: transform 0.2s;
}

.back-btn:active {
    transform: scale(0.9);
}

.score-display,
.timer-display,
.streak-display {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.8);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 1.2rem;
    font-weight: 700;
}

.score-display {
    color: #ff6b9d;
}

.timer-display {
    color: #6eb5ff;
}

.streak-display {
    color: #ff8c42;
}

.game-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    position: relative;
}

.pony-helper {
    width: 120px;
    height: 120px;
    position: absolute;
    top: 10px;
    right: 20px;
}

.question-container {
    margin-bottom: 40px;
}

.question-card {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    background: white;
    padding: 30px 50px;
    border-radius: 30px;
    box-shadow: 0 10px 40px rgba(255, 107, 157, 0.2);
    border: 4px solid #ffeef8;
}

.number {
    font-size: 4rem;
    font-weight: 800;
    color: #c44cff;
    min-width: 80px;
    text-align: center;
}

.operator {
    font-size: 3rem;
    font-weight: 700;
    color: #ff6b9d;
}

.equals {
    font-size: 3rem;
    font-weight: 700;
    color: #6eb5ff;
}

.answer-box {
    font-size: 4rem;
    font-weight: 800;
    color: #2d5a47;
    background: linear-gradient(135deg, #e8f4ff 0%, #ffeef8 100%);
    padding: 10px 30px;
    border-radius: 20px;
    min-width: 100px;
    text-align: center;
    border: 3px dashed #c44cff;
}

.answer-buttons {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    width: 100%;
    max-width: 400px;
    padding: 0 20px;
}

.answer-btn {
    padding: 25px 20px;
    font-size: 2rem;
    font-weight: 700;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.1);
}

.answer-btn:nth-child(1) { background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 100%); color: #8b3a62; }
.answer-btn:nth-child(2) { background: linear-gradient(135deg, #a8e6cf 0%, #7fcdbb 100%); color: #2d5a47; }
.answer-btn:nth-child(3) { background: linear-gradient(135deg, #ffd93d 0%, #ffb347 100%); color: #6b4e00; }
.answer-btn:nth-child(4) { background: linear-gradient(135deg, #6eb5ff 0%, #4facfe 100%); color: #1a4a6e; }
.answer-btn:nth-child(5) { background: linear-gradient(135deg, #c44cff 0%, #8b5cf6 100%); color: white; }
.answer-btn:nth-child(6) { background: linear-gradient(135deg, #ff6b9d 0%, #ff4757 100%); color: white; }

.answer-btn:active {
    transform: scale(0.92);
}

.answer-btn.correct {
    animation: correctPulse 0.5s ease;
}

.answer-btn.wrong {
    animation: wrongShake 0.5s ease;
}

@keyframes correctPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.15); box-shadow: 0 0 30px rgba(168, 230, 207, 0.8); }
    100% { transform: scale(1); }
}

@keyframes wrongShake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-10px); }
    40%, 80% { transform: translateX(10px); }
}

.progress-bar {
    position: relative;
    width: 100%;
    max-width: 400px;
    height: 30px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 15px;
    margin-top: 30px;
    overflow: hidden;
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.1);
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #ff6b9d 0%, #c44cff 50%, #6eb5ff 100%);
    border-radius: 15px;
    transition: width 0.3s ease;
    width: 0%;
}

.progress-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.9rem;
    font-weight: 600;
    color: #666;
}

.feedback-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 100;
}

.feedback-content {
    font-size: 5rem;
    animation: feedbackPop 0.6s ease forwards;
    opacity: 0;
}

@keyframes feedbackPop {
    0% { transform: scale(0); opacity: 0; }
    50% { transform: scale(1.3); opacity: 1; }
    100% { transform: scale(1); opacity: 0; }
}

/* ===== Collection Screen ===== */
.collection-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: linear-gradient(180deg, rgba(255,255,255,0.9) 0%, rgba(255,255,255,0.7) 100%);
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.collection-header h2 {
    font-size: 1.5rem;
    background: linear-gradient(135deg, #c44cff 0%, #8b5cf6 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.collection-count {
    font-weight: 600;
    color: #666;
}

.collection-grid {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    padding: 10px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    align-content: start;
}

.collection-card {
    width: 100%;
    background: transparent;
    border-radius: 15px;
    display: block;
    position: relative;
}

.collection-card.locked .pony-card {
    filter: grayscale(100%) brightness(0.5);
}

.collection-card.locked .rainbow-border::before,
.collection-card.locked .rainbow-border::after {
    background: linear-gradient(135deg, #666 0%, #888 50%, #666 100%);
    animation: none;
}

.lock-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 12px;
    z-index: 10;
}

.collection-card.collected {
    animation: cardGlow 2s ease-in-out infinite alternate;
}

@keyframes cardGlow {
    0% { filter: drop-shadow(0 0 5px rgba(255, 215, 0, 0.3)); }
    100% { filter: drop-shadow(0 0 15px rgba(255, 215, 0, 0.6)); }
}

.collection-card .card-image {
    width: 80%;
    height: 60%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.collection-card .card-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: #666;
    margin-top: 8px;
    text-align: center;
}

/* ===== Popup ===== */
.popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.popup.hidden {
    display: none;
}

.hidden {
    display: none !important;
}

.popup-content {
    background: white;
    border-radius: 30px;
    padding: 40px;
    text-align: center;
    max-width: 90%;
    width: 350px;
    position: relative;
    animation: popupIn 0.4s ease;
}

@keyframes popupIn {
    0% { transform: scale(0.5); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.popup-content h2 {
    font-size: 1.5rem;
    color: #c44cff;
    margin-bottom: 20px;
}

.card-showcase {
    width: 170px;
    margin: 20px auto;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: cardFloat 2s ease-in-out infinite;
}

.card-reward-message {
    color: #777;
    margin: -8px 0 10px;
}

@keyframes cardFloat {
    0%, 100% { transform: translateY(0) rotate(-2deg); }
    50% { transform: translateY(-10px) rotate(2deg); }
}

.popup-btn {
    background: linear-gradient(135deg, #ff6b9d 0%, #c44cff 100%);
    color: white;
    border: none;
    padding: 15px 40px;
    border-radius: 25px;
    font-size: 1.2rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(196, 76, 255, 0.4);
    transition: transform 0.2s;
}

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

.user-switcher {
    width: min(92vw, 390px);
    max-height: 90vh;
    overflow-y: auto;
    padding: 30px;
}

.user-switch-hint {
    color: #777;
    font-size: 0.95rem;
    line-height: 1.5;
    margin: -8px 0 16px;
}

.avatar-picker-section {
    margin: 4px 0 20px;
    padding: 14px;
    border-radius: 18px;
    background: linear-gradient(135deg, #fffaf0 0%, #f7f0ff 100%);
    border: 2px solid #f2e5ff;
}

.avatar-picker-title {
    margin-bottom: 10px;
    color: #6b4e7a;
    font-size: 0.9rem;
    font-weight: 700;
    text-align: left;
}

.avatar-options {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
}

.avatar-option {
    aspect-ratio: 1;
    border: 2px solid transparent;
    border-radius: 14px;
    background: #fff;
    font-size: 1.7rem;
    cursor: pointer;
    transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.avatar-option:hover,
.avatar-option:focus-visible {
    transform: scale(1.08);
    border-color: #c44cff;
}

.avatar-option.active {
    border-color: #8b5cf6;
    background: #eee4ff;
    box-shadow: 0 3px 9px rgba(139, 92, 246, 0.25);
}

.save-avatar-btn {
    width: 100%;
    margin-top: 10px;
    padding: 9px 15px;
    font-size: 0.95rem;
}

.user-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 190px;
    overflow-y: auto;
    margin-bottom: 20px;
    padding: 2px;
}

.user-option {
    width: 100%;
    border: 2px solid #eadcff;
    border-radius: 16px;
    padding: 12px 15px;
    background: #fbf8ff;
    color: #7046a0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.05rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.user-option:hover,
.user-option:focus-visible {
    border-color: #c44cff;
    background: #f4eaff;
}

.user-option.active {
    border-color: #8b5cf6;
    background: linear-gradient(135deg, #f4eaff 0%, #e8f4ff 100%);
    box-shadow: 0 3px 10px rgba(139, 92, 246, 0.2);
}

.user-card-count {
    color: #999;
    font-size: 0.82rem;
    font-weight: 500;
}

.new-user-form {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    text-align: left;
}

.new-user-form label {
    color: #6b4e7a;
    font-size: 0.9rem;
    font-weight: 600;
}

.new-user-row {
    display: flex;
    gap: 8px;
}

.new-user-row input {
    flex: 1;
    min-width: 0;
    border: 2px solid #eadcff;
    border-radius: 15px;
    padding: 11px 13px;
    font-size: 1rem;
    outline: none;
}

.new-user-row input:focus {
    border-color: #8b5cf6;
}

.create-user-btn {
    padding: 10px 17px;
    font-size: 0.95rem;
    white-space: nowrap;
}

.user-cancel-btn {
    margin-top: 16px;
    background: linear-gradient(135deg, #b9c6d6 0%, #8d9bab 100%);
    box-shadow: 0 4px 12px rgba(90, 105, 120, 0.25);
}

/* ===== Leaderboard ===== */
.leaderboard-header {
    gap: 14px;
}

.leaderboard-header > div {
    flex: 1;
    text-align: center;
}

.leaderboard-header h2 {
    margin: 0;
}

.leaderboard-header p {
    margin-top: 3px;
    color: #999;
    font-size: 0.78rem;
}

.leaderboard-no-password {
    color: #8b5cf6;
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
}

.leaderboard-list {
    flex: 1;
    width: min(94%, 680px);
    margin: 0 auto;
    padding: 22px 0 30px;
    overflow-y: auto;
}

.leaderboard-item {
    display: grid;
    grid-template-columns: 42px 46px minmax(0, 1fr) auto;
    gap: 11px;
    align-items: center;
    margin-bottom: 12px;
    padding: 13px 16px;
    border: 2px solid rgba(196, 76, 255, 0.12);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.86);
    box-shadow: 0 4px 13px rgba(125, 82, 170, 0.1);
}

.leaderboard-item.current-user {
    border-color: #8b5cf6;
    background: linear-gradient(135deg, #f5edff 0%, #eef8ff 100%);
}

.leaderboard-rank {
    color: #8c7b99;
    font-size: 1.2rem;
    font-weight: 800;
    text-align: center;
}

.leaderboard-rank.rank-1,
.leaderboard-rank.rank-2,
.leaderboard-rank.rank-3 {
    font-size: 1.7rem;
}

.leaderboard-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: #fff6d8;
    font-size: 1.65rem;
}

.leaderboard-identity {
    display: flex;
    flex-direction: column;
    min-width: 0;
    gap: 3px;
}

.leaderboard-identity strong {
    overflow: hidden;
    color: #604476;
    font-size: 1.05rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.leaderboard-identity span {
    overflow: hidden;
    color: #999;
    font-size: 0.78rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.leaderboard-score {
    color: #c44cff;
    font-size: 1.35rem;
    font-weight: 800;
}

.leaderboard-loading,
.leaderboard-empty {
    padding: 50px 20px;
    color: #999;
    text-align: center;
}

/* ===== Wrong Answer Popup ===== */
.wrong-answer {
    background: linear-gradient(180deg, #fff5f5 0%, #ffe8ec 100%);
    border: 4px solid #ff6b9d;
}

.sad-pony-showcase {
    width: 120px;
    height: 120px;
    margin: 0 auto 15px;
}

.wrong-title {
    font-size: 1.8rem;
    color: #ff4757;
    margin-bottom: 10px;
}

.wrong-message {
    font-size: 1.1rem;
    color: #666;
    margin-bottom: 20px;
}

.correct-answer-box {
    background: linear-gradient(135deg, #e8f4ff 0%, #d4f5e9 100%);
    border-radius: 20px;
    padding: 15px 30px;
    margin-bottom: 25px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    border: 3px solid #27ae60;
}

.correct-label {
    font-size: 1.2rem;
    color: #2d5a47;
    font-weight: 600;
}

.correct-number {
    font-size: 3rem;
    font-weight: 800;
    color: #27ae60;
    animation: numberPop 0.5s ease;
}

.wrong-btn {
    background: linear-gradient(135deg, #6eb5ff 0%, #4facfe 100%);
    box-shadow: 0 6px 20px rgba(110, 181, 255, 0.4);
}

.sparkles {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
}

/* ===== iPad Specific ===== */
@media (min-width: 768px) {
    .game-title {
        font-size: 5rem;
    }

    .difficulty-buttons {
        flex-direction: row;
        max-width: 700px;
    }

    .difficulty-btn {
        flex: 1;
    }

    .question-card {
        padding: 40px 70px;
    }

    .number {
        font-size: 5rem;
    }

    .answer-buttons {
        max-width: 600px;
    }

    .answer-btn {
        padding: 35px 30px;
        font-size: 2.5rem;
    }

    .collection-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 20px;
        padding: 30px;
    }
}

/* ===== Landscape iPad ===== */
@media (min-width: 1024px) {
    .game-area {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        align-items: center;
    }

    .question-container {
        width: 100%;
    }

    .answer-buttons {
        grid-template-columns: repeat(6, 1fr);
        max-width: 800px;
    }
}

/* ===== Pony Card Styles ===== */
.pony-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    border-radius: 15px;
    overflow: hidden;
    background: linear-gradient(145deg, #1a1a2e 0%, #16213e 50%, #0f0f23 100%);
    padding: 6px;
}

.pony-card-image {
    width: 100%;
    flex: 1;
    object-fit: contain;
    border-radius: 10px;
}

.pony-card-text {
    width: 100%;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 700;
    padding: 6px 4px;
    background: linear-gradient(135deg, #ffd700 0%, #ffec8b 50%, #ffd700 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
    flex-shrink: 0;
}

/* Rainbow Border Animation */
.rainbow-border {
    position: relative;
    z-index: 1;
}

.rainbow-border::before {
    content: '';
    position: absolute;
    top: -3px;
    left: -3px;
    right: -3px;
    bottom: -3px;
    z-index: -1;
    border-radius: 18px;
    background: linear-gradient(
        45deg,
        #ff0000,
        #ff7f00,
        #ffff00,
        #00ff00,
        #0000ff,
        #4b0082,
        #9400d3,
        #ff0000
    );
    background-size: 400% 400%;
    animation: rainbowMove 3s ease infinite;
}

.rainbow-border::after {
    content: '';
    position: absolute;
    top: -3px;
    left: -3px;
    right: -3px;
    bottom: -3px;
    z-index: -1;
    border-radius: 18px;
    background: linear-gradient(
        45deg,
        #ff0000,
        #ff7f00,
        #ffff00,
        #00ff00,
        #0000ff,
        #4b0082,
        #9400d3,
        #ff0000
    );
    background-size: 400% 400%;
    animation: rainbowMove 3s ease infinite;
    filter: blur(8px);
    opacity: 0.7;
}

@keyframes rainbowMove {
    0% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
    100% {
        background-position: 0% 50%;
    }
}

/* Gold Border Variant */
.gold-border {
    position: relative;
    z-index: 1;
}

.gold-border::before {
    content: '';
    position: absolute;
    top: -3px;
    left: -3px;
    right: -3px;
    bottom: -3px;
    z-index: -1;
    border-radius: 18px;
    background: linear-gradient(
        135deg,
        #ffd700 0%,
        #ffec8b 25%,
        #ffd700 50%,
        #b8860b 75%,
        #ffd700 100%
    );
    background-size: 200% 200%;
    animation: goldShimmer 2s ease infinite;
}

.gold-border::after {
    content: '';
    position: absolute;
    top: -3px;
    left: -3px;
    right: -3px;
    bottom: -3px;
    z-index: -1;
    border-radius: 18px;
    background: linear-gradient(
        135deg,
        #ffd700 0%,
        #ffec8b 25%,
        #ffd700 50%,
        #b8860b 75%,
        #ffd700 100%
    );
    background-size: 200% 200%;
    animation: goldShimmer 2s ease infinite;
    filter: blur(6px);
    opacity: 0.6;
}

@keyframes goldShimmer {
    0% {
        background-position: 0% 0%;
    }
    50% {
        background-position: 100% 100%;
    }
    100% {
        background-position: 0% 0%;
    }
}

/* ===== Hanzi Game Styles ===== */
.hanzi-btn {
    background: linear-gradient(135deg, #ff9a56 0%, #ff6b6b 100%);
    color: white;
    border: none;
    padding: 16px 40px;
    border-radius: 30px;
    font-size: 1.2rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(255, 154, 86, 0.4);
    transition: all 0.3s ease;
    margin-bottom: 15px;
}

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

.hanzi-title {
    background: linear-gradient(135deg, #ff9a56 0%, #ff6b6b 50%, #c44cff 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hanzi-back {
    position: absolute;
    top: 20px;
    left: 20px;
}

/* Hanzi Difficulty Buttons */
.difficulty-btn.hanzi-easy {
    background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
    color: #8b4513;
}

.difficulty-btn.hanzi-medium {
    background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
    color: #4a4a4a;
}

.difficulty-btn.hanzi-hard {
    background: linear-gradient(135deg, #ff9a56 0%, #ff6b6b 100%);
    color: white;
}

/* Hanzi Game Area */
.hanzi-game-area {
    background: linear-gradient(180deg, #fff5eb 0%, #ffe8d6 100%);
}

.hanzi-question-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 30px;
}

.emoji-display {
    font-size: 8rem;
    line-height: 1.2;
    text-align: center;
    animation: emojiPulse 2s ease-in-out infinite;
    filter: drop-shadow(0 10px 30px rgba(255, 107, 157, 0.3));
    margin-bottom: 15px;
}

@keyframes emojiPulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

.hint-text {
    font-size: 1.5rem;
    color: #ff6b6b;
    font-weight: 600;
    text-shadow: 0 2px 10px rgba(255, 107, 107, 0.2);
}

/* Hanzi Answer Buttons */
.hanzi-answer-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    width: 100%;
    max-width: 350px;
    padding: 0 20px;
}

.hanzi-answer-btn {
    padding: 25px 20px;
    font-size: 2.5rem;
    font-weight: 700;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.1);
    background: white;
    color: #333;
    border: 3px solid transparent;
}

.hanzi-answer-btn:nth-child(1) {
    background: linear-gradient(135deg, #fff5f5 0%, #ffe0e6 100%);
    border-color: #ff9a9e;
}

.hanzi-answer-btn:nth-child(2) {
    background: linear-gradient(135deg, #f0fff4 0%, #c6f6d5 100%);
    border-color: #68d391;
}

.hanzi-answer-btn:nth-child(3) {
    background: linear-gradient(135deg, #fffff0 0%, #fefcbf 100%);
    border-color: #f6e05e;
}

.hanzi-answer-btn:nth-child(4) {
    background: linear-gradient(135deg, #ebf8ff 0%, #bee3f8 100%);
    border-color: #63b3ed;
}

.hanzi-answer-btn:active {
    transform: scale(0.92);
}

.hanzi-answer-btn.correct {
    animation: correctPulse 0.5s ease;
    background: linear-gradient(135deg, #68d391 0%, #48bb78 100%) !important;
    color: white !important;
    border-color: #38a169 !important;
}

.hanzi-answer-btn.wrong {
    animation: wrongShake 0.5s ease;
    background: linear-gradient(135deg, #fc8181 0%, #f56565 100%) !important;
    color: white !important;
    border-color: #e53e3e !important;
}

/* Hanzi background classes */
.bg-hanzi-easy {
    background: linear-gradient(180deg, #fff5eb 0%, #ffe8d6 100%);
}

.bg-hanzi-medium {
    background: linear-gradient(180deg, #e6fffa 0%, #b2f5ea 100%);
}

.bg-hanzi-hard {
    background: linear-gradient(180deg, #fff5f5 0%, #fed7d7 100%);
}

/* ===== Visual Math ===== */
.bg-visual-math {
    background: linear-gradient(180deg, #fff9e6 0%, #ffe9c7 100%);
}

.visual-math-area {
    background: linear-gradient(180deg, rgba(255, 250, 236, 0.92) 0%, rgba(255, 232, 198, 0.92) 100%);
}

.visual-question-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 24px;
}

.visual-prompt {
    color: #bd6c20;
    font-size: 2rem;
    font-weight: 800;
    margin-bottom: 14px;
}

.visual-objects {
    min-height: 110px;
    max-width: min(90vw, 640px);
    padding: 18px 28px;
    border-radius: 28px;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 9px 24px rgba(188, 117, 38, 0.2);
    font-size: clamp(3rem, 10vw, 6rem);
    line-height: 1.25;
    letter-spacing: 5px;
    text-align: center;
    word-break: break-all;
}

.hint-btn {
    margin-top: 16px;
    border: 2px solid #f1b84b;
    border-radius: 22px;
    padding: 9px 18px;
    background: #fffaf0;
    color: #9a6317;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
}

.hint-btn:disabled {
    opacity: 0.55;
    cursor: default;
}

.hint-message {
    min-height: 28px;
    margin-top: 8px;
    color: #8b5a1e;
    font-size: 0.98rem;
}

.visual-answer-buttons {
    display: grid;
    grid-template-columns: repeat(4, minmax(60px, 1fr));
    gap: 14px;
    width: min(92vw, 460px);
}

.visual-answer-btn {
    min-height: 72px;
    border: 3px solid #f2c46d;
    border-radius: 22px;
    background: linear-gradient(135deg, #fff 0%, #fff0c8 100%);
    color: #8b5a1e;
    font-size: 2.4rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 5px 14px rgba(188, 117, 38, 0.16);
    transition: transform 0.2s ease;
}

.visual-answer-btn:active {
    transform: scale(0.92);
}

.visual-answer-btn.correct {
    background: linear-gradient(135deg, #9be7bf 0%, #4fc78a 100%);
    border-color: #299b66;
    color: #fff;
}

.visual-answer-btn.wrong {
    background: linear-gradient(135deg, #ffb1b1 0%, #f26c6c 100%);
    border-color: #d33d3d;
    color: #fff;
}

/* ===== Parent Dashboard ===== */
.parent-dashboard-content {
    flex: 1;
    width: min(94%, 720px);
    margin: 0 auto;
    padding: 30px 0 50px;
    overflow-y: auto;
}

.parent-pin-form {
    width: min(92vw, 380px);
    margin: 40px auto;
    padding: 30px;
    border-radius: 26px;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 8px 24px rgba(45, 157, 132, 0.16);
    text-align: center;
}

.parent-pin-form h3 {
    margin-bottom: 10px;
    color: #2d9d84;
}

.parent-pin-form p {
    color: #777;
    line-height: 1.5;
}

.parent-pin-form input {
    display: block;
    width: 100%;
    margin: 14px 0;
    border: 2px solid #bde6da;
    border-radius: 15px;
    padding: 13px;
    font-size: 1.2rem;
    text-align: center;
    letter-spacing: 5px;
}

.parent-pin-error {
    color: #d33d3d !important;
    min-height: 24px;
}

.parent-dashboard-data {
    padding: 24px;
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.88);
}

.parent-dashboard-data h3 {
    margin-bottom: 20px;
    color: #2d9d84;
    text-align: center;
}

.parent-stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.parent-stat-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 14px 8px;
    border-radius: 16px;
    background: #ecfbf6;
    color: #267a69;
}

.parent-stat-card strong {
    font-size: 1.5rem;
}

.parent-stat-card span {
    margin-top: 4px;
    font-size: 0.8rem;
}

.parent-section {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 2px solid #e1f2ec;
    color: #555;
}

.parent-section h4 {
    margin-bottom: 10px;
    color: #2d9d84;
}

.parent-progress-row {
    padding: 8px 0;
}

@media (max-width: 520px) {
    .parent-stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* iPad adjustments for Hanzi */
@media (min-width: 768px) {
    .emoji-display {
        font-size: 12rem;
    }

    .hint-text {
        font-size: 2rem;
    }

    .hanzi-answer-buttons {
        max-width: 500px;
        gap: 20px;
    }

    .hanzi-answer-btn {
        padding: 35px 30px;
        font-size: 3.5rem;
    }
}

@media (min-width: 1024px) {
    .hanzi-answer-buttons {
        grid-template-columns: repeat(4, 1fr);
        max-width: 700px;
    }
}

/* Card showcase in popup - larger with golden rainbow glow */
.card-showcase .pony-card {
    width: 150px !important;
    position: relative;
    border: 3px solid transparent;
    background: linear-gradient(145deg, #1a1a2e 0%, #16213e 50%, #0f0f23 100%);
    animation: goldenGlow 2s ease-in-out infinite alternate;
}

.card-showcase .pony-card::before {
    content: '';
    position: absolute;
    top: -4px;
    left: -4px;
    right: -4px;
    bottom: -4px;
    background: linear-gradient(
        90deg,
        #ff0000, #ff7f00, #ffff00, #00ff00, #0000ff, #4b0082, #9400d3,
        #ff0000, #ff7f00, #ffff00, #00ff00, #0000ff, #4b0082, #9400d3
    );
    background-size: 200% 100%;
    border-radius: 18px;
    z-index: -1;
    animation: rainbowBorder 3s linear infinite;
}

.card-showcase .pony-card::after {
    content: '';
    position: absolute;
    top: -8px;
    left: -8px;
    right: -8px;
    bottom: -8px;
    background: linear-gradient(
        90deg,
        rgba(255, 0, 0, 0.5), rgba(255, 127, 0, 0.5), rgba(255, 255, 0, 0.5),
        rgba(0, 255, 0, 0.5), rgba(0, 0, 255, 0.5), rgba(75, 0, 130, 0.5), rgba(148, 0, 211, 0.5),
        rgba(255, 0, 0, 0.5)
    );
    background-size: 200% 100%;
    border-radius: 22px;
    z-index: -2;
    filter: blur(15px);
    animation: rainbowBorder 3s linear infinite;
}

@keyframes rainbowBorder {
    0% { background-position: 0% 50%; }
    100% { background-position: 200% 50%; }
}

@keyframes goldenGlow {
    0% {
        box-shadow:
            0 0 20px rgba(255, 215, 0, 0.8),
            0 0 40px rgba(255, 215, 0, 0.5);
    }
    100% {
        box-shadow:
            0 0 30px rgba(255, 215, 0, 1),
            0 0 60px rgba(255, 215, 0, 0.7);
    }
}

.card-showcase .pony-card-text {
    font-size: 1rem;
    padding: 10px 8px;
    background: linear-gradient(180deg, #2a1f00 0%, #1a1200 100%);
    -webkit-background-clip: unset;
    -webkit-text-fill-color: unset;
    background-clip: unset;
    color: #ffd700;
    text-shadow:
        0 0 5px rgba(255, 215, 0, 0.8),
        0 1px 2px rgba(0, 0, 0, 0.8);
    border-top: 1px solid rgba(255, 215, 0, 0.3);
}

/* Collection grid card adjustments */
.collection-card .pony-card {
    width: 100% !important;
    border-radius: 10px;
    padding: 4px;
}

.collection-card.collected .pony-card {
    position: relative;
    animation: collectedGlow 3s ease-in-out infinite alternate;
}

.collection-card.collected .pony-card::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(
        90deg,
        #ff0000, #ff7f00, #ffff00, #00ff00, #0000ff, #4b0082, #9400d3,
        #ff0000, #ff7f00, #ffff00
    );
    background-size: 200% 100%;
    border-radius: 12px;
    z-index: -1;
    animation: rainbowBorder 4s linear infinite;
}

.collection-card.collected .pony-card::after {
    content: '';
    position: absolute;
    top: -4px;
    left: -4px;
    right: -4px;
    bottom: -4px;
    background: linear-gradient(
        90deg,
        rgba(255, 215, 0, 0.4), rgba(255, 127, 0, 0.3), rgba(255, 255, 0, 0.4),
        rgba(0, 255, 0, 0.3), rgba(0, 0, 255, 0.3), rgba(148, 0, 211, 0.3),
        rgba(255, 215, 0, 0.4)
    );
    background-size: 200% 100%;
    border-radius: 14px;
    z-index: -2;
    filter: blur(8px);
    animation: rainbowBorder 4s linear infinite;
}

@keyframes collectedGlow {
    0% {
        box-shadow: 0 0 8px rgba(255, 215, 0, 0.6);
    }
    100% {
        box-shadow: 0 0 15px rgba(255, 215, 0, 0.9);
    }
}

.collection-card .pony-card-image {
    width: 100%;
    border-radius: 8px;
}

.collection-card .pony-card-text {
    font-size: 0.7rem;
    padding: 5px 3px;
}

.collection-card.collected .pony-card-text {
    background: linear-gradient(180deg, #2a1f00 0%, #1a1200 100%);
    -webkit-background-clip: unset;
    -webkit-text-fill-color: unset;
    background-clip: unset;
    color: #ffd700;
    text-shadow: 0 0 3px rgba(255, 215, 0, 0.6);
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===== Viewport-safe responsive layout ===== */
html {
    min-height: 100%;
}

body {
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: none;
}

#app {
    min-height: 100vh;
    min-height: 100dvh;
    height: auto;
}

.screen {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
}

.menu-container {
    flex: 0 0 auto;
    min-height: 100%;
    min-height: 100dvh;
    height: auto;
    justify-content: flex-start;
    justify-content: safe center;
    padding: calc(20px + env(safe-area-inset-top, 0px)) 20px
        calc(28px + env(safe-area-inset-bottom, 0px));
}

.game-header,
.collection-header {
    flex-shrink: 0;
    padding-top: calc(12px + env(safe-area-inset-top, 0px));
}

.game-area {
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    justify-content: safe center;
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    -webkit-overflow-scrolling: touch;
}

.question-container,
.hanzi-question-container,
.visual-question-container,
.answer-buttons,
.hanzi-answer-buttons,
.visual-answer-buttons,
.progress-bar {
    flex-shrink: 0;
}

.collection-grid,
.leaderboard-list,
.parent-dashboard-content {
    min-height: 0;
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    -webkit-overflow-scrolling: touch;
}

.popup {
    box-sizing: border-box;
    padding: calc(12px + env(safe-area-inset-top, 0px)) 12px
        calc(12px + env(safe-area-inset-bottom, 0px));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.popup-content {
    max-height: 100%;
    overflow-y: auto;
}

/* Keep the newer learning screens stacked so the question stays centered
   instead of competing for one horizontal row with the answer controls. */
.visual-math-area,
.hanzi-game-area {
    flex-direction: column;
    flex-wrap: nowrap;
    justify-content: safe center;
}

.visual-question-container,
.hanzi-question-container {
    width: 100%;
}

@media (max-width: 430px) {
    .game-header,
    .collection-header {
        gap: 6px;
        padding-right: 10px;
        padding-left: 10px;
    }

    .back-btn {
        width: 44px;
        height: 44px;
        font-size: 1.25rem;
    }

    .score-display,
    .timer-display,
    .streak-display {
        min-width: 0;
        padding: 6px 8px;
        font-size: 0.95rem;
    }

    .collection-header h2 {
        font-size: 1.2rem;
    }

    .leaderboard-no-password,
    .collection-count {
        font-size: 0.7rem;
    }
}

@media (max-height: 700px) {
    .menu-container {
        padding-top: calc(12px + env(safe-area-inset-top, 0px));
        padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px));
    }

    .game-title {
        font-size: clamp(2.25rem, 10vw, 3rem);
        letter-spacing: 2px;
        margin-bottom: 8px;
    }

    .pony-decoration {
        width: 140px;
        height: 140px;
        margin: 8px 0;
    }

    .difficulty-buttons {
        gap: 8px;
        margin-bottom: 16px;
    }

    .difficulty-btn {
        padding: 12px 20px;
        border-radius: 18px;
    }

    .difficulty-btn .star {
        font-size: 1.1rem;
    }

    .difficulty-btn .label {
        font-size: 1.1rem;
    }

    .difficulty-btn .desc {
        font-size: 0.75rem;
    }

    .hanzi-btn,
    .collection-btn,
    .visual-math-btn,
    .parent-btn {
        padding-top: 10px;
        padding-bottom: 10px;
    }

    .visual-math-secondary {
        padding-top: 8px;
        padding-bottom: 8px;
    }

    .game-area {
        justify-content: flex-start;
        padding: 12px 12px calc(18px + env(safe-area-inset-bottom, 0px));
    }

    .pony-helper {
        top: 4px;
        right: 8px;
        width: 72px;
        height: 72px;
    }

    .question-container {
        margin-bottom: 16px;
    }

    .question-card {
        gap: 8px;
        padding: 14px 18px;
        border-width: 3px;
        border-radius: 20px;
    }

    .number {
        min-width: 44px;
        font-size: clamp(2.5rem, 12vw, 3.5rem);
    }

    .operator,
    .equals {
        font-size: 2rem;
    }

    .answer-box {
        min-width: 65px;
        padding: 6px 16px;
        font-size: clamp(2.5rem, 12vw, 3.5rem);
    }

    .answer-buttons {
        gap: 8px;
        padding: 0;
    }

    .answer-btn {
        padding: 14px 10px;
        border-radius: 15px;
        font-size: clamp(1.25rem, 5vw, 1.75rem);
    }

    .progress-bar {
        height: 26px;
        margin-top: 16px;
    }

    .hanzi-question-container {
        margin-bottom: 12px;
    }

    .emoji-display {
        margin-bottom: 8px;
        font-size: clamp(4.5rem, 22vh, 7rem);
    }

    .hint-text {
        font-size: 1.2rem;
    }

    .hanzi-answer-buttons {
        gap: 8px;
        padding: 0;
    }

    .hanzi-answer-btn {
        padding: 14px 10px;
        border-radius: 15px;
        font-size: clamp(1.8rem, 8vw, 2.5rem);
    }

    .visual-question-container {
        margin-bottom: 14px;
    }

    .visual-prompt {
        margin-bottom: 8px;
        font-size: 1.5rem;
    }

    .visual-objects {
        min-height: 76px;
        padding: 10px 14px;
        font-size: clamp(2.3rem, 14vw, 4.5rem);
    }

    .hint-btn {
        margin-top: 10px;
        padding-top: 7px;
        padding-bottom: 7px;
    }

    .hint-message {
        min-height: 22px;
        margin-top: 4px;
    }

    .visual-answer-buttons {
        gap: 8px;
    }

    .visual-answer-btn {
        min-height: 60px;
        border-radius: 16px;
        font-size: clamp(1.6rem, 7vw, 2.2rem);
    }
}
