/* ===== base & theme (shared look with My Word Book, greener accent) ===== */
:root {
  --bg: #f3f7ff;
  --card: #ffffff;
  --primary: #5b8def;
  --primary-dark: #3f6fd1;
  --accent: #ff9f43;
  --green: #2ecc71;
  --green-dark: #27ae60;
  --red: #ff6b6b;
  --purple: #a55eea;
  --text: #2d3a4b;
  --text-soft: #7a8aa0;
  --line: #e6ecf7;
  --shadow: 0 6px 20px rgba(91, 141, 239, 0.15);
  --radius: 20px;
  font-size: 18px;
}

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

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, -apple-system, sans-serif;
  overscroll-behavior: none;
}

#app {
  display: flex; flex-direction: column;
  height: 100vh;            /* fallback */
  height: 100svh;           /* small viewport: never covered by browser chrome */
  height: 100dvh;           /* dynamic viewport where supported */
  max-width: 900px; margin: 0 auto; background: var(--bg);
  overflow: hidden;         /* only .view scrolls; frame stays put */
}

/* ===== top bar (fixed frame, adapts to notch / narrow screens) ===== */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  background: linear-gradient(135deg, var(--green), var(--primary));
  color: #fff; box-shadow: var(--shadow); z-index: 5;
  flex-shrink: 0;           /* never let the bar collapse */
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand-emoji { font-size: 1.5rem; flex-shrink: 0; }
.brand-title {
  font-size: 1.2rem; font-weight: 800; letter-spacing: 0.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.score-chip {
  display: flex; align-items: center; gap: 4px;
  background: rgba(255,255,255,0.25);
  padding: 5px 10px; border-radius: 999px;
  font-weight: 800; font-size: 1rem; white-space: nowrap;
}
.score-star { font-size: 1.05rem; }
.icon-btn {
  background: rgba(255,255,255,0.2); border: none; color: #fff;
  width: 40px; height: 40px; border-radius: 50%;
  font-size: 1.25rem; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:active { transform: scale(0.92); }

/* narrow phones: shrink the title a touch so nothing overlaps */
@media (max-width: 400px) {
  .brand-title { font-size: 1.05rem; }
  .topbar { padding-left: 12px; padding-right: 12px; }
}

/* ===== main (the ONLY scrolling area) ===== */
.view { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 18px; -webkit-overflow-scrolling: touch; }

/* ===== bottom nav (fixed frame) ===== */
.tabbar {
  display: flex; background: var(--card); border-top: 2px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
  flex-shrink: 0;
}
.tab-btn {
  flex: 1; background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px; border-radius: 14px;
  color: var(--text-soft); font-size: 0.8rem; font-weight: 700; position: relative;
}
.tab-emoji { font-size: 1.5rem; filter: grayscale(0.4); }
.tab-btn.active { color: var(--green-dark); background: #eafaf0; }
.tab-btn.active .tab-emoji { filter: none; transform: translateY(-2px); }
.tab-btn:active { transform: scale(0.95); }
.tab-badge {
  position: absolute; top: 2px; right: 22%;
  background: var(--red); color: #fff;
  min-width: 20px; height: 20px; border-radius: 999px;
  font-size: 0.72rem; font-weight: 800;
  display: flex; align-items: center; justify-content: center; padding: 0 5px;
}

/* ===== generic card / button ===== */
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.btn {
  border: none; border-radius: 999px;
  padding: 14px 22px; font-size: 1.05rem; font-weight: 800;
  cursor: pointer; transition: transform .08s; font-family: inherit;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-green { background: var(--green); color: #fff; }
.btn-ghost { background: #eef2fb; color: var(--text); }
.btn-danger { background: var(--red); color: #fff; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.section-title {
  font-size: 1.1rem; font-weight: 800; margin: 14px 0 12px;
  display: flex; align-items: center; gap: 8px;
}
.empty {
  text-align: center; color: var(--text-soft);
  padding: 40px 20px; font-size: 1.05rem; line-height: 1.7;
}
.empty-emoji { font-size: 3rem; display: block; margin-bottom: 10px; }
.empty-mini { color: var(--text-soft); text-align: center; padding: 16px; font-size: 0.95rem; }

/* ===== import bar ===== */
.import-bar { margin-bottom: 16px; }

/* ===== date section header ===== */
.date-header {
  display: flex; align-items: center; gap: 8px;
  margin: 18px 2px 10px; font-weight: 800; font-size: 1.15rem; color: var(--text);
}
.date-header:first-child { margin-top: 4px; }
.date-header-icon { font-size: 1.2rem; }

/* ===== rainbow subject cards (WorkBuddy-style) ===== */
.rb-card { padding: 0; overflow: hidden; }
.rb-head {
  cursor: pointer;
  user-select: none;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; color: #fff;
}
.rb-head-left { display: flex; align-items: center; gap: 8px; }
.rb-emoji { font-size: 1.25rem; }
.rb-subject { font-weight: 800; font-size: 1.1rem; letter-spacing: 0.5px; }
.rb-star { font-size: 1rem; }
.rb-head-right { display: flex; align-items: center; gap: 8px; }
.rb-count {
  background: rgba(255,255,255,0.28); color: #fff;
  font-weight: 800; font-size: 0.9rem;
  padding: 3px 12px; border-radius: 999px;
}
.rb-caret { color: #fff; font-size: 0.85rem; opacity: 0.9; }
.rb-list { padding: 4px 14px 10px; }
/* collapsed finished card: keep only the colored header, hide the task rows */
.rb-card.collapsed .rb-list { display: none; }

/* ===== archive: notice banner, buttons, history rows ===== */
.archive-notice {
  display: flex; align-items: center; gap: 8px;
  background: #fff6e0; border: 1px solid #ffd580; color: #7a5200;
  border-radius: 12px; padding: 10px 12px; margin-bottom: 12px;
  font-size: 0.9rem;
}
.archive-notice-emoji { font-size: 1.2rem; }
.archive-notice-text { flex: 1; line-height: 1.35; }
.archive-btn-row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.archive-btn-row .btn { flex: 1; min-width: 130px; }
.arch-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 2px; border-bottom: 1px solid var(--line);
}
.arch-row:last-child { border-bottom: 0; }
.arch-mark { color: #2ecc71; font-weight: 800; }
.arch-subj { font-size: 1.05rem; }
.arch-text { flex: 1; color: var(--ink, #333); }

.task-row {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 4px; border-bottom: 1px solid var(--line);
}
.task-row:last-child { border-bottom: none; }

.task-check { padding-top: 2px; }
.check-box {
  width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid var(--line); background: #fff;
  font-size: 1rem; font-weight: 900; cursor: pointer;
  display: flex; align-items: center; justify-content: center; color: #fff;
  flex-shrink: 0;
}
.check-box.checked, .check-box.skipped { color: #fff; }
.check-box:active { transform: scale(0.9); }

.task-body { flex: 1; min-width: 0; }
.task-text { font-size: 1.08rem; font-weight: 700; line-height: 1.4; word-break: break-word; }
.task-text.closed-text { text-decoration: line-through; color: var(--text-soft); font-weight: 600; }

.task-timer {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 8px;
}
.timer-clock { font-size: 0.95rem; }
.timer-num {
  font-variant-numeric: tabular-nums; font-weight: 800;
  color: var(--primary-dark); min-width: 54px; font-size: 0.95rem;
}
.task-bonus { display: flex; align-items: center; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.bonus-have { font-size: 0.85rem; font-weight: 800; color: var(--accent); }

.tinybtn {
  border: none; border-radius: 999px; padding: 6px 12px;
  font-size: 0.82rem; font-weight: 800; cursor: pointer;
  font-family: inherit; background: #eef4ff; color: var(--primary-dark);
}
.tinybtn:active { transform: scale(0.94); }
.tinybtn.go { background: var(--green); color: #fff; }
.tinybtn.stop { background: var(--accent); color: #fff; }
.tinybtn.ghost { background: #f0f3fa; color: var(--text-soft); }

.task-actions { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }

/* ===== add / edit form ===== */
.form-label { font-weight: 800; font-size: 0.95rem; margin: 14px 0 8px; }
.subject-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.subject-chip {
  border: 2px solid var(--line); background: #fff; color: var(--text);
  border-radius: 999px; padding: 8px 14px; font-size: 0.95rem; font-weight: 700;
  cursor: pointer; font-family: inherit;
}
.subject-chip.active { border-color: var(--green); background: #eafaf0; color: var(--green-dark); }
.form-textarea {
  width: 100%; border: 2px solid var(--line); border-radius: 14px;
  padding: 12px 14px; font-size: 1.05rem; font-family: inherit;
  color: var(--text); outline: none; resize: vertical;
}
.form-textarea:focus { border-color: var(--primary); }
.date-row { display: flex; gap: 12px; margin-top: 14px; }
.date-field { flex: 1; }
.date-field input {
  width: 100%; border: 2px solid var(--line); border-radius: 12px;
  padding: 10px 12px; font-size: 1rem; font-family: inherit; color: var(--text); outline: none;
}
.date-field input:focus { border-color: var(--primary); }

/* ===== report ===== */
.report-week { font-weight: 800; font-size: 1rem; margin-bottom: 12px; }
.report-stars { color: var(--green-dark); }
.report-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.report-subj { width: 92px; font-size: 0.9rem; font-weight: 700; flex-shrink: 0; }
.report-bar-track { flex: 1; height: 16px; background: var(--line); border-radius: 999px; overflow: hidden; }
.report-bar-fill { height: 100%; background: linear-gradient(90deg, var(--green), var(--primary)); border-radius: 999px; }
.report-time { width: 74px; text-align: right; font-size: 0.85rem; font-weight: 700; color: var(--text-soft); flex-shrink: 0; }
.report-total { margin-top: 6px; text-align: right; font-weight: 800; color: var(--primary-dark); }

/* ===== rewards: member card + growing badge ===== */
.member-card { padding: 0; overflow: hidden; }
.member-hero {
  padding: 18px 18px 20px; color: #fff; text-align: center;
}
.member-top { display: flex; align-items: center; justify-content: space-between; }
.member-rank { font-size: 1.25rem; font-weight: 900; letter-spacing: 0.5px; }
.member-life { font-size: 0.9rem; font-weight: 700; opacity: 0.9; }

.badge-stage {
  height: 120px; display: flex; align-items: center; justify-content: center;
  margin: 6px 0 4px;
}
.grow-badge {
  font-size: 5rem; line-height: 1; transition: transform .5s cubic-bezier(.34,1.56,.64,1);
  filter: drop-shadow(0 4px 10px rgba(0,0,0,0.25));
}
.grow-badge.ready-pulse { animation: badgePulse 1s ease-in-out infinite; }
@keyframes badgePulse {
  0%,100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.member-track {
  height: 12px; background: rgba(255,255,255,0.3); border-radius: 999px;
  overflow: hidden; margin: 6px 4px 8px;
}
.member-fill {
  height: 100%; background: #fff; border-radius: 999px; transition: width .5s;
}
.member-next { font-size: 0.92rem; font-weight: 700; opacity: 0.95; }

.member-spend { text-align: center; padding: 12px; font-size: 1rem; color: var(--text); }
.member-spend b { font-size: 1.4rem; color: var(--accent); }

/* badge wall */
.badge-wall {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px;
  padding: 0 12px 16px;
}
.badge-wall.wall-7 { grid-template-columns: repeat(7, 1fr); gap: 4px; }
.badge-wall.wall-7 .badge-cell { padding: 6px 1px; }
.badge-wall.wall-7 .badge-cell-emoji { font-size: 1.5rem; }
.badge-wall.wall-7 .badge-cell-name { font-size: 0.56rem; }
.badge-wall.wall-7 .badge-cell-min { font-size: 0.52rem; }
.badge-cell {
  text-align: center; padding: 8px 2px; border-radius: 12px; background: #f7faff;
}
.badge-cell-emoji { font-size: 1.8rem; line-height: 1.2; transition: transform .3s; }
.badge-cell-name { font-size: 0.62rem; font-weight: 700; margin-top: 2px; line-height: 1.1; }
.badge-cell-min { font-size: 0.58rem; color: var(--text-soft); }
.badge-cell.locked .badge-cell-emoji { filter: grayscale(1) opacity(0.35); transform: scale(0.82); }
.badge-cell.locked .badge-cell-name { color: var(--text-soft); }
.badge-cell.lit { background: #fff7e6; }
.badge-cell.current { background: #fff0d6; box-shadow: 0 0 0 2px var(--accent) inset; }

/* theme switcher */
.theme-switch { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 0 14px 16px; }
.theme-switch-label { font-size: 0.85rem; font-weight: 700; color: var(--text-soft); }
.theme-chip {
  border: 2px solid var(--line); background: #fff; color: var(--text);
  border-radius: 999px; padding: 6px 12px; font-size: 0.85rem; font-weight: 700;
  cursor: pointer; font-family: inherit;
}
.theme-chip.active { border-color: var(--accent); background: #fff7e6; }

/* ===== reward shop: 6 fixed tiers grid ===== */
.wish-intro { font-size: 0.9rem; color: var(--text-soft); margin: 4px 0 12px; line-height: 1.5; }
.reward-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  grid-auto-rows: 1fr;              /* every row the same height */
  align-items: stretch;
}
.reward-box {
  position: relative; border-radius: 16px; padding: 30px 12px 14px;
  background: #f7faff; border: 2px solid var(--line); text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  height: 100%;                     /* fill the equal-height row */
}
.reward-box.approved { background: #fff7e6; border-color: #ffe0a3; }
.reward-box.empty { background: #fbfcff; }
.reward-cost {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
  background: var(--accent); color: #fff; font-weight: 800; font-size: 0.8rem;
  padding: 3px 12px; border-radius: 999px; cursor: pointer; white-space: nowrap;
}
.reward-emoji { font-size: 2.6rem; line-height: 1; margin-top: 2px; }
/* name takes the flexible middle space so the money + button below always line up */
.reward-name {
  font-weight: 800; font-size: 0.98rem; line-height: 1.3; word-break: break-word;
  flex: 1 0 auto; display: flex; align-items: center; justify-content: center;
}
.reward-name.reward-hint { font-weight: 600; font-size: 0.82rem; color: var(--text-soft); }
.reward-money { font-size: 0.72rem; color: var(--text-soft); }
.reward-btn { width: 100%; padding: 9px; font-size: 0.88rem; margin-top: 4px; }
.reward-edit {
  border: none; background: none; color: var(--text-soft);
  font-size: 0.78rem; cursor: pointer; text-decoration: underline; padding: 2px;
}

/* wish dialog */
.wish-input {
  width: 100%; border: 2px solid var(--line); border-radius: 12px;
  padding: 12px 14px; font-size: 1rem; font-family: inherit; color: var(--text); outline: none;
  margin-bottom: 4px;
}
.wish-input:focus { border-color: var(--primary); }
.emoji-picker { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.emoji-chip {
  border: 2px solid var(--line); background: #fff; border-radius: 12px;
  width: 44px; height: 44px; font-size: 1.4rem; cursor: pointer; line-height: 1;
}
.emoji-chip.active { border-color: var(--accent); background: #fff7e6; transform: scale(1.05); }

/* transaction history */
.txn-list { display: flex; flex-direction: column; gap: 4px; }
.txn-row { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; background: #f7faff; font-size: 0.9rem; }
.txn-reason { flex: 1; }
.txn-day { color: var(--text-soft); font-size: 0.8rem; }
.txn-delta { font-weight: 800; min-width: 56px; text-align: right; }
.txn-delta.pos { color: var(--green-dark); }
.txn-delta.neg { color: var(--red); }

/* ===== modal ===== */
.modal {
  position: fixed; inset: 0; background: rgba(45,58,75,0.5);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 18px;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--card); border-radius: 24px; padding: 24px;
  width: 100%; max-width: 460px; max-height: 90vh; overflow-y: auto; position: relative;
}
.modal-card h2 { margin: 0 0 6px; }
.modal-close {
  position: absolute; top: 16px; right: 16px; background: #eef2fb;
  border: none; width: 36px; height: 36px; border-radius: 50%; font-size: 1rem; cursor: pointer; color: var(--text-soft);
}
.settings-hint { color: var(--text-soft); font-size: 0.92rem; line-height: 1.6; margin: 6px 0 16px; }
.app-version { font-size: 0.8rem; font-weight: 700; color: var(--text-soft); background: #f2f2f2; border-radius: 999px; padding: 3px 10px; vertical-align: middle; }
.field-hint { display: block; color: var(--text-soft); font-size: 0.78rem; margin-top: 4px; line-height: 1.4; }
.preset-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.preset-chip {
  border: 2px solid var(--line); background: #fff; color: var(--primary-dark);
  border-radius: 999px; padding: 5px 12px; font-size: 0.82rem; font-weight: 700;
  cursor: pointer; font-family: inherit;
}
.preset-chip:active { transform: scale(0.95); }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-weight: 700; margin-bottom: 6px; font-size: 0.95rem; }
.field input {
  width: 100%; border: 2px solid var(--line); border-radius: 12px;
  padding: 12px 14px; font-size: 1rem; outline: none; font-family: inherit; color: var(--text);
}
.field input:focus { border-color: var(--primary); }
.settings-actions { display: flex; gap: 10px; margin-top: 8px; }
.settings-actions .btn { flex: 1; }
.settings-status { margin-top: 12px; font-size: 0.95rem; font-weight: 700; min-height: 22px; }
.settings-status.ok { color: var(--green-dark); }
.settings-status.err { color: var(--red); }
.settings-divider { border: none; border-top: 1px solid var(--line); margin: 20px 0; }
.settings-danger summary { font-weight: 700; cursor: pointer; color: var(--text-soft); }
.danger-row { display: flex; gap: 10px; margin: 12px 0; }
.danger-row .btn { flex: 1; }

/* ===== busy overlay ===== */
.busy-overlay {
  position: fixed; inset: 0; background: rgba(45,58,75,0.55);
  display: flex; align-items: center; justify-content: center; z-index: 58;
}
.busy-overlay[hidden] { display: none; }
.busy-card { background: #fff; border-radius: 20px; padding: 26px 34px; text-align: center; }
.busy-msg { margin-top: 12px; font-weight: 700; color: var(--text); }
.spinner {
  width: 40px; height: 40px; border: 4px solid var(--line);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin 0.8s linear infinite; margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== toast & celebrate ===== */
.toast {
  position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff; padding: 12px 22px; border-radius: 999px;
  font-weight: 700; font-size: 1rem; z-index: 60; box-shadow: var(--shadow);
  animation: toastIn .25s;
}
.toast[hidden] { display: none; }
.toast.score { background: var(--green-dark); }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 12px); } }

.celebrate {
  position: fixed; inset: 0; z-index: 55; pointer-events: none;
  display: flex; align-items: center; justify-content: center;
}
.celebrate[hidden] { display: none; }
.celebrate-card {
  background: #fff; border-radius: 24px; padding: 30px 36px; text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,0.2); pointer-events: auto; animation: pop .4s;
}
.celebrate-emoji { font-size: 4rem; }
.celebrate-title { font-size: 1.6rem; font-weight: 900; margin: 8px 0; color: var(--green-dark); }
.celebrate-sub { color: var(--text-soft); font-size: 1.1rem; }
@keyframes pop { from { transform: scale(0.6); opacity: 0; } }

.confetti {
  position: fixed; width: 12px; height: 12px; top: -20px; z-index: 54;
  animation: fall linear forwards;
}
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); opacity: 0.9; } }

/* topbar links (switch between apps) look like the old brand/icon button */
a.brand { text-decoration: none; color: inherit; cursor: pointer; }
a.icon-btn { text-decoration: none; }
