/* ===== 睡前故事 AI — 温暖儿童风 ===== */

:root {
    --bg: #fdf6ee;
    --card-bg: #ffffff;
    --primary: #e8877a;
    --primary-light: #fce4e0;
    --primary-dark: #d47062;
    --text: #4a3728;
    --text-light: #8b7a6b;
    --text-lighter: #b8a99a;
    --border: #f0e6d8;
    --shadow: 0 8px 30px rgba(200, 160, 140, 0.15);
    --radius: 20px;
    --radius-sm: 12px;
    --font: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.8;
}

/* ===== 容器 ===== */
.container {
    max-width: 640px;
    margin: 0 auto;
    padding: 24px 20px 60px;
}

/* ===== 头部 ===== */
.header {
    text-align: center;
    padding: 32px 0 24px;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 8px;
}

.logo-icon {
    font-size: 40px;
    animation: float 3s ease-in-out infinite;
}

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

.logo-text {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: 2px;
}

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

/* ===== 卡片 ===== */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px 24px;
    transition: all 0.3s ease;
}

/* ===== 输入区 ===== */
.form-row {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

.name-group {
    flex: 1;
}

.age-group {
    width: 120px;
    flex-shrink: 0;
}

.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 6px;
}

.hint {
    color: var(--text-lighter);
    font-weight: 400;
    font-size: 13px;
}

input[type="text"],
select {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-family: var(--font);
    color: var(--text);
    background: #faf8f5;
    outline: none;
    transition: border-color 0.2s;
}

input[type="text"]:focus,
select:focus {
    border-color: var(--primary);
    background: #fff;
}

/* ===== 主题标签 ===== */
.theme-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}

.tag {
    display: inline-block;
    padding: 6px 14px;
    background: #f5f0eb;
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
}

.tag:hover {
    background: var(--primary-light);
}

.tag.active {
    background: var(--primary);
    color: #fff;
}

/* ===== 长度选择 ===== */
.length-options {
    display: flex;
    gap: 10px;
}

.length-option {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 8px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.length-option:hover {
    border-color: var(--primary-light);
}

.length-option.selected {
    border-color: var(--primary);
    background: var(--primary-light);
}

.length-option input {
    display: none;
}

.length-option span {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}

.length-option small {
    font-size: 12px;
    color: var(--text-light);
    margin-top: 2px;
}

/* ===== 生成按钮 ===== */
.generate-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 16px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 18px;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: all 0.3s;
    margin-top: 4px;
}

.generate-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(232, 135, 122, 0.4);
}

.generate-btn:active {
    transform: translateY(0);
}

.btn-icon {
    font-size: 22px;
}

/* ===== 加载动画 ===== */
.loading-section {
    padding: 20px 0;
}

.loading-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 48px 24px;
    text-align: center;
}

.magic-stars {
    font-size: 32px;
    margin-bottom: 16px;
    animation: twinkle 1.5s ease-in-out infinite;
}

@keyframes twinkle {
    0%, 100% { opacity: 0.5; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.1); }
}

.loading-text {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 16px;
}

.loading-bar {
    width: 240px;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    margin: 0 auto 12px;
    overflow: hidden;
}

.loading-progress {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--primary), #f0a88a);
    border-radius: 3px;
    transition: width 0.5s ease;
}

.loading-sub {
    font-size: 13px;
    color: var(--text-light);
}

/* ===== 结果区 ===== */
.result-section {
    padding: 8px 0;
}

.story-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 16px;
    line-height: 1.4;
}

/* 播放器 */
.player-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    padding: 12px 16px;
    background: #faf8f5;
    border-radius: var(--radius-sm);
}

.play-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: var(--primary);
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
}

.play-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(232, 135, 122, 0.4);
}

.play-btn.playing {
    background: var(--primary-dark);
}

.player-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
}

.duration,
.current-time {
    font-size: 12px;
    color: var(--text-light);
    white-space: nowrap;
    min-width: 36px;
}

.progress-bar {
    flex: 1;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    cursor: pointer;
    position: relative;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: var(--primary);
    border-radius: 2px;
    transition: width 0.1s linear;
}

/* 故事正文 */
.story-content {
    padding: 16px 0;
    line-height: 2;
    font-size: 16px;
    color: var(--text);
    white-space: pre-wrap;
}

.story-content p {
    margin-bottom: 12px;
    text-indent: 2em;
}

/* 晚安寄语 */
.blessing-box {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
    background: linear-gradient(135deg, #f8f0ea, #fce8e4);
    border-radius: var(--radius-sm);
    margin: 16px 0;
}

.blessing-icon {
    font-size: 24px;
    flex-shrink: 0;
    margin-top: 2px;
}

.blessing-text {
    font-size: 15px;
    color: var(--text);
    font-style: italic;
    line-height: 1.8;
}

/* 操作按钮 */
.story-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.action-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card-bg);
    font-size: 14px;
    font-weight: 600;
    font-family: var(--font);
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s;
}

.action-btn:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

/* ===== 顶部用户区 ===== */
.header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.user-area {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-email {
    color: var(--text-light);
    font-size: 12px;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.daily-badge {
    font-size: 12px;
    color: var(--primary);
    background: var(--primary-light);
    padding: 2px 8px;
    border-radius: 10px;
    white-space: nowrap;
}

.text-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 4px 12px;
    font-size: 12px;
    font-family: var(--font);
    color: var(--text-light);
    cursor: pointer;
    transition: all 0.2s;
}

.text-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* ===== 登录弹窗 ===== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 32px 24px;
    max-width: 400px;
    width: 100%;
    position: relative;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
    max-height: 90vh;
    overflow-y: auto;
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 16px;
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-light);
    cursor: pointer;
    line-height: 1;
}

.modal-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 24px;
    border-bottom: 2px solid var(--border);
}

.modal-tab {
    flex: 1;
    padding: 10px;
    background: none;
    border: none;
    font-size: 15px;
    font-weight: 600;
    font-family: var(--font);
    color: var(--text-light);
    cursor: pointer;
    transition: all 0.2s;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
}

.modal-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.auth-form .form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

.auth-form input {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: var(--font);
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.auth-form input:focus {
    outline: none;
    border-color: var(--primary);
}

.auth-form .generate-btn {
    margin-top: 4px;
}

.auth-error {
    text-align: center;
    color: #e74c3c;
    font-size: 13px;
    min-height: 20px;
}

/* ===== 底部 ===== */
.footer {
    text-align: center;
    padding: 32px 0 20px;
    color: var(--text-lighter);
    font-size: 13px;
}

/* ===== 工具类 ===== */
.hidden {
    display: none;
}

/* ===== 错误提示 ===== */
.error-msg {
    text-align: center;
    padding: 16px;
    color: #e74c3c;
    background: #fdedec;
    border-radius: var(--radius-sm);
    margin: 12px 0;
    font-size: 14px;
}

/* ===== 移动端适配 ===== */
@media (max-width: 480px) {
    .container {
        padding: 16px 12px 40px;
    }

    .card {
        padding: 20px 16px;
    }

    .logo-text {
        font-size: 24px;
    }

    .story-title {
        font-size: 19px;
    }

    .form-row {
        flex-direction: column;
    }

    .age-group {
        width: 100%;
    }

    .length-options {
        gap: 6px;
    }

    .length-option {
        padding: 8px 4px;
    }

    .length-option span {
        font-size: 13px;
    }
}
