:root {
  --ink: #1d1d1f;
  --ink-soft: #6e6e73;
  --muted: #86868b;
  --line: #d2d2d7;
  --line-strong: #d2d2d7;
  --bg: #ffffff;
  --bg-subtle: #f5f5f7;
  --surface: #ffffff;
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-deep: #0071e3;
  --warm: #bf4800;
  --danger: #bf4800;
  --ok: #008009;
  --radius: 18px;
  --radius-sm: 12px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
    sans-serif;
  --display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
    "Helvetica Neue", "PingFang SC", sans-serif;
  --mono: "SF Mono", ui-monospace, Menlo, monospace;
  --pad: clamp(1.25rem, 4vw, 2.5rem);
  --max: 980px;
  --ease: cubic-bezier(0.25, 0.1, 0.25, 1);
  --tap: 44px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

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

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.47059;
  font-weight: 400;
  letter-spacing: -0.022em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

.shell {
  width: min(var(--max), calc(100% - 2 * var(--pad)));
  margin: 0 auto;
  padding: calc(var(--pad) + env(safe-area-inset-top)) 0
    calc(3rem + env(safe-area-inset-bottom));
}

/* —— Nav —— */
.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: clamp(2rem, 5vw, 3rem);
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}

body[data-mode="auth"] .masthead {
  display: none;
}

.brand {
  margin: 0;
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.125rem;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.brand-sub {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 400;
  letter-spacing: 0;
}

.mast-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
}

body[data-mode="auth"] .shell {
  width: min(920px, calc(100% - 2 * var(--pad)));
  min-height: 100dvh;
  display: grid;
  align-content: center;
  padding-top: calc(var(--pad) + env(safe-area-inset-top));
  padding-bottom: calc(var(--pad) + env(safe-area-inset-bottom));
}

/* —— Auth (Apple split) —— */
.auth-gate {
  display: grid;
  gap: 2rem;
  align-items: stretch;
  animation: rise 0.6s var(--ease) both;
}

@media (min-width: 900px) {
  .auth-gate {
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
    min-height: min(70vh, 560px);
  }
}

.auth-visual {
  display: grid;
  align-content: center;
  gap: 0.85rem;
  padding: clamp(2rem, 5vw, 3.5rem);
  border-radius: 28px;
  background: var(--bg-subtle);
  min-height: 240px;
}

.auth-brand {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted);
  text-transform: none;
}

.auth-headline {
  margin: 0;
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(2.5rem, 6vw, 3.5rem);
  letter-spacing: -0.025em;
  line-height: 1.05;
  color: var(--ink);
}

.auth-lead {
  margin: 0.35rem 0 0;
  max-width: 22ch;
  color: var(--ink-soft);
  font-size: 1.05rem;
  line-height: 1.4;
  font-weight: 400;
}

.auth-card {
  width: min(100%, 420px);
  justify-self: center;
  display: grid;
  grid-template-rows: 1fr auto;
  border-radius: 28px;
  background: var(--bg);
  border: 1px solid var(--line);
  overflow: hidden;
  animation: rise 0.65s var(--ease) 0.05s both;
}

@media (min-width: 900px) {
  .auth-card {
    justify-self: stretch;
    width: 100%;
    max-width: none;
  }
}

.auth-card-body {
  padding: clamp(1.5rem, 3vw, 2rem);
  display: grid;
  gap: 0.75rem;
  align-content: start;
}

