/* ===== 全局重置 ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --color-sky: #4FC3F7;
    --color-sky-light: #B3E5FC;
    --color-sun: #FFD54F;
    --color-strawberry: #FF8A95;
    --color-mint: #81C784;
    --color-white: #FFFFFF;
    --color-text: #3E4660;
    --color-text-light: #7B8AA8;
    --radius-card: 24px;
    --radius-btn: 50px;
    --shadow-soft: 0 8px 32px rgba(0, 0, 0, 0.12);
    --shadow-card: 0 12px 40px rgba(0, 0, 0, 0.15);
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    background: linear-gradient(180deg, #E3F2FD 0%, #BBDEFB 100%);
    color: var(--color-text);
    user-select: none;
}

#app {
    width: 100%;
    max-width: 480px;
    height: 100%;
    margin: 0 auto;
    position: relative;
    overflow: hidden;
}

/* ===== 页面通用 ===== */
.page {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.5s ease, visibility 0.5s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.page.active {
    opacity: 1;
    visibility: visible;
    z-index: 10;
}

/* ===== 页面1：欢迎页 ===== */
#page-welcome {
    background: linear-gradient(180deg, #E3F2FD 0%, #90CAF9 100%);
}

.welcome-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    width: 100%;
}

.logo-tooth {
    position: relative;
    margin-bottom: 8px;
}

.tooth-icon {
    position: relative;
    width: 120px;
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: tooth-bounce 2s ease-in-out infinite;
}

.tooth-icon svg {
    filter: drop-shadow(0 4px 12px rgba(79, 195, 247, 0.4));
}

.tooth-eyes {
    position: absolute;
    top: 48px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 22px;
}

.eye {
    width: 10px;
    height: 14px;
    background: #3E4660;
    border-radius: 50%;
    animation: blink 4s infinite;
}

.eye.left {}

.tooth-smile {
    position: absolute;
    bottom: 42px;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 10px;
    border: 3px solid #3E4660;
    border-top: none;
    border-radius: 0 0 20px 20px;
}

.sparkles {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.sparkle {
    position: absolute;
    font-size: 20px;
    animation: sparkle-float 3s ease-in-out infinite;
}

.sparkle.s1 { top: 0; right: 0; animation-delay: 0s; }
.sparkle.s2 { top: 30%; right: -15px; font-size: 16px; animation-delay: 1s; }
.sparkle.s3 { bottom: 10%; left: -10px; font-size: 14px; animation-delay: 0.5s; }

.title {
    font-size: 36px;
    font-weight: 800;
    color: var(--color-text);
    text-shadow: 0 2px 8px rgba(255, 255, 255, 0.6);
}

.subtitle {
    font-size: 22px;
    color: var(--color-text-light);
    font-weight: 600;
}

.input-row {
    width: 100%;
    max-width: 300px;
}

#nameInput {
    width: 100%;
    height: 64px;
    font-size: 22px;
    text-align: center;
    border: 3px solid var(--color-sky);
    border-radius: var(--radius-btn);
    outline: none;
    background: white;
    color: var(--color-text);
    box-shadow: var(--shadow-soft);
    transition: border-color 0.3s, box-shadow 0.3s;
}

#nameInput::placeholder {
    color: #B0BEC5;
}

#nameInput:focus {
    border-color: var(--color-strawberry);
    box-shadow: 0 8px 32px rgba(255, 138, 149, 0.3);
}

#nameInput.shake {
    animation: shake 0.5s ease;
    border-color: #FF5252;
}

/* ===== 按钮通用 ===== */
.btn-primary {
    height: 60px;
    padding: 0 40px;
    font-size: 22px;
    font-weight: 700;
    color: white;
    background: linear-gradient(135deg, #FF8A95 0%, #FF6B6B 100%);
    border: none;
    border-radius: var(--radius-btn);
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(255, 107, 107, 0.4);
    transition: transform 0.2s, box-shadow 0.2s;
    -webkit-appearance: none;
}

.btn-primary:active {
    transform: scale(0.95);
    box-shadow: 0 3px 12px rgba(255, 107, 107, 0.4);
}

/* ===== 页面2：选择页 ===== */
#page-select {
    background: linear-gradient(180deg, #FFF8E1 0%, #FFE082 100%);
    justify-content: flex-start;
    padding-top: 40px;
}

.select-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    width: 100%;
}

