:root {
  --bg: #FFF8F0;
  --bg-soft: #FFFFFF;
  --card: #FFFFFF;
  --ink: #5D4037;
  --ink-soft: #8D6E63;
  --primary: #FF8A65;
  --primary-deep: #F4511E;
  --accent: #4FC3F7;
  --green: #81C784;
  --yellow: #FFD54F;
  --border: #F3E5D8;
  --shadow: 0 6px 24px rgba(181, 136, 99, 0.14);
  --story-font: 26px;
  --radius: 22px;
}

body.dark {
  --bg: #1B2430;
  --bg-soft: #223041;
  --card: #263447;
  --ink: #F3EAD8;
  --ink-soft: #BFAE93;
  --primary: #FF8A65;
  --primary-deep: #FFB59E;
  --border: #33465C;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

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

html, body { height: 100%; }

body {
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-soft) 100%);
  background-attachment: fixed;
  color: var(--ink);
  line-height: 1.6;
  transition: background 0.3s ease, color 0.3s ease;
}

.hidden { display: none !important; }

.view {
  max-width: 560px;
  margin: 0 auto;
  padding: 18px 18px 120px;
  min-height: 100vh;
  animation: fadeIn 0.35s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- 首页 ---------- */

.home-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px 16px;
}

.home-title h1 {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 1px;
  background: linear-gradient(120deg, var(--primary-deep), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.home-sub { font-size: 13px; color: var(--ink-soft); margin-top: 2px; }

.icon-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 14px;
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease;
}
.icon-btn:active { transform: scale(0.92); }

.streak-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.streak-day {
  width: 76px;
  height: 76px;
  flex-shrink: 0;
  border-radius: 20px;
  background: linear-gradient(135deg, #FFD54F, #FFB74D);
  color: #5D4037;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(255, 179, 71, 0.4);
}

.streak-num { font-size: 30px; font-weight: 800; line-height: 1.1; }

.streak-label { font-size: 11px; font-weight: 600; }

.streak-info p { font-size: 15px; font-weight: 700; }

.streak-note { font-size: 12px !important; font-weight: 400 !important; color: var(--ink-soft); margin-top: 2px; }

.today-card {
  background: var(--card);
  border-radius: 26px;
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 22px;
}

.today-cover { padding: 14px 14px 0; }

.svg-wrap { border-radius: 18px; overflow: hidden; line-height: 0; }
.svg-wrap svg { width: 100%; height: auto; display: block; }

.today-body { padding: 16px 20px 20px; }

.badge {
  display: inline-block;
  background: linear-gradient(135deg, var(--primary), var(--primary-deep));
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  margin-bottom: 8px;
  letter-spacing: 1px;
}

.today-body h2 { font-size: 26px; font-weight: 800; }

.today-sub { color: var(--ink-soft); font-size: 14px; margin-top: 2px; }

.today-meta { display: flex; gap: 8px; margin: 10px 0 14px; }

.meta-chip {
  font-size: 12px;
  color: var(--ink-soft);
  background: var(--bg);
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 600;
}

.primary-btn {
  width: 100%;
  border: none;
  border-radius: 16px;
  padding: 14px;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-deep));
  box-shadow: 0 6px 18px rgba(244, 81, 30, 0.32);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
  transition: transform 0.15s ease;
}
.primary-btn:active { transform: scale(0.97); }

.list-section { margin-top: 6px; }

.history-section { margin: 20px 0 6px; }

.history-list { display: flex; flex-direction: column; gap: 8px; }

.history-empty {
  font-size: 13px;
  color: var(--ink-soft);
  background: var(--card);
  border: 2px dashed var(--border);
  border-radius: 16px;
  padding: 18px 16px;
  text-align: center;
  line-height: 1.7;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--card);
  border: 2px solid transparent;
  border-radius: 16px;
  padding: 10px 14px;
  cursor: pointer;
  color: inherit;
  font-family: inherit;
  box-shadow: var(--shadow);
  transition: border 0.2s ease;
}
.history-item.today { border-color: var(--green); }

