:root {
  --ink: #2c1b12;
  --ink-soft: #6a4a3a;
  --paper: #f7efe4;
  --paper-2: #fffaf3;
  --line: rgba(44, 27, 18, 0.1);
  --terracotta: #b4532a;
  --terracotta-deep: #8d3c1d;
  --gold: #e8a54b;
  --sage: #5f8a66;
  --coral: #d4675a;
  --teal: #2a6b6b;
  --shadow: 0 18px 40px rgba(90, 38, 16, 0.12);
  --radius: 22px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  touch-action: pan-y;
  overscroll-behavior-x: none;
}
body {
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, #f3c27a 0%, transparent 50%),
    radial-gradient(900px 420px at 100% 0%, #f0b8a0 0%, transparent 46%),
    var(--paper);
  padding: calc(18px + var(--safe-top)) 16px calc(28px + var(--safe-bottom));
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
img { display: block; max-width: 100%; }

.app {
  width: min(560px, 100%);
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

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

.brand img {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  object-fit: cover;
  box-shadow: 0 8px 18px rgba(180, 83, 42, 0.28);
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0.08em;
}

.brand p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--ink-soft);
}

.icon-btn, .ghost-btn, .primary-btn, .danger-btn {
  border: 0;
  border-radius: 14px;
  transition: transform 0.12s ease, opacity 0.12s ease;
}
.icon-btn:active, .ghost-btn:active, .primary-btn:active, .danger-btn:active {
  transform: scale(0.97);
}

.icon-btn {
  width: 42px;
  height: 42px;
  background: var(--paper-2);
  box-shadow: var(--shadow);
}

.ghost-btn {
  background: transparent;
  border: 1px solid var(--line);
  padding: 9px 14px;
}

.primary-btn {
  background: linear-gradient(180deg, #d26a38, var(--terracotta));
  color: #fff8f1;
  padding: 12px 16px;
  box-shadow: 0 10px 20px rgba(180, 83, 42, 0.25);
}

.danger-btn {
  background: #f8e4df;
  color: #9a2f24;
  padding: 10px 14px;
}

.card {
  background: var(--paper-2);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 14px;
}

.goal-card {
  background:
    linear-gradient(180deg, rgba(255,250,243,0.2), rgba(255,250,243,0.88)),
    linear-gradient(160deg, #c25a2e 0%, #e39a45 72%);
  color: #3a1d10;
}

.goal-kicker {
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  opacity: 0.78;
}

.goal-title {
  margin: 8px 0 4px;
  font-size: 28px;
  line-height: 1.2;
}

.goal-range, .muted {
  color: var(--ink-soft);
  font-size: 13px;
}

.goal-card .goal-range { color: rgba(58, 29, 16, 0.78); }

.goal-row {
  display: grid;
  grid-template-columns: 132px 1fr;
  gap: 14px;
  align-items: center;
  margin-top: 16px;
}

.ring-wrap {
  position: relative;
  width: 132px;
  height: 132px;
}

.ring-wrap svg { width: 132px; height: 132px; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: rgba(255,255,255,0.35); stroke-width: 10; }
.ring-value { fill: none; stroke: #fff8ee; stroke-width: 10; stroke-linecap: round; }
.ring-center {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
}
.ring-center strong { display: block; font-size: 26px; line-height: 1; }
.ring-center span { font-size: 11px; opacity: 0.75; }

.stats {
  display: grid;
  gap: 8px;
}

.stat {
  background: rgba(255,250,243,0.55);
  border-radius: 14px;
  padding: 10px 12px;
}

.stat b { display: block; font-size: 18px; }
.stat span { font-size: 12px; opacity: 0.75; }

.countdown {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 14px;
}

.tick {
  flex: 1;
  text-align: center;
  background: rgba(44, 27, 18, 0.08);
  border-radius: 14px;
  padding: 10px 4px;
}

.tick b { display: block; font-size: 22px; }
.tick span { font-size: 11px; opacity: 0.7; }

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

.section-head h2 {
  margin: 0;
  font-size: 16px;
}

.stack {
  height: 18px;
  border-radius: 999px;
  overflow: hidden;
  display: flex;
  background: #efe4d6;
  margin-bottom: 12px;
}

.stack i { display: block; height: 100%; }

.segment {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.dot { width: 10px; height: 10px; border-radius: 50%; }
.segment h3 { margin: 0; font-size: 15px; }
.segment p { margin: 2px 0 0; font-size: 12px; color: var(--ink-soft); }
.seg-meta { text-align: right; font-size: 13px; }

.today-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.choice {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 16px;
  padding: 14px 10px;
  text-align: left;
  min-height: 72px;
}
.choice strong { display: block; font-size: 16px; }
.choice small {
  display: block;
  color: var(--ink-soft);
  margin-top: 4px;
  line-height: 1.35;
  font-size: 12px;
}

.choice.on-done {
  background: #e8f3ea;
  border-color: #b7d7bc;
}

.choice.on-miss {
  background: #fbeceb;
  border-color: #efc4be;
}

.today-task {
  margin: 0 0 12px;
  padding: 10px 12px;
  background: #f4ebe0;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.45;
}

.checks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.chip {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 7px 11px;
  font-size: 13px;
}

.chip.on { color: #fff; border-color: transparent; }

.cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.weekdays, .grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.weekdays span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  text-align: center;
  font-size: 12px;
  line-height: 1;
  color: var(--ink-soft);
  white-space: nowrap;
}

.day {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  aspect-ratio: 1;
  border: 0;
  border-radius: 12px;
  background: #f4ebe0;
  font-size: 13px;
  position: relative;
  padding: 0;
}

.day.empty {
  background: transparent;
  pointer-events: none;
  color: transparent;
}
.day.out { opacity: 0.35; }
.day.today { box-shadow: inset 0 0 0 2px var(--terracotta); }
.day.done { background: #d8edd9; }
.day.miss { background: #f5d4ce; }
.day.future { background: #efe6da; }

.legend {
  display: flex;
  gap: 12px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--ink-soft);
}

.legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 4px;
  vertical-align: -1px;
}

.empty {
  text-align: center;
  padding: 28px 12px;
}

.empty h2 { margin: 0 0 8px; }
.empty p { margin: 0 0 18px; color: var(--ink-soft); }

.install {
  display: none;
  position: sticky;
  bottom: calc(10px + var(--safe-bottom));
  background: var(--ink);
  color: #fff8f1;
  border-radius: 18px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.install.show { display: flex; }
.install button {
  background: var(--gold);
  color: #3a1d10;
  border: 0;
  border-radius: 12px;
  padding: 8px 12px;
}

.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(32, 16, 8, 0.42);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
  padding: 12px;
}

.modal-back.open { display: flex; }

.sheet {
  width: min(560px, 100%);
  background: var(--paper-2);
  border-radius: 24px 24px 18px 18px;
  padding: 18px 18px calc(18px + var(--safe-bottom));
  max-height: min(92vh, 760px);
  overflow: auto;
}

.sheet h2 { margin: 0 0 14px; font-size: 20px; }

label {
  display: block;
  font-size: 13px;
  color: var(--ink-soft);
  margin: 12px 0 6px;
}

input[type="text"], input[type="date"], input[type="number"], textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 14px;
  padding: 12px;
}

.actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.actions > * { flex: 1; }

.colors {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid transparent;
}

.swatch.on { border-color: var(--ink); }

.ios-tip {
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.5;
}

@media (min-width: 720px) {
  body { padding-top: 28px; }
  .modal-back { align-items: center; }
  .sheet { border-radius: 24px; }
}
