:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --text: #1f1f1d;
  --muted: #6c6a64;
  --line: #e3e0d8;
  --accent: #2d6a4f;
  --accent-text: #ffffff;
  --accent-soft: #e2efe7;
  --warn-bg: #fff3d6;
  --warn-text: #6e4a00;
  --danger: #b42318;
  --chip: #efede7;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .05);
  --breakfast: #d08a1c;
  --lunch: #3b78b8;
  --dinner: #7651ab;
  --snack: #c4527a;
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161715;
    --surface: #212220;
    --surface-2: #1b1c1a;
    --text: #ecebe6;
    --muted: #a3a19a;
    --line: #34352f;
    --accent: #6fbf93;
    --accent-text: #0f1a14;
    --accent-soft: #1f3a2b;
    --warn-bg: #3a2f14;
    --warn-text: #f3d48a;
    --danger: #ff8a7a;
    --chip: #2c2d29;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --breakfast: #e6a440;
    --lunch: #6ea6e0;
    --dinner: #a88ad8;
    --snack: #e37fa2;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 16px 120px;
}

h1, h2 { margin: 0; line-height: 1.3; }
h1 { font-size: 20px; }
h2 { font-size: 17px; }
p { margin: 0; }
a { color: var(--accent); }
button { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }

/* ---- top bar ---- */
.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 -16px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.bar h1 { flex: 1; text-align: center; font-size: 18px; }
.bar .list-title { text-align: left; }
.nav {
  min-width: 44px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
  font-size: 22px;
}
.nav:hover { background: var(--chip); }
.nav.text { font-size: 14px; padding: 0 8px; }

