:root {
  --bg: #eaf4fc;
  --bg2: #d9ecfa;
  --card: #ffffff;
  --shark: #8ec5ef;
  --shark-2: #6aaee3;
  --navy: #34597f;
  --ink: #2c3e55;
  --muted: #7e93a8;
  --pink: #f7b6c2;
  --ok: #6cc59a;
  --warn: #f2a65a;
  --danger: #e46c7b;
  --radius: 20px;
  --shadow: 0 6px 18px rgba(80, 140, 190, 0.13);
  --tabbar-h: 64px;
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font-family: ui-rounded, "SF Pro Rounded", "Hiragino Maru Gothic ProN", "Nunito", system-ui, -apple-system, sans-serif;
  background: linear-gradient(180deg, var(--bg2) 0%, var(--bg) 260px) fixed, var(--bg);
  color: var(--ink);
  min-height: 100vh;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; }
h2 { font-size: 1.05rem; color: var(--navy); }
h3 { font-size: .98rem; color: var(--navy); margin-top: 14px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
code { background: var(--bg); padding: 1px 6px; border-radius: 6px; font-size: .85em; word-break: break-all; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 8px) 16px 8px;
  background: rgba(217, 236, 250, .88);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 1.25rem; color: var(--navy); letter-spacing: .3px; }
.brand small { color: var(--muted); font-weight: 600; }
.top-cat .mofu { display: block; }
.mofu { object-fit: contain; display: block; margin: 0 auto; -webkit-user-select: none; user-select: none; }
.icon-btn {
  border: 0; background: var(--card); width: 40px; height: 40px; border-radius: 14px;
  font-size: 1.2rem; box-shadow: var(--shadow); cursor: pointer;
}

main { padding: 8px 16px 0; max-width: 560px; margin: 0 auto; }
.view { display: none; animation: fade .25s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Cards ---------- */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 14px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card > h2 { margin-bottom: 10px; }
.hint { background: var(--bg); padding: 10px 12px; border-radius: 14px; font-size: .9rem; margin: 12px 0 0; }

/* ---------- Buttons ---------- */
.btn {
  border: 0; border-radius: 14px; padding: 11px 14px; background: var(--bg);
  color: var(--navy); font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn.primary { background: var(--shark-2); color: #fff; }
.btn.danger { background: #fde6ea; color: var(--danger); }
.btn.small { padding: 7px 11px; font-size: .88rem; border-radius: 11px; }
.btn.full { width: 100%; margin-top: 12px; }
.btn:active, .icon-btn:active { transform: scale(.96); }
.btn-row { display: flex; gap: 8px; margin-top: 12px; }
.btn-row > .btn { flex: 1; }
.btn-row.wrap { flex-wrap: wrap; margin: 0 0 10px; }
.btn-row.wrap > .btn { flex: 0 1 auto; }
.link { border: 0; background: none; color: var(--shark-2); font-weight: 700; cursor: pointer; padding: 0; }

/* ---------- Inputs ---------- */
input, select, textarea {
  width: 100%; border: 2px solid var(--bg2); background: #f7fbfe; border-radius: 14px;
  padding: 11px 12px; font-size: 16px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--shark); background: #fff; }
textarea { resize: vertical; }
.inline-form { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.inline-form input { flex: 1; min-width: 0; }
.unit { color: var(--muted); font-weight: 700; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); font-weight: 700; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid .check { flex-direction: row; align-items: center; gap: 10px; color: var(--ink); font-weight: 600; }
.form-grid .check input { width: 22px; height: 22px; flex: none; }

/* ---------- Date nav ---------- */
.date-nav { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 12px; }
.date-label { border: 0; background: none; font-weight: 800; color: var(--navy); font-size: 1.05rem; position: relative; }

/* ---------- Ring ---------- */
.ring-card { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; }
.ring-wrap { position: relative; width: 150px; height: 150px; flex: none; margin: 0 auto; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--bg); stroke-width: 12; }
.ring-fg { fill: none; stroke: var(--shark-2); stroke-width: 12; stroke-linecap: round; transition: stroke-dashoffset .6s ease, stroke .3s; }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.big { font-size: 2rem; font-weight: 800; color: var(--navy); line-height: 1.1; }
.ring-center .muted { font-size: .8rem; }
.ring-stats { flex: 1; min-width: 150px; display: grid; gap: 8px; }
.ring-stats div { display: flex; justify-content: space-between; align-items: center; gap: 8px; white-space: nowrap; background: var(--bg); padding: 8px 12px; border-radius: 12px; }
.ring-card .hint { flex-basis: 100%; }

/* ---------- Cat bubble ---------- */
.bubble-row { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; }
.home-cat .mofu { animation: bob 3s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-4px) rotate(-2deg); } }
.bubble {
  position: relative; flex: 1; background: var(--card); border-radius: 18px; padding: 12px 14px;
  box-shadow: var(--shadow); font-weight: 600; font-size: .92rem;
}
.bubble::before {
  content: ""; position: absolute; left: -8px; top: 50%; transform: translateY(-50%);
  border: 8px solid transparent; border-right-color: var(--card); border-left: 0;
}

/* ---------- Bars ---------- */
.steps-row { display: flex; align-items: baseline; gap: 8px; }
.bar { height: 12px; background: var(--bg); border-radius: 99px; overflow: hidden; margin: 10px 0 4px; }
.bar-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--shark), var(--shark-2)); border-radius: 99px; transition: width .6s ease; }
.big-bar { height: 16px; }