.history-date {
  flex-shrink: 0;
  width: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.history-date-main {
  font-size: 14px;
  font-weight: 800;
  color: var(--ink);
}

.history-date-time {
  font-size: 10px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-top: 1px;
  display: block;
}

.history-item.today .history-date-main { color: #2E7D32; }

.history-date-badge {
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  background: var(--green);
  padding: 2px 7px;
  border-radius: 999px;
}

.history-title {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-arrow { font-size: 20px; color: var(--ink-soft); flex-shrink: 0; }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
}
.section-head h3 { font-size: 18px; font-weight: 800; }
.section-count { font-size: 12px; color: var(--ink-soft); }

.story-list { display: flex; flex-direction: column; gap: 10px; }

.story-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  text-align: left;
  background: var(--card);
  border: 2px solid transparent;
  border-radius: 18px;
  padding: 10px;
  cursor: pointer;
  color: inherit;
  font-family: inherit;
  box-shadow: var(--shadow);
  transition: border 0.2s ease;
}
.story-item.active { border-color: var(--primary); }

.story-item-cover { width: 66px; height: 54px; flex-shrink: 0; border-radius: 12px; overflow: hidden; line-height: 0; }
.story-item-cover svg { width: 100%; height: 100%; object-fit: cover; }

.story-item-body { display: flex; flex-direction: column; min-width: 0; }
.story-item-title { font-size: 16px; font-weight: 700; }
.story-item-sub { font-size: 12px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.story-item-meta { font-size: 11px; color: var(--ink-soft); opacity: 0.85; margin-top: 2px; }

.cat-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 2px 8px;
  scrollbar-width: none;
}
.cat-tabs::-webkit-scrollbar { display: none; }

.cat-tab {
  flex-shrink: 0;
  padding: 8px 16px;
  border: none;
  border-radius: 20px;
  background: var(--card);
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  box-shadow: var(--shadow);
  transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
}
.cat-tab:active { transform: scale(0.95); }
.cat-tab.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-deep));
  color: #fff;
  box-shadow: 0 4px 12px rgba(244, 81, 30, 0.3);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 16px;
}

.page-btn {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border: none;
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  transition: transform 0.15s ease, opacity 0.2s ease;
}
.page-btn:active { transform: scale(0.9); }
.page-btn:disabled { opacity: 0.35; cursor: default; }

.page-nums {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  max-width: 60%;
  padding: 4px 2px;
  scrollbar-width: none;
}
.page-nums::-webkit-scrollbar { display: none; }

.page-num {
  min-width: 34px;
  height: 34px;
  border: none;
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, background 0.2s ease, color 0.2s ease;
}
.page-num:active { transform: scale(0.9); }
.page-num.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-deep));
  color: #fff;
  box-shadow: 0 4px 12px rgba(244, 81, 30, 0.3);
}

/* ---------- 故事阅读页 ---------- */

.story-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 4px 14px;
}

.story-header-title { flex: 1; min-width: 0; }
.story-header-title h2 { font-size: 19px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.progress-text { font-size: 12px; color: var(--ink-soft); }

.speak-btn.speaking { color: var(--primary-deep); animation: pulse 1.2s infinite; }

.page-text.reading {
  background: rgba(255, 183, 77, 0.16);
  border-radius: 10px;
  box-shadow: inset 0 0 0 2px rgba(255, 183, 77, 0.35);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%) translateY(16px);
  background: rgba(38, 40, 52, 0.92);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 24px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
  z-index: 99;
  transition: opacity 0.25s ease, transform 0.25s ease;
  max-width: 84vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.home-actions { display: flex; align-items: center; gap: 10px; }
.auth-area { display: flex; align-items: center; gap: 8px; }

.auth-btn {
  border: none;
  background: linear-gradient(135deg, var(--primary), var(--primary-deep));
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  height: 44px;
  padding: 0 18px;
  border-radius: 22px;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 4px 12px rgba(244, 81, 30, 0.3);
  transition: transform 0.15s ease;
  display: flex;
  align-items: center;
  white-space: nowrap;
}
.auth-btn:active { transform: scale(0.95); }

.user-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: var(--card);
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  height: 44px;
  padding: 0 14px;
  border-radius: 22px;
  cursor: pointer;
  font-family: inherit;
  box-shadow: var(--shadow);
  max-width: 120px;
  transition: transform 0.15s ease;
  white-space: nowrap;
}
.user-chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip:active { transform: scale(0.95); }

