* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --accent:       #2D6A4F;
  --accent-light: #E8F5EE;
  --accent-dim:   #52976E;
  --bg:           #F5F2ED;
  --surface:      #FEFCF8;
  --text:         #1C1917;
  --text-light:   #78716C;
  --border:       #E8E2D9;
  --radius:       16px;
  --shadow:       0 1px 4px rgba(0,0,0,0.06), 0 4px 16px rgba(0,0,0,0.04);
  --breakfast:    #D97706;
  --lunch:        #2563EB;
  --dinner:       #DC2626;
  --snack:        #7C3AED;
}

body {
  font-family: 'Noto Sans JP', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ヘッダー */
header {
  background: var(--surface);
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

header h1 {
  font-family: 'Shippori Mincho', serif;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

/* タブ */
.tabs {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 57px;
  z-index: 10;
  padding: 0 4px;
}

.tab {
  flex: 1;
  padding: 13px 8px;
  border: none;
  background: none;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-light);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

/* メイン */
main {
  padding: 20px 16px 48px;
}

.view { display: none; }
.view.active { display: block; }

/* 日付ナビ */
.date-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  padding: 0 4px;
}

.date-nav button {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 34px;
  height: 34px;
  font-size: 18px;
  color: var(--text-light);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.date-nav button:active {
  background: var(--accent-light);
  color: var(--accent);
}

.date-nav span {
  font-family: 'Shippori Mincho', serif;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.05em;
}

/* カード */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  animation: slideUp 0.3s ease both;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* 体重 */
.weight-value {
  font-family: 'Shippori Mincho', serif;
  font-size: 42px;
  font-weight: 400;
  color: var(--accent);
  line-height: 1;
}

.weight-value::after {
  content: ' kg';
  font-size: 16px;
  font-family: 'Noto Sans JP', sans-serif;
  font-weight: 500;
  color: var(--accent-dim);
}

.weight-value.empty {
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 15px;
  color: var(--text-light);
  font-weight: 400;
}

.weight-value.empty::after {
  content: '';
}

/* 食事セクション */
.meal-section {
  background: var(--surface);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  animation: slideUp 0.3s ease both;
}

.meal-section:nth-child(1) { animation-delay: 0.05s; }
.meal-section:nth-child(2) { animation-delay: 0.10s; }
.meal-section:nth-child(3) { animation-delay: 0.15s; }
.meal-section:nth-child(4) { animation-delay: 0.20s; }

.meal-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.meal-section-title {
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.meal-section-title::before {
  content: '';
  display: inline-block;
  width: 4px;
  height: 16px;
  border-radius: 2px;
  background: var(--meal-color, var(--accent));
}

.meal-section[data-type="breakfast"] { --meal-color: var(--breakfast); }
.meal-section[data-type="lunch"]     { --meal-color: var(--lunch); }
.meal-section[data-type="dinner"]    { --meal-color: var(--dinner); }
.meal-section[data-type="snack"]     { --meal-color: var(--snack); }

.meal-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  transition: background 0.15s;
}

.meal-item:last-child { border-bottom: none; }
.meal-item:active { background: var(--bg); }

.meal-photo {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
}

.meal-photo-placeholder {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px dashed var(--border);
  flex-shrink: 0;
}

.meal-info { flex: 1; min-width: 0; }

.meal-name {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meal-grams {
  font-size: 12px;
  color: var(--text-light);
  margin-top: 3px;
}

.btn-delete {
  background: none;
  border: none;
  color: var(--border);
  font-size: 16px;
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}

.btn-delete:active {
  color: #DC2626;
  background: #FEF2F2;
}

.meal-empty {
  padding: 20px 16px;
  color: var(--text-light);
  font-size: 13px;
  text-align: center;
}

/* 追加ボタン */
.btn-add {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
  flex-shrink: 0;
}

.btn-add:active {
  background: var(--accent-dim);
  transform: scale(0.92);
}

/* 週ビュー */
.week-day {
  background: var(--surface);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.week-day-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--accent-light);
  border-bottom: 1px solid var(--border);
}

.week-day-label {
  font-family: 'Shippori Mincho', serif;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
}

.week-day-weight {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-dim);
}

.week-meal-row {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.week-meal-row:last-child { border-bottom: none; }

.week-meal-type {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-light);
  margin-bottom: 3px;
}

.week-empty {
  padding: 14px 16px;
  color: var(--text-light);
  font-size: 13px;
}

/* 月ビュー */
.month-week {
  background: var(--surface);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.month-week-label {
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-light);
  background: var(--accent-light);
  border-bottom: 1px solid var(--border);
}

.month-day-row {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  font-size: 13px;
}

.month-day-row:last-child { border-bottom: none; }

.month-day-date {
  width: 30px;
  font-weight: 600;
  color: var(--text-light);
  flex-shrink: 0;
  font-size: 12px;
}

.month-day-weight {
  width: 58px;
  color: var(--accent);
  font-weight: 600;
  flex-shrink: 0;
  font-size: 13px;
}

.month-day-meals {
  flex: 1;
  color: var(--text-light);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* モーダル */
.modal {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  z-index: 100;
  padding: 8px 20px 40px;
  box-shadow: 0 -4px 32px rgba(0,0,0,0.12);
  animation: modalIn 0.3s cubic-bezier(0.32, 0.72, 0, 1) both;
}

@keyframes modalIn {
  from { transform: translateX(-50%) translateY(100%); }
  to   { transform: translateX(-50%) translateY(0); }
}

.modal.hidden { display: none; }

.modal-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 20px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.modal-header h2 {
  font-family: 'Shippori Mincho', serif;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.btn-close {
  background: var(--bg);
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 14px;
  color: var(--text-light);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.btn-close:active { background: var(--border); }

/* オーバーレイ */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 25, 23, 0.5);
  z-index: 99;
  backdrop-filter: blur(2px);
  animation: overlayIn 0.25s ease;
}

@keyframes overlayIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.overlay.hidden { display: none; }

/* フォーム */
.form-group { margin-bottom: 20px; }

.form-group label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-light);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.form-group input[type="text"],
.form-group input[type="number"]:not(.item-grams) {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  font-size: 16px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s, background 0.2s;
}

.form-group input:focus {
  border-color: var(--accent);
  background: var(--surface);
}

.form-group input[type="file"] {
  width: 100%;
  font-size: 14px;
  padding: 10px 0;
  color: var(--text-light);
}

.required { color: #DC2626; }

/* 食事タイプ選択 */
.meal-type-selector {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.type-btn {
  padding: 10px 4px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-light);
  cursor: pointer;
  transition: all 0.15s;
}

.type-btn[data-type="breakfast"].active { background: #FEF3C7; border-color: var(--breakfast); color: var(--breakfast); }
.type-btn[data-type="lunch"].active     { background: #EFF6FF; border-color: var(--lunch);     color: var(--lunch); }
.type-btn[data-type="dinner"].active    { background: #FEF2F2; border-color: var(--dinner);    color: var(--dinner); }
.type-btn[data-type="snack"].active     { background: #F5F3FF; border-color: var(--snack);     color: var(--snack); }

/* 食材行 */
#meal-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.meal-item-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.meal-item-row .item-name {
  flex: 1;
  padding: 12px 12px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  font-size: 15px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
  min-width: 0;
}

.meal-item-row .item-grams {
  width: 56px;
  padding: 12px 8px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  font-size: 15px;
  color: var(--text);
  outline: none;
  text-align: right;
  transition: border-color 0.2s;
  flex-shrink: 0;
}

.meal-item-row input:focus {
  border-color: var(--accent);
  background: var(--surface);
}

.item-grams-label {
  font-size: 13px;
  color: var(--text-light);
  flex-shrink: 0;
}

.btn-remove-item {
  background: none;
  border: none;
  color: var(--text-light);
  font-size: 14px;
  cursor: pointer;
  padding: 6px;
  flex-shrink: 0;
}

#btn-add-item {
  background: none;
  border: 1.5px dashed var(--border);
  border-radius: 10px;
  width: 100%;
  padding: 10px;
  font-size: 13px;
  color: var(--text-light);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}

#btn-add-item:active {
  border-color: var(--accent);
  color: var(--accent);
}

/* 送信ボタン */
.btn-submit {
  width: 100%;
  padding: 16px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
  letter-spacing: 0.04em;
  transition: background 0.15s, transform 0.1s;
}

.btn-submit:active {
  background: var(--accent-dim);
  transform: scale(0.98);
}
