:root {
  --ink: #0c0a09;
  --ink-2: #14100e;
  --surface: #1a1513;
  --surface-2: #221b18;
  --line: rgba(216, 178, 106, 0.16);
  --line-strong: rgba(216, 178, 106, 0.34);
  --text: #ece3d4;
  --muted: #9a8d7c;
  --gold: #d8b26a;
  --red: #c0413a;
  --jade: #59a583;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --serif: "Songti SC", "Noto Serif SC", "Source Han Serif SC", serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  /* 关掉 iOS 双击放大（manipulation = 保留拖动/双指缩放，去掉双击缩放） */
  touch-action: manipulation;
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

button,
a,
label,
select,
input,
textarea {
  touch-action: manipulation; /* 去掉双击缩放带来的 300ms 延迟 */
}

body {
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(192, 65, 58, 0.14), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(216, 178, 106, 0.08), transparent 55%), var(--ink);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

.app {
  max-width: 860px;
  margin: 0 auto;
  padding: 20px 16px 104px;
  /* iOS 装到主屏幕后使用 black-translucent 状态栏，内容会顶到刘海/灵动岛下面 */
  padding-top: max(20px, env(safe-area-inset-top));
}

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.seal {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(160deg, var(--red), #7d2620);
  color: #f7ecd8;
  font-family: var(--serif);
  font-size: 22px;
  box-shadow: 0 6px 18px rgba(192, 65, 58, 0.32);
}

.brand-text {
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

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

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.02);
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
}

.chip b {
  color: var(--gold);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

/* ---------- 通用卡片 ---------- */
.card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0.012));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.card-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.06em;
}

.card-head .hint {
  color: var(--muted);
  font-size: 12.5px;
}

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

.placeholder {
  color: var(--muted);
  padding: 28px 4px;
  text-align: center;
}

/* ---------- 日期切换 + 进度 ---------- */
.daybar {
  display: flex;
  align-items: center;
  gap: 12px;
}

.daybar .navbtn {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
}

.daybar .navbtn:hover:not(:disabled) {
  border-color: var(--line-strong);
  color: var(--gold);
}

.daybar .navbtn:disabled {
  opacity: 0.35;
  cursor: default;
}

.daylabel {
  flex: 1;
  min-width: 0;
  text-align: center;
}

.daylabel .d1 {
  font-family: var(--serif);
  font-size: 17px;
  letter-spacing: 0.04em;
}

.daylabel .d2 {
  color: var(--muted);
  font-size: 12px;
}

.progress-wrap {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 14px;
}

.ring {
  width: 62px;
  height: 62px;
  flex: 0 0 auto;
  transform: rotate(-90deg);
}

.ring circle {
  fill: none;
  stroke-width: 3.2;
  stroke-linecap: round;
}

.ring .bg {
  stroke: rgba(255, 255, 255, 0.08);
}

.ring .fg {
  stroke: var(--gold);
  transition: stroke-dasharray 0.3s ease;
}

.progress-meta {
  flex: 1;
  min-width: 0;
}

.progress-meta .big {
  font-size: 15px;
}

.progress-meta .big b {
  font-family: var(--serif);
  font-size: 22px;
  color: var(--gold);
}

.progress-meta .sub {
  color: var(--muted);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

.bar {
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
  margin-top: 8px;
}

.bar > i {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--gold), #f0d9a4);
  transition: width 0.3s ease;
}

/* ---------- 活动列表 ---------- */
.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.015);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.row:hover {
  border-color: var(--line-strong);
}

.row.is-done {
  background: linear-gradient(90deg, rgba(216, 178, 106, 0.12), rgba(255, 255, 255, 0.015));
  border-color: var(--line-strong);
}

.tick {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 1.5px solid var(--line-strong);
  background: transparent;
  color: transparent;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.15s ease;
}

.tick:hover {
  border-color: var(--gold);
}

.row.is-done .tick {
  background: var(--gold);
  border-color: var(--gold);
  color: #1a1513;
}

