:root {
  color-scheme: light;
  --bg: #f7faf8;
  --surface: #ffffff;
  --surface-soft: #eef7f5;
  --ink: #173233;
  --muted: #718182;
  --line: #dbe6e3;
  --teal: #22a7a5;
  --teal-dark: #087b7a;
  --coral: #f0785a;
  --gold: #f4c95d;
  --blue: #527aa3;
  --rose: #df8a9b;
  --shadow: 0 18px 44px rgba(33, 76, 78, 0.12);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 15% 0%, rgba(34, 167, 165, 0.12), transparent 26rem),
    linear-gradient(180deg, #f9fcfb 0%, var(--bg) 42%, #edf5f3 100%);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
}

.app-shell {
  width: min(100%, 520px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 0 18px 28px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  gap: 10px;
  min-height: 72px;
  padding: 10px 0;
  background: rgba(247, 250, 248, 0.88);
  backdrop-filter: blur(18px);
}

.sync-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  margin: -2px 0 12px;
  padding: 0 11px;
  border: 1px solid rgba(219, 230, 227, 0.88);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  color: var(--muted);
  box-shadow: 0 8px 18px rgba(33, 76, 78, 0.06);
  cursor: pointer;
}

.sync-status span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.sync-status strong {
  font-size: 12px;
  font-weight: 650;
}

.sync-status[data-state="synced"] {
  color: var(--teal-dark);
}

.sync-status[data-state="synced"] span {
  background: var(--teal);
}

.sync-status[data-state="saving"],
.sync-status[data-state="checking"] {
  color: #a46913;
}

.sync-status[data-state="saving"] span,
.sync-status[data-state="checking"] span {
  background: var(--gold);
}

.sync-status[data-state="locked"],
.sync-status[data-state="error"] {
  color: #a5452e;
}

.sync-status[data-state="locked"] span,
.sync-status[data-state="error"] span {
  background: var(--coral);
}

.cloud-unlock {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 76px;
  gap: 8px;
  margin: -4px 0 14px;
}

.cloud-unlock[hidden] {
  display: none;
}

.cloud-unlock input,
.cloud-unlock button {
  min-height: 40px;
  border-radius: 8px;
}

.cloud-unlock input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

.cloud-unlock input:focus {
  border-color: rgba(34, 167, 165, 0.86);
  box-shadow: 0 0 0 3px rgba(34, 167, 165, 0.12);
}

.cloud-unlock button {
  background: var(--teal);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--surface);
  color: var(--teal-dark);
  box-shadow: 0 8px 22px rgba(24, 78, 82, 0.08);
  cursor: pointer;
}

.icon-button.accent {
  background: var(--coral);
  color: #fff;
}

.icon-button svg,
.tab svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.child-switcher {
  display: grid;
  gap: 4px;
  min-width: 0;
  text-align: center;
}

.child-switcher label,
.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.child-switcher select {
  width: 100%;
  min-height: 34px;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: center;
  font-size: 22px;
  font-weight: 650;
  outline: none;
}

.hero-section {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 94px;
  align-items: center;
  gap: 16px;
  padding: 20px 0 18px;
}

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

h1 {
  margin-bottom: 8px;
  font-size: clamp(30px, 9vw, 42px);
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 20px;
  letter-spacing: 0;
}

