:root {
  --ink: #24231f;
  --muted: #77736a;
  --paper: #f6f3ed;
  --card: #fffdf9;
  --line: #e7e1d7;
  --accent: #2d6651;
  --accent-soft: #dce9e1;
  --shadow: 0 10px 30px rgba(54, 45, 33, 0.07);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 10% -5%, rgba(237, 205, 159, .25), transparent 28rem),
    var(--paper);
}

button, input, select { font: inherit; }
button { color: inherit; cursor: pointer; }

.app-shell {
  width: min(100%, 720px);
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 18px max(54px, env(safe-area-inset-bottom));
}

.topbar, .section-heading, .dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.top-actions { display: flex; gap: 8px; }
.top-actions .icon-button { padding-inline: 11px; }

h1, h2, p { margin: 0; }
h1 { margin-top: 2px; font-size: 32px; letter-spacing: -1px; }
h2 { font-size: 20px; letter-spacing: -.35px; }
.eyebrow, .section-kicker { color: var(--muted); font-size: 12px; letter-spacing: .08em; }
.section-kicker { margin-bottom: 4px; }

.icon-button, .text-button, .close-button {
  border: 0;
  background: transparent;
}

.icon-button {
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255,255,255,.45);
}

.timer-card {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 104px;
  margin: 24px 0 30px;
  padding: 18px;
  overflow: hidden;
  border-radius: 24px;
  color: white;
  background: var(--accent);
  box-shadow: 0 16px 40px rgba(45, 102, 81, .2);
  transition: background .25s ease, transform .2s ease;
}

.timer-card.idle {
  color: var(--ink);
  background: var(--card);
  box-shadow: var(--shadow);
}

.timer-orb {
  display: grid;
  flex: 0 0 54px;
  height: 54px;
  place-items: center;
  border-radius: 18px;
  font-size: 27px;
  background: rgba(255,255,255,.18);
}
.idle .timer-orb { background: var(--paper); color: var(--muted); }
.timer-copy { flex: 1; min-width: 0; }
.timer-status { margin-bottom: 5px; font-size: 14px; opacity: .82; }
.timer-value { display: block; font-size: clamp(21px, 6vw, 28px); font-variant-numeric: tabular-nums; }

.stop-button {
  flex: 0 0 auto;
  padding: 10px 15px;
  border: 0;
  border-radius: 999px;
  color: var(--accent);
  background: white;
  font-weight: 700;
}

.section { margin: 0 0 36px; }
.text-button { padding: 8px 0; color: var(--accent); font-weight: 700; }
.total-time { color: var(--muted); font-size: 13px; white-space: nowrap; }

.activity-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 15px;
}

.activity-button {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 92px;
  padding: 13px 8px 11px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 19px;
  background: var(--activity-soft);
  transition: transform .12s ease, box-shadow .12s ease;
}
.activity-button:active { transform: scale(.96); }
.activity-button.active {
  border-color: var(--activity);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--activity), transparent 70%);
}
.activity-icon {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 2px solid rgba(255,255,255,.82);
  border-radius: 15px 17px 14px 18px;
  background: rgba(255,255,255,.62);
  box-shadow:
    0 3px 0 color-mix(in srgb, var(--activity), transparent 78%),
    0 7px 14px rgba(68, 54, 38, .1);
  line-height: 1;
  transform: rotate(-2deg);
}
.activity-icon svg, .timer-orb svg, .timeline-icon svg, .manage-item-icon svg, .history-entry svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.activity-button:nth-child(even) .activity-icon { transform: rotate(2deg); }
.activity-button:nth-child(3n) .activity-icon { transform: rotate(-1deg) translateY(-1px); }
.activity-button { overflow: visible; }
.timer-orb svg { width: 27px; height: 27px; }
.activity-icon .emoji-fallback {
  font-size: 30px;
  filter: drop-shadow(0 2px 1px rgba(70,50,30,.12));
}
.activity-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; font-size: 13px; white-space: nowrap; }
.active-dot {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--activity);
}

