:root {
  color-scheme: light;
  --bg: #f4f7f2;
  --surface: #ffffff;
  --surface-soft: #eaf2ec;
  --ink: #17352a;
  --muted: #667970;
  --primary: #33735a;
  --primary-dark: #20543f;
  --primary-light: #cfe3d6;
  --accent: #e8a94d;
  --danger: #a53f3f;
  --danger-bg: #fff0ef;
  --line: #dce7df;
  --shadow: 0 18px 45px rgba(37, 78, 60, 0.09);
  --radius-lg: 28px;
  --radius-md: 20px;
  --radius-sm: 13px;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 10% 0%, rgba(186, 219, 198, 0.45), transparent 28rem),
    radial-gradient(circle at 90% 30%, rgba(236, 211, 157, 0.18), transparent 24rem),
    var(--bg);
  color: var(--ink);
  background-position: center;
  background-size: cover;
  background-attachment: fixed;
}

button, input { font: inherit; }
button { color: inherit; }

button:focus-visible, input:focus-visible, a:focus-visible {
  outline: 3px solid rgba(51, 115, 90, 0.36);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 12px;
  left: 12px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--ink);
  color: white;
  transform: translateY(-150%);
}
.skip-link:focus { transform: translateY(0); }

.app-shell { width: min(calc(100% - 28px), 820px); margin: 0 auto; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 84px;
  padding-top: env(safe-area-inset-top);
}
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 1.25rem;
  font-weight: 800;
  text-decoration: none;
  letter-spacing: 0.08em;
}

.brand-mark {
  display: grid;
  width: 37px;
  height: 37px;
  place-items: center;
  border-radius: 12px;
  background: var(--primary);
  color: white;
  box-shadow: 0 7px 16px rgba(51, 115, 90, 0.24);
}

.button, .icon-button, .mini-button, .emoji-button {
  border: 0;
  cursor: pointer;
  transition: transform 160ms ease, background-color 160ms ease, color 160ms ease, box-shadow 160ms ease;
}
.button:active:not(:disabled), .icon-button:active:not(:disabled), .mini-button:active:not(:disabled), .emoji-button:active:not(:disabled) { transform: translateY(1px); }
.button:disabled, .icon-button:disabled, .mini-button:disabled { cursor: not-allowed; opacity: 0.36; }