.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(30, 32, 44, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 90;
}
.modal-mask.hidden { display: none; }

.modal-card {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border-radius: 22px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}

.auth-tabs {
  display: flex;
  background: var(--bg);
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  position: relative;
}
.auth-tab {
  flex: 1;
  border: none;
  background: none;
  color: var(--ink-soft);
  font-size: 16px;
  font-weight: 800;
  padding: 16px 0;
  cursor: pointer;
  font-family: inherit;
  position: relative;
  transition: color 0.2s ease;
}
.auth-tab.active { color: var(--primary-deep); }
.auth-tab.active::after {
  content: '';
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 40px;
  height: 3px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--primary), var(--primary-deep));
}
.modal-close {
  position: absolute;
  right: 8px;
  top: 8px;
  width: 34px;
  height: 34px;
  border: none;
  background: none;
  color: var(--ink-soft);
  cursor: pointer;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}
.modal-close:active { transform: scale(0.9); }

.auth-form { padding: 22px 24px 26px; }
.auth-form.hidden { display: none; }
.auth-title {
  margin: 0 0 16px;
  font-size: 18px;
  font-weight: 800;
  color: var(--ink);
  text-align: center;
}
.auth-label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-soft);
  margin: 12px 0 6px;
}
.auth-input {
  width: 100%;
  box-sizing: border-box;
  border: 2px solid rgba(0, 0, 0, 0.08);
  background: var(--bg);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 15px;
  font-family: inherit;
  color: var(--ink);
  outline: none;
  transition: border-color 0.2s ease;
}
.auth-input:focus { border-color: var(--primary); }
.auth-tip { min-height: 18px; margin: 8px 0 0; font-size: 12px; color: #e53935; font-weight: 600; }
.auth-submit { width: 100%; margin-top: 14px; }

.record-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  border: none;
  background: var(--card);
  color: var(--primary-deep);
  font-size: 13px;
  font-weight: 800;
  padding: 6px 12px;
  border-radius: 16px;
  cursor: pointer;
  font-family: inherit;
  box-shadow: var(--shadow);
  margin-left: auto;
  transition: transform 0.15s ease;
}
.record-btn:active { transform: scale(0.94); }

.record-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 16px 8px;
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
}
.header-spacer { width: 44px; flex-shrink: 0; }

.record-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 8px 16px 4px;
}
.stat-card {
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 16px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.stat-num {
  font-size: 26px;
  font-weight: 800;
  color: var(--primary-deep);
  line-height: 1.1;
}
.stat-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
}

.calendar-section { margin: 0 16px 20px; }

.calendar {
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 14px 12px 16px;
}

.cal-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 10px;
}
.cal-title { font-size: 16px; font-weight: 800; color: var(--ink); min-width: 100px; text-align: center; }
.cal-nav {
  width: 32px; height: 32px; border: none; border-radius: 10px;
  background: var(--bg); color: var(--ink-soft); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-family: inherit; transition: transform 0.12s ease;
}
.cal-nav:active { transform: scale(0.9); }

