/* ===== Design Tokens ===== */
:root {
    --warm-bg: #faf8f4;
    --paper: #fefcf8;
    --ink: #2c2416;
    --ink-light: #6b5e4f;
    --blush: #e8a0a0;
    --accent: #d4856a;
    --sage: #a8b89c;
    --cream: #f0ebe0;
    --radius-lg: 20px;
    --radius-sm: 12px;
    --font-display: 'Ma Shan Zheng', cursive;
    --font-fun: 'ZCOOL KuaiLe', cursive;
    --font-handwrite: 'Caveat', cursive;
    --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --max-width: 430px;
}

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

body {
    font-family: var(--font-body);
    background: var(--warm-bg);
    color: var(--ink);
    max-width: var(--max-width);
    margin: 0 auto;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

#app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

#page-container {
    flex: 1;
    padding-bottom: 70px;
}

.hidden { display: none !important; }

/* ===== Bottom Navigation ===== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: var(--max-width);
    background: var(--paper);
    border-top: 1px solid var(--cream);
    display: flex;
    justify-content: space-around;
    padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
    z-index: 100;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: var(--ink-light);
    font-size: 11px;
    padding: 4px 16px;
    transition: color 0.2s;
}

.nav-item.active { color: var(--accent); }
.nav-icon { font-size: 22px; margin-bottom: 2px; }

.nav-item.record-btn {
    position: relative;
    top: -16px;
    background: var(--accent);
    color: white !important;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    padding: 0;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(244,164,96,0.4);
}

.nav-item.record-btn .nav-icon {
    font-size: 26px;
    margin-bottom: 0;
}

.nav-item.record-btn .nav-label {
    display: none;
}

/* ===== Page Header ===== */
.page-header {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    position: relative;
}

.page-header .back-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--ink);
    padding: 4px 8px;
    margin-left: -8px;
}

.page-header .title {
    flex: 1;
    text-align: center;
    font-family: var(--font-fun);
    font-size: 18px;
    color: var(--ink);
}

/* ===== Cards ===== */
.card {
    background: var(--paper);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin: 12px 16px;
    box-shadow: 0 2px 8px rgba(44, 36, 22, 0.06);
}

.card-sm {
    background: var(--paper);
    border-radius: var(--radius-sm);
    padding: 14px;
    margin: 8px 16px;
    box-shadow: 0 1px 4px rgba(44, 36, 22, 0.04);
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-family: var(--font-body);
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:active { transform: scale(0.97); opacity: 0.9; }

.btn-secondary {
    background: var(--cream);
    color: var(--ink);
}

.btn-ghost {
    background: transparent;
    color: var(--accent);
}

.btn-block { width: 100%; }

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ===== Login Page ===== */
.login-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 40px 20px;
    text-align: center;
}

.login-page .logo {
    font-size: 64px;
    margin-bottom: 16px;
}

.login-page h1 {
    font-family: var(--font-display);
    font-size: 36px;
    color: var(--ink);
    margin-bottom: 8px;
}

.login-page .subtitle {
    font-family: var(--font-handwrite);
    font-size: 20px;
    color: var(--ink-light);
    margin-bottom: 48px;
}

.login-page .btn {
    width: 80%;
    max-width: 300px;
    padding: 16px;
    font-size: 17px;
    font-family: var(--font-fun);
}

.login-terms {
    margin-top: 16px;
    font-size: 12px;
    color: #999;
}

.login-terms a {
    color: #c9a96e;
    text-decoration: none;
}

.login-terms a:hover {
    text-decoration: underline;
}

/* ===== Character Selection Page ===== */
.character-page {
    padding: 40px 20px 20px;
}

.character-page h2 {
    font-family: var(--font-display);
    font-size: 28px;
    text-align: center;
    margin-bottom: 8px;
}

.character-page .subtitle {
    text-align: center;
    color: var(--ink-light);
    margin-bottom: 32px;
    font-size: 14px;
}

.character-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.character-card {
    background: var(--paper);
    border-radius: var(--radius-lg);
    padding: 16px;
    text-align: center;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
}

.character-card.selected {
    border-color: var(--accent);
    box-shadow: 0 4px 12px rgba(212, 133, 106, 0.2);
}

.character-card img, .character-card .char-avatar {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 8px;
    background: var(--cream);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    margin-left: auto;
    margin-right: auto;
}

.character-card .char-name {
    font-family: var(--font-fun);
    font-size: 14px;
    color: var(--ink);
}

.custom-character-section {
    margin-top: 24px;
    padding: 20px;
    background: var(--paper);
    border-radius: var(--radius-lg);
}

.custom-character-section h3 {
    font-family: var(--font-fun);
    font-size: 16px;
    margin-bottom: 12px;
}

