:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
  --ink: #101828;
  --muted: #667085;
  --line: #e4e7ec;
  --soft: #f6f8f7;
  --green: #176b4d;
  --green-soft: #edf7f3;
  --red: #b42318;
  --red-soft: #fff4f2;
}

* { box-sizing: border-box; }

html { background: #f7f8f8; }

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background: #f7f8f8;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea { font: inherit; }
button { touch-action: manipulation; }

.page-shell {
  width: min(860px, 100%);
  margin: 0 auto;
  padding: 22px 18px calc(112px + env(safe-area-inset-bottom));
}

.page-header, .score-summary, .behavior-main, .behavior-stats, .section-heading,
.dialog-header, .manage-list-heading, .edit-actions, .confirm-actions, .bottom-summary {
  display: flex;
}

.page-header {
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 4px; font-size: clamp(25px, 6vw, 34px); line-height: 1.2; }
h2 { margin-bottom: 5px; font-size: 21px; }
h3 { margin-bottom: 16px; font-size: 18px; }

.eyebrow {
  margin-bottom: 5px;
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .08em;
}

.active-date, .section-note, .section-heading p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 14px;
}

.score-summary {
  align-items: stretch;
  margin-bottom: 28px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}

.score-summary > div { flex: 1; }
.score-summary > div + div { padding-left: 22px; border-left: 1px solid var(--line); }
.score-summary span { display: block; color: var(--muted); font-size: 14px; }
.score-summary strong { display: block; margin-top: 6px; color: var(--green); font-size: 42px; line-height: 1; }

.section-heading { align-items: flex-end; justify-content: space-between; margin-bottom: 13px; }
.behavior-list { display: grid; gap: 12px; }

.behavior-card, .panel, .empty-card {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fff;
}

.behavior-main { align-items: center; gap: 14px; }
.behavior-copy { flex: 1; min-width: 0; }
.behavior-name { font-size: 16px; font-weight: 650; line-height: 1.55; overflow-wrap: anywhere; }
.score-tag {
  display: inline-block;
  margin-top: 8px;
  padding: 4px 9px;
  border-radius: 6px;
  color: var(--green);
  background: var(--green-soft);
  font-size: 13px;
  font-weight: 650;
}