.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-soft);
  margin-bottom: 6px;
}
.cal-weekdays span { padding: 4px 0; }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}
.cal-cell {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  border-radius: 10px;
  position: relative;
  line-height: 1.2;
}
.cal-cell.cal-empty { visibility: hidden; }
.cal-cell.cal-today { background: var(--primary); color: #fff; font-weight: 900; }
.cal-cell.cal-checked { color: var(--green); }
.cal-cell.cal-today.cal-checked { color: #fff; }
.cal-cell.cal-today .cal-check { color: rgba(255,255,255,0.9); }

.cal-check { font-size: 10px; color: var(--green, #43A047); display: block; line-height: 1; margin-top: -2px; }

#recordPagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 10px;
}
#recordPagination .page-btn {
  width: 34px; height: 34px; flex-shrink: 0;
  border: none; border-radius: 10px;
  background: var(--card); color: var(--ink);
  box-shadow: var(--shadow); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-family: inherit; transition: transform 0.12s ease;
}
#recordPagination .page-btn:active { transform: scale(0.9); }
#recordPagination .page-btn.disabled { opacity: 0.3; cursor: default; }
#recordPagination .page-num {
  min-width: 30px; height: 30px; border: none; border-radius: 8px;
  background: var(--card); color: var(--ink); font-size: 13px; font-weight: 700;
  cursor: pointer; font-family: inherit; box-shadow: var(--shadow);
  transition: transform 0.12s ease, background 0.2s ease, color 0.2s ease;
}
#recordPagination .page-num:active { transform: scale(0.9); }
#recordPagination .page-num.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-deep));
  color: #fff;
  box-shadow: 0 4px 12px rgba(244, 81, 30, 0.3);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.story-canvas {
  background: var(--card);
  border-radius: 26px;
  box-shadow: var(--shadow);
  padding: 22px 20px 26px;
  min-height: 420px;
  animation: pageIn 0.4s ease;
}

@keyframes pageIn {
  from { opacity: 0; transform: translateX(24px); }
  to { opacity: 1; transform: translateX(0); }
}

.page-art { margin-bottom: 14px; }
.page-dot {
  display: block;
  width: 48px;
  height: 48px;
  margin: 0 auto;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, var(--yellow) 34%, transparent 36%);
}

.page-text {
  font-size: var(--story-font);
  line-height: 1.95;
  font-weight: 500;
  text-align: justify;
  letter-spacing: 0.02em;
  white-space: pre-wrap;
}

.word-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 22px;
  padding-top: 16px;
  border-top: 2px dashed var(--border);
}

.word-label { font-size: 13px; font-weight: 700; color: var(--ink-soft); }

.word-chip {
  border: 2px solid var(--accent);
  background: rgba(79, 195, 247, 0.1);
  color: var(--ink);
  font-size: 17px;
  font-weight: 800;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.15s ease, background 0.2s ease;
}
.word-chip:active { transform: scale(0.9); background: rgba(79, 195, 247, 0.25); }

/* 寓意页 */

.page-moral { text-align: center; }

.moral-cover { margin: 0 auto 8px; max-width: 240px; }

.moral-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--primary-deep);
  letter-spacing: 2px;
  margin: 6px 0 10px;
}

.moral-big {
  font-size: 24px;
  font-weight: 800;
  line-height: 1.5;
  background: linear-gradient(135deg, var(--primary-deep), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 14px;
}

.moral-text {
  font-size: 16px;
  line-height: 1.9;
  text-align: justify;
  color: var(--ink);
}

.parent-tip {
  margin-top: 16px;
  text-align: left;
  background: var(--bg);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.7;
}
.parent-tip strong { display: block; color: var(--ink); font-size: 13px; margin-bottom: 2px; }

.page-moral .primary-btn { margin-top: 18px; }

/* 底部导航 */

.story-nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 74px;
  width: 100%;
  max-width: 560px;
  padding: 0 18px;
  display: flex;
  gap: 12px;
  z-index: 10;
}

.nav-btn {
  flex: 1;
  border: none;
  border-radius: 16px;
  padding: 15px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.15s ease;
}
.nav-btn:active { transform: scale(0.96); }

.nav-btn:disabled { opacity: 0.4; }

.primary-nav {
  background: linear-gradient(135deg, var(--primary), var(--primary-deep));
  color: #fff;
  box-shadow: 0 6px 18px rgba(244, 81, 30, 0.32);
}

.primary-nav.finish { background: linear-gradient(135deg, var(--green), #4CAF50); box-shadow: 0 6px 18px rgba(76, 175, 80, 0.32); }

.nav-btn:not(.primary-nav) { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

.font-controls {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 18px;
  display: flex;
  gap: 10px;
  z-index: 10;
}

.font-btn {
  width: 46px;
  height: 46px;
  border: none;
  border-radius: 50%;
  background: var(--card);
  color: var(--ink);
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: var(--shadow);
  font-family: inherit;
  transition: transform 0.15s ease;
}
.font-btn:active { transform: scale(0.9); }

@media (max-width: 420px) {
  .today-body h2 { font-size: 23px; }
  .moral-big { font-size: 21px; }
}