.button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 16px;
  border-radius: 14px;
  font-weight: 700;
}
.button-primary { background: var(--primary); color: white; box-shadow: 0 8px 18px rgba(51, 115, 90, 0.18); }
.button-primary:hover { background: var(--primary-dark); }
.button-quiet { background: var(--surface); color: var(--primary-dark); border: 1px solid var(--line); }
.button-quiet:hover { background: var(--surface-soft); }
.button-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid #f0d1cf; }
.button-danger:hover { background: #f9dedd; }

.hero {
  position: relative;
  overflow: hidden;
  padding: clamp(26px, 6vw, 48px);
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, #285f49, #43856a);
  color: white;
  box-shadow: 0 20px 52px rgba(31, 83, 61, 0.2);
  background-position: center;
  background-size: cover;
}
.hero::after {
  position: absolute;
  right: -72px;
  bottom: -110px;
  width: 280px;
  height: 280px;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 50%;
  box-shadow: 0 0 0 38px rgba(255,255,255,0.035), 0 0 0 82px rgba(255,255,255,0.025);
  content: "";
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.hero .eyebrow { color: #cde5d6; }
.hero-heading { position: relative; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 24px; }
h1, h2, h3, p { overflow-wrap: anywhere; }
h1 { max-width: 520px; margin: 8px 0 8px; font-size: clamp(1.75rem, 6vw, 2.65rem); line-height: 1.2; letter-spacing: -0.035em; }
h2 { margin: 0; font-size: clamp(1.35rem, 4vw, 1.75rem); letter-spacing: -0.02em; }
h3 { margin: 0; }
.hero-copy { margin: 0; color: rgba(255,255,255,0.76); }

.progress-ring {
  --progress: 0deg;
  position: relative;
  z-index: 1;
  display: grid;
  width: 112px;
  height: 112px;
  flex: 0 0 112px;
  place-content: center;
  border-radius: 50%;
  background: radial-gradient(circle at center, #39765e 59%, transparent 61%), conic-gradient(#f4d08b var(--progress), rgba(255,255,255,0.16) 0);
  text-align: center;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.12);
}
.progress-ring strong { font-size: 1.45rem; }
.progress-ring span { color: rgba(255,255,255,0.72); font-size: 0.7rem; }
.progress-track { position: relative; z-index: 1; overflow: hidden; height: 7px; margin-top: 28px; border-radius: 99px; background: rgba(255,255,255,0.14); }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: #f4d08b; transition: width 350ms ease; }

.section { margin-top: 22px; padding: clamp(20px, 5vw, 32px); border: 1px solid rgba(211, 226, 216, 0.85); border-radius: var(--radius-lg); background: rgba(255,255,255,0.86); box-shadow: var(--shadow); backdrop-filter: blur(14px); }
#habitsSection, .calendar-section { background-position: center; background-size: cover; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; }

.habit-list { display: grid; gap: 12px; }
.habit-card { overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); transition: border-color 180ms ease, box-shadow 180ms ease; }
.habit-card:hover { border-color: #bad1c2; box-shadow: 0 8px 24px rgba(45, 89, 69, 0.07); }
.habit-card.is-complete { border-color: #a8ccb7; background: #f5faf6; }
.habit-check { display: flex; width: 100%; min-height: 82px; align-items: center; gap: 15px; padding: 15px 17px; border: 0; background: transparent; text-align: left; cursor: pointer; }
.habit-icon { display: grid; width: 48px; height: 48px; flex: 0 0 48px; place-items: center; border-radius: 15px; background: var(--surface-soft); font-size: 1.45rem; }
.uploaded-icon { display: block; width: 100%; height: 100%; border-radius: inherit; object-fit: cover; }
.habit-copy { display: grid; flex: 1; gap: 4px; }
.habit-copy strong { font-size: 1.03rem; }
.habit-copy small { color: var(--muted); }
.check-mark { display: grid; width: 31px; height: 31px; flex: 0 0 31px; place-items: center; border: 2px solid #bfd0c5; border-radius: 50%; color: transparent; font-weight: 900; transition: all 180ms ease; }
.is-complete .check-mark { border-color: var(--primary); background: var(--primary); color: white; transform: scale(1.05); }
.is-complete .habit-copy strong { color: var(--primary-dark); text-decoration: line-through; text-decoration-color: #99b9a6; }
.habit-actions { display: flex; justify-content: flex-end; gap: 5px; padding: 0 14px 12px; }
.mini-button { min-width: 34px; min-height: 32px; padding: 5px 8px; border-radius: 9px; background: transparent; color: var(--muted); font-size: 0.76rem; }
.mini-button:hover:not(:disabled) { background: var(--surface-soft); color: var(--primary-dark); }
.mini-button.delete:hover { background: var(--danger-bg); color: var(--danger); }

.empty-state { padding: 32px 16px; text-align: center; }
.empty-state > span { display: block; margin-bottom: 10px; font-size: 2.2rem; }
.empty-state p, .data-section p, .muted { color: var(--muted); }

.calendar-heading { align-items: flex-end; }
.month-nav { display: flex; align-items: center; gap: 8px; }
.month-nav strong { min-width: 116px; text-align: center; font-size: 0.94rem; }
.icon-button { display: grid; width: 40px; height: 40px; place-items: center; border-radius: 12px; background: var(--surface-soft); color: var(--primary-dark); font-size: 1.5rem; line-height: 1; }
.icon-button:hover:not(:disabled) { background: var(--primary-light); }
.calendar-weekdays, .calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 7px; }
.calendar-weekdays { margin-bottom: 8px; text-align: center; color: var(--muted); font-size: 0.72rem; font-weight: 700; }
.calendar-day { position: relative; display: grid; min-width: 0; aspect-ratio: 1; place-content: center; gap: 1px; border: 1px solid transparent; border-radius: 13px; background: #f2f5f1; color: var(--ink); cursor: pointer; }
.calendar-day span { font-weight: 750; }
.calendar-day small { color: var(--muted); font-size: clamp(0.56rem, 2vw, 0.68rem); }
.calendar-day.level-some { background: #e2efe6; color: var(--primary-dark); }
.calendar-day.level-all { background: var(--primary); color: white; }
.calendar-day.level-all small { color: rgba(255,255,255,0.75); }
.calendar-day.outside { opacity: 0.3; }
.calendar-day.today { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.calendar-day:disabled { cursor: default; opacity: 0.22; }
.calendar-legend { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 14px; margin-top: 14px; color: var(--muted); font-size: 0.7rem; }
.calendar-legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend-dot { display: inline-block; width: 9px; height: 9px; border-radius: 3px; }
.legend-none { background: #e5ebe6; }.legend-some { background: #c9e0d0; }.legend-all { background: var(--primary); }

.day-detail-dialog { width: min(92vw, 470px); }
.day-summary { display: flex; align-items: center; gap: 12px; margin-bottom: 17px; padding: 14px 16px; border-radius: 15px; background: var(--surface-soft); }
.day-summary strong { color: var(--primary-dark); font-size: 1.5rem; }
.day-summary span { color: var(--muted); font-size: 0.8rem; font-weight: 700; }
.day-detail-list { display: grid; gap: 9px; margin: 0; padding: 0; list-style: none; }
.day-detail-list li { display: flex; min-height: 54px; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 13px; background: #fbfcfb; }
.day-detail-list li.done { border-color: #bad7c4; background: #f2f8f4; }
.day-habit-name { display: inline-flex; min-width: 0; align-items: center; gap: 10px; }
.day-habit-name strong { overflow: hidden; font-size: 0.9rem; text-overflow: ellipsis; white-space: nowrap; }
.detail-habit-icon { display: grid; width: 32px; height: 32px; flex: 0 0 32px; place-items: center; border-radius: 9px; object-fit: cover; font-style: normal; }
.detail-status { flex: 0 0 auto; color: var(--muted); font-size: 0.76rem; font-weight: 750; }
.done .detail-status { color: var(--primary); }
.empty-day { padding: 24px 10px; color: var(--muted); text-align: center; }
.empty-day span { font-size: 1.8rem; }
.empty-day p { margin-bottom: 0; }
.detail-note { margin: 12px 0 0; color: var(--muted); font-size: 0.78rem; }

.data-section { display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.data-section p:last-child { max-width: 480px; margin: 8px 0 0; font-size: 0.9rem; }
footer { padding: 30px 16px max(30px, env(safe-area-inset-bottom)); color: var(--muted); text-align: center; font-size: 0.78rem; }

.settings-dialog { width: min(94vw, 760px); max-height: 90vh; }
.settings-dialog form { max-height: 90vh; overflow-y: auto; }
.settings-dialog-heading { position: sticky; z-index: 3; top: -26px; margin: -2px -2px 18px; padding: 2px 2px 14px; background: linear-gradient(#fff 84%, rgba(255,255,255,0)); }
.settings-summary { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.settings-summary p { max-width: 480px; margin: 0; color: var(--muted); font-size: 0.84rem; line-height: 1.6; }
.theme-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.theme-card { display: grid; grid-template-columns: 58px 1fr; gap: 12px; padding: 13px; border: 1px solid var(--line); border-radius: 17px; background: rgba(255,255,255,0.82); }
.theme-preview { display: grid; overflow: hidden; width: 58px; height: 58px; grid-row: span 2; place-items: center; border: 1px solid rgba(28,65,49,0.12); border-radius: 15px; background-position: center; background-size: cover; color: var(--primary-dark); font-size: 0.68rem; font-weight: 800; text-shadow: 0 1px 4px rgba(255,255,255,0.85); }
.theme-preview.preview-hero { color: white; text-shadow: 0 1px 4px rgba(0,0,0,0.4); }
.theme-copy { display: grid; align-content: center; gap: 2px; min-width: 0; }
.theme-copy strong { font-size: 0.9rem; }
.theme-copy small { overflow: hidden; color: var(--muted); font-size: 0.68rem; text-overflow: ellipsis; white-space: nowrap; }
.theme-controls { display: flex; grid-column: 1 / -1; align-items: center; gap: 7px; }
.color-control { display: inline-flex; min-height: 36px; align-items: center; gap: 6px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 10px; background: white; color: var(--muted); font-size: 0.68rem; font-weight: 700; cursor: pointer; }
.color-control input { width: 24px; height: 24px; padding: 0; border: 0; border-radius: 7px; background: transparent; cursor: pointer; }
.color-control input::-webkit-color-swatch-wrapper { padding: 0; }
.color-control input::-webkit-color-swatch { border: 0; border-radius: 6px; }
.theme-upload { position: relative; overflow: hidden; min-height: 36px; flex: 1; padding: 7px 9px; font-size: 0.7rem; cursor: pointer; }
.theme-file-input { position: absolute; z-index: 1; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; font-size: 16px; }
.reset-theme { min-height: 36px; border: 1px solid var(--line); background: white; }
.appearance-error { margin-bottom: 0; }

.dialog { width: min(92vw, 490px); padding: 0; border: 0; border-radius: 24px; background: var(--surface); color: var(--ink); box-shadow: 0 28px 90px rgba(22, 55, 41, 0.28); }
.dialog::backdrop { background: rgba(18, 40, 31, 0.48); backdrop-filter: blur(4px); }
.dialog form { padding: 26px; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 15px; margin-bottom: 22px; }
.field { display: grid; gap: 8px; }
.field > span, .emoji-fieldset legend { font-size: 0.83rem; font-weight: 750; }
.field input { width: 100%; min-height: 50px; padding: 11px 14px; border: 1px solid #cfded4; border-radius: 13px; background: #fbfcfb; color: var(--ink); }
.emoji-fieldset { margin: 20px 0 0; padding: 0; border: 0; }
.emoji-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin-top: 9px; }
.emoji-button { display: grid; aspect-ratio: 1; place-items: center; border: 2px solid transparent; border-radius: 12px; background: var(--surface-soft); font-size: 1.25rem; }
.emoji-button:hover { background: var(--primary-light); }
.emoji-button.selected { border-color: var(--primary); background: #e1efe6; }
.custom-icon-field { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 18px; padding: 14px; border: 1px dashed #bdd2c4; border-radius: 15px; background: #f7faf7; }
.custom-icon-field > div:first-child { display: grid; gap: 3px; }
.custom-icon-field strong { font-size: 0.84rem; }
.custom-icon-field small { color: var(--muted); font-size: 0.7rem; }
.custom-icon-control { display: flex; flex: 0 0 auto; align-items: center; gap: 9px; }
.custom-icon-preview { display: grid; overflow: hidden; width: 44px; height: 44px; place-items: center; border-radius: 12px; background: var(--surface-soft); font-size: 1.25rem; }
#customIconInput { position: absolute; z-index: 1; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; font-size: 16px; }
.upload-button { position: relative; overflow: hidden; min-height: 40px; padding: 8px 12px; font-size: 0.78rem; cursor: pointer; }
.form-error { min-height: 20px; margin: 9px 0 0; color: var(--danger); font-size: 0.8rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 20px; }
.compact-dialog { width: min(90vw, 420px); text-align: center; }
.compact-dialog .dialog-actions { justify-content: center; }
.compact-dialog .dialog-heading { text-align: left; }
.confirm-icon { display: grid; width: 52px; height: 52px; margin: 0 auto 15px; place-items: center; border-radius: 50%; background: var(--danger-bg); color: var(--danger); font-size: 1.4rem; font-weight: 900; }
.compact-dialog p { color: var(--muted); line-height: 1.65; }
.install-help { text-align: left; }

.toast { position: fixed; z-index: 90; bottom: max(22px, env(safe-area-inset-bottom)); left: 50%; max-width: calc(100vw - 32px); padding: 11px 17px; border-radius: 99px; background: #17352a; color: white; font-size: 0.85rem; box-shadow: 0 10px 32px rgba(23, 53, 42, 0.25); opacity: 0; pointer-events: none; transform: translate(-50%, 16px); transition: opacity 200ms ease, transform 200ms ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.update-banner { position: fixed; z-index: 95; right: 20px; bottom: max(20px, env(safe-area-inset-bottom)); display: flex; width: min(calc(100vw - 40px), 540px); align-items: center; gap: 13px; padding: 14px; border: 1px solid #bdd3c4; border-radius: 19px; background: rgba(255,255,255,0.96); box-shadow: 0 18px 50px rgba(22, 55, 41, 0.22); backdrop-filter: blur(14px); }
.update-banner[hidden] { display: none; }
.update-icon { display: grid; width: 42px; height: 42px; flex: 0 0 42px; place-items: center; border-radius: 13px; background: var(--surface-soft); color: var(--primary); font-size: 1.35rem; font-weight: 900; }
.update-copy { display: grid; flex: 1; gap: 2px; min-width: 0; }
.update-copy strong { font-size: 0.9rem; }
.update-copy span { color: var(--muted); font-size: 0.73rem; }
.update-actions { display: flex; gap: 7px; }
.update-actions .button { min-height: 38px; padding: 7px 11px; font-size: 0.74rem; }
.celebration { position: fixed; z-index: 80; inset: 0; overflow: hidden; pointer-events: none; }
.celebration i { position: absolute; top: -18px; left: var(--x); width: 9px; height: 17px; border-radius: 3px; background: var(--color); opacity: 0; transform: rotate(12deg); }
.celebration.play i { animation: confetti 1.25s ease-out var(--delay) both; }
@keyframes confetti { 0% { opacity: 1; transform: translateY(-20px) rotate(0deg); } 100% { opacity: 0; transform: translateY(72vh) rotate(620deg); } }

noscript { display: block; padding: 20px; background: #fff0ef; color: var(--danger); text-align: center; }

@media (max-width: 620px) {
  .app-shell { width: min(calc(100% - 18px), 820px); }
  .topbar { min-height: 70px; }
  .install-button, .settings-button { min-height: 40px; padding: 8px 10px; font-size: 0.74rem; }
  .hero-heading { align-items: flex-start; }
  .progress-ring { width: 86px; height: 86px; flex-basis: 86px; }
  .progress-ring strong { font-size: 1.15rem; }
  .section-heading { align-items: flex-end; }
  .habit-check { min-height: 76px; padding: 13px; }
  .habit-icon { width: 43px; height: 43px; flex-basis: 43px; }
  .calendar-weekdays, .calendar-grid { gap: 4px; }
  .calendar-day { border-radius: 10px; }
  .data-section { align-items: flex-start; flex-direction: column; }
  .data-section .button { width: 100%; }
  .theme-grid { grid-template-columns: 1fr; }
  .settings-summary { align-items: stretch; flex-direction: column; }
  .settings-summary .button { width: 100%; }
  .update-banner { right: 9px; bottom: max(9px, env(safe-area-inset-bottom)); width: calc(100vw - 18px); align-items: flex-start; flex-wrap: wrap; }
  .update-copy { padding-top: 3px; }
  .update-actions { width: 100%; padding-left: 55px; }
  .update-actions .button { flex: 1; }
}

@media (max-width: 410px) {
  .hero-heading { display: grid; }
  .progress-ring { position: absolute; right: 0; top: -3px; opacity: 0.18; }
  .hero-heading > div:first-child { position: relative; z-index: 2; padding-right: 10px; }
  .calendar-heading { align-items: flex-start; flex-direction: column; }
  .month-nav { width: 100%; justify-content: space-between; }
  .habit-actions { justify-content: space-between; }
  .emoji-grid { grid-template-columns: repeat(4, 1fr); }
  .custom-icon-field { align-items: flex-start; flex-direction: column; }
  .custom-icon-control { width: 100%; justify-content: space-between; }
  .topbar-actions { gap: 5px; }
  .install-button, .settings-button { padding-inline: 8px; }
}

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