:root {
  --bg: #0f1a2b; --card: #17263d; --card2: #1e3150; --ink: #eef3fb; --mute: #93a4bf;
  --acc: #37d49b; --acc2: #ffcf4a; --bad: #ff6b6b; --r: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; overflow-x: hidden; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
main { max-width: 560px; margin: 0 auto; padding: 8px 16px calc(96px + var(--safe-b)); }

.top { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center; padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px; background: rgba(15,26,43,.92); backdrop-filter: blur(8px); max-width: 560px; margin: 0 auto; }
.brand { font-size: 20px; }
.streak { background: var(--card); border-radius: 99px; padding: 4px 12px; font-weight: 700; }

.view { display: none; } .view.active { display: block; }
.section { font-size: 15px; color: var(--mute); font-weight: 600; margin: 22px 2px 10px; }

.today { text-align: center; padding: 14px 0 4px; }
.today-count { font-size: 34px; font-weight: 800; }
.today-count span:first-child { color: var(--acc); }
.today-sub { color: var(--mute); }
.daytoggle { display: inline-flex; background: var(--card); border-radius: 99px; padding: 3px; margin-top: 10px; }
.daytoggle button { padding: 6px 14px; border-radius: 99px; color: var(--mute); font-size: 14px; }
.daytoggle button.on { background: var(--card2); color: var(--ink); font-weight: 600; }

.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.tile { background: var(--card); border-radius: var(--r); padding: 12px 4px 10px; text-align: center; position: relative; transition: transform .08s; min-width: 0; }
.tile:active { transform: scale(.92); }
.tile .e { font-size: 34px; line-height: 1.1; display: block; }
.tile .l { font-size: 12px; color: var(--mute); display: block; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .n { position: absolute; top: 6px; right: 8px; background: var(--acc); color: #04261a; font-size: 12px; font-weight: 800; border-radius: 99px; min-width: 20px; padding: 0 5px; }
.tile.pop { animation: pop .45s ease; }
@keyframes pop { 0% { transform: scale(1); } 30% { transform: scale(1.15) rotate(-4deg); background: #1f5a48; } 100% { transform: scale(1); } }
.add-custom { width: 100%; margin-top: 12px; padding: 12px; border: 1.5px dashed #34496b; border-radius: var(--r); color: var(--mute); }

.entries { list-style: none; margin: 0; padding: 0; }
.entries li { display: flex; align-items: center; gap: 10px; background: var(--card); border-radius: 14px; padding: 10px 12px; margin-bottom: 8px; }
.entries .e { font-size: 26px; }
.entries .t { flex: 1; min-width: 0; }
.entries .t small { display: block; color: var(--mute); font-size: 12px; }
.entries .x { color: var(--mute); font-size: 20px; padding: 4px 8px; }
.entries .empty { background: none; color: var(--mute); justify-content: center; }
.strike { text-decoration: line-through; text-decoration-color: var(--bad); text-decoration-thickness: 2px; }

.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; display: flex; justify-content: center; gap: 4px; padding: 8px 8px calc(8px + var(--safe-b)); background: rgba(15,26,43,.96); border-top: 1px solid #22324d; }
.tabs button { flex: 1; max-width: 180px; padding: 6px; border-radius: 14px; font-size: 22px; color: var(--mute); display: flex; flex-direction: column; align-items: center; }
.tabs button span { font-size: 12px; }
.tabs button.on { background: var(--card); color: var(--ink); }

.toast { position: fixed; left: 12px; right: 12px; bottom: calc(84px + var(--safe-b)); z-index: 7; max-width: 536px; margin: 0 auto; background: #203a5e; border-radius: var(--r); padding: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.45); animation: up .2s ease; }
@keyframes up { from { transform: translateY(20px); opacity: 0; } }
.toast-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-weight: 700; }
.toast-head button { color: var(--acc2); font-weight: 600; font-size: 14px; }
.toast-q { color: var(--mute); font-size: 13px; margin: 8px 0 6px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips button { flex: 0 0 auto; background: var(--card); border-radius: 99px; padding: 6px 10px; font-size: 14px; white-space: nowrap; }
.chips button.on { background: var(--acc); color: #04261a; font-weight: 700; }

.weeknav { display: flex; align-items: center; justify-content: space-between; margin: 10px 0; }
.weeknav button { font-size: 28px; width: 44px; height: 44px; border-radius: 50%; background: var(--card); }
.weeknav button:disabled { opacity: .3; }
#wk-title { font-weight: 700; text-align: center; }
.jar-wrap { text-align: center; }
.jar { position: relative; margin: 6px auto 0; width: 230px; height: 270px; border: 4px solid #6f89b3; border-top-width: 10px; border-radius: 22px 22px 60px 60px; background: linear-gradient(180deg, rgba(111,137,179,.06), rgba(111,137,179,.16)); display: flex; flex-wrap: wrap-reverse; align-content: flex-start; justify-content: center; padding: 10px; gap: 2px; overflow: hidden; }
.jar span { font-size: 28px; line-height: 1; animation: drop .5s ease both; }
.jar.dense span { font-size: 20px; }
.jar.xdense span { font-size: 14px; }
@keyframes drop { from { transform: translateY(-200px); opacity: 0; } }
.jar-empty { color: var(--mute); align-self: center; margin: auto; font-size: 14px; }
.jar-label { color: var(--mute); font-size: 13px; margin-top: 8px; }
.big-kcal { text-align: center; font-size: 44px; font-weight: 900; color: var(--acc); margin-top: 14px; }
.big-kcal small { font-size: 16px; color: var(--mute); font-weight: 600; }
.level { text-align: center; font-weight: 700; color: var(--acc2); margin: 4px 0 10px; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--card); border-radius: var(--r); padding: 12px; }
.stat b { font-size: 22px; display: block; }
.stat small { color: var(--mute); font-size: 12px; }
.tally { list-style: none; margin: 0; padding: 0; }
.tally li { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px solid #22324d; }
.tally .e { font-size: 24px; width: 32px; text-align: center; }
.tally .t { flex: 1; }
.tally .k { color: var(--mute); font-size: 13px; }
.repl-summary { display: flex; flex-wrap: wrap; gap: 8px; }
.repl-summary span { background: var(--card); border-radius: 99px; padding: 6px 12px; }
.repl-summary .none { background: none; color: var(--mute); padding: 0; }

.total-card { background: linear-gradient(135deg, #1e3a5f, #1a4d42); border-radius: var(--r); padding: 16px; margin-top: 12px; }
.total-card h3 { margin: 0 0 8px; font-size: 15px; color: var(--mute); }
.total-card b { font-size: 28px; }
.total-card p { margin: 4px 0 0; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding: 8px 4px 0; background: var(--card); border-radius: var(--r); overflow-x: auto; }
.bar { flex: 1 0 28px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; font-size: 10px; color: var(--mute); }
.bar i { display: block; width: 70%; background: var(--acc); border-radius: 6px 6px 2px 2px; min-height: 2px; }
.bar.cur i { background: var(--acc2); }
.bar em { font-style: normal; margin: 3px 0 6px; }
.note { color: var(--mute); font-size: 12px; margin-top: 18px; }

dialog { background: var(--card); color: var(--ink); border: 0; border-radius: var(--r); padding: 18px; width: min(92vw, 420px); }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h3 { margin: 0 0 12px; }
dialog label { display: block; font-size: 13px; color: var(--mute); margin-bottom: 10px; flex: 1; }
dialog input, dialog select { display: block; width: 100%; margin-top: 4px; padding: 10px; border-radius: 10px; border: 1px solid #34496b; background: var(--bg); color: var(--ink); font-size: 16px; }
dialog .row { display: flex; gap: 10px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.dlg-actions button { padding: 10px 16px; border-radius: 12px; }
.primary { background: var(--acc); color: #04261a; font-weight: 700; }
.ghost { color: var(--mute); }

.locked main { text-align: center; padding-top: 25vh; }
.locked .logo { font-size: 64px; }
.locked p { color: var(--mute); }

@media (max-width: 360px) { .grid { grid-template-columns: repeat(3, 1fr); } }
