:root {
  --accent: #0e7c66;
  --accent-strong: #0a6150;
  --accent-soft: #e3f3ee;
  --bg: #f4f7f5;
  --surface: #ffffff;
  --text: #1c2622;
  --muted: #5f6f69;
  --border: #dbe4e0;
  --error: #c62828;
  --error-soft: #fdecea;
  --shadow: 0 1px 2px rgba(16, 40, 32, 0.06), 0 4px 16px rgba(16, 40, 32, 0.06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #3fbf9f;
    --accent-strong: #5fd4b6;
    --accent-soft: #173a31;
    --bg: #0f1513;
    --surface: #18211e;
    --text: #e6eeeb;
    --muted: #9db0a9;
    --border: #2a3632;
    --error: #ff8a80;
    --error-soft: #3a1f1d;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN",
    "Noto Sans JP", "Yu Gothic", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

[hidden] { display: none !important; }

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 16px calc(32px + env(safe-area-inset-bottom));
}

/* ヘッダー */
.header { padding: 8px 4px 16px; }
.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
}
.greeting { margin: 4px 0 0; font-size: 22px; font-weight: 700; line-height: 1.4; }
.trainer { margin: 2px 0 0; color: var(--muted); font-size: 14px; }

/* カード */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 20px 18px;
  margin-bottom: 16px;
}
.card-title { margin: 0 0 14px; font-size: 17px; font-weight: 700; }

/* フォーム */
.field { margin-bottom: 14px; }
.field label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}
input[type="number"], input[type="date"] {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 18px;
  appearance: none;
  -webkit-appearance: none;
}
input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input[aria-invalid="true"] { border-color: var(--error); }

.weight-input-wrap { position: relative; }
.weight-input-wrap input { padding-right: 48px; font-size: 24px; font-weight: 700; }
.unit {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-weight: 600;
  pointer-events: none;
}

.form-error {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--error-soft);
  color: var(--error);
  font-size: 14px;
  font-weight: 600;
}

.form-notice {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 14px;
  font-weight: 600;
}

/* ボタン */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 20px;
  border-radius: 12px;
  border: none;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.button-primary {
  width: 100%;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
}
.button-primary:active { background: var(--accent-strong); }
.button-secondary {
  background: var(--accent-soft);
  color: var(--accent);
}
.button:disabled { opacity: 0.55; cursor: default; }

@media (prefers-color-scheme: dark) {
  .button-primary { color: #0f1513; }
}

/* 履歴 */
.history { list-style: none; margin: 0; padding: 0; }
.history li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 2px;
  border-top: 1px solid var(--border);
}
.history li:first-child { border-top: none; padding-top: 2px; }
.history .date { flex: 1; color: var(--muted); font-size: 15px; }
.history .weight { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.history .weight small { margin-left: 2px; color: var(--muted); font-size: 13px; font-weight: 600; }
.badge {
  min-width: 72px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}
.badge.chat { background: var(--border); color: var(--muted); }
.empty { margin: 0; color: var(--muted); text-align: center; padding: 12px 0; }

/* 読み込み中・エラー */
.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 80px 16px;
  text-align: center;
  color: var(--muted);
}
.state p { margin: 0; }
.state-message { color: var(--text); font-weight: 600; white-space: pre-line; }
.state-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--error-soft);
  color: var(--error);
  font-size: 24px;
  font-weight: 800;
}
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* トースト */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 12px 20px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  animation: toast-in 0.2s ease-out;
}
@media (prefers-color-scheme: dark) {
  .toast { color: #0f1513; }
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .spinner, .toast { animation: none; }
}