.select-title {
    font-size: 24px;
    font-weight: 800;
    color: var(--color-text);
    text-align: center;
}

.cards {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
    max-width: 360px;
}

.card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: white;
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
    cursor: pointer;
    transition: transform 0.25s, box-shadow 0.25s;
    border: 3px solid transparent;
}

.card:active {
    transform: scale(0.97);
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.18);
}

.card-great { border-color: #FFD54F; }
.card-good { border-color: #81C784; }
.card-try { border-color: #FFB74D; }

.card-image {
    flex-shrink: 0;
    width: 80px;
    height: 80px;
    border-radius: 16px;
    overflow: hidden;
}

.card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.card-stars {
    font-size: 14px;
    line-height: 1;
}

.card-great .card-stars { color: #FFD54F; }
.card-good .card-stars { color: #FFD54F; }
.card-try .card-stars { color: #FFD54F; }

.card-label {
    font-size: 20px;
    font-weight: 800;
    color: var(--color-text);
}

.card-desc {
    font-size: 14px;
    color: var(--color-text-light);
    margin-top: 2px;
}

.btn-back {
    height: 48px;
    padding: 0 28px;
    font-size: 18px;
    font-weight: 600;
    color: var(--color-text-light);
    background: rgba(255, 255, 255, 0.6);
    border: 2px solid rgba(255, 255, 255, 0.8);
    border-radius: var(--radius-btn);
    cursor: pointer;
    transition: background 0.2s;
    -webkit-appearance: none;
}

.btn-back:active {
    background: rgba(255, 255, 255, 0.9);
}

/* ===== 页面3：结果页 ===== */
#page-result {
    justify-content: flex-start;
    padding-top: 30px;
}

#page-result.bg-great {
    background: linear-gradient(180deg, #E3F2FD 0%, #4FC3F7 100%);
}

#page-result.bg-good {
    background: linear-gradient(180deg, #FFF8E1 0%, #FFD54F 100%);
}

#page-result.bg-try {
    background: linear-gradient(180deg, #FFF3E0 0%, #FFB74D 100%);
}

.result-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    width: 100%;
}

.result-header {
    text-align: center;
}

.result-title {
    font-size: 28px;
    font-weight: 800;
    color: var(--color-text);
    margin-bottom: 8px;
}

.result-stars {
    font-size: 36px;
    line-height: 1.2;
}

.result-stars .star {
    display: inline-block;
    opacity: 0;
    transform: scale(0);
    animation: star-pop 0.4s ease forwards;
}

.result-tooth-wrapper {
    position: relative;
    width: 240px;
    height: 240px;
    border-radius: 50%;
    overflow: hidden;
    box-shadow: var(--shadow-card);
    background: white;
    animation: tooth-appear 0.6s ease;
}

.result-tooth-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.bug-count {
    position: absolute;
    top: 12px;
    right: 12px;
    min-width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    font-weight: 800;
    color: white;
    background: rgba(255, 107, 107, 0.9);
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.bug-count.zero {
    background: rgba(129, 199, 132, 0.9);
}

.result-message {
    font-size: 20px;
    line-height: 1.6;
    text-align: center;
    color: var(--color-text);
    font-weight: 600;
    max-width: 340px;
    padding: 16px 24px;
    background: rgba(255, 255, 255, 0.85);
    border-radius: 16px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    animation: msg-fade-in 0.8s ease 0.5s both;
}

/* ===== 音色选择器 ===== */
.voice-selector {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.85);
    padding: 10px 20px;
    border-radius: 16px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

.voice-label {
    font-size: 18px;
    font-weight: 700;
    color: var(--color-text);
    white-space: nowrap;
}

.voice-select {
    flex: 1;
    min-width: 140px;
    height: 44px;
    font-size: 16px;
    font-weight: 600;
    color: var(--color-text);
    background: white;
    border: 2px solid var(--color-sky);
    border-radius: 12px;
    padding: 0 12px;
    outline: none;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%234FC3F7' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

.voice-select:focus {
    border-color: var(--color-strawberry);
}

.result-actions {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    justify-content: center;
    margin-top: 8px;
}

.btn-replay {
    background: linear-gradient(135deg, #4FC3F7 0%, #29B6F6 100%);
    box-shadow: 0 6px 20px rgba(79, 195, 247, 0.4);
}

.btn-again {
    background: linear-gradient(135deg, #81C784 0%, #66BB6A 100%);
    box-shadow: 0 6px 20px rgba(129, 199, 132, 0.4);
}

/* ===== 动画 ===== */
@keyframes tooth-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

@keyframes blink {
    0%, 90%, 100% { transform: scaleY(1); }
    95% { transform: scaleY(0.1); }
}

@keyframes sparkle-float {
    0%, 100% { transform: translateY(0) rotate(0deg); opacity: 0.8; }
    50% { transform: translateY(-8px) rotate(15deg); opacity: 1; }
}

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

@keyframes star-pop {
    0% { opacity: 0; transform: scale(0) rotate(-180deg); }
    60% { opacity: 1; transform: scale(1.3) rotate(10deg); }
    100% { opacity: 1; transform: scale(1) rotate(0deg); }
}

@keyframes tooth-appear {
    0% { opacity: 0; transform: scale(0.5) rotate(-10deg); }
    100% { opacity: 1; transform: scale(1) rotate(0deg); }
}

@keyframes msg-fade-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== 礼花动画（超级棒） ===== */
.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    pointer-events: none;
    animation: confetti-fall 2s ease-out forwards;
}

@keyframes confetti-fall {
    0% { transform: translateY(-20px) rotate(0deg); opacity: 1; }
    100% { transform: translateY(400px) rotate(720deg); opacity: 0; }
}

/* ===== 拍照提示弹窗 ===== */
.photo-prompt-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: overlay-fade 0.3s ease;
}

.photo-prompt-overlay.show {
    display: flex;
}

.photo-prompt-modal {
    background: white;
    border-radius: 28px;
    padding: 32px 28px 24px;
    width: 88%;
    max-width: 360px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: modal-pop 0.4s ease;
}

.photo-prompt-icon {
    font-size: 56px;
    margin-bottom: 8px;
    animation: tooth-bounce 2s ease-in-out infinite;
}

.photo-prompt-title {
    font-size: 22px;
    font-weight: 800;
    color: var(--color-text);
    margin-bottom: 8px;
}

.photo-prompt-desc {
    font-size: 16px;
    color: var(--color-text-light);
    margin-bottom: 24px;
    line-height: 1.5;
}

.photo-prompt-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.btn-camera {
    background: linear-gradient(135deg, #4FC3F7 0%, #29B6F6 100%);
    box-shadow: 0 6px 20px rgba(79, 195, 247, 0.4);
}

.btn-skip {
    height: 48px;
    font-size: 18px;
    font-weight: 600;
    color: var(--color-text-light);
    background: transparent;
    border: 2px solid #E0E0E0;
    border-radius: var(--radius-btn);
    cursor: pointer;
    transition: background 0.2s;
    -webkit-appearance: none;
}

.btn-skip:active {
    background: #F5F5F5;
}

/* ===== 拍照结果展示 ===== */
.result-photo-wrapper {
    position: relative;
    width: 260px;
    max-width: 90vw;
    border-radius: 50%;
    overflow: hidden;
    box-shadow: var(--shadow-card);
    aspect-ratio: 1;
    animation: tooth-appear 0.6s ease;
}

.result-photo-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* 虫子叠加层 */
.bug-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.bug-element {
    position: absolute;
    width: 36px;
    height: 36px;
    transform: translate(-50%, -50%);
    animation: bug-wiggle 1.5s ease-in-out infinite;
    filter: drop-shadow(2px 2px 4px rgba(0, 0, 0, 0.3));
}

@keyframes bug-wiggle {
    0%, 100% { transform: translate(-50%, -50%) rotate(-8deg); }
    25% { transform: translate(-48%, -52%) rotate(5deg); }
    50% { transform: translate(-50%, -50%) rotate(-3deg); }
    75% { transform: translate(-52%, -48%) rotate(8deg); }
}

@keyframes overlay-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes modal-pop {
    0% { opacity: 0; transform: scale(0.7) translateY(20px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}

/* ===== 响应式 ===== */
@media (max-width: 380px) {
    .title { font-size: 30px; }
    .subtitle { font-size: 20px; }
    .result-tooth-wrapper { width: 200px; height: 200px; }
    .result-message { font-size: 18px; }
}

@media (max-height: 640px) {
    .page { padding: 12px; }
    .logo-tooth { margin-bottom: 0; }
    .tooth-icon { width: 90px; height: 90px; }
}
