:root {
  --primary: #3bbeb9;
  --primary-dark: #14928f;
  --accent: #5bc8c5;
  --bg: #f1f6f6;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --danger: #c62828;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.appbar {
  background: var(--primary);
  color: white;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 2px 4px rgba(0,0,0,.12);
}
.appbar.trainer { background: #455a64; }
.appbar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}
.appbar nav {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}
.appbar nav a {
  color: white;
  text-decoration: none;
  font-size: 14px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255,255,255,.12);
}
.appbar nav a.active {
  background: rgba(255,255,255,.28);
  font-weight: 600;
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}

.card {
  background: var(--card);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.card h2 {
  margin: 0 0 8px;
  font-size: 16px;
}
.hint {
  color: var(--muted);
  font-size: 13px;
  margin: 4px 0 12px;
}

.camera-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--primary);
  color: white;
  padding: 18px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  margin: 8px 0 12px;
}
.camera-button:active { background: var(--primary-dark); }
.camera-icon { font-size: 24px; }

.meal-type {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0;
}
.meal-type label {
  flex: 1 1 calc(50% - 8px);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  text-align: center;
  font-size: 14px;
  background: #fafafa;
  cursor: pointer;
}
.meal-type label:has(input:checked) {
  background: #e3f6f5;
  border-color: var(--primary);
  color: var(--primary-dark);
  font-weight: 600;
}
.meal-type input { display: none; }

textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  margin: 8px 0;
}

button, .secondary, .primary {
  border: none;
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.primary { background: var(--primary); color: white; }
.primary:active { background: var(--primary-dark); }
.primary:disabled { background: #9e9e9e; cursor: not-allowed; }
.secondary { background: #e0e0e0; color: var(--text); }
.secondary:active { background: #bdbdbd; }
.danger { background: #c62828; color: white; }
.danger:active { background: #8e0000; }
.danger:disabled { background: #9e9e9e; cursor: not-allowed; }

.danger-zone {
  margin-top: 16px;
  border-top: 1px dashed var(--border);
  padding-top: 12px;
}
.danger-zone summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: #c62828;
}
.policy-link {
  margin-top: 14px;
  font-size: 12px;
}
.policy-link a { color: var(--primary-dark, #2a8d89); }

.preview {
  margin-top: 12px;
  border-top: 1px dashed var(--border);
  padding-top: 12px;
}
.preview canvas {
  width: 100%;
  height: auto;
  border-radius: 8px;
  display: block;
}
.memo-block {
  margin-top: 12px;
}
.memo-block > label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.memo-input {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.memo-input textarea {
  flex: 1;
  margin: 0;
}
.voice-btn {
  flex: 0 0 auto;
  width: 56px;
  font-size: 24px;
  background: #e3f6f5;
  border: 1px solid var(--primary);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.voice-btn:active { background: #c7eceb; }
.voice-btn.recording {
  background: var(--danger);
  border-color: var(--danger);
  animation: pulse 1s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}
.voice-hint {
  font-size: 12px;
  color: var(--muted);
  margin: 6px 0 0;
  min-height: 14px;
}

.actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.actions button { flex: 1; }

.status {
  font-size: 13px;
  color: var(--muted);
  min-height: 18px;
  margin-top: 8px;
}
.status.error { color: var(--danger); }
.status.success { color: var(--primary-dark); }

.name-field {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}
.name-field input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}
.name-saved {
  font-size: 12px;
  color: var(--primary-dark);
  min-height: 14px;
  margin: 4px 0 8px;
}

.share-box {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.share-box input {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  font-family: monospace;
}

.filter {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.filter input[type="date"] {
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
}
.filter button.active {
  background: var(--primary);
  color: #fff;
}

.meal-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
@media (min-width: 480px) {
  .meal-list { grid-template-columns: repeat(2, 1fr); }
}
.meal-item {
  background: #fafafa;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
/* 写真は切り取らず全体を表示する(本人の一覧・トレーナー共有ビュー共通) */
.meal-item img {
  width: 100%;
  height: auto;
  max-height: 70vh;
  object-fit: contain;
  background: #eee;
}
.meal-meta {
  padding: 10px 12px;
  font-size: 13px;
}
.meal-meta .when {
  font-weight: 600;
  color: var(--primary-dark);
}
.meal-meta .type {
  display: inline-block;
  background: #e3f6f5;
  color: var(--primary-dark);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  margin-left: 6px;
}
.meal-meta .cal {
  margin-top: 4px;
  font-size: 13px;
  font-weight: 600;
  color: #e65100;
}
.meal-meta .cal.analyzing {
  color: var(--muted);
  font-weight: 400;
  font-style: italic;
}
.meal-meta .cal-items {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  font-size: 12px;
  color: var(--muted);
  font-weight: 400;
}
.meal-meta .cal-items li {
  padding: 1px 0;
}
.meal-meta .cal-items .amt {
  color: #9aa0a6;
}
.meal-meta .prot {
  margin-top: 4px;
  font-size: 12.5px;
  font-weight: 600;
  color: #2e7d32;
}
.meal-meta .advice {
  margin-top: 6px;
  padding: 8px 10px;
  background: #e3f6f5;
  border-radius: 8px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--primary-dark);
  word-break: break-word;
}
.meal-meta .memo {
  color: var(--muted);
  margin-top: 4px;
  white-space: pre-wrap;
  word-break: break-word;
}
.meal-item .item-actions {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  padding: 0 6px 6px;
}
.meal-item .item-actions button {
  background: transparent;
  font-size: 12px;
  padding: 6px 10px;
}
.meal-item .edit { color: var(--primary-dark); }
.meal-item .delete { color: var(--danger); }
.meal-item .reanalyze { color: var(--primary-dark); font-weight: 600; }

.meal-meta .cal.failed {
  color: #b26a00;
  font-weight: 600;
}

.meal-meta .cal .edited {
  color: var(--primary-dark);
  font-size: 11px;
  font-weight: 600;
}
.meal-meta .cal .learned {
  color: #2e7d32;
  font-size: 11px;
  font-weight: 600;
}

.edit-form { margin-top: 8px; }
.edit-form label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}
.edit-form input {
  display: block;
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  margin-top: 2px;
}
.edit-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.edit-actions button { flex: 1; padding: 10px; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 24px;
  font-size: 14px;
}
