:root {
  --bg: #f5f7f5;
  --card: #ffffff;
  --text: #14231a;
  --muted: #6b7a70;
  --accent: #16a34a;
  --accent-soft: #dcf5e4;
  --border: #e4e9e5;
  --danger: #dc2626;
  --breakfast: #f59e0b;
  --lunch: #16a34a;
  --dinner: #2563eb;
  --snack: #a855f7;
  --radius: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1410;
    --card: #131f18;
    --text: #eaf3ec;
    --muted: #8ea698;
    --accent: #22c55e;
    --accent-soft: #163826;
    --border: #21322a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  height: 100%;
}

body {
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 12px 16px 100px;
}

header.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0 16px;
}

header.topbar .date-nav {
  display: flex;
  align-items: center;
  gap: 10px;
}

header.topbar button.icon-btn {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

header.topbar #dateLabel {
  font-weight: 600;
  font-size: 15px;
  min-width: 96px;
  text-align: center;
}

.summary-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 18px;
}

.ring {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  flex-shrink: 0;
  background: conic-gradient(var(--accent) calc(var(--pct, 0) * 1%), var(--border) 0);
  display: flex;
  align-items: center;
  justify-content: center;
}

.ring::before {
  content: "";
  width: 74px;
  height: 74px;
  border-radius: 50%;
  background: var(--card);
}

.summary-text { flex: 1; }

.summary-text .kcal-total {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.1;
}

.summary-text .kcal-goal {
  color: var(--muted);
  font-size: 14px;
  margin-top: 2px;
}

.summary-text .kcal-remaining {
  margin-top: 8px;
  font-size: 13px;
  font-weight: 600;
}

.summary-text .kcal-remaining.over { color: var(--danger); }
.summary-text .kcal-remaining.under { color: var(--accent); }

.meal-group {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
  overflow: hidden;
}

.meal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
}

.meal-header .meal-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
}

.meal-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.meal-dot.breakfast { background: var(--breakfast); }
.meal-dot.lunch { background: var(--lunch); }
.meal-dot.dinner { background: var(--dinner); }
.meal-dot.snack { background: var(--snack); }

.meal-header .meal-subtotal {
  color: var(--muted);
  font-size: 13px;
  margin-right: 8px;
}

.add-btn {
  background: var(--accent-soft);
  color: var(--accent);
  border: none;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
}

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

.entry-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
}

.entry-list .entry-name { font-size: 14px; }
.entry-list .entry-portion { color: var(--muted); font-size: 12px; }
.entry-list .entry-kcal { font-weight: 600; font-size: 14px; white-space: nowrap; }

.entry-list .entry-del {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 16px;
  padding: 4px;
}

.empty-hint {
  padding: 14px 16px;
  color: var(--muted);
  font-size: 13px;
}

/* Dialog */
dialog {
  border: none;
  border-radius: 20px 20px 0 0;
  padding: 0;
  width: 100%;
  max-width: 480px;
  margin: auto auto 0;
  background: var(--card);
  color: var(--text);
  max-height: 88vh;
}

dialog::backdrop { background: rgba(0,0,0,0.5); }

.dialog-inner {
  padding: 16px 18px calc(20px + env(safe-area-inset-bottom));
  overflow-y: auto;
  max-height: 88vh;
}

.dialog-title {
  font-size: 17px;
  font-weight: 700;
  margin: 4px 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.dialog-title .close-btn {
  background: var(--border);
  border: none;
  color: var(--text);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 14px;
}

.mode-tabs { display: flex; gap: 8px; margin-bottom: 14px; }

.mode-tabs button {
  flex: 1;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}

.mode-tabs button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.field { margin-bottom: 14px; }

.field label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}

textarea, input[type="text"], input[type="number"] {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 12px;
  padding: 12px;
  font-size: 15px;
  font-family: inherit;
  resize: vertical;
}

textarea { min-height: 80px; }

.photo-drop {
  border: 1.5px dashed var(--border);
  border-radius: 14px;
  padding: 18px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
}

.photo-preview {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: 14px;
  margin-bottom: 10px;
  display: none;
}

.btn {
  width: 100%;
  padding: 14px;
  border-radius: 14px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
}

.btn:disabled { opacity: 0.5; }

.btn.secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.clarify-box, .result-box {
  background: var(--accent-soft);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 14px;
}

.clarify-box .q { font-size: 14px; font-weight: 600; margin-bottom: 8px; }

.result-box .items { margin: 8px 0 12px; }

.result-box .items div {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  padding: 4px 0;
}

.result-box .total {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
  font-size: 16px;
  border-top: 1px solid var(--border);
  padding-top: 8px;
  margin-top: 4px;
}

.confidence-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  margin-top: 8px;
}

.confidence-badge.high { background: #dcf5e4; color: #16a34a; }
.confidence-badge.medium { background: #fef3c7; color: #b45309; }
.confidence-badge.low { background: #fee2e2; color: #b91c1c; }

.status-msg {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 10px 0;
}

.error-msg {
  color: var(--danger);
  font-size: 13px;
  padding: 8px 0;
  text-align: center;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

.fab-row { display: flex; gap: 10px; margin-top: 4px; }