.hero-note {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.score-ring {
  position: relative;
  display: grid;
  place-items: center;
  width: 88px;
  height: 88px;
  border-radius: 50%;
  background:
    radial-gradient(circle at center, var(--surface) 56%, transparent 57%),
    conic-gradient(var(--teal) 0 72%, rgba(34, 167, 165, 0.18) 72% 100%);
  box-shadow: var(--shadow);
}

.score-ring span {
  font-size: 24px;
  font-weight: 760;
  color: var(--teal-dark);
}

.score-ring small {
  position: absolute;
  bottom: 19px;
  color: var(--muted);
  font-size: 11px;
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.metric-card {
  min-height: 96px;
  padding: 13px 12px;
  border: 1px solid rgba(219, 230, 227, 0.9);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 12px 26px rgba(33, 76, 78, 0.07);
}

.metric-card small {
  display: block;
  min-height: 17px;
  color: var(--muted);
  font-size: 12px;
}

.metric-card strong {
  display: block;
  margin-top: 8px;
  font-size: clamp(17px, 4.8vw, 22px);
  line-height: 1.05;
  color: var(--ink);
}

.metric-card span {
  display: block;
  margin-top: 7px;
  color: var(--teal-dark);
  font-size: 11px;
  line-height: 1.25;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 0 0 16px;
  padding: 6px;
  border: 1px solid rgba(219, 230, 227, 0.92);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.tab {
  display: grid;
  grid-template-rows: 22px 18px;
  justify-items: center;
  align-items: center;
  gap: 4px;
  min-height: 58px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.tab.active {
  background: var(--teal);
  color: #fff;
  box-shadow: 0 10px 22px rgba(34, 167, 165, 0.25);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.tool-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  width: 100%;
  gap: 6px;
}

.segmented button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}

.segmented button.active {
  border-color: var(--teal);
  background: var(--surface-soft);
  color: var(--teal-dark);
  font-weight: 700;
}

.chart-panel,
.entry-form,
.data-tools {
  border: 1px solid rgba(219, 230, 227, 0.9);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.chart-panel {
  padding: 16px 14px 12px;
}

.chart-head,
.section-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.standard-badge {
  flex: 0 0 auto;
  padding: 6px 9px;
  border-radius: 999px;
  background: rgba(244, 201, 93, 0.18);
  color: #8a640b;
  font-size: 12px;
}

.chart-wrap {
  position: relative;
  width: 100%;
  height: clamp(300px, 76vw, 380px);
  margin-top: 12px;
}

#growthChart {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  min-height: 25px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend i {
  display: block;
  width: 18px;
  height: 3px;
  border-radius: 999px;
  background: currentColor;
}

.insight-section {
  padding: 22px 0 0;
}

.section-title {
  margin-bottom: 12px;
}

.section-title span {
  color: var(--muted);
  font-size: 12px;
}

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

.insight-item {
  display: grid;
  grid-template-columns: 7px 1fr;
  gap: 11px;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.insight-item::before {
  content: "";
  width: 7px;
  min-height: 100%;
  border-radius: 999px;
  background: var(--teal);
}

.insight-item.warn::before {
  background: var(--gold);
}

.insight-item.alert::before {
  background: var(--coral);
}

.insight-item h3 {
  margin: 0 0 5px;
  font-size: 15px;
}

.insight-item p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

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

.record-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.record-row h3 {
  margin: 0 0 7px;
  font-size: 16px;
  letter-spacing: 0;
}

.record-row p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
}

.record-values {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 9px;
}

.value-chip {
  padding: 5px 8px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--teal-dark);
  font-size: 12px;
}

.row-actions {
  display: grid;
  gap: 8px;
  align-content: start;
}

.mini-button {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #f4f8f7;
  color: var(--teal-dark);
  cursor: pointer;
}

.mini-button svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.entry-form {
  padding: 16px;
}

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

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
  color: var(--ink);
  outline: none;
  padding: 10px 12px;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(34, 167, 165, 0.13);
}

.full-field {
  margin-top: 12px;
}

.primary-button,
.text-button,
.import-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border-radius: 8px;
  cursor: pointer;
}

.primary-button {
  width: 100%;
  margin-top: 16px;
  background: var(--teal);
  color: #fff;
  font-weight: 740;
  box-shadow: 0 14px 28px rgba(34, 167, 165, 0.24);
}

.text-button,
.import-button {
  padding: 0 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--teal-dark);
  font-size: 13px;
}

.text-button.subtle {
  color: var(--muted);
}

.text-button.danger {
  color: #b85043;
}

.data-tools {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
  padding: 14px;
}

.import-button input {
  display: none;
}

.empty {
  padding: 20px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 390px) {
  .app-shell {
    padding-inline: 12px;
  }

  .metric-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .hero-section {
    grid-template-columns: 1fr;
  }

  .score-ring {
    justify-self: start;
  }
}

@media (min-width: 760px) {
  .app-shell {
    width: min(100%, 900px);
  }

  .view.active {
    animation: fadeIn 150ms ease-out;
  }

  #chartView.active {
    display: grid;
    grid-template-columns: minmax(0, 1.3fr) minmax(260px, 0.7fr);
    gap: 18px;
    align-items: start;
  }

  #chartView .tool-row,
  #chartView .chart-panel {
    grid-column: 1;
  }

  #chartView .insight-section {
    grid-column: 2;
    grid-row: 1 / span 2;
    padding-top: 0;
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