/* ---------- Meal log ---------- */
.meal { margin-bottom: 10px; }
.meal-title { display: flex; justify-content: space-between; font-weight: 800; color: var(--navy); font-size: .92rem; padding: 4px 0; border-bottom: 2px dashed var(--bg2); }
.meal-item { display: flex; align-items: center; gap: 8px; padding: 7px 0; font-size: .92rem; }
.meal-item .name { flex: 1; }
.meal-item .kc { font-weight: 700; color: var(--navy); white-space: nowrap; }
.del { border: 0; background: #fde6ea; color: var(--danger); width: 28px; height: 28px; border-radius: 9px; font-weight: 800; cursor: pointer; flex: none; }
.empty { text-align: center; color: var(--muted); padding: 12px 0; font-size: .92rem; }

/* ---------- Charts ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart text { font-size: 9px; fill: var(--muted); font-family: inherit; }
.chart .val { fill: var(--navy); font-weight: 700; }

/* ---------- Food search ---------- */
.search-bar { position: sticky; top: calc(env(safe-area-inset-top) + 58px); z-index: 5; padding: 4px 0 8px; background: transparent; }
.search-bar input { box-shadow: var(--shadow); border-color: #fff; background: #fff; border-radius: 16px; padding: 13px 14px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 0; background: var(--card); padding: 8px 12px; border-radius: 99px; font-weight: 700; color: var(--navy); box-shadow: var(--shadow); font-size: .86rem; cursor: pointer; }
.chip.on { background: var(--shark-2); color: #fff; }
.food-list { list-style: none; padding: 0; margin: 0; }
.food-list li {
  display: flex; align-items: center; gap: 12px; background: var(--card); border-radius: 16px;
  padding: 11px 12px; margin-bottom: 8px; box-shadow: var(--shadow); cursor: pointer;
}
.food-list li:active { transform: scale(.99); }
.food-emoji { width: 38px; height: 38px; border-radius: 12px; background: var(--bg); display: grid; place-items: center; font-size: 1.2rem; flex: none; }
.food-info { flex: 1; min-width: 0; }
.food-name { font-weight: 700; }
.food-sub { font-size: .8rem; color: var(--muted); }
.food-kcal { font-weight: 800; color: var(--navy); text-align: right; white-space: nowrap; }
.food-kcal small { display: block; color: var(--muted); font-weight: 600; }

/* ---------- Weight ---------- */
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--bg); border-radius: 14px; padding: 10px 8px; text-align: center; }
.stat b { display: block; font-size: 1.1rem; color: var(--navy); }
.stat span { font-size: .75rem; color: var(--muted); font-weight: 700; }
.seg { display: flex; background: var(--bg); border-radius: 12px; padding: 3px; }
.seg button { border: 0; background: none; padding: 5px 10px; border-radius: 9px; font-weight: 700; color: var(--muted); font-size: .82rem; cursor: pointer; }
.seg button.on { background: #fff; color: var(--navy); box-shadow: 0 2px 6px rgba(0,0,0,.06); }
.plain-list { list-style: none; padding: 0; margin: 0; }
.plain-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 0; border-bottom: 1px solid var(--bg); }
.plain-list li:last-child { border-bottom: 0; }
.up { color: var(--danger); } .down { color: var(--ok); }

/* ---------- Notes ---------- */
.notes { list-style: none; padding: 0; margin: 0; }
.note { background: var(--card); border-radius: 18px; box-shadow: var(--shadow); padding: 14px; margin-bottom: 10px; }
.note-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.note-date { font-size: .8rem; color: var(--muted); font-weight: 700; }
.note-text { white-space: pre-wrap; word-wrap: break-word; }
.note-actions { display: flex; gap: 6px; }

/* ---------- Ranks ---------- */
.rank-hero { text-align: center; }
.rank-hero .mofu { animation: bob 3s ease-in-out infinite; margin-bottom: 6px; }
.rank-name { font-size: 1.4rem; font-weight: 800; color: var(--navy); }
.collection { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.cat-card { background: var(--bg); border-radius: 16px; padding: 8px 4px; text-align: center; border: 3px solid transparent; cursor: pointer; position: relative; }

.cat-card .cn { font-size: .72rem; font-weight: 800; color: var(--navy); line-height: 1.15; min-height: 2.3em; display: flex; align-items: center; justify-content: center; }
.cat-card .rar { font-size: .66rem; font-weight: 800; text-transform: uppercase; letter-spacing: .4px; }
.cat-card.locked .mofu, .locked-art .mofu { filter: brightness(0) opacity(.18); }
.cat-card.locked .cn { color: var(--muted); }
.cat-card.current { box-shadow: 0 0 0 3px var(--shark-2) inset; }
.xp-rules li b { color: var(--shark-2); }

/* ---------- Guide ---------- */
.guide { padding-left: 20px; margin: 8px 0 0; }
.guide li { margin-bottom: 9px; line-height: 1.45; font-size: .92rem; }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around;
  padding: 6px 6px calc(env(safe-area-inset-bottom) + 6px);
  background: rgba(255, 255, 255, .92); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 -4px 16px rgba(80, 140, 190, .12);
}
.tabbar button {
  flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: .7rem; font-weight: 700; color: var(--muted); padding: 4px 0; border-radius: 14px; cursor: pointer;
}
.tabbar button span { font-size: 1.35rem; filter: grayscale(.6); transition: transform .2s; }
.tabbar button.on { color: var(--navy); background: var(--bg); }
.tabbar button.on span { filter: none; transform: translateY(-2px) scale(1.1); }

/* ---------- Sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(40, 70, 100, .35); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop[hidden] { display: none; }
.sheet {
  width: 100%; max-width: 560px; background: #fff; border-radius: 26px 26px 0 0;
  padding: 18px 16px calc(env(safe-area-inset-bottom) + 18px); max-height: 88vh; overflow-y: auto;
  animation: up .25s ease;
}
@keyframes up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
.sheet h2 { font-size: 1.2rem; margin-bottom: 4px; }
.sheet .grab { width: 44px; height: 5px; background: var(--bg2); border-radius: 9px; margin: -6px auto 12px; }
.stepper { display: flex; align-items: center; gap: 10px; margin: 12px 0; }
.stepper button { width: 44px; height: 44px; border-radius: 14px; border: 0; background: var(--bg); font-size: 1.4rem; font-weight: 800; color: var(--navy); cursor: pointer; }
.stepper input { text-align: center; font-weight: 800; font-size: 1.2rem; }
.kcal-preview { text-align: center; font-size: 2rem; font-weight: 800; color: var(--navy); margin: 6px 0; }
.meal-pick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 10px 0; }
.meal-pick button { border: 0; background: var(--bg); border-radius: 12px; padding: 8px 2px; font-size: .78rem; font-weight: 700; color: var(--navy); cursor: pointer; }
.meal-pick button.on { background: var(--shark-2); color: #fff; }
.unlock { text-align: center; }
.unlock .mofu { margin: 8px auto; }
.unlock .pop { animation: pop .6s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes pop { from { transform: scale(.3) rotate(-20deg); opacity: 0; } to { transform: none; opacity: 1; } }
.rarity-tag { display: inline-block; padding: 3px 10px; border-radius: 99px; color: #fff; font-weight: 800; font-size: .78rem; letter-spacing: .5px; text-transform: uppercase; margin: 6px 0; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 18px);
  background: var(--navy); color: #fff; padding: 11px 16px; border-radius: 14px; font-weight: 700; z-index: 60;
  box-shadow: var(--shadow); max-width: calc(100% - 32px); text-align: center; animation: fade .2s ease;
}
.toast[hidden] { display: none; }