.custom-character-section textarea {
    width: 100%;
    border: 1px solid var(--cream);
    border-radius: var(--radius-sm);
    padding: 12px;
    font-size: 14px;
    resize: none;
    min-height: 80px;
    font-family: var(--font-body);
    background: var(--warm-bg);
}

.candidate-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin: 16px 0;
}

.candidate-card {
    border-radius: var(--radius-sm);
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
}

.candidate-card.selected { border-color: var(--accent); }
.candidate-card img { width: 100%; aspect-ratio: 1; object-fit: cover; }

/* ===== Home Page ===== */
.home-page { padding: 0; }

.home-header {
    padding: 20px 20px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-logo {
    width: 36px;
    height: 36px;
    border-radius: 8px;
}

.header-avatar {
    font-size: 28px;
    text-decoration: none;
}

.home-header h1 {
    font-family: var(--font-display);
    font-size: 28px;
}

.home-header .date-display {
    font-family: var(--font-handwrite);
    font-size: 16px;
    color: var(--ink-light);
}

/* Calendar bar */
.calendar-wrapper {
    display: flex;
    align-items: center;
    padding: 0 8px;
}

.calendar-arrow {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--ink-light);
    cursor: pointer;
    padding: 8px;
    flex-shrink: 0;
}

.calendar-arrow:hover {
    color: var(--ink);
}

.calendar-bar {
    display: flex;
    flex: 1;
    justify-content: space-around;
    padding: 8px 0;
    gap: 4px;
    scrollbar-width: none;
}

.calendar-bar::-webkit-scrollbar { display: none; }

.calendar-day {
    flex-shrink: 0;
    width: 44px;
    height: 58px;
    border-radius: var(--radius-sm);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: var(--ink-light);
    cursor: pointer;
    transition: all 0.2s;
}

.calendar-day .day-num {
    font-size: 18px;
    font-weight: 600;
    color: var(--ink);
}

.calendar-day.active {
    background: var(--accent);
    color: white;
}

.calendar-day.active .day-num { color: white; }

.calendar-day.has-diary::after {
    content: '';
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--blush);
    margin-top: 2px;
}

.calendar-day.active.has-diary::after { background: white; }

/* Diary list */
.diary-list { padding: 8px 0; }

.diary-card {
    background: var(--paper);
    border-radius: var(--radius-lg);
    margin: 12px 16px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s;
    box-shadow: 0 2px 8px rgba(44, 36, 22, 0.06);
}

.diary-card:active { transform: scale(0.98); }

.diary-card .images {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px;
}

.diary-card .images img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
}

.diary-card .content {
    padding: 14px 16px;
}

.diary-card .content h3 {
    font-family: var(--font-fun);
    font-size: 16px;
    margin-bottom: 6px;
}

.diary-card .content .tags {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.tag {
    display: inline-block;
    padding: 3px 10px;
    background: var(--cream);
    border-radius: 20px;
    font-size: 12px;
    color: var(--ink-light);
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--ink-light);
}

.empty-state .emoji {
    font-size: 48px;
    margin-bottom: 16px;
}

.empty-state p {
    font-size: 15px;
    margin-bottom: 20px;
}

/* ===== Record Page ===== */
.record-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px 20px;
    min-height: calc(100vh - 70px);
}

.record-character {
    width: 120px;
    height: 120px;
    margin-bottom: 16px;
}

.quota-display {
    font-size: 13px;
    color: var(--ink-light);
    margin-top: 4px;
    letter-spacing: 2px;
}

.record-page h2 {
    font-family: var(--font-display);
    font-size: 24px;
    margin-bottom: 8px;
}

.record-page .hint {
    color: var(--ink-light);
    font-size: 14px;
    margin-bottom: 40px;
}

.record-btn {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    border: 4px solid var(--accent);
    background: var(--paper);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 48px;
    transition: all 0.2s;
    margin-bottom: 20px;
}

.record-btn.recording {
    background: var(--blush);
    border-color: var(--blush);
    animation: pulse 1.5s ease-in-out infinite;
}

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

.timer {
    font-family: var(--font-handwrite);
    font-size: 32px;
    color: var(--ink);
    margin-bottom: 8px;
}

.timer-warning { color: var(--blush); }

/* Progress steps */
.progress-steps {
    width: 100%;
    max-width: 320px;
    margin-top: 30px;
}

.progress-step {
    display: flex;
    align-items: center;
    padding: 12px 0;
    font-size: 14px;
    color: var(--ink-light);
}

.progress-step .step-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--cream);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    font-size: 14px;
    flex-shrink: 0;
}

.progress-step.done .step-icon {
    background: var(--sage);
    color: white;
}