/* ---- buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 34px; padding: 0 10px; font-size: 14px; }
.btn.wide { width: 100%; min-height: 50px; font-size: 17px; }
.btn:disabled { opacity: .45; cursor: default; filter: none; }
.link {
  border: 0;
  background: none;
  padding: 6px 0;
  color: var(--accent);
  cursor: pointer;
  font-size: 14px;
}
.link.armed { color: var(--danger); font-weight: 600; }
.link:disabled { color: var(--muted); }

/* ---- day list ---- */
.days { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 8px; }
.day-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  padding: 12px 14px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: var(--text);
  text-decoration: none;
}
.day-date { font-weight: 600; }
.day-kcal { text-align: right; font-variant-numeric: tabular-nums; }
.day-sub { color: var(--muted); font-size: 13px; }
.badges { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--chip);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.badge.ok { background: var(--accent-soft); color: var(--accent); }
.badge.todo { background: var(--warn-bg); color: var(--warn-text); }
.badge.bad { background: var(--danger); color: #fff; }
.empty { margin-top: 32px; text-align: center; color: var(--muted); }

/* ---- day summary ---- */
.summary {
  margin-top: 14px;
  padding: 16px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 4px 12px;
}
.total { font-size: 15px; color: var(--muted); }
.total-kcal { font-size: 32px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.pfc { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.status { grid-row: 1; grid-column: 2; align-self: start; }

.notice {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--warn-bg);
  color: var(--warn-text);
  font-size: 14px;
}
.notice.info { background: var(--chip); color: var(--muted); }

/* ---- panels ---- */
.panel {
  margin-top: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 14px;
}
.panel.quiet { background: transparent; box-shadow: none; border: 1px dashed var(--line); color: var(--muted); }
.panel h2 { font-size: 15px; margin-bottom: 6px; }
.panel .ok { color: var(--accent); }
.mini {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--chip);
  cursor: zoom-in;
}

/* ---- slots ---- */
.hint { color: var(--muted); font-size: 13px; margin-top: 16px; }
.slot {
  margin-top: 16px;
  padding: 10px;
  border-radius: calc(var(--radius) + 4px);
  border: 2px solid transparent;
  transition: background .12s, border-color .12s;
}
.slot.drop { border-color: var(--accent); background: var(--accent-soft); }
.slot-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 0 4px 8px;
}
.slot-head h2::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 8px;
  border-radius: 3px;
  background: var(--slot-color, var(--muted));
}
.slot-breakfast { --slot-color: var(--breakfast); }
.slot-lunch { --slot-color: var(--lunch); }
.slot-dinner { --slot-color: var(--dinner); }
.slot-snack { --slot-color: var(--snack); }
.slot-total { margin-left: auto; font-weight: 600; font-variant-numeric: tabular-nums; }
.slot-head .pfc { white-space: nowrap; }
.unassigned { border: 2px dashed var(--line); }
.drop-hint {
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

/* ---- photo card ---- */
.card {
  margin-top: 8px;
  padding: 10px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border-left: 4px solid var(--slot-color, var(--line));
}
.card.dragging { opacity: .35; }
.card.ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 100;
  margin: 0;
  pointer-events: none;
  opacity: .95;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
}
.card-head { display: flex; gap: 10px; align-items: flex-start; }
.handle {
  flex: none;
  width: 32px;
  align-self: stretch;
  min-height: 72px;
  border: 0;
  border-radius: 8px;
  background: var(--chip);
  color: var(--muted);
  font-size: 18px;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.handle:active { cursor: grabbing; }
.thumb-btn { flex: none; padding: 0; border: 0; background: none; cursor: zoom-in; }
.thumb {
  width: 88px;
  height: 88px;
  object-fit: cover;
  border-radius: 10px;
  background: var(--chip);
}
.meta { flex: 1; min-width: 0; }
.time { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.kcal { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.chips { display: flex; gap: 6px; margin-top: 8px; }
.chip {
  flex: 1;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}
.chip.on { background: var(--slot-color); border-color: var(--slot-color); color: #fff; font-weight: 600; }
.chip[data-slot="breakfast"] { --slot-color: var(--breakfast); }
.chip[data-slot="lunch"] { --slot-color: var(--lunch); }
.chip[data-slot="dinner"] { --slot-color: var(--dinner); }
.chip[data-slot="snack"] { --slot-color: var(--snack); }

.items { list-style: none; margin: 8px 0 0; padding: 0; }
.item { display: flex; align-items: flex-start; gap: 8px; border-top: 1px solid var(--line); }
.item-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 8px;
  padding: 8px 0;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}
.item-main:disabled { cursor: default; }
.item-portion, .item-note { color: var(--muted); font-size: 13px; }
.item-note { flex-basis: 100%; }
.item-kcal { padding-top: 8px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.item.excluded .item-name, .item.excluded .item-kcal { text-decoration: line-through; color: var(--muted); }
.notes { margin-top: 6px; color: var(--muted); font-size: 13px; }
.memo {
  margin-top: 8px;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--warn-bg);
  color: var(--text);
  font-size: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.memo-label { margin-right: 8px; color: var(--warn-text); font-size: 12px; font-weight: 600; }
.memo-form { margin-top: 8px; display: grid; gap: 6px; }
.memo-form .hint, .phone .hint { margin: 0; }
textarea {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  resize: vertical;
}
.item { flex-wrap: wrap; }
.item-sources { flex-basis: 100%; padding-bottom: 6px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }

/* ---- photos still on the phone (inside the app) ---- */
.phone { display: grid; gap: 10px; }
.phone-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.phone-head h2 { margin: 0; }
.phone-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.phone-photo { display: grid; gap: 4px; align-content: start; }
.phone-photo img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 8px; background: var(--chip); }
.phone-photo .memo { margin-top: 0; }
.phone-time { color: var(--muted); font-size: 12px; }
.card-actions { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 4px; }

.item-form { flex: 1; padding: 10px 0; display: grid; gap: 8px; }
.item-form label { display: grid; gap: 2px; font-size: 12px; color: var(--muted); }
.item-form input {
  width: 100%;
  min-height: 38px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 16px;
}
.num-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---- other photos ---- */
.others { margin-top: 20px; }
.others summary { cursor: pointer; color: var(--muted); padding: 8px 0; }
.other-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-top: 8px; }
.other {
  padding: 8px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 13px;
}
.other .mini { width: 100%; height: 110px; }
.other p { margin-top: 4px; color: var(--muted); overflow-wrap: anywhere; }

/* ---- bottom action bar ---- */
.actionbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
}
.actionbar > div { max-width: 608px; margin: 0 auto; display: grid; gap: 6px; }
.actionbar .hint { margin: 0; text-align: center; }

/* ---- misc ---- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .88);
  cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  z-index: 300;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
#toast.show { opacity: 1; }

.login { margin-top: 48px; display: grid; gap: 14px; }
.login p { color: var(--muted); font-size: 14px; }
.login form { display: grid; gap: 10px; }
.login input {
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
}
.error { margin-top: 32px; display: grid; gap: 12px; justify-items: start; }
.phone .link { justify-self: start; }

/* ---- photos of the same thing ---- */
.thumb-btn { position: relative; }
.thumb-count {
  position: absolute;
  right: 4px;
  bottom: 4px;
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .65);
  color: #fff;
  font-size: 12px;
}
.members { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.member { position: relative; display: grid; justify-items: center; gap: 2px; }
.member .mini { width: 64px; height: 64px; }
.member-time { color: var(--muted); font-size: 11px; }
.member .remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 50%;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  line-height: 24px;
  cursor: pointer;
}
.selectbar {
  position: sticky;
  top: 61px;
  z-index: 9;
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--warn-bg);
  color: var(--warn-text);
  display: grid;
  gap: 8px;
  box-shadow: var(--shadow);
}
.card.selectable, .other.selectable { cursor: pointer; }
.card.selectable:hover, .other.selectable:hover { outline: 2px dashed var(--accent); }
.card.picked, .other.picked { outline: 3px solid var(--accent); }
.card.source { outline: 3px solid var(--warn-text); }
