:root {
  --bg: #f5f6f1;
  --surface: #ffffff;
  --ink: #24271f;
  --muted: #6d7268;
  --line: #e4e7dd;
  --accent: #3f7d5e;
  --accent-soft: #e5efe8;
  --accent-ink: #2d5c45;
  --warm: #cf7a52;
  --warm-soft: #f8e9df;
  --teal: #397a77;
  --danger: #b85743;
  --danger-soft: #f6e4de;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(30, 40, 30, 0.05), 0 10px 28px rgba(30, 40, 30, 0.06);
  --tabbar-h: 62px;
  --topbar-h: 54px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

#app {
  max-width: 760px;
  margin: 0 auto;
  min-height: 100dvh;
  position: relative;
  padding-bottom: calc(var(--tabbar-h) + 22px);
}

#topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: rgba(245, 246, 241, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 17px;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
}

.top-date {
  color: var(--muted);
  font-size: 13px;
}

#view {
  padding: 16px 16px 8px;
}

h1,
h2,
h3 {
  margin: 0 0 10px;
  font-weight: 700;
}

h1 {
  font-size: 22px;
}

h2 {
  font-size: 18px;
}

h3 {
  font-size: 15px;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 13px;
}

.center {
  text-align: center;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.wrap {
  flex-wrap: wrap;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}

.card-flat {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 20px 2px 10px;
}

.section-title h2 {
  margin: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 42px;
  padding: 9px 15px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: filter 0.15s ease, transform 0.05s ease;
}

.btn:active {
  transform: translateY(1px);
}

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

.btn-soft {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.btn-warm {
  background: var(--warm);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.btn-block {
  width: 100%;
}

.btn-sm {
  min-height: 34px;
  padding: 6px 11px;
  font-size: 13px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.icon-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.seg {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  gap: 2px;
  padding: 3px;
}

.seg button {
  flex: 1;
  min-height: 36px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  border-radius: 6px;
  padding: 7px 6px;
}

.seg button.active {
  background: var(--accent);
  color: #fff;
}

.seg button.active-warm {
  background: var(--warm);
  color: #fff;
}

.field {
  margin-bottom: 14px;
}

.field label,
.field-label {
  display: block;
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 7px;
  color: var(--ink);
}

.field-hint {
  color: var(--muted);
  font-size: 12px;
  margin-top: 5px;
}

input[type="text"],
input[type="number"],
input[type="time"],
input[type="date"],
select,
textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(63, 125, 94, 0.14);
}

textarea {
  min-height: 76px;
  resize: vertical;
}

.check-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.check-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  user-select: none;
}

.check-chip.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.check-chip input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.goal-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.goal-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 10px;
  background: var(--surface);
  text-align: left;
  cursor: pointer;
  font-weight: 600;
}

.goal-card.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.goal-card small {
  display: block;
  font-weight: 400;
  color: var(--muted);
  margin-top: 3px;
}

.stepper {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.stepper button {
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  display: grid;
  place-items: center;
}

.stepper-value {
  min-width: 54px;
  text-align: center;
  font-weight: 700;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0 12px;
}

@media (min-width: 560px) {
  .form-grid {
    grid-template-columns: 1fr 1fr;
  }
  .check-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .goal-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.hero-card {
  background: linear-gradient(135deg, #3f7d5e 0%, #397a77 100%);
  color: #fff;
  border: 0;
}

.hero-card .muted,
.hero-card .small {
  color: rgba(255, 255, 255, 0.78);
}

.hero-title {
  font-size: 22px;
  margin-bottom: 6px;
}

.hero-sub {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.82);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 10px;
  background: var(--surface);
}

.stat-label {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 3px;
}

.stat-value {
  font-size: 18px;
  font-weight: 700;
}

.stat-value small {
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
}

.day-list {
  display: grid;
  gap: 8px;
}

.day-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.day-card.today {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(63, 125, 94, 0.12);
}

.day-badge {
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 700;
  flex: 0 0 auto;
}

.day-badge.run {
  background: var(--warm-soft);
  color: var(--warm);
}

.day-badge.rest {
  background: #eef0ea;
  color: var(--muted);
}

.day-main {
  flex: 1;
  min-width: 0;
}

.day-title {
  font-weight: 700;
  font-size: 15px;
}

.day-meta {
  color: var(--muted);
  font-size: 13px;
}

.exercise-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}

.exercise-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.ex-name {
  font-weight: 600;
}

.ex-meta {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 12px;
  padding: 4px 9px;
  margin: 4px 4px 0 0;
}

.chip.warm {
  background: var(--warm-soft);
  color: var(--warm);
}

.chip.muted {
  background: #eef0ea;
  color: var(--muted);
}

.banner {
  border-radius: var(--radius);
  padding: 13px 14px;
  margin-bottom: 12px;
  font-size: 14px;
}

.banner-tip {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.banner-warn {
  background: var(--warm-soft);
  color: #925437;
}

.banner-info {
  background: #e7eff0;
  color: var(--teal);
}

.banner .row {
  margin-bottom: 6px;
}

.chart-wrap {
  width: 100%;
  overflow-x: auto;
}

.chart {
  display: block;
  width: 100%;
  min-width: 300px;
  height: auto;
}

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}

.list-row:last-child {
  border-bottom: 0;
}

.list-main {
  min-width: 0;
}

.list-sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 26px 10px;
}

.big-num {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 0;
}

.divider {
  height: 1px;
  background: var(--line);
  margin: 14px 0;
}

.tip-list {
  display: grid;
  gap: 8px;
}

.tip {
  display: flex;
  gap: 10px;
  padding: 10px;
  border-radius: var(--radius);
  background: #f8f9f5;
  border: 1px solid var(--line);
}

.tip-icon {
  flex: 0 0 auto;
  color: var(--accent);
}

.guide-svg {
  width: 100%;
  max-width: 260px;
  margin: 6px auto;
  display: block;
}

.switch {
  position: relative;
  width: 46px;
  height: 27px;
  flex: 0 0 auto;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-track {
  position: absolute;
  inset: 0;
  background: #dfe2d9;
  border-radius: 999px;
  transition: background 0.15s ease;
}

.switch-track::after {
  content: "";
  position: absolute;
  width: 21px;
  height: 21px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.15s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.switch input:checked + .switch-track {
  background: var(--accent);
}

.switch input:checked + .switch-track::after {
  transform: translateX(19px);
}

.week-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(86px, 1fr));
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.week-cell {
  min-height: 78px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 8px;
  font-size: 12px;
}

.week-cell.today {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.week-cell .dow {
  font-weight: 700;
  margin-bottom: 5px;
}

.week-cell .kind {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

#tabbar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 760px;
  height: var(--tabbar-h);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--line);
  z-index: 30;
  padding-bottom: env(safe-area-inset-bottom);
}

.tab {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--muted);
  font-size: 11px;
  text-decoration: none;
}

.tab.active {
  color: var(--accent);
}

.tab-badge {
  position: absolute;
  top: 8px;
  right: calc(50% - 20px);
  min-width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--warm);
}