.more-button {
  width: 100%;
  margin-top: 11px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: transparent;
  color: var(--muted);
}
.microcopy { margin-top: 11px; color: var(--muted); font-size: 12px; text-align: center; }

.empty-state {
  margin-top: 15px;
  padding: 28px 16px;
  border: 1px dashed #d8d0c4;
  border-radius: 20px;
  color: var(--muted);
  text-align: center;
}
.empty-state span { display: block; margin-bottom: 7px; font-size: 25px; }
.empty-state small { display: block; margin-top: 5px; opacity: .8; }

.timeline { margin-top: 14px; }
.timeline-item {
  display: grid;
  grid-template-columns: 82px 34px 1fr auto;
  align-items: center;
  min-height: 62px;
  margin: 7px 0;
  padding: 0 10px;
  border: 1px solid color-mix(in srgb, var(--activity), transparent 80%);
  border-radius: 13px;
  background: color-mix(in srgb, var(--activity-soft), white 42%);
}
.timeline-time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.timeline-icon {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 1px solid rgba(255,255,255,.7);
  border-radius: 11px 13px 10px 14px;
  color: var(--activity);
  background: var(--activity-soft);
  box-shadow: 0 2px 0 color-mix(in srgb, var(--activity), transparent 76%);
}
.timeline-name { font-weight: 650; }
.timeline-category { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; }
.timeline-note {
  display: block;
  max-width: 100%;
  margin-top: 3px;
  overflow: hidden;
  color: color-mix(in srgb, var(--activity), #4c4842 40%);
  font-size: 11px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.timeline-duration { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.timeline-edit {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
}
.timeline-edit:disabled { color: inherit; cursor: default; }

.journal-meta { display: flex; align-items: center; gap: 9px; }
.journal-clear {
  padding: 0;
  border: 0;
  color: #a2574f;
  background: transparent;
  font-size: 12px;
}
.journal-card {
  margin-top: 14px;
  padding: 14px 15px 10px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--card);
  box-shadow: var(--shadow);
}
.journal-card textarea {
  width: 100%;
  min-height: 90px;
  padding: 0;
  resize: vertical;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
  font: inherit;
  line-height: 1.65;
}
.journal-card textarea::placeholder { color: #aaa398; }
.autosave-note { color: var(--muted); font-size: 11px; text-align: right; }

.insight-card {
  display: flex;
  gap: 13px;
  margin-top: 14px;
  padding: 18px;
  border-radius: 20px;
  background: #242f2a;
  color: white;
}
.insight-mark { color: #e8bd76; font-size: 22px; }
.insight-card strong { font-size: 16px; }
.insight-card p { margin-top: 6px; color: rgba(255,255,255,.72); font-size: 13px; line-height: 1.6; }

.category-bars { margin-top: 15px; }
.category-row {
  display: grid;
  grid-template-columns: 48px 1fr 64px;
  align-items: center;
  gap: 10px;
  margin: 10px 0;
  color: var(--muted);
  font-size: 12px;
}
.bar-track { height: 7px; overflow: hidden; border-radius: 99px; background: var(--line); }
.bar-fill { height: 100%; border-radius: inherit; background: var(--bar-color); }
.bar-time { text-align: right; font-variant-numeric: tabular-nums; }

footer { padding: 10px 0; color: var(--muted); font-size: 11px; text-align: center; }
.danger-link { margin-bottom: 12px; border: 0; background: transparent; color: #a2574f; font-size: 12px; }
.data-actions { display: flex; justify-content: center; gap: 8px; margin-bottom: 13px; }
.data-button {
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  background: rgba(255,255,255,.55);
  font-size: 11px;
}

dialog {
  width: min(calc(100% - 28px), 480px);
  max-height: 88vh;
  padding: 0;
  overflow: auto;
  border: 0;
  border-radius: 25px;
  background: var(--card);
  box-shadow: 0 30px 80px rgba(30,25,20,.25);
}
dialog::backdrop { background: rgba(37,34,29,.4); backdrop-filter: blur(3px); }
.dialog-card { padding: 22px; }
.close-button { width: 38px; height: 38px; border-radius: 50%; background: var(--paper); font-size: 23px; }
label, legend { color: var(--muted); font-size: 12px; }
label { display: block; margin-top: 20px; }
input, select {
  width: 100%;
  margin-top: 7px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 13px;
  outline: none;
  color: var(--ink);
  background: white;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
fieldset { margin: 20px 0 0; padding: 0; border: 0; }
.choice-row, .category-choices { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 9px; }
.choice-chip input { position: absolute; opacity: 0; pointer-events: none; }
.choice-chip span {
  display: grid;
  min-width: 42px;
  min-height: 40px;
  padding: 9px 12px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
  font-size: 14px;
}
.choice-chip input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.choice-chip svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.primary-button, .delete-button {
  width: 100%;
  margin-top: 22px;
  padding: 14px;
  border: 0;
  border-radius: 14px;
  font-weight: 700;
}
.primary-button { color: white; background: var(--accent); }
.delete-button { margin-top: 10px; color: #a2574f; background: transparent; }
.time-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.manage-help { margin: 14px 0; color: var(--muted); font-size: 13px; line-height: 1.55; }
.manage-tools { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.manage-tools .manage-help { flex: 1; }
.manage-item {
  display: grid;
  grid-template-columns: 38px 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.rename-button {
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--muted);
  background: white;
  font-size: 12px;
}
.manage-item-icon { display: grid; width: 36px; height: 36px; place-items: center; border-radius: 11px; color: var(--activity); background: var(--activity-soft); }
.manage-item small { display: block; color: var(--muted); margin-top: 2px; }
.pin-button { border: 0; background: transparent; color: #c4bcb0; font-size: 22px; }
.pin-button.pinned { color: #d49b38; }
.category-manage-item {
  display: grid;
  grid-template-columns: 12px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.category-color { width: 12px; height: 12px; border-radius: 50%; background: var(--category-color); }
.category-manage-item small { display: block; margin-top: 3px; color: var(--muted); }

.history-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 18px 0 14px;
  padding: 4px;
  border-radius: 14px;
  background: var(--paper);
}
.history-tab {
  padding: 9px;
  border: 0;
  border-radius: 11px;
  color: var(--muted);
  background: transparent;
}
.history-tab.active {
  color: var(--ink);
  background: white;
  box-shadow: 0 2px 8px rgba(45, 38, 30, .07);
  font-weight: 700;
}
.history-summary {
  margin-bottom: 14px;
  padding: 14px;
  border-radius: 16px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  line-height: 1.55;
}
.history-empty { padding: 32px 8px; color: var(--muted); text-align: center; }
.swipe-hint { margin: -3px 0 9px; color: var(--muted); font-size: 11px; text-align: right; }
.overview-wrap {
  overflow-x: auto;
  padding: 2px 0 10px;
  scrollbar-width: thin;
  overscroll-behavior-x: contain;
}
.week-table {
  width: 100%;
  min-width: 690px;
  border-spacing: 0;
  border-collapse: separate;
  font-size: 12px;
}
.week-table th, .week-table td {
  min-width: 82px;
  padding: 10px 6px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  text-align: center;
}
.week-table th:first-child, .week-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  min-width: 88px;
  color: var(--muted);
  background: var(--card);
  text-align: left;
}
.week-table thead th {
  color: var(--muted);
  background: var(--paper);
  font-weight: 650;
}
.week-table thead th:first-child { z-index: 3; border-top-left-radius: 12px; }
.week-day-number { display: block; margin-top: 3px; color: var(--ink); font-size: 16px; }
.week-cell-value { color: var(--ink); font-weight: 700; }
.week-cell-activity {
  display: block;
  margin: 3px 0;
  padding: 4px 5px;
  overflow: hidden;
  border-radius: 7px;
  color: var(--cell-color);
  background: var(--cell-bg);
  font-size: 10px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.week-cell-empty { color: #c9c2b7; }
.week-total-row td { background: color-mix(in srgb, var(--accent-soft), white 40%); }

.month-calendar {
  display: grid;
  grid-template-columns: repeat(7, minmax(72px, 1fr));
  min-width: 560px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--line);
  gap: 1px;
}
.calendar-weekday {
  padding: 9px 3px;
  color: var(--muted);
  background: var(--paper);
  font-size: 11px;
  text-align: center;
}
.calendar-day {
  min-height: 86px;
  padding: 8px;
  background: var(--card);
}
.calendar-day.outside { background: #f3efe8; }
.calendar-number { color: var(--muted); font-size: 11px; }
.calendar-total { display: block; margin-top: 12px; color: var(--ink); font-size: 13px; font-weight: 750; }
.calendar-main { display: block; margin-top: 5px; color: var(--muted); font-size: 10px; }

.share-card {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}
.share-card h3 { margin: 0; font-size: 17px; }
.share-content {
  display: grid;
  grid-template-columns: 132px 1fr;
  align-items: center;
  gap: 20px;
  margin-top: 15px;
}
.donut {
  position: relative;
  width: 132px;
  height: 132px;
  border-radius: 50%;
  background: var(--donut);
}
.donut::after {
  content: "";
  position: absolute;
  inset: 27px;
  border-radius: 50%;
  background: var(--card);
}
.donut-center {
  position: absolute;
  z-index: 1;
  inset: 0;
  display: grid;
  place-content: center;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}
.donut-center strong { display: block; margin-bottom: 2px; color: var(--ink); font-size: 15px; }
.share-legend { display: grid; gap: 9px; }
.legend-row {
  display: grid;
  grid-template-columns: 9px 1fr auto;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 11px;
}
.legend-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--legend); }
.legend-row strong { color: var(--ink); font-size: 12px; }
.share-empty { grid-column: 1 / -1; padding: 18px 0; color: var(--muted); text-align: center; }

.journal-book-summary {
  margin: 16px 0 5px;
  color: var(--muted);
  font-size: 13px;
}
.journal-book-item {
  margin: 12px 0;
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(145deg, #fffefb, #faf6ef);
  box-shadow: 0 6px 18px rgba(54, 45, 33, .055);
}
.journal-book-date {
  display: block;
  margin-bottom: 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 750;
}
.journal-book-text {
  color: var(--ink);
  font-size: 14px;
  line-height: 1.75;
  white-space: pre-wrap;
}
.journal-book-item:nth-child(even) { background: linear-gradient(145deg, #fbfdfb, #f2f7f3); }

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  padding: 10px 16px;
  border-radius: 99px;
  opacity: 0;
  pointer-events: none;
  color: white;
  background: #24231f;
  font-size: 13px;
  transform: translate(-50%, 12px);
  transition: .2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.sync-button::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 5px;
  border-radius: 50%;
  background: #c4bcb0;
}
.sync-button.online::before { background: #58a77b; }
.sync-button.syncing::before { background: #d49b38; }
.sync-button.error::before { background: #c96868; }
.sync-state {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 16px 0;
  padding: 12px 14px;
  border-radius: 14px;
  color: var(--muted);
  background: var(--paper);
  font-size: 13px;
}
.sync-state p { margin: 0; }
.sync-state-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #c4bcb0;
}
.sync-state-dot.online { background: #58a77b; }
.sync-state-dot.syncing { background: #d49b38; }
.sync-state-dot.error { background: #c96868; }
.sync-auth-form, .sync-account { display: grid; gap: 12px; }
.sync-auth-form[hidden], .sync-account[hidden] { display: none; }
.sync-secondary { justify-self: center; }
.sync-help {
  margin: -2px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
  text-align: center;
}
.sync-account p {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

@media (max-width: 480px) {
  .top-actions { gap: 4px; }
  .top-actions .icon-button { padding: 8px 7px; font-size: 11px; }
  .activity-grid { grid-template-columns: repeat(3, 1fr); }
  .activity-button { min-height: 98px; }
  .timeline-item { grid-template-columns: 78px 32px 1fr auto; }
  .share-content { grid-template-columns: 116px 1fr; gap: 14px; }
  .donut { width: 116px; height: 116px; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}