.row-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.row-title {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.row-title .nm {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row.is-done .row-title .nm {
  color: var(--gold);
}

.row-sub {
  margin-left: auto;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-sub .sep {
  opacity: 0.45;
  margin: 0 4px;
}

.row-sub.is-strong {
  color: var(--gold);
}

.step {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.step button {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.step button:hover {
  border-color: var(--line-strong);
  color: var(--gold);
}

.step .val {
  min-width: 38px;
  text-align: center;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.row.is-done .step .val {
  color: var(--gold);
}

/* ---------- 备注 ---------- */
textarea {
  width: 100%;
  min-height: 76px;
  resize: vertical;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font: inherit;
}

textarea:focus,
input:focus,
select:focus {
  outline: none;
  border-color: var(--gold);
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="url"],
select {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font: inherit;
  min-width: 0;
}

input[type="number"] {
  width: 68px;
}

label.field {
  display: block;
  margin-bottom: 12px;
}

label.field > span {
  display: block;
  color: var(--muted);
  font-size: 12.5px;
  margin-bottom: 4px;
}

label.field input,
label.field select {
  width: 100%;
}

.btn {
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.btn:hover {
  border-color: var(--gold);
  color: var(--gold);
}

.btn.primary {
  background: linear-gradient(160deg, var(--red), #7d2620);
  border-color: transparent;
  color: #f7ecd8;
}

.btn.primary:hover {
  color: #fff;
}

.btn.danger:hover {
  border-color: var(--red);
  color: #e6857f;
}

.btn.small {
  padding: 6px 10px;
  font-size: 13px;
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

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

/* ---------- 日历 ---------- */
.cal {
  display: grid;
  /* minmax(0, 1fr)：否则单元格内容的 min-content 会把整个网格顶宽（320px 屏幕上会横向溢出） */
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.cal-head {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding-bottom: 2px;
}

.cell {
  position: relative;
  min-width: 0;
  overflow: hidden;
  aspect-ratio: 1 / 1;
  /* 宽屏保持正方形，窄屏靠 min-height 兜底：日期 + 进度条 + x/x 三行不能被裁掉 */
  min-height: 54px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.015);
  color: var(--text);
  font: inherit;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 2px;
  touch-action: manipulation;
}

.cell:hover {
  border-color: var(--line-strong);
}

.cell.out {
  opacity: 0.32;
}

.cell.future {
  opacity: 0.24;
  cursor: default;
}

.cell.today {
  border-color: var(--gold);
  box-shadow: inset 0 0 0 1px rgba(216, 178, 106, 0.4);
}

.cell .ratio {
  font-size: 10px;
  line-height: 1.1;
  color: var(--muted);
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cell .meter {
  width: 68%;
  height: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.09);
  overflow: hidden;
}

.cell .meter > i {
  display: block;
  height: 100%;
  background: var(--gold);
}

.cell.level-1 {
  background: rgba(216, 178, 106, 0.08);
}
.cell.level-2 {
  background: rgba(216, 178, 106, 0.16);
}
.cell.level-3 {
  background: rgba(216, 178, 106, 0.26);
}
.cell.full {
  background: linear-gradient(160deg, rgba(216, 178, 106, 0.42), rgba(216, 178, 106, 0.22));
  border-color: var(--line-strong);
}
.cell.full .ratio {
  color: #fdf3df;
}

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

.month-head .title {
  font-family: var(--serif);
  font-size: 16px;
}

/* ---------- 统计 ---------- */
.grid-4 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}

.stat {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.015);
}

.stat .k {
  color: var(--muted);
  font-size: 12.5px;
}

.stat .v {
  font-family: var(--serif);
  font-size: 24px;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

.stat .v small {
  font-size: 12px;
  color: var(--muted);
  font-family: var(--sans);
  margin-left: 3px;
}

.spark {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 78px;
  margin-top: 4px;
}

.spark .sp {
  flex: 1;
  min-width: 2px;
  border-radius: 3px 3px 1px 1px;
  background: rgba(255, 255, 255, 0.1);
  position: relative;
}

.spark .sp.done {
  background: linear-gradient(180deg, var(--gold), rgba(216, 178, 106, 0.35));
}

.spark .sp.empty {
  background: rgba(255, 255, 255, 0.05);
}

table.rates {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

table.rates th {
  text-align: left;
  color: var(--muted);
  font-weight: 400;
  font-size: 12px;
  padding: 0 6px 8px;
  border-bottom: 1px solid var(--line);
}

table.rates td {
  padding: 8px 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  vertical-align: middle;
}

table.rates .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  white-space: nowrap;
}

table.rates .rate-cell {
  width: 34%;
}

.mini-bar {
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  min-width: 60px;
}

.mini-bar > i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--gold), #f0d9a4);
}

.seg {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.seg button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 6px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.seg button.on {
  background: rgba(216, 178, 106, 0.16);
  color: var(--gold);
}

.week-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.week-item:last-child {
  border-bottom: 0;
}

.week-item .nm {
  flex: 1;
  min-width: 0;
}

.week-item .prog {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 12.5px;
}

.week-item.done .prog {
  color: var(--gold);
}

/* ---------- 设置 ---------- */
.setting-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.015);
  margin-bottom: 8px;
}

.sr-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sr-top input[type="text"] {
  flex: 1;
  min-width: 0;
}

.icon-input {
  width: 52px;
  flex: 0 0 auto;
  text-align: center;
}

.sr-bottom {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.sr-bottom .switch {
  margin-left: auto;
  padding: 0 2px;
}

.setting-row.is-off {
  opacity: 0.55;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12.5px;
  cursor: pointer;
  user-select: none;
}

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

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

.steps {
  margin: 0 0 0 4px;
  padding-left: 20px;
  font-size: 13px;
  line-height: 1.7;
}

/* ---------- 底部导航 ---------- */
.tabbar {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(860px, 100%);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: rgba(12, 10, 9, 0.86);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}

.tabbar button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  padding: 7px 4px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.tabbar button .ti {
  font-size: 17px;
  line-height: 1;
}

.tabbar button.on {
  color: var(--gold);
  background: rgba(216, 178, 106, 0.1);
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 84px;
  transform: translate(-50%, 12px);
  padding: 9px 16px;
  border-radius: 999px;
  background: rgba(34, 27, 24, 0.96);
  border: 1px solid var(--line-strong);
  color: var(--text);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  max-width: min(520px, 88vw);
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.err {
  border-color: var(--red);
  color: #f0c4c1;
}

@media (min-width: 720px) {
  .app {
    padding-top: 34px;
  }
  .tabbar {
    position: sticky;
    /* 覆盖窄屏的 fixed 居中定位，否则 sticky 下会左移半个宽度 */
    left: auto;
    transform: none;
    width: min(860px, 100%);
    margin: 0 auto;
    bottom: 12px;
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow);
  }
}

/* ---------- 手机（窄屏）微调 ---------- */
@media (max-width: 420px) {
  .app {
    padding-left: 12px;
    padding-right: 12px;
  }
  .card {
    padding: 14px;
  }
  /* iOS 上 font-size < 16px 的输入框聚焦时会自动放大页面 */
  input[type='text'],
  input[type='password'],
  input[type='number'],
  input[type='url'],
  select,
  textarea {
    font-size: 16px;
  }
  /* 让「每日 / 目标 / 启用 / ↑ / ↓ / 删除」挤在同一行 */
  .switch span {
    display: none;
  }
  .btn.small {
    padding: 6px 9px;
  }
  .sr-bottom {
    gap: 6px;
  }
}

@media (max-width: 380px) {
  /* 320px 屏：格子更窄，收一下间距，进度文字保留（高度已由 min-height 兜住） */
  .cal {
    gap: 4px;
  }
  .cell {
    min-height: 50px;
  }
}
