:root {
  --blue-50: #eef6ff;
  --blue-100: #d9ebff;
  --blue-200: #b5d8ff;
  --blue-400: #5aa8ff;
  --blue-500: #2b7de9;
  --blue-600: #1f63c9;
  --blue-800: #123a7a;
  --ink: #12305e;
  --muted: #6b84a8;
  --card: rgba(255, 255, 255, 0.78);
  --border: rgba(255, 255, 255, 0.9);
  --shadow: 0 10px 30px -12px rgba(31, 99, 201, 0.35);
  --radius: 24px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { min-height: 100%; }
body {
  font-family: "Prompt", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, #e6f3ff 0%, #cfe6ff 45%, #b9dbff 100%);
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
[hidden] { display: none !important; }

/* floating blobs */
.bg-blobs span {
  position: fixed; border-radius: 50%; filter: blur(60px); opacity: .55; z-index: -1;
  animation: float 18s ease-in-out infinite;
}
.bg-blobs span:nth-child(1) { width: 320px; height: 320px; background: #8fd0ff; top: -80px; left: -60px; }
.bg-blobs span:nth-child(2) { width: 260px; height: 260px; background: #6aa8ff; bottom: 10%; right: -80px; animation-delay: -6s; }
.bg-blobs span:nth-child(3) { width: 200px; height: 200px; background: #c4ecff; top: 40%; left: 30%; animation-delay: -12s; }
@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(30px, -40px) scale(1.1); }
}

.app { max-width: 480px; margin: 0 auto; padding: 18px 16px 0; }

/* top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 6px 4px 16px; }
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 46px; height: 46px; border-radius: 16px; display: grid; place-items: center; font-size: 24px;
  background: linear-gradient(135deg, #7fd3ff, #2b6fe0); box-shadow: var(--shadow);
}
.brand h1 { font-size: 22px; font-weight: 700; letter-spacing: -.3px; }
.sub { font-size: 13px; color: var(--muted); margin-top: -2px; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center;
  background: var(--card); border: 1px solid var(--border); color: var(--blue-600);
  box-shadow: var(--shadow); backdrop-filter: blur(12px); transition: transform .2s;
}
.icon-btn:active { transform: scale(.92) rotate(30deg); }

/* card */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  padding: 18px;
}
.summary { padding-top: 14px; }

.date-nav { display: flex; align-items: center; justify-content: space-between; }
.chev {
  width: 38px; height: 38px; border-radius: 12px; font-size: 24px; line-height: 1;
  background: var(--blue-50); color: var(--blue-600); transition: background .2s, opacity .2s;
}
.chev:hover { background: var(--blue-100); }
.chev:disabled { opacity: .3; cursor: default; }
.date-label { text-align: center; display: flex; flex-direction: column; }
.date-label strong { font-size: 17px; }
.date-label span { font-size: 12px; color: var(--muted); }

/* ring */
.ring-wrap { position: relative; width: 210px; height: 210px; margin: 10px auto 8px; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 16; stroke-linecap: round; }
.ring-bg { stroke: var(--blue-100); }
.ring-fg {
  stroke: url(#ringGrad); stroke-dasharray: 527.79; stroke-dashoffset: 527.79;
  transition: stroke-dashoffset 1s cubic-bezier(.2,.8,.2,1), stroke .3s;
  filter: drop-shadow(0 4px 8px rgba(43,111,224,.35));
}
.ring-fg.over { stroke: #ff8a8a; }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.kcal { font-size: 44px; font-weight: 700; line-height: 1; color: var(--blue-800); }
.kcal-unit { font-size: 13px; color: var(--muted); margin-top: 4px; }
.kcal-left {
  margin-top: 10px; font-size: 12px; font-weight: 500; padding: 4px 12px; border-radius: 99px;
  background: var(--blue-50); color: var(--blue-600);
}
.kcal-left.over { background: #ffecec; color: #d64545; }

/* macros */
.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 8px; }
.macro { background: var(--blue-50); border-radius: 16px; padding: 10px; }
.macro-top { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); }
.macro-top b { font-size: 15px; color: var(--ink); margin-top: 2px; }
.bar { height: 6px; border-radius: 99px; background: #fff; margin-top: 8px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; border-radius: inherit; transition: width .8s ease; }
.bar .p { background: linear-gradient(90deg, #7fb6ff, #2b6fe0); }
.bar .c { background: linear-gradient(90deg, #8ee6ff, #26a8e0); }
.bar .f { background: linear-gradient(90deg, #b9c8ff, #5f7cf0); }

/* sections */
.section { margin-top: 22px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; padding: 0 4px; }
.chart-card .section-head { padding: 0; }
.section-head h2 { font-size: 18px; font-weight: 600; }
.pill { font-size: 12px; padding: 4px 10px; border-radius: 99px; background: var(--blue-500); color: #fff; }
.pill.soft { background: var(--blue-50); color: var(--blue-600); }

/* meals */
.meal-list { display: flex; flex-direction: column; gap: 10px; }
.meal {
  display: flex; gap: 12px; align-items: center; padding: 10px; border-radius: 20px;
  background: var(--card); border: 1px solid var(--border); box-shadow: var(--shadow);
  backdrop-filter: blur(12px); animation: pop .35s ease both;
}
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.meal-thumb {
  width: 64px; height: 64px; border-radius: 16px; object-fit: cover; flex-shrink: 0;
  background: linear-gradient(135deg, var(--blue-100), var(--blue-200)); display: grid; place-items: center; font-size: 28px;
}
.meal-body { flex: 1; min-width: 0; }
.meal-type { font-size: 12px; color: var(--muted); }
.meal-names { font-weight: 500; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meal-kcal { font-size: 13px; color: var(--blue-600); font-weight: 600; }
.meal-del {
  width: 34px; height: 34px; border-radius: 12px; color: #a3b5cf; font-size: 18px; transition: all .2s;
}
.meal-del:hover { background: #ffecec; color: #d64545; }

.empty {
  text-align: center; padding: 28px 16px; border-radius: 20px; color: var(--muted);
  border: 2px dashed var(--blue-200); background: rgba(255,255,255,.4);
}
.empty .emo { font-size: 40px; display: block; margin-bottom: 6px; }

/* chart */
.chart-card { margin-top: 22px; }
.week-chart { position: relative; display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; height: 150px; padding-top: 10px; }
.wbar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; cursor: pointer; }
.wbar .col {
  width: 100%; max-width: 30px; border-radius: 10px 10px 6px 6px; min-height: 4px;
  background: linear-gradient(180deg, #7fd3ff, #2b6fe0); transition: height .8s cubic-bezier(.2,.8,.2,1);
}
.wbar .col.over { background: linear-gradient(180deg, #ffb3b3, #ff7a7a); }
.wbar .col.zero { background: var(--blue-100); }
.wbar.active .col { box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--blue-400); }
.wbar small { font-size: 11px; color: var(--muted); }
.wbar.active small { color: var(--blue-600); font-weight: 600; }
.goal-line {
  position: absolute; left: 0; right: 0; border-top: 2px dashed var(--blue-400); opacity: .6; pointer-events: none;
}
.goal-line span { position: absolute; right: 0; top: -18px; font-size: 10px; color: var(--blue-600); }

.spacer { height: 120px; }

/* FAB */
.fab {
  position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: 72px; height: 72px; border-radius: 50%; display: grid; place-items: center; color: #fff; cursor: pointer;
  background: linear-gradient(135deg, #6cc6ff, #1f63c9);
  box-shadow: 0 14px 30px -8px rgba(31, 99, 201, .7), inset 0 2px 0 rgba(255,255,255,.35);
  transition: transform .2s; z-index: 10;
}
.fab::before {
  content: ""; position: absolute; inset: -6px; border-radius: 50%; border: 2px solid rgba(43,125,233,.35);
  animation: pulse 2.4s ease-out infinite;
}
@keyframes pulse { 0% { transform: scale(.9); opacity: 1; } 100% { transform: scale(1.35); opacity: 0; } }
.fab:hover { transform: translateX(-50%) scale(1.06); }
.fab:active { transform: translateX(-50%) scale(.94); }

/* sheets */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(18, 48, 94, .35); backdrop-filter: blur(4px);
  display: flex; align-items: flex-end; justify-content: center; z-index: 50; animation: fade .2s ease;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: 100%; max-width: 480px; max-height: 92vh; overflow-y: auto; background: #fff;
  border-radius: 28px 28px 0 0; padding: 10px 18px calc(22px + env(safe-area-inset-bottom));
  animation: up .3s cubic-bezier(.2,.8,.2,1);
}
@keyframes up { from { transform: translateY(100%); } }
.sheet-handle { width: 44px; height: 5px; border-radius: 99px; background: var(--blue-100); margin: 4px auto 14px; }
.sheet-title { font-size: 20px; margin-bottom: 14px; }

.preview-wrap { position: relative; border-radius: 22px; overflow: hidden; background: var(--blue-50); aspect-ratio: 4/3; }
.preview-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.chip-btn {
  padding: 6px 12px; border-radius: 99px; font-size: 13px; font-weight: 500;
  background: var(--blue-50); color: var(--blue-600); transition: background .2s;
}
.chip-btn:hover { background: var(--blue-100); }
.chip-btn.change { position: absolute; right: 10px; bottom: 10px; background: rgba(255,255,255,.9); backdrop-filter: blur(6px); }
.chip-btn.add { margin-top: 8px; }

.scan { position: absolute; inset: 0; background: rgba(43,125,233,.12); }
.scan-line {
  position: absolute; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, transparent, #7fd3ff, #fff, #7fd3ff, transparent);
  box-shadow: 0 0 18px 4px rgba(127,211,255,.8); animation: scan 1.6s ease-in-out infinite;
}
@keyframes scan { 0% { top: 0; } 50% { top: calc(100% - 3px); } 100% { top: 0; } }

.state { margin-top: 16px; display: flex; flex-direction: column; gap: 10px; }
.state.center { align-items: center; padding: 10px 0; }
.row { display: flex; gap: 10px; margin-top: 8px; }
.row .btn { flex: 1; }

.btn {
  padding: 13px 18px; border-radius: 16px; font-weight: 600; font-size: 15px; transition: transform .15s, box-shadow .2s, background .2s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(135deg, #4fb2ff, #1f63c9); color: #fff; box-shadow: 0 8px 20px -8px rgba(31,99,201,.8); }
.btn.primary:disabled { opacity: .6; }
.btn.big { padding: 16px; font-size: 16px; }
.btn.ghost { background: var(--blue-50); color: var(--blue-600); }
.btn.danger { color: #d64545; background: #fff1f1; }

.dots { display: flex; gap: 8px; }
.dots span { width: 12px; height: 12px; border-radius: 50%; background: var(--blue-400); animation: bounce 1s infinite ease-in-out; }
.dots span:nth-child(2) { animation-delay: .15s; background: var(--blue-500); }
.dots span:nth-child(3) { animation-delay: .3s; background: var(--blue-600); }
@keyframes bounce { 0%, 100% { transform: translateY(0); opacity: .6; } 50% { transform: translateY(-10px); opacity: 1; } }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.result-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 10px; }
.result-total { font-size: 34px; font-weight: 700; color: var(--blue-800); line-height: 1.1; }
.result-total small { font-size: 15px; color: var(--muted); font-weight: 500; }
.select {
  padding: 9px 12px; border-radius: 14px; border: 1px solid var(--blue-100); background: var(--blue-50);
  color: var(--blue-800); outline: none;
}
.select.full { width: 100%; }

.result-items { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.ritem {
  display: grid; grid-template-columns: 1fr 86px 30px; gap: 8px; align-items: center;
  padding: 8px 8px 8px 12px; border-radius: 16px; background: var(--blue-50); animation: pop .3s ease both;
}
.ritem input {
  width: 100%; border: none; background: transparent; outline: none; min-width: 0;
}
.ritem .rname { font-weight: 500; }
.ritem .rportion { font-size: 12px; color: var(--muted); }
.ritem .kc { display: flex; align-items: center; gap: 4px; background: #fff; border-radius: 12px; padding: 6px 8px; }
.ritem .kc input { text-align: right; font-weight: 600; color: var(--blue-600); }
.ritem .kc em { font-style: normal; font-size: 11px; color: var(--muted); }
.ritem .rdel { color: #a3b5cf; font-size: 16px; height: 30px; border-radius: 10px; }
.ritem .rdel:hover { color: #d64545; background: #ffecec; }

.note { font-size: 13px; color: var(--blue-600); background: var(--blue-50); padding: 10px 12px; border-radius: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 500; }
.field input {
  padding: 12px 14px; border-radius: 14px; border: 1px solid var(--blue-100); background: var(--blue-50); outline: none; width: 100%;
  transition: border-color .2s, box-shadow .2s;
}
.field input:focus, .select:focus { border-color: var(--blue-400); box-shadow: 0 0 0 4px rgba(90,168,255,.2); }
.input-row { display: flex; gap: 8px; align-items: center; }
.warn { font-size: 12px; color: var(--muted); background: #f5f9ff; border-radius: 14px; padding: 10px 12px; line-height: 1.55; }

.toast {
  position: fixed; left: 50%; top: 18px; transform: translate(-50%, -140%);
  background: var(--blue-800); color: #fff; padding: 12px 18px; border-radius: 16px; font-size: 14px;
  box-shadow: 0 12px 30px -10px rgba(18,58,122,.6); z-index: 100; transition: transform .35s cubic-bezier(.2,.8,.2,1);
  max-width: calc(100% - 32px); text-align: center;
}
.toast.show { transform: translate(-50%, 0); }
.toast.error { background: #d64545; }
