:root {
  color-scheme: light;
  --bg: #f4f3ee;
  --surface: #ffffff;
  --surface-soft: #f1f4f2;
  --ink: #20252b;
  --muted: #67707a;
  --line: #d8dcd8;
  --accent: #df3f37;
  --accent-dark: #b82c27;
  --cyan: #147d94;
  --green: #18765c;
  --amber: #c68112;
  --shadow: 0 12px 32px rgba(29, 36, 42, 0.09);
  --radius: 8px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin-top: 0; }

.app-shell {
  width: min(1240px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.challenge-header {
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  flex-direction: column;
  gap: 20px;
  min-height: 390px;
  margin-bottom: 16px;
  padding: 28px;
  border-radius: var(--radius);
  background-color: #20252b;
  background-image: url("./growth-hero.png");
  background-position: center;
  background-size: cover;
  color: #fff;
  box-shadow: var(--shadow);
}

.brand-block { max-width: 560px; }

.eyebrow, .section-kicker {
  margin: 0 0 6px;
  color: #f06a61;
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin-bottom: 10px;
  font-size: clamp(2.25rem, 5vw, 4.5rem);
  line-height: 1;
}

h2 { margin-bottom: 0; font-size: 1.18rem; }
.battle-cry { margin: 0; color: #cbd1d5; font-size: 1rem; }

.header-scoreboard {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  width: min(100%, 540px);
  border: 1px solid #48515a;
  border-radius: var(--radius);
  background: #2b3239;
}

.header-scoreboard div { padding: 16px; border-right: 1px solid #48515a; }
.header-scoreboard div:last-child { border-right: 0; }
.header-scoreboard span { display: block; color: #aeb8bf; font-size: 0.76rem; }
.header-scoreboard strong { display: block; margin-top: 6px; white-space: nowrap; font-size: 1rem; }
.header-scoreboard b { color: #ff7066; font-size: 1.65rem; }

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

.stat-card, .mission-panel, .goals-panel, .calendar-panel, .trend-panel,
.storage-panel, .entry-panel, .records-panel, .cloud-panel, .quick-entry {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.stat-card { padding: 18px; border-top: 4px solid var(--cyan); }
.stat-fitness { border-top-color: var(--accent); }
.stat-spend { border-top-color: var(--amber); }
.stat-kicker { display: block; color: var(--muted); font-size: 0.82rem; font-weight: 800; }
.stat-card strong { display: block; margin: 7px 0 12px; font-size: 1.75rem; }
.stat-card small { display: block; margin-top: 7px; color: var(--muted); }

.progress-track { width: 100%; height: 7px; overflow: hidden; border-radius: 4px; background: #e5e8e6; }
.progress-track span { display: block; width: 0; height: 100%; background: var(--cyan); transition: width 0.35s ease; }
.stat-fitness .progress-track span { background: var(--accent); }
.stat-spend .progress-track span { background: var(--amber); }
.stat-spend.over-budget { border-top-color: var(--accent); background: #fff7f6; }
.stat-spend.over-budget .progress-track span { background: var(--accent); }

.mission-panel, .goals-panel, .calendar-panel, .trend-panel { padding: 20px; }
.mission-panel { margin-bottom: 16px; border-left: 5px solid var(--accent); }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.mission-state, .active-days { flex: 0 0 auto; color: var(--muted); font-size: 0.82rem; font-weight: 900; }
.mission-state.done { color: var(--green); }

.mission-control { display: grid; grid-template-columns: 46px minmax(0, 1fr) auto; gap: 10px; margin-top: 16px; }
.mission-check { position: relative; display: block; width: 46px; height: 46px; }
.mission-check input { position: absolute; opacity: 0; }
.mission-check span { display: grid; place-items: center; width: 46px; height: 46px; border: 2px solid #c7ceca; border-radius: var(--radius); color: transparent; font-size: 1.35rem; font-weight: 900; }
.mission-check input:checked + span { border-color: var(--green); background: var(--green); color: #fff; }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr); gap: 16px; margin-bottom: 16px; }
.goal-inputs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 18px; }
.goal-verdict { margin: 16px 0 0; padding: 12px; border-left: 4px solid var(--accent); background: #fff2f1; color: #6f2824; font-weight: 800; line-height: 1.5; }

.activity-calendar { display: grid; grid-template-columns: repeat(10, minmax(18px, 1fr)); gap: 7px; margin-top: 18px; }
.activity-day { position: relative; aspect-ratio: 1; min-width: 0; border: 1px solid #d8ddda; border-radius: 4px; background: #edf0ee; }
.activity-day.today { outline: 2px solid var(--ink); outline-offset: 2px; }
.level-0 { background: #edf0ee; }
.level-1 { background: #badbd1; }
.level-2 { background: #72b7a1; }
.level-3 { background: #258466; }
.level-4 { background: #df3f37; }
.calendar-legend { display: flex; align-items: center; justify-content: flex-end; gap: 5px; margin-top: 12px; color: var(--muted); font-size: 0.72rem; }
.calendar-legend i { width: 13px; height: 13px; border: 1px solid rgba(0,0,0,.08); border-radius: 3px; }

.trend-panel { margin-bottom: 16px; }
.chart-wrap { width: 100%; margin-top: 14px; overflow-x: auto; }
#trendChart { display: block; width: 100%; height: 280px; min-width: 560px; }
.chart-legend { display: flex; justify-content: center; gap: 22px; color: var(--muted); font-size: 0.78rem; }
.chart-legend span::before { content: ""; display: inline-block; width: 9px; height: 9px; margin-right: 6px; border-radius: 50%; background: var(--cyan); }
.chart-legend .legend-fitness::before { background: var(--accent); }
.chart-legend .legend-spend::before { background: var(--amber); }

.storage-panel { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 16px; padding: 16px 18px; }
.storage-summary { display: flex; align-items: center; gap: 12px; min-width: 0; }
.storage-icon { display: grid; flex: 0 0 auto; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: #e5f2f5; color: var(--cyan); }
.storage-status { margin: 4px 0 0; color: var(--muted); font-size: 0.82rem; overflow-wrap: anywhere; }
.storage-status.success { color: var(--green); }
.storage-status.error { color: var(--accent-dark); }
.storage-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

.cloud-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
  padding: 14px 18px;
}

.cloud-copy { display: flex; align-items: center; gap: 11px; min-width: 0; }
.cloud-copy p { margin: 4px 0 0; color: var(--muted); font-size: .8rem; }
.cloud-indicator { flex: 0 0 auto; width: 11px; height: 11px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 0 4px rgba(198,129,18,.14); }
.cloud-indicator.online { background: var(--green); box-shadow: 0 0 0 4px rgba(24,118,92,.14); }
.auth-form { display: grid; grid-template-columns: 180px 180px auto auto; gap: 8px; }
.account-actions { display: flex; align-items: center; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.account-actions span { max-width: 240px; color: var(--muted); font-size: .82rem; overflow-wrap: anywhere; }

.quick-entry {
  display: grid;
  gap: 16px;
  margin-bottom: 16px;
  padding: 22px;
  border-top: 5px solid var(--accent);
}
.entry-hint { color: var(--muted); font-size: .78rem; }
.quick-form-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.quick-form-lower { display: grid; grid-template-columns: minmax(230px, .65fr) minmax(0, 1.35fr); gap: 12px; align-items: start; }
.gain-field textarea { min-height: 76px; }
.quick-entry-actions { display: flex; justify-content: flex-end; gap: 9px; }
.quick-entry-actions .primary-button { min-width: 180px; }

.workspace { display: grid; grid-template-columns: minmax(330px, 430px) minmax(0, 1fr); gap: 16px; align-items: start; }
.history-section { display: block; }
.entry-panel { display: grid; gap: 16px; padding: 20px; }
.records-panel { min-height: 520px; padding: 20px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: grid; gap: 7px; }
.field span { color: var(--muted); font-size: 0.84rem; font-weight: 800; }

input, select, textarea {
  width: 100%;
  border: 1px solid #c9cfcb;
  border-radius: var(--radius);
  background: #fbfcfb;
  color: var(--ink);
  outline: none;
  transition: border-color .18s, box-shadow .18s, background .18s;
}
input, select { min-height: 44px; padding: 0 11px; }
textarea { min-height: 112px; padding: 11px; resize: vertical; line-height: 1.6; }
input:focus, select:focus, textarea:focus { border-color: var(--cyan); background: #fff; box-shadow: 0 0 0 3px rgba(20,125,148,.14); }

.segmented { display: grid; grid-template-columns: 1fr 1fr; overflow: hidden; border: 1px solid #c9cfcb; border-radius: var(--radius); background: #eef1ef; }
.segmented label { position: relative; }
.segmented input { position: absolute; inset: 0; opacity: 0; }
.segmented span { display: grid; place-items: center; min-height: 44px; color: var(--ink); font-size: .84rem; font-weight: 900; }
.segmented input:checked + span { background: var(--accent); color: #fff; }
.segmented.small { width: 190px; }
.segmented.small span { min-height: 38px; }

.primary-button, .secondary-button, .ghost-button, .danger-button, .record-action {
  min-height: 40px;
  padding: 0 13px;
  border: 0;
  border-radius: var(--radius);
  font-weight: 900;
}
.primary-button { min-height: 48px; background: var(--accent); color: #fff; }
.primary-button:hover { background: var(--accent-dark); }
.primary-button.compact { min-height: 46px; }
.secondary-button { background: var(--cyan); color: #fff; }
.secondary-button:hover { background: #0f6578; }
.ghost-button, .record-action { background: #e9efec; color: #285b4b; }
.danger-button, .record-action.delete { background: #f9e8e6; color: #9b302b; }
button:disabled { cursor: not-allowed; opacity: .5; }

.record-filters { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr auto; gap: 8px; margin-top: 16px; }
.filter-result { min-height: 18px; margin: 10px 0 0; color: var(--muted); font-size: .78rem; }
.records-list { display: grid; gap: 11px; margin-top: 8px; }
.record-card { display: grid; gap: 11px; padding: 15px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.record-head { display: flex; align-items: start; justify-content: space-between; gap: 12px; }
.record-date { margin: 0 0 4px; font-size: 1.02rem; }
.record-meta { color: var(--muted); font-size: .76rem; }
.record-actions { display: flex; gap: 7px; }
.record-metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; }
.metric { min-height: 66px; padding: 9px; border-radius: var(--radius); background: var(--surface-soft); }
.metric span { display: block; color: var(--muted); font-size: .73rem; font-weight: 800; }
.metric strong { display: block; margin-top: 5px; overflow-wrap: anywhere; font-size: .92rem; }
.record-gain { margin: 0; padding: 11px; border-left: 4px solid var(--amber); background: #fff8e9; color: #493a20; line-height: 1.6; white-space: pre-wrap; }

.empty-state { display: grid; place-items: center; align-content: center; min-height: 300px; color: var(--muted); text-align: center; }
.empty-state strong { color: var(--ink); font-size: 1.1rem; }
.empty-state p { margin: 8px 0 0; }

.toast { position: fixed; right: 20px; bottom: 20px; z-index: 10; display: flex; align-items: center; gap: 16px; max-width: min(420px, calc(100% - 32px)); padding: 13px 16px; border-radius: var(--radius); background: #20252b; color: #fff; box-shadow: 0 16px 42px rgba(0,0,0,.24); opacity: 0; pointer-events: none; transform: translateY(12px); transition: .22s ease; }
.toast.show { opacity: 1; pointer-events: auto; transform: translateY(0); }
.toast button { border: 0; background: transparent; color: #ff776e; font-weight: 900; cursor: pointer; }
.mobile-log-button { display: none; }

@media (max-width: 1000px) {
  .challenge-header { min-height: 360px; }
  .cloud-panel { align-items: stretch; flex-direction: column; }
  .auth-form { grid-template-columns: 1fr 1fr auto auto; }
  .quick-form-grid { grid-template-columns: 1fr 1fr; }
  .dashboard-grid, .workspace { grid-template-columns: 1fr; }
  .record-filters { grid-template-columns: repeat(2, 1fr); }
  .record-filters button { min-height: 44px; }
}

@media (max-width: 720px) {
  .app-shell { width: min(100% - 20px, 620px); padding: 10px 0 28px; }
  .challenge-header { min-height: 420px; padding: 16px; background-position: 64% center; }
  .brand-block { padding: 10px; border-radius: var(--radius); background: rgba(32,37,43,.86); }
  .header-scoreboard { grid-template-columns: 1fr 1fr; }
  .header-scoreboard div { border-bottom: 1px solid #48515a; }
  .header-scoreboard div:nth-child(2) { border-right: 0; }
  .header-scoreboard div:last-child { grid-column: 1 / -1; border-bottom: 0; }
  .stats-grid { grid-template-columns: 1fr; }
  .auth-form { grid-template-columns: 1fr 1fr; }
  .auth-form input { grid-column: 1 / -1; }
  .quick-form-lower { grid-template-columns: 1fr; }
  .mission-control { grid-template-columns: 46px minmax(0, 1fr); }
  .mission-control button { grid-column: 1 / -1; }
  .goal-inputs { grid-template-columns: 1fr; }
  .storage-panel { align-items: stretch; flex-direction: column; }
  .storage-actions { justify-content: stretch; }
  .storage-actions button { flex: 1 1 150px; }
  .record-metrics { grid-template-columns: 1fr 1fr; }
  .mobile-log-button { position: fixed; right: 14px; bottom: 14px; z-index: 9; display: grid; place-items: center; min-width: 108px; min-height: 48px; padding: 0 16px; border-radius: 24px; background: var(--accent); color: #fff; box-shadow: 0 12px 28px rgba(184,44,39,.3); font-weight: 900; text-decoration: none; }
}

@media (max-width: 480px) {
  h1 { font-size: 2.2rem; }
  .challenge-header, .mission-panel, .goals-panel, .calendar-panel, .trend-panel, .entry-panel, .records-panel { padding: 16px; }
  .challenge-header { min-height: 420px; padding: 12px; }
  .quick-entry { padding: 16px; }
  .quick-entry .section-heading { flex-wrap: wrap; }
  .entry-hint { width: 100%; }
  .section-heading { align-items: flex-start; }
  .section-heading .segmented { width: 160px; }
  .activity-calendar { grid-template-columns: repeat(6, minmax(18px, 1fr)); }
  .form-row, .record-filters, .quick-form-grid { grid-template-columns: 1fr; }
  .record-head { display: grid; }
  .record-actions { width: 100%; }
  .record-action { flex: 1; }
  .records-heading { flex-wrap: wrap; }
  .records-heading .danger-button { width: 100%; }
  .chart-legend { gap: 10px; font-size: .7rem; }
}
