:root {
  color-scheme: light;
  --canvas: #f2f5ef;
  --surface: #ffffff;
  --surface-soft: #f8faf6;
  --text: #1e2b27;
  --muted: #66736e;
  --line: #dce5dd;
  --accent: #2e7d57;
  --accent-deep: #1f5f41;
  --accent-soft: #e6f2ea;
  --accent-line: #bfd9ca;
  --warning: #b7791f;
  --danger: #bd4436;
  --danger-soft: #fbecea;
  --shadow: 0 1px 2px rgba(21, 50, 38, 0.05), 0 12px 28px rgba(21, 50, 38, 0.06);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  background: var(--canvas);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button {
  touch-action: manipulation;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  width: min(100%, 680px);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 22px 16px calc(28px + env(safe-area-inset-bottom));
}

.hero {
  padding-bottom: 10px;
}

.heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 2px 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-deep);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 30px;
  line-height: 1.2;
  letter-spacing: 0;
}

h2 {
  letter-spacing: 0;
}

.summary-tool {
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.summary-copy {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

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

.summary-title {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.3;
}

.summary-date {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.score-wrap {
  display: flex;
  align-items: baseline;
  gap: 2px;
  flex: 0 0 auto;
  color: var(--accent-deep);
  font-variant-numeric: tabular-nums;
}

.score-wrap > span:first-child {
  font-size: 36px;
  font-weight: 800;
  line-height: 1;
}

.score-wrap > span:last-child {
  font-size: 15px;
  font-weight: 700;
}

.progress-track {
  height: 10px;
  margin-top: 16px;
  overflow: hidden;
  background: var(--accent-soft);
  border-radius: 999px;
}

.progress-fill {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #55a078);
  border-radius: inherit;
  transition: width 220ms ease;
}

.date-strip {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 7px;
  margin-top: 12px;
  padding: 2px 2px 4px;
}

.date-chip {
  min-width: 0;
  min-height: 58px;
  padding: 8px 2px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

.date-chip span,
.date-chip strong {
  display: block;
}

.date-chip span {
  overflow: hidden;
  font-size: 12px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.date-chip strong {
  margin-top: 4px;
  font-size: 17px;
  line-height: 1.1;
}

.date-chip.is-selected {
  color: var(--accent-deep);
  background: var(--accent-soft);
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.date-chip.is-today {
  font-weight: 700;
}

main {
  padding-top: 8px;
}

.list-heading-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 2px 12px;
}

.list-heading-row h2 {
  margin: 0;
  font-size: 18px;
}

.list-meta {
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.habit-list {
  display: grid;
  gap: 10px;
}

.habit-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 68px;
  padding: 10px 10px 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  transition: background 150ms ease, border-color 150ms ease;
}

.habit-row.is-done {
  background: var(--accent-soft);
  border-color: var(--accent-line);
}

.check-button {
  display: grid;
  width: 46px;
  height: 46px;
  padding: 0;
  place-items: center;
  color: transparent;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
  transition: color 150ms ease, background 150ms ease, border-color 150ms ease;
}

.is-done .check-button {
  color: #ffffff;
  background: var(--accent);
  border-color: var(--accent);
}

.check-button svg,
.icon-btn svg {
  width: 22px;
  height: 22px;
  pointer-events: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.check-button svg {
  width: 26px;
  height: 26px;
}

.habit-name {
  display: block;
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 17px;
  font-weight: 600;
  line-height: 1.4;
}

.is-done .habit-name {
  color: #476a5b;
}

.habit-actions {
  display: flex;
  gap: 2px;
  align-items: center;
}

.icon-btn {
  display: grid;
  width: 42px;
  height: 42px;
  padding: 0;
  place-items: center;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease;
}

.icon-btn:hover {
  color: var(--text);
  background: var(--surface-soft);
}

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

button:disabled,
body.is-busy .habit-row {
  cursor: wait;
}

.add-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  margin-top: 16px;
  padding: 6px 6px 6px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(21, 50, 38, 0.04);
}

.add-form:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(46, 125, 87, 0.14);
}

.add-input {
  width: 100%;
  min-width: 0;
  padding: 0;
  color: var(--text);
  background: transparent;
  border: 0;
  outline: 0;
}

.add-input::placeholder {
  color: #8a9891;
}

.add-btn {
  color: #ffffff;
  background: var(--accent);
}

.add-btn:hover {
  color: #ffffff;
  background: var(--accent-deep);
}

.empty-state {
  padding: 34px 12px;
  color: var(--muted);
  text-align: center;
}

.status-banner {
  position: fixed;
  z-index: 40;
  bottom: calc(16px + env(safe-area-inset-bottom));
  left: 50%;
  width: min(calc(100% - 32px), 420px);
  padding: 11px 14px;
  color: #ffffff;
  background: #263c33;
  border-radius: 8px;
  box-shadow: 0 10px 26px rgba(17, 35, 28, 0.24);
  font-size: 14px;
  line-height: 1.45;
  text-align: center;
  transform: translateX(-50%);
}

.dev-stats {
  margin-top: 12px;
  padding: 14px 16px;
  color: #33413c;
  background: #f8f3e7;
  border: 1px solid #e4d7b7;
  border-radius: 8px;
}

.dev-stats-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.dev-stats-heading h2 {
  margin: 0;
  font-size: 14px;
  letter-spacing: 0.06em;
}

.dev-stats-heading span {
  color: #7d735e;
  font-size: 12px;
}

.dev-stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.dev-stat {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.dev-stat strong {
  font-size: 24px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.dev-stat span {
  color: #7d735e;
  font-size: 13px;
}

.dev-stat-button {
  margin: -6px -8px;
  padding: 6px 8px;
  color: inherit;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.dev-stat-button:hover,
.dev-stat-button:focus-visible {
  background: rgba(111, 100, 76, 0.08);
  outline: 0;
}

.dev-stats-list-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid #e8dec6;
}

.dev-stats-list-heading h3 {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.04em;
}

.dev-stats-list-heading span {
  color: #7d735e;
  font-size: 12px;
}

.visitor-log-list {
  display: grid;
  gap: 0;
}

.visitor-log-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid rgba(232, 222, 198, 0.72);
}

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

.visitor-device-line {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.visitor-device-block {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.visitor-device-name {
  min-width: 0;
  overflow: hidden;
  font-size: 14px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.visitor-device-detail {
  overflow: hidden;
  color: #8c816a;
  font-size: 12px;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.visitor-device-kind {
  flex: 0 0 auto;
  padding: 2px 6px;
  color: #6f644c;
  background: #efe6cf;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
}

.visitor-when {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.visitor-when strong {
  font-size: 15px;
}

.visitor-when span {
  color: #7d735e;
  font-size: 12px;
}

.visitor-empty {
  padding: 12px 0 4px;
  color: #8c816a;
  font-size: 13px;
  text-align: center;
}

.history-dialog {
  width: min(calc(100% - 24px), 680px);
  max-height: min(85dvh, 760px);
  padding: 18px;
  overflow: hidden;
  border: 0;
  border-radius: 8px;
  box-shadow: 0 24px 60px rgba(13, 32, 25, 0.28);
}

.history-dialog::backdrop {
  background: rgba(16, 30, 26, 0.42);
}

.history-dialog-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.history-dialog-heading h2 {
  margin: 0;
  font-size: 19px;
}

.history-summary {
  padding: 10px 12px;
  color: #5d655f;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
}

.visitor-history-list {
  max-height: 58dvh;
  margin-top: 12px;
  overflow-y: auto;
  border-top: 1px solid var(--line);
}

.history-day {
  padding: 14px 0 4px;
  border-bottom: 1px solid var(--line);
}

.history-day-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 0 2px 6px;
}

.history-day-head strong {
  font-size: 15px;
}

.history-day-head span {
  color: var(--muted);
  font-size: 12px;
}

.visitor-history-list .visitor-log-entry {
  padding-right: 2px;
  padding-left: 2px;
}

.edit-dialog {
  width: min(calc(100% - 32px), 360px);
  padding: 18px;
  border: 0;
  border-radius: 8px;
  box-shadow: 0 24px 60px rgba(13, 32, 25, 0.28);
}

.edit-dialog::backdrop {
  background: rgba(16, 30, 26, 0.36);
}

.edit-form {
  display: grid;
  gap: 14px;
}

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

.dialog-heading h2 {
  margin: 0;
  font-size: 18px;
}

.dialog-close {
  margin: -8px -8px -8px 0;
}

.edit-input {
  width: 100%;
  padding: 11px 12px;
  color: var(--text);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
}

.edit-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(46, 125, 87, 0.14);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.button {
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}

.button-secondary {
  color: var(--text);
  background: var(--surface-soft);
  border-color: var(--line);
}

.button-primary {
  color: #ffffff;
  background: var(--accent);
}

.button-primary:hover {
  background: var(--accent-deep);
}

@media (min-width: 600px) {
  .app-shell {
    padding-top: 32px;
  }

  h1 {
    font-size: 34px;
  }

  .summary-title {
    font-size: 22px;
  }

  .habit-row {
    min-height: 72px;
    padding-left: 14px;
  }

  .habit-name {
    font-size: 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