.auth-form-title {
  margin: 0;
  font-family: var(--display);
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.auth-form-desc {
  margin: 0 0 0.35rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.auth-form {
  display: grid;
  gap: 0.9rem;
}

.auth-form.is-hidden {
  display: none !important;
}

.auth-form.is-switching {
  animation: rise 0.35s var(--ease);
}

.auth-hint {
  margin: 0;
  padding: 0.75rem 0.9rem;
  border-radius: 12px;
  background: var(--bg-subtle);
  color: var(--ink-soft);
  font-size: 0.875rem;
  line-height: 1.4;
}

.auth-card-footer {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-top: 1px solid var(--line);
  background: var(--bg-subtle);
}

.mode-btn {
  appearance: none;
  border: 0;
  background: transparent;
  min-height: 52px;
  font-weight: 400;
  font-size: 0.95rem;
  color: var(--muted);
  cursor: pointer;
  position: relative;
  z-index: 2;
  pointer-events: auto;
  transition: color 0.2s ease, background 0.2s ease;
}

.mode-btn:first-child {
  border-right: 1px solid var(--line);
}

.mode-btn.is-active {
  color: var(--ink);
  font-weight: 600;
  background: var(--bg);
}

.mode-btn:hover {
  color: var(--ink);
}

/* legacy admin login stage */
.auth-stage,
.login-stage {
  min-height: min(70vh, 560px);
  display: grid;
  align-items: center;
  gap: 2rem;
  animation: rise 0.6s var(--ease) both;
}

@media (min-width: 820px) {
  .auth-stage,
  .login-stage {
    grid-template-columns: 1fr 1fr;
  }
}

.display {
  margin: 0;
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(2.2rem, 5vw, 3rem);
  letter-spacing: -0.025em;
  line-height: 1.07;
  color: var(--ink);
}

.lead {
  margin: 0.75rem 0 0;
  color: var(--ink-soft);
  font-size: 1.05rem;
  max-width: 28ch;
}

.auth-panel,
.login-form,
.compose,
.snapshot {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.auth-panel,
.login-form {
  padding: 1.5rem;
  display: grid;
  gap: 0.9rem;
  max-width: 420px;
  width: 100%;
}

.stack {
  display: grid;
  gap: 0.85rem;
}

.welcome {
  margin: 0 0 1.5rem;
  color: var(--muted);
  font-size: 1.05rem;
  font-weight: 400;
}

.app-stage {
  animation: rise 0.55s var(--ease) both;
}

.hero-grid {
  display: grid;
  gap: 1rem;
}

@media (min-width: 900px) {
  .hero-grid {
    grid-template-columns: 1.05fr 0.95fr;
    gap: 1.25rem;
    align-items: stretch;
  }
}

.snapshot {
  padding: clamp(1.25rem, 3vw, 1.75rem);
  display: grid;
  gap: 0.85rem;
  min-height: 100%;
  background: var(--bg-subtle);
  border-color: transparent;
}

.section-kicker {
  margin: 0;
  font-size: 0.75rem;
  letter-spacing: 0.01em;
  color: var(--muted);
  font-weight: 400;
  text-transform: none;
}

.snapshot-main {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.75rem 1.25rem;
}

.big-metric {
  display: flex;
  align-items: baseline;
  gap: 0.3rem;
}

.big-num {
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(3.2rem, 9vw, 4.5rem);
  letter-spacing: -0.035em;
  line-height: 0.95;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.big-unit {
  font-size: 1.1rem;
  color: var(--muted);
  font-weight: 400;
}

.snapshot-meta {
  text-align: right;
}

.meta-line {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.meta-line.waist {
  margin-top: 0.25rem;
}

.delta {
  margin: 0.25rem 0 0;
  font-family: var(--mono);
  font-size: 0.9rem;
  font-weight: 500;
}

.delta.down {
  color: var(--ok);
}

.delta.up {
  color: var(--warm);
}

.delta.flat {
  color: var(--muted);
}

.spark-wrap {
  height: 72px;
  margin-top: 0.15rem;
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, rgba(0, 113, 227, 0.06), transparent 70%);
  overflow: hidden;
}

.sparkline {
  width: 100%;
  height: 100%;
  display: block;
}

.sparkline path.area {
  fill: rgba(0, 113, 227, 0.1);
}

.sparkline path.line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.summary-line {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.compose {
  padding: clamp(1.25rem, 3vw, 1.75rem);
  display: grid;
  gap: 1rem;
}

.compose-head h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.compose-hint {
  margin: 0.3rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}

.field-span {
  grid-column: 1 / -1;
}

@media (max-width: 520px) {
  .fields {
    grid-template-columns: 1fr;
  }

  .snapshot-meta {
    text-align: left;
    width: 100%;
  }
}

.field {
  display: grid;
  gap: 0.35rem;
}

.field > span {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 400;
}

.field input {
  width: 100%;
  min-height: var(--tap);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.7rem 0.9rem;
  background: var(--bg);
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 400;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.field-emphasis input {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.18);
}

.field input::placeholder {
  color: #a1a1a6;
  font-weight: 400;
}

.field select {
  width: 100%;
  min-height: var(--tap);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.7rem 0.9rem;
  background: var(--bg);
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 400;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2386868b' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  padding-right: 2.2rem;
}

.field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.18);
}

.profile-diet-grid {
  display: grid;
  gap: 1rem;
  margin-top: clamp(1.5rem, 3vw, 2rem);
}

@media (min-width: 900px) {
  .profile-diet-grid {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
}

.diet-result {
  margin-top: 1rem;
  display: grid;
  gap: 0.75rem;
}

.diet-result[hidden] {
  display: none;
}

.advice-block {
  padding: 1.15rem 1.25rem;
  border-radius: 18px;
  background: var(--bg);
  border: 1px solid var(--line);
}

.advice-block:first-child {
  background: var(--bg-subtle);
  border-color: transparent;
}

.advice-kicker {
  margin: 0 0 0.55rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: none;
  color: var(--muted, #86868b);
}

.advice-body {
  color: var(--ink);
  font-size: 0.98rem;
  line-height: 1.58;
  letter-spacing: -0.01em;
}

.advice-body p {
  margin: 0 0 0.55rem;
}

.advice-body p:last-child {
  margin-bottom: 0;
}

.advice-body strong {
  font-weight: 600;
}

.advice-body .md-ul {
  margin: 0.15rem 0 0.35rem;
  padding: 0;
  list-style: none;
}

.advice-body .md-ul li {
  position: relative;
  margin: 0;
  padding: 0.55rem 0 0.55rem 1rem;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  color: var(--ink);
}

.advice-body .md-ul li:first-child {
  border-top: 0;
  padding-top: 0.15rem;
}

.advice-body .md-ul li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 1.15em;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.85;
}

.advice-body .md-ul li:first-child::before {
  top: 0.75em;
}

.compose-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

/* —— Buttons (Apple pill) —— */
.btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.65rem 1.35rem;
  border-radius: 980px;
  font-weight: 400;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  min-width: 7rem;
}

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

.btn-block {
  width: 100%;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
}

.btn-ghost:hover {
  background: var(--bg-subtle);
}

button:disabled {
  opacity: 0.55;
  cursor: wait;
}

/* —— History —— */
.history {
  margin-top: clamp(2rem, 4vw, 3rem);
}

.history-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.history-head h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.history-tip {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.table-scroll {
  border-top: 1px solid var(--line);
}

.list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.item {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.8fr) auto;
  gap: 0.5rem 1rem;
  align-items: center;
  padding: 1.05rem 0.15rem;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background 0.15s ease;
  animation: rise 0.4s var(--ease) both;
}

.item:hover {
  background: var(--bg-subtle);
}

.item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.item .date {
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.item .note {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item .metrics {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.item .metrics .w {
  font-weight: 600;
  font-size: 1.02rem;
}

.item .metrics .waist {
  margin-top: 0.15rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.item .del {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--danger);
  min-height: 40px;
  min-width: 40px;
  padding: 0.4rem 0.65rem;
  border-radius: 980px;
  font-size: 0.82rem;
  font-weight: 400;
  cursor: pointer;
  opacity: 0.75;
}

.item .del:hover,
.item:hover .del {
  opacity: 1;
  border-color: var(--line);
  background: var(--bg);
}

@media (max-width: 640px) {
  .item {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "date del"
      "metrics del";
    gap: 0.25rem 0.75rem;
    padding: 1rem 0.1rem;
  }

  .item .date-block {
    grid-area: date;
  }

  .item .metrics {
    grid-area: metrics;
    text-align: left;
  }

  .item .del {
    grid-area: del;
    align-self: center;
  }

  .history-tip {
    display: none;
  }
}

.empty {
  margin: 1.5rem 0 0;
  color: var(--muted);
  text-align: center;
  padding: 2rem 1rem;
  font-size: 0.95rem;
}

.error {
  margin: 0;
  color: var(--danger);
  font-size: 0.9rem;
}

.msg {
  margin: 0;
  font-size: 0.9rem;
  color: var(--ok);
  font-weight: 400;
}

.msg.is-error {
  color: var(--danger);
}

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

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

[hidden] {
  display: none !important;
}