#sheet {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
}

body.sheet-open {
  overflow: hidden;
}

body.sheet-open #sheet {
  display: block;
}

.sheet-mask {
  position: absolute;
  inset: 0;
  background: rgba(30, 35, 28, 0.38);
}

.sheet {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 760px;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 14px 14px 0 0;
  padding: 18px 16px 26px;
  box-shadow: 0 -8px 40px rgba(30, 40, 30, 0.16);
}

@media (min-width: 640px) {
  .sheet {
    border-radius: 14px;
    bottom: auto;
    top: 50%;
    transform: translate(-50%, -50%);
  }
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.sheet-head h2 {
  margin: 0;
}

#toast {
  position: fixed;
  bottom: calc(var(--tabbar-h) + 18px);
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: #2c3028;
  color: #fff;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 80;
  max-width: calc(100vw - 32px);
  text-align: center;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.log-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.log-row:last-child {
  border-bottom: 0;
}

.log-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.rir-seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.rir-seg button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 8px 4px;
  font-size: 13px;
  color: var(--muted);
}

.rir-seg button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 600;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

.reason-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.reason-grid button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 11px 8px;
  font-weight: 600;
}

.mini-ex {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}

.mini-ex:last-child {
  border-bottom: 0;
}

.mini-check {
  width: 24px;
  height: 24px;
  accent-color: var(--accent);
}

.metric-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.metric-chip {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  background: var(--surface);
  font-size: 13px;
  color: var(--muted);
}

.metric-chip.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 600;
}

.delta-up {
  color: var(--accent);
  font-weight: 700;
}

.delta-down {
  color: var(--warm);
  font-weight: 700;
}

.collapsible summary {
  cursor: pointer;
  font-weight: 600;
  padding: 6px 0;
}

.collapsible[open] summary {
  margin-bottom: 8px;
}

@media (max-width: 480px) {
  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .btn {
    padding-left: 12px;
    padding-right: 12px;
  }
}
