:root {
  --bg: #f4f8fc;
  --paper: #ffffff;
  --ink: #14233a;
  --muted: #5b6b7f;
  --line: #d9e3ee;
  --primary: #1769aa;
  --primary-soft: #e7f1fa;
  --success: #ffd8a8;
  --success-ink: #593407;
  --success-soft: #fff2e2;
  --gold: #f2a51a;
  --danger: #b2483f;
  --shadow: 0 12px 30px rgba(37, 74, 111, 0.1);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", "Yu Gothic", Meiryo, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

button, input, select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  width: min(100%, 520px);
  min-height: 100vh;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 14px calc(82px + env(safe-area-inset-bottom));
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px 0;
}

.login-panel { width: 100%; }
.login-panel label { display: grid; gap: 6px; margin-top: 16px; color: var(--muted); font-weight: 700; }
.login-panel input { min-height: 48px; border: 1px solid var(--line); border-radius: 8px; padding: 0 12px; background: #fff; }
.login-error { min-height: 22px; margin: 10px 0 0; color: var(--danger); font-size: 14px; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 2px 12px;
}

.date-title {
  margin: 0;
  font-size: 28px;
  letter-spacing: 0;
}

.subtle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.status-pill {
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 999px;
  padding: 9px 12px;
  color: var(--primary);
  font-weight: 700;
}

.sync-inline { max-width: 150px; margin: 5px 0 0; color: var(--muted); font-size: 11px; text-align: right; }
.sync-row { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 14px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.sync-row strong { color: var(--primary); text-align: right; }
.sign-out { margin-top: 10px; }

.panel {
  background: var(--paper);
  border: 1px solid rgba(23, 105, 170, 0.1);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
  margin: 10px 0;
}

.record-panel {
  border-top: 5px solid var(--primary);
}

.section-title {
  margin: 0 0 12px;
  font-size: 20px;
}

.weight-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.weight-input {
  min-width: 0;
  height: 58px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 0 14px;
  font-size: 24px;
  font-weight: 800;
}

.unit {
  font-size: 18px;
  font-weight: 700;
  color: var(--muted);
}

.quick-grid {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.choice-group {
  display: grid;
  gap: 8px;
}

.choice-label {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.segmented button,
.snack-types button,
.primary-btn,
.secondary-btn,
.gym-item {
  min-height: 48px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-weight: 800;
}

.segmented button.active,
.snack-types button.active,
.gym-item.done {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.segmented button.achieved {
  position: relative;
  overflow: hidden;
  background: var(--success);
  border-color: var(--success);
  color: var(--success-ink);
}

.gym-item.done {
  background: var(--success);
  border-color: var(--success);
  color: var(--success-ink);
}

.shine {
  display: inline-block;
  margin-right: 7px;
  color: #fff0bd;
}

.just-achieved {
  animation: achievement-glow 650ms ease-out;
}

@keyframes achievement-glow {
  0% { box-shadow: 0 0 0 0 rgba(242, 165, 26, 0.78); transform: scale(0.98); }
  55% { box-shadow: 0 0 0 7px rgba(242, 165, 26, 0.18); transform: scale(1.02); }
  100% { box-shadow: 0 0 0 0 rgba(242, 165, 26, 0); transform: scale(1); }
}

.today-wins {
  margin-top: 14px;
  padding-top: 13px;
  border-top: 1px solid var(--line);
}

.today-wins-title {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.win-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin: 0 6px 6px 0;
  padding: 7px 9px;
  border-radius: 6px;
  background: var(--success);
  color: var(--success-ink);
  font-size: 13px;
  font-weight: 800;
}

.win-chip span { color: var(--gold); }

.snack-types {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 8px;
}

.snack-types button {
  min-height: 40px;
  font-size: 13px;
}

.primary-btn {
  width: 100%;
  margin-top: 14px;
  min-height: 58px;
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  font-size: 18px;
}

.secondary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  text-decoration: none;
  color: var(--primary);
}

.metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.metric.full {
  grid-column: 1 / -1;
}

.metric-value {
  display: block;
  font-size: 24px;
  font-weight: 900;
  margin-top: 4px;
}

.metric-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.meter {
  height: 8px;
  background: #e6ece8;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 10px;
}

.meter > span {
  display: block;
  height: 100%;
  background: var(--primary);
}

.nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 3;
  transform: translateX(-50%);
  width: min(100%, 520px);
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  background: rgba(255, 255, 255, 0.95);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.nav button {
  min-height: 52px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.nav button.active {
  background: var(--primary);
  color: #fff;
}

.chart-wrap {
  height: 260px;
  overflow: hidden;
}

canvas {
  width: 100%;
  height: 100%;
}

.range-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}

.range-tabs button {
  min-height: 40px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
  font-weight: 800;
}

.range-tabs button.active {
  background: var(--primary);
  color: #fff;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form-grid label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-weight: 700;
  font-size: 13px;
}

.form-grid input {
  min-width: 0;
  height: 46px;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 0 10px;
  background: #fff;
}

.calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
}

.day-name {
  color: var(--muted);
  text-align: center;
  font-size: 12px;
  font-weight: 800;
}

.day-cell {
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 6px 4px;
}

.day-number {
  font-size: 13px;
  font-weight: 800;
}

.marks {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
  margin-top: 5px;
  font-size: 14px;
}

.gym-list {
  display: grid;
  gap: 8px;
}

.gym-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 12px;
  text-align: left;
}

.settings-textarea {
  width: 100%;
  min-height: 92px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(82px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--primary);
  color: #fff;
  border-radius: 999px;
  padding: 12px 18px;
  font-weight: 800;
  box-shadow: var(--shadow);
}

.support-hero {
  position: relative;
  overflow: hidden;
  min-height: 310px;
  margin: 10px 0;
  padding: 28px 22px 22px;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow);
}

.support-hero.strong { background: var(--primary); }
.support-hero.gentle { background: #315f8a; }

.support-mark {
  color: #ffd47a;
  font-size: 34px;
  line-height: 1;
}

.support-label {
  margin: 18px 0 8px;
  color: #d9ecfb;
  font-size: 14px;
  font-weight: 800;
}

.support-hero h2 {
  max-width: 420px;
  margin: 0;
  font-size: 26px;
  line-height: 1.45;
}

.support-detail {
  margin: 14px 0 24px;
  color: #edf6fd;
  font-size: 15px;
  line-height: 1.7;
}

.support-refresh {
  min-height: 48px;
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-weight: 800;
}

.weekly-win-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
}

.weekly-win-row:first-of-type { border-top: 0; }
.weekly-win-row strong { color: var(--success-ink); }

.journal-shortcut {
  width: 100%;
  min-height: 70px;
  margin: 10px 0;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--gold);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  text-align: left;
  box-shadow: var(--shadow);
}

