:root {
  --bg: #faf9f7;
  --panel: #ffffff;
  --ink: #333331;
  --muted: #8a8a86;
  --line: #e4e2dd;
  --accent: #6f6f6a;
  --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC",
    "Microsoft JhengHei", "Noto Sans TC", "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
}

.topbar {
  padding: 20px 20px 8px;
  max-width: 720px;
  margin: 0 auto;
}
.topbar h1 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.05em;
  margin: 0;
  color: var(--ink);
}

.view {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 20px 96px;
}

h2 {
  font-size: 16px;
  font-weight: 600;
  margin: 28px 0 10px;
  color: var(--ink);
}
h3 {
  font-size: 15px;
  font-weight: 600;
  margin: 20px 0 8px;
}

p.muted, .muted { color: var(--muted); }
.small { font-size: 13px; }

/* 導航列（手機優先，固定底部） */
.navbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  background: var(--panel);
  border-top: 1px solid var(--line);
  z-index: 10;
}
.navbar a {
  flex: 1;
  text-align: center;
  padding: 12px 0;
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
}
.navbar a.active {
  color: var(--ink);
  font-weight: 600;
  box-shadow: inset 0 2px 0 var(--ink);
}

/* 區塊 */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin: 12px 0;
}

/* 軟提醒橫幅 */
.banner {
  background: #f3f1ec;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin: 12px 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}
.banner .spacer { flex: 1; }

/* 表單 */
label.field {
  display: block;
  margin: 14px 0 4px;
  font-size: 14px;
  color: var(--muted);
}
input[type="text"],
input[type="number"],
input[type="week"],
select,
textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  font-size: 15px;
  font-family: inherit;
}
textarea { min-height: 72px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 1px solid var(--accent);
  outline-offset: -1px;
}

button, .btn {
  display: inline-block;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
}
button:hover, .btn:hover { border-color: var(--accent); }
button.primary {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}
button.linklike {
  border: none;
  background: none;
  padding: 2px 4px;
  color: var(--muted);
  text-decoration: underline;
  font-size: 13px;
}
button:disabled { opacity: 0.5; cursor: default; }

.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.mt { margin-top: 16px; }

/* 快速輸入（首頁） */
.quick {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 15px;
}
.quick input[type="text"] { flex: 1 1 140px; width: auto; }
.quick select { width: auto; }

/* 7 格頻率視覺 */
.daycells {
  display: inline-flex;
  gap: 4px;
}
.daycells .dc {
  width: 22px;
  height: 22px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  background: var(--panel);
}
.daycells .dc.done {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
button.dc { cursor: pointer; padding: 0; }

/* 記錄列 */
.entry {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 12px 14px;
  margin: 8px 0;
}
.entry .head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}
.entry .old { font-weight: 600; }
.entry .arrow { color: var(--muted); }
.entry .rep { color: var(--ink); }
.entry .meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
}
.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.15);
  vertical-align: middle;
}
.dotbar {
  display: inline-block;
  width: 4px;
  align-self: stretch;
  border-radius: 2px;
  margin-right: 4px;
}
.tag {
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 8px;
}
.why {
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
  white-space: pre-wrap;
}

/* 時間線 */
.tl-group { margin: 20px 0 8px; }
.tl-group > h3 {
  border-left: 3px solid var(--line);
  padding-left: 8px;
}
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 14px;
  color: var(--muted);
  align-items: center;
}
.filter-bar label { display: inline-flex; align-items: center; gap: 4px; }

/* 管理頁 */
.manage-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.manage-item:last-child { border-bottom: none; }
.manage-item .name { flex: 0 1 auto; min-width: 6em; }
.manage-item.archived .name { color: var(--muted); text-decoration: line-through; }
.manage-item .grow { flex: 1; }
input[type="color"] {
  width: 34px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: none;
}

/* 盤點 */
.review-q { margin: 18px 0; }
.review-q .q-title { font-weight: 600; margin-bottom: 6px; }
.review-item { font-size: 14px; }
.review-item .answers { color: var(--muted); margin-top: 4px; white-space: pre-wrap; }

/* 設定 */
.stat-grid { display: flex; flex-wrap: wrap; gap: 16px 32px; }
.stat-grid .num { font-size: 20px; font-weight: 600; }
.stat-grid .lbl { font-size: 13px; color: var(--muted); }

@media (min-width: 721px) {
  .navbar {
    max-width: 720px;
    left: 50%;
    transform: translateX(-50%);
    border: 1px solid var(--line);
    border-bottom: none;
    border-radius: 12px 12px 0 0;
  }
}
