@import url('https://fonts.googleapis.com/css2?family=M+PLUS+Rounded+1c:wght@400;500;700;800&display=swap');

/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green:     #5B9157;
  --green-lt:  #EDF5EC;
  --green-mid: #7AB377;
  --navy:      #2C3A2C;
  --muted:     #7B8C7B;
  --amber:     #E8A020;
  --red:       #D95F5F;
  --bg:        #F4F7F4;
  --card:      #FFFFFF;
  --border:    #E4EBE4;
  --shadow:    rgba(60, 90, 60, 0.10);
  --bnav-h:    64px;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'M PLUS Rounded 1c', -apple-system, BlinkMacSystemFont,
               'Hiragino Maru Gothic Pro', 'Yu Gothic UI', sans-serif;
  color: var(--navy);
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 430px;
  margin: 0 auto;
  height: 100%;
  background: var(--bg);
  position: relative;
  overflow: hidden;
}

/* ===== SCREENS ===== */
.screen {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}
.screen.hidden { display: none; }
.has-bnav { bottom: var(--bnav-h); }

.scroll-area {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ===== HEADER ===== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  height: 52px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.main-header { box-shadow: 0 1px 6px var(--shadow); position: relative; }
.main-header #main-header-date {
  position: absolute; left: 0; right: 0;
  text-align: center; pointer-events: none;
}

.header-logo {
  height: 34px;
  width: auto;
  object-fit: contain;
  flex-shrink: 0;
}

.app-title { font-size: 17px; font-weight: 700; }
.header-date { font-size: 15px; font-weight: 600; color: var(--navy); }
.header-actions { display: flex; align-items: center; gap: 6px; }

.icon-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  border: none; background: none; cursor: pointer;
  border-radius: 50%;
  -webkit-tap-highlight-color: transparent;
  color: var(--navy);
}
.icon-btn.flat { font-size: 20px; color: var(--muted); }

.text-btn {
  font-size: 14px; color: var(--muted);
  background: none; border: none; cursor: pointer;
  padding: 6px 4px; font-family: inherit;
}
.text-btn.muted { color: var(--muted); }

/* ===== PILL TABS ===== */
.pill-tabs {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.pill-tabs::-webkit-scrollbar { display: none; }

.ptab {
  padding: 7px 18px;
  border-radius: 50px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  background: var(--bg);
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, color 0.15s;
}
.ptab.active {
  background: var(--green);
  color: #fff;
}

/* ===== MAIN SCREEN ===== */
#main-content { padding: 16px 14px; }

.slot-heading {
  font-size: 14px;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 14px;
}

/* Meal cards */
.meal-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--card);
  border: 1.5px solid #C8D8C8;
  border-radius: 16px;
  margin-bottom: 10px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s, background 0.15s;
}
.meal-card.selected {
  border-color: var(--green);
  background: var(--green-lt);
}
.avatar-char {
  width: 100%; height: 100%;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 800; color: #fff;
  letter-spacing: 0;
}
.after-food-img .avatar-char { font-size: 52px; }