.score-actions { display: flex; flex: 0 0 auto; gap: 9px; }
.score-button {
  width: 54px;
  height: 54px;
  padding: 0;
  border-radius: 11px;
  font-size: 33px;
  font-weight: 650;
  line-height: 1;
}
.minus-button { border: 1px solid #efb4ae; color: var(--red); background: var(--red-soft); }
.plus-button { border: 1px solid var(--green); color: #fff; background: var(--green); }
.score-button:active { transform: scale(.95); opacity: .72; }

.behavior-stats {
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  padding-top: 13px;
  border-top: 1px solid #f0f2f4;
  color: #475467;
  font-size: 13px;
}

.panel { margin-top: 26px; }
form label, .field-caption { display: block; margin: 16px 0 7px; color: #344054; font-size: 14px; font-weight: 650; }
input, textarea {
  width: 100%;
  padding: 12px 13px;
  border: 1px solid #cfd4dc;
  border-radius: 9px;
  outline: none;
  color: var(--ink);
  background: #fff;
}
textarea { resize: vertical; line-height: 1.5; }
input:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(23, 107, 77, .12); }

.preset-list { display: flex; flex-wrap: wrap; gap: 8px; }
.preset-button {
  padding: 8px 11px;
  border: 0;
  border-radius: 999px;
  color: #344054;
  background: #f0f2f4;
  font-size: 13px;
}

.primary-button, .outline-button, .danger-button {
  min-height: 43px;
  padding: 9px 16px;
  border-radius: 9px;
  font-weight: 700;
  cursor: pointer;
}
.primary-button { border: 1px solid var(--green); color: #fff; background: var(--green); }
.outline-button { border: 1px solid #9dbfaf; color: var(--green); background: #fff; }
.danger-button { border: 1px solid #e9a6a0; color: var(--red); background: var(--red-soft); }
.full-button { width: 100%; margin-top: 20px; }

.history-row { display: flex; align-items: center; justify-content: space-between; padding: 13px 0; border-bottom: 1px solid #f0f2f4; }
.history-row:last-child { border-bottom: 0; padding-bottom: 0; }
.history-name { font-weight: 650; }
.history-date { margin-top: 3px; color: #98a2b3; font-size: 12px; }
.history-score { color: var(--red); font-weight: 700; }

.bottom-summary {
  position: fixed;
  z-index: 20;
  right: 0;
  bottom: 0;
  left: 0;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px max(18px, calc((100vw - 824px) / 2)) calc(15px + env(safe-area-inset-bottom));
  border-top: 1px solid #d0d5dd;
  background: rgba(255,255,255,.97);
  box-shadow: 0 -4px 18px rgba(16,24,40,.08);
  backdrop-filter: blur(10px);
}
.bottom-summary div { display: flex; align-items: baseline; gap: 10px; }
.bottom-summary span { color: #475467; font-size: 13px; }
.bottom-summary strong { font-size: 24px; }
.bottom-summary .bottom-balance { color: var(--green); font-size: 15px; font-weight: 700; white-space: nowrap; }

.manage-dialog {
  width: min(720px, calc(100% - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 0;
  border-radius: 16px;
  color: var(--ink);
  background: #f7f8f8;
  box-shadow: 0 24px 80px rgba(16,24,40,.28);
}
.manage-dialog::backdrop { background: rgba(16,24,40,.55); }
.dialog-header {
  position: sticky;
  z-index: 2;
  top: 0;
  align-items: center;
  justify-content: space-between;
  padding: 18px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}
.dialog-header h2 { margin-bottom: 0; }
.icon-button { width: 42px; height: 42px; padding: 0; border: 0; border-radius: 50%; color: #344054; background: #f0f2f4; font-size: 29px; line-height: 1; }
.add-goal-form { margin: 16px; padding: 18px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.add-goal-form .primary-button { margin-top: 18px; }
.manage-list-heading { align-items: baseline; justify-content: space-between; margin: 24px 18px 10px; }
.manage-list-heading h3 { margin-bottom: 0; }
.manage-list-heading span { color: var(--muted); font-size: 13px; }
.manage-list { display: grid; gap: 11px; padding: 0 16px 22px; }
.edit-card { padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.edit-card label { display: block; margin: 0 0 6px; color: #344054; font-size: 13px; font-weight: 650; }
.edit-card label:not(:first-child) { margin-top: 13px; }
.edit-card .score-input { max-width: 160px; }
.edit-actions { gap: 9px; margin-top: 14px; }
.edit-actions button { flex: 1; }

.confirm-layer {
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  margin: 0;
  padding: 20px;
  border: 0;
  background: transparent;
}
.confirm-layer[open] { display: grid; place-items: center; }
.confirm-layer::backdrop { background: rgba(16,24,40,.55); }
.confirm-box { width: min(390px, 100%); padding: 22px; border-radius: 14px; background: #fff; box-shadow: 0 18px 60px rgba(16,24,40,.25); }
.confirm-box p { color: #475467; line-height: 1.6; white-space: pre-line; }
.confirm-actions { justify-content: flex-end; gap: 10px; }

.toast {
  position: fixed;
  z-index: 80;
  top: calc(18px + env(safe-area-inset-top));
  left: 50%;
  max-width: calc(100% - 36px);
  padding: 10px 15px;
  border-radius: 999px;
  color: #fff;
  background: #344054;
  box-shadow: 0 8px 24px rgba(16,24,40,.22);
  transform: translateX(-50%);
  font-size: 14px;
  text-align: center;
}

.empty-card { color: var(--muted); text-align: center; }
[hidden] { display: none !important; }

@media (max-width: 520px) {
  .page-shell { padding-right: 12px; padding-left: 12px; }
  .page-header { align-items: flex-start; }
  .outline-button { padding-right: 12px; padding-left: 12px; }
  .score-summary { padding: 18px 15px; }
  .score-summary > div + div { padding-left: 15px; }
  .score-summary strong { font-size: 36px; }
  .behavior-card { padding: 15px 13px; }
  .behavior-main { gap: 10px; }
  .behavior-name { font-size: 15px; }
  .score-button { width: 50px; height: 50px; }
  .bottom-summary { padding-right: 14px; padding-left: 14px; }
}

@media (prefers-reduced-motion: no-preference) {
  .score-button, .primary-button, .outline-button, .danger-button { transition: transform .08s ease, opacity .08s ease; }
}