.journal-shortcut strong,
.journal-shortcut small { display: block; }
.journal-shortcut small { margin-top: 4px; color: var(--muted); }
.journal-shortcut-arrow { color: var(--primary); font-size: 30px; line-height: 1; }

.journal-panel { border-top: 5px solid var(--gold); }
.journal-date-row { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; gap: 8px; text-align: center; }
.journal-date-row .section-title { margin: 0; font-size: 20px; }
.journal-date-row p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.journal-date-button { width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--primary); font-size: 28px; }

.journal-score-field { margin: 20px 0 0; padding: 0; border: 0; }
.journal-score-field legend { margin-bottom: 8px; color: var(--muted); font-size: 14px; font-weight: 800; }
.journal-score-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; }
.journal-score-grid button { min-width: 0; min-height: 58px; padding: 5px 2px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); }
.journal-score-grid button span,
.journal-score-grid button small { display: block; }
.journal-score-grid button span { font-size: 17px; font-weight: 900; }
.journal-score-grid button small { margin-top: 3px; overflow-wrap: anywhere; color: var(--muted); font-size: 10px; line-height: 1.15; }
.journal-score-grid button.active { border-color: var(--primary); background: var(--primary); color: #fff; }
.journal-score-grid button.active small { color: #fff; }

.journal-events-label { display: block; margin: 22px 0 8px; color: var(--muted); font-size: 14px; font-weight: 800; }
.journal-events { width: 100%; min-height: 42vh; resize: vertical; border: 1px solid var(--line); border-radius: 8px; padding: 14px; background: #fff; color: var(--ink); font: inherit; font-size: 16px; line-height: 1.75; }
.journal-events:focus { border-color: var(--primary); outline: 3px solid var(--primary-soft); }
.journal-save-status { min-height: 20px; margin: 8px 0 0; color: var(--muted); font-size: 13px; text-align: right; }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
.body-import-panel { border-top: 5px solid var(--gold); }
.body-image-picker { display: grid; gap: 4px; min-height: 74px; place-content: center; border: 2px dashed var(--primary); border-radius: 8px; background: var(--primary-soft); color: var(--primary); text-align: center; cursor: pointer; }
.body-image-picker span { color: var(--muted); font-size: 13px; }
.body-image-summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 18px 0 10px; }
.body-image-summary button { border: 0; background: transparent; color: var(--primary); font-weight: 800; }
.body-image-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.body-image-preview { min-width: 0; margin: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.body-image-preview img { display: block; width: 100%; aspect-ratio: 9 / 16; object-fit: contain; background: #eef2f5; }
.body-image-preview figcaption { display: flex; align-items: center; justify-content: space-between; gap: 6px; min-height: 42px; padding: 5px 8px; }
.body-image-preview figcaption span { overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.body-image-preview figcaption button { flex: 0 0 32px; width: 32px; height: 32px; border: 0; background: transparent; color: var(--danger); font-size: 24px; }
.body-import-status { margin: 12px 0 0; padding: 10px 12px; border-left: 4px solid var(--gold); background: var(--success-soft); color: var(--ink); font-size: 13px; line-height: 1.6; }
.pilot-status { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; padding: 10px 12px; border-left: 4px solid var(--gold); background: var(--success-soft); }
.pilot-status span { color: var(--muted); font-size: 12px; }
.restore-picker { display: grid; place-items: center; margin-top: 10px; }
.restore-preview { display: grid; gap: 8px; margin-top: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.restore-preview span { color: var(--muted); font-size: 13px; }
.backup-message { min-height: 20px; color: var(--muted); font-size: 13px; }

.more-panel { padding: 0 16px; }
.more-panel .section-title { padding: 16px 0 4px; }
.more-row { width: 100%; min-height: 58px; display: flex; align-items: center; justify-content: space-between; border-top: 1px solid var(--line); background: transparent; color: var(--ink); font-weight: 800; text-align: left; }
.more-row span:last-child { color: var(--primary); font-size: 25px; }

@media (prefers-reduced-motion: reduce) {
  .just-achieved { animation: none; }
}

@media (max-width: 360px) {
  .date-title { font-size: 24px; }
  .snack-types { grid-template-columns: repeat(2, 1fr); }
  .metrics { grid-template-columns: 1fr; }
  .nav { gap: 2px; padding-inline: 6px; }
  .nav button { font-size: 11px; }
}