.meal-food-img {
  width: 52px; height: 52px;
  border-radius: 50%;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  font-size: 26px;
  flex-shrink: 0;
  border: 1.5px solid var(--border);
}
.meal-card.selected .meal-food-img { background: #fff; border-color: var(--green-lt); }
.meal-name { flex: 1; font-size: 15px; font-weight: 600; color: var(--navy); }
.meal-radio {
  width: 24px; height: 24px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
  color: transparent;
  transition: all 0.15s;
}
.meal-card.selected .meal-radio {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}

/* RANDOM button */
.btn-random {
  width: 100%;
  padding: 15px;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 50px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 6px;
  box-shadow: 0 4px 14px rgba(91,145,87,0.32);
  font-family: inherit;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  -webkit-tap-highlight-color: transparent;
}
.btn-random:active { opacity: 0.85; }
.btn-random svg { width: 18px; height: 18px; fill: #fff; }

.btn-noteat {
  width: 100%;
  padding: 13px;
  background: var(--card);
  color: var(--muted);
  border: 1.5px solid var(--border);
  border-radius: 50px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 10px;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}
.btn-noteat:active { background: var(--bg); }

.btn-other {
  display: block;
  width: 100%;
  padding: 10px;
  background: none;
  border: none;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  margin-top: 6px;
  font-family: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  -webkit-tap-highlight-color: transparent;
}
.btn-other:active { opacity: 0.6; }

.empty-state {
  text-align: center;
  padding: 56px 24px;
  color: var(--muted);
}
.empty-state .ei { font-size: 52px; margin-bottom: 18px; display: block; }
.empty-state p { font-size: 14px; line-height: 1.8; margin-bottom: 24px; }

/* ===== AFTER SCREEN ===== */
.after-content { padding: 0 0 40px; }

.after-heading {
  text-align: center;
  font-size: 20px;
  font-weight: 800;
  color: var(--navy);
  padding: 20px 16px 0;
}

.after-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 16px 24px;
}
.sparkle {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 14px;
  letter-spacing: 0.5px;
}
.after-food-img {
  width: 120px; height: 120px;
  border-radius: 50%;
  background: var(--green-lt);
  display: flex; align-items: center; justify-content: center;
  font-size: 56px;
  margin-bottom: 14px;
  box-shadow: 0 4px 20px rgba(91,145,87,0.18);
}
.after-meal-name {
  font-size: 20px;
  font-weight: 800;
  color: var(--navy);
}

.after-form {
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.3px;
}

/* Stars */
.stars-row {
  display: flex;
  gap: 6px;
  padding: 4px 0;
}
.star-i {
  font-size: 38px;
  cursor: pointer;
  color: #ddd;
  transition: color 0.1s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.star-i:active { transform: scale(1.2); }
.star-i.c-green  { color: #4CAF50; }
.star-i.c-yellow { color: var(--amber); }
.star-i.c-red    { color: var(--red); }

/* Memo */
.memo-wrap { position: relative; }
.memo-textarea {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px 28px 14px;
  font-size: 14px;
  font-family: inherit;
  color: var(--navy);
  resize: none;
  height: 90px;
  background: var(--card);
  outline: none;
  transition: border-color 0.15s;
}
.memo-textarea:focus { border-color: var(--green); }
.memo-textarea::placeholder { color: #c0c8c0; }
.memo-count {
  position: absolute;
  bottom: 8px; right: 12px;
  font-size: 11px;
  color: #bbb;
}

.btn-primary {
  width: 100%;
  padding: 15px;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 50px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 4px 14px rgba(91,145,87,0.28);
  margin-top: 8px;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary:active { opacity: 0.85; }

.btn-redo {
  width: 100%;
  padding: 12px;
  background: transparent;
  color: var(--muted);
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.btn-ghost {
  width: 100%;
  padding: 12px;
  background: transparent;
  color: #bbb;
  border: none;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
  margin-top: 4px;
}

/* ===== REGISTER SCREEN ===== */
.slot-label-row {
  padding: 10px 14px 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  background: var(--card);
  letter-spacing: 0.3px;
}
.list-section-label {
  padding: 10px 14px 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  background: var(--bg);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  letter-spacing: 0.3px;
}

.cand-list { background: var(--card); }
.cand-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px;
  border-bottom: 1px solid #f0f4f0;
  background: var(--card);
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}
.cand-row:active { background: var(--green-lt); }
.drag-handle { font-size: 16px; color: #ccc; letter-spacing: -2px; flex-shrink: 0; cursor: grab; }
.cand-name { flex: 1; font-size: 15px; color: var(--navy); }
.cand-prio {
  font-size: 14px;
  flex-shrink: 0;
}
.cand-del {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: none;
  background: #f0f0f0;
  color: #aaa;
  font-size: 16px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.cand-del:active { background: #fde8e8; color: var(--red); }
.cand-row.fixed .cand-del { opacity: 0; pointer-events: none; }

.btn-add-cand {
  width: calc(100% - 28px);
  margin: 14px;
  padding: 14px;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 50px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 4px 12px rgba(91,145,87,0.28);
  -webkit-tap-highlight-color: transparent;
}
.btn-add-cand:disabled { background: #ccc; box-shadow: none; cursor: not-allowed; }
.add-hint {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  padding: 0 14px 20px;
}
.limit-msg {
  padding: 8px 14px;
  font-size: 12px;
  color: #92400e;
  background: #fffbe6;
  border-bottom: 1px solid #fde68a;
}

/* ===== HISTORY SCREEN ===== */
.hist-month-header {
  padding: 12px 14px 8px;
  font-size: 14px;
  font-weight: 700;
  color: var(--navy);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  letter-spacing: 0.3px;
}

.hist-date-block {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  background: var(--card);
  border-bottom: 1px solid #f0f4f0;
}
.hist-date-left {
  flex-shrink: 0;
  width: 36px;
  text-align: center;
}
.hist-date-num {
  font-size: 26px;
  font-weight: 800;
  line-height: 1.1;
  color: var(--navy);
}
.hist-date-dow {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}
.hist-date-meals { flex: 1; min-width: 0; }

.hist-entry { padding: 5px 0; border-bottom: 1px solid #f5f8f5; }
.hist-entry:last-child { border-bottom: none; }
.hist-entry-row { display: flex; align-items: center; gap: 6px; }
.hist-slot {
  font-size: 11px;
  font-weight: 700;
  color: var(--green);
  background: var(--green-lt);
  padding: 2px 7px;
  border-radius: 20px;
  white-space: nowrap;
  flex-shrink: 0;
}
.hist-meal {
  font-size: 14px;
  font-weight: 600;
  color: var(--navy);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hist-stars { font-size: 13px; flex-shrink: 0; }
.hist-stars.sg { color: #4CAF50; }
.hist-stars.sy { color: var(--amber); }
.hist-stars.sr { color: var(--red); }
.no-rating { font-size: 12px; color: #ddd; }
.hist-memo { font-size: 12px; color: #aaa; margin-top: 3px; padding-left: 2px; }

.history-empty {
  text-align: center;
  padding: 72px 24px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.8;
}
.history-footer { text-align: center; padding: 18px; font-size: 11px; color: #ccc; }

/* ===== SETTINGS SCREEN ===== */
.settings-section { padding: 16px 14px; background: var(--card); }
.settings-section-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 4px;
}
.settings-section-desc {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 14px;
}
.settings-divider { height: 8px; background: var(--bg); }

.settings-footer {
  padding: 32px 0 52px;
  display: flex;
  justify-content: center;
}
.settings-footer-logo {
  height: 32px;
  width: auto;
  object-fit: contain;
}

.about-section { padding-bottom: 24px; }
.about-text {
  font-size: 13px; line-height: 1.8;
  color: var(--navy); margin: 0 0 12px;
}
.about-text em {
  font-style: normal; font-weight: 700; color: var(--green);
}
.about-ref {
  font-size: 11px; color: var(--muted);
  line-height: 1.7; margin: 0; padding-top: 4px;
  border-top: 1px solid var(--border);
}

.bmc-section {
  text-align: center;
  padding: 20px 24px 24px;
}
.bmc-text {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.7;
  margin: 0 0 16px;
}
.btn-bmc {
  display: inline-block;
  background: #FFDD00;
  color: #000000;
  font-size: 15px;
  font-weight: 700;
  text-decoration: none;
  padding: 12px 28px;
  border-radius: 40px;
  transition: opacity 0.15s, transform 0.1s;
}
.btn-bmc:active { opacity: 0.85; transform: scale(0.97); }

.settings-links {
  display: flex;
  justify-content: center;
  gap: 24px;
  padding: 20px 24px;
}
.settings-link {
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
  padding-bottom: 1px;
  transition: color 0.15s;
}
.settings-link:hover { color: var(--green); }

.prio-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  background: var(--bg);
  border-radius: 12px;
  margin-bottom: 8px;
}
.prio-icon { font-size: 22px; flex-shrink: 0; }
.prio-text { flex: 1; }
.prio-label { font-size: 14px; font-weight: 700; color: var(--navy); }
.prio-desc { font-size: 12px; color: var(--muted); margin-top: 2px; }
.drag-handle { font-size: 18px; color: #ccc; letter-spacing: -2px; cursor: grab; flex-shrink: 0; }

.count-stepper-wrap {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 4px 0 8px;
}
.stepper-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1.5px solid var(--green);
  background: var(--card);
  color: var(--green);
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.stepper-btn:disabled { border-color: #ccc; color: #ccc; cursor: not-allowed; }
.stepper-label {
  font-size: 20px;
  font-weight: 800;
  color: var(--navy);
  min-width: 50px;
  text-align: center;
}
.stepper-hint { font-size: 12px; color: var(--muted); }

.other-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.other-label { font-size: 15px; color: var(--navy); }
.toggle-switch {
  width: 48px; height: 28px;
  background: #ddd;
  border-radius: 14px;
  position: relative;
  transition: background 0.25s;
  flex-shrink: 0;
}
.toggle-switch.on { background: var(--green); }
.toggle-thumb {
  position: absolute;
  top: 2px; left: 2px;
  width: 24px; height: 24px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
  transition: transform 0.25s;
}
.toggle-switch.on .toggle-thumb { transform: translateX(20px); }

/* ===== ONBOARDING ===== */
.onboard-slide {
  display: flex; flex-direction: column;
  height: 100%; background: var(--card);
}
.onboard-slide.hidden { display: none; }
.onboard-body {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 48px 32px 0; text-align: center;
}
.onboard-emoji { font-size: 88px; margin-bottom: 32px; }
.onboard-body h2 { font-size: 24px; font-weight: 800; line-height: 1.35; margin-bottom: 14px; color: var(--navy); }
.onboard-body p { font-size: 15px; color: var(--muted); line-height: 1.9; }
.onboard-footer { padding: 32px 28px 48px; display: flex; flex-direction: column; }
.dots { display: flex; justify-content: center; gap: 6px; margin-bottom: 24px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #ddd; transition: all 0.2s; }
.dot.active { width: 22px; border-radius: 4px; background: var(--green); }

/* ===== FREQ BARS (priority indicator) ===== */
.freq-bars {
  display: flex;
  gap: 2.5px;
  align-items: flex-end;
  height: 22px;
  flex-shrink: 0;
}
.freq-bars.sm { height: 16px; gap: 2px; }

.fb {
  width: 7px;
  border-radius: 3px;
  background: #ddd;
}
.fb.b1 { height: 35%; }
.fb.b2 { height: 65%; }
.fb.b3 { height: 100%; }
.freq-bars.sm .fb { width: 5px; }

/* high: all green */
.freq-bars.high .fb { background: var(--green); }
/* mid: b1+b2 amber, b3 gray */
.freq-bars.mid .fb.b1,
.freq-bars.mid .fb.b2 { background: var(--amber); }
.freq-bars.mid .fb.b3 { background: #ddd; }
/* low: coral/red */
.freq-bars.low .fb.b1 { background: #C87070; }
.freq-bars.low .fb.b2,
.freq-bars.low .fb.b3 { background: #ddd; }

/* ===== BOTTOM NAV ===== */
.bottom-nav {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: var(--bnav-h);
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  box-shadow: 0 -2px 12px rgba(0,0,0,0.07);
  z-index: 200;
}
.bottom-nav.hidden { display: none; }

.bnav {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 3px;
  border: none;
  border-right: 1px solid var(--border);
  background: none;
  font-size: 10px; font-weight: 600;
  color: #bbb;
  cursor: pointer;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s;
}
.bnav:last-child { border-right: none; }
.bnav.active { color: var(--green); }
.bi {
  width: 22px; height: 22px;
  fill: currentColor;
  display: block;
}

/* ===== DATE NAV ===== */
.date-nav {
  display: flex; align-items: center; gap: 4px;
}
.nav-arrow {
  width: 32px; height: 32px;
  border: none; background: none;
  font-size: 20px; color: var(--muted);
  cursor: pointer; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.nav-arrow:disabled { color: #ddd; cursor: default; }
.nav-arrow:not(:disabled):hover { background: var(--green-lt); color: var(--green); }
.nav-date { font-size: 14px; font-weight: 700; color: var(--navy); min-width: 110px; text-align: center; }

/* single day history items */
.hist-day-item {
  padding: 14px 16px;
  background: var(--card);
  border-bottom: 1px solid #f0f4f0;
}

/* ===== MODAL ===== */
.modal {
  position: absolute; inset: 0;
  z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.45); }
.modal-box {
  position: relative;
  background: var(--card);
  width: 100%;
  border-radius: 20px;
  padding: 24px 20px 28px;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.18);
}
.modal-box h3 { font-size: 17px; font-weight: 700; color: var(--navy); }
.modal-input {
  width: 100%;
  padding: 14px 16px;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  font-size: 16px; font-family: inherit;
  color: var(--navy); background: var(--bg);
  outline: none; transition: border-color 0.15s;
}
.modal-input:focus { border-color: var(--green); background: var(--card); }

.prio-sel-modal { display: flex; gap: 8px; }
.prio-btn {
  flex: 1; padding: 10px 4px 8px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  font-size: 12px; font-weight: 700;
  color: var(--muted);
  cursor: pointer; font-family: inherit;
  text-align: center;
  display: flex; flex-direction: column;
  align-items: center; gap: 6px;
  transition: all 0.15s;
}
.prio-btn .freq-bars { margin: 0 auto; }
.prio-btn.active { border-color: var(--green); background: var(--green-lt); color: var(--green); }

.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

.btn-primary-sm {
  padding: 10px 22px;
  background: var(--green); color: #fff;
  border: none; border-radius: 50px;
  font-size: 14px; font-weight: 700;
  cursor: pointer; font-family: inherit;
}
.btn-ghost-sm {
  padding: 10px 16px;
  background: transparent; color: var(--muted);
  border: 1.5px solid var(--border);
  border-radius: 50px;
  font-size: 14px; cursor: pointer; font-family: inherit;
}