.progress-step.processing .step-icon {
    background: var(--accent);
    color: white;
    animation: pulse 1s ease-in-out infinite;
}
.progress-step.processing span:last-child::after {
    content: '';
    animation: dots 1.5s steps(3, end) infinite;
}
@keyframes dots {
    0% { content: ''; }
    33% { content: '.'; }
    66% { content: '..'; }
    100% { content: '...'; }
}

.progress-step.done { color: var(--ink); }
.progress-step.processing { color: var(--accent); font-weight: 500; }

/* ===== Diary Detail Page ===== */
.diary-detail {
    padding: 0 0 20px;
}

.diary-detail .scene {
    margin: 0 16px 16px;
}

.diary-detail .scene img {
    width: 100%;
    border-radius: var(--radius-lg);
    margin-bottom: 10px;
}

.diary-detail .scene .caption {
    font-family: var(--font-handwrite);
    font-size: 20px;
    color: var(--ink-light);
    text-align: center;
    padding: 0 12px;
    line-height: 1.5;
}

.diary-detail .title-section {
    text-align: center;
    padding: 20px;
}

.diary-detail .title-section h2 {
    font-family: var(--font-display);
    font-size: 26px;
    margin-bottom: 6px;
}

.diary-detail .title-section .date {
    font-family: var(--font-handwrite);
    font-size: 16px;
    color: var(--ink-light);
}

.diary-detail .original-text {
    margin: 0 16px;
    padding: 16px;
    background: var(--cream);
    border-radius: var(--radius-sm);
    font-size: 14px;
    line-height: 1.6;
    color: var(--ink-light);
}

.diary-detail .original-text summary {
    cursor: pointer;
    font-size: 13px;
    color: var(--ink-light);
    margin-bottom: 8px;
}

.diary-detail .actions {
    display: flex;
    gap: 12px;
    padding: 20px 16px;
    justify-content: center;
}

.diary-nav {
    display: flex;
    justify-content: space-between;
    padding: 0 16px;
}

.diary-nav button {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 14px;
    cursor: pointer;
    padding: 8px;
}

.diary-nav button:disabled { color: var(--cream); }

/* ===== Share Preview Page ===== */
.share-page {
    padding: 20px;
}

.share-preview {
    background: var(--paper);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: 20px;
    box-shadow: 0 4px 16px rgba(44, 36, 22, 0.1);
}

.share-preview img {
    width: 100%;
}

.share-caption {
    padding: 16px;
    font-size: 14px;
    line-height: 1.6;
    color: var(--ink-light);
    background: var(--cream);
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    white-space: pre-wrap;
}

/* ===== Profile Page ===== */
.profile-page { padding: 20px 0; }

.profile-header {
    text-align: center;
    padding: 20px 20px 24px;
}

.profile-header .avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--cream);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    margin: 0 auto 12px;
}

.profile-header .name {
    font-family: var(--font-fun);
    font-size: 20px;
}

.profile-header .email {
    font-size: 13px;
    color: var(--ink-light);
}

.day-count {
    font-size: 12px;
    color: var(--accent);
    margin-top: 4px;
    font-family: var(--font-handwrite);
}

.character-scroll {
    display: flex;
    gap: 8px;
    padding: 8px 0;
    overflow-x: auto;
    scrollbar-width: none;
}

.character-scroll::-webkit-scrollbar { display: none; }

.stats-row {
    display: flex;
    justify-content: space-around;
    padding: 20px 16px;
    background: var(--paper);
    border-radius: var(--radius-lg);
    margin: 0 16px 20px;
}

.stat-item {
    text-align: center;
}

.stat-item .num {
    font-family: var(--font-fun);
    font-size: 28px;
    color: var(--accent);
}

.stat-item .label {
    font-size: 12px;
    color: var(--ink-light);
    margin-top: 4px;
}

.settings-section {
    margin: 0 16px;
}

.settings-section h3 {
    font-family: var(--font-fun);
    font-size: 16px;
    padding: 8px 4px;
}

.setting-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--paper);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
}

.setting-item .label { font-size: 14px; }
.setting-item .value { font-size: 14px; color: var(--ink-light); }

.time-input {
    border: 1px solid var(--cream);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 14px;
    background: var(--paper);
    color: var(--ink);
}

/* Toggle switch */
.toggle {
    width: 44px;
    height: 24px;
    background: var(--cream);
    border-radius: 12px;
    position: relative;
    cursor: pointer;
    transition: background 0.2s;
}

.toggle.active { background: var(--sage); }

.toggle::after {
    content: '';
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    position: absolute;
    top: 2px;
    left: 2px;
    transition: transform 0.2s;
}

.toggle.active::after { transform: translateX(20px); }

/* ===== Loading & Toast ===== */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(250, 248, 244, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.loading-spinner {
    font-size: 36px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.toast {
    position: fixed;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--ink);
    color: white;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 14px;
    z-index: 300;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}

.toast.show { opacity: 1; }
