:root {
  --bg: #fafafa;
  --fg: #111111;
  --muted: #8a8a8a;
  --line: #e6e6e6;
  --accent: #2f6df6;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  /* liquid glass */
  --glass-bg: rgba(255, 255, 255, .45);
  --glass-border: rgba(255, 255, 255, .8);
  --glass-shadow: 0 10px 30px rgba(0, 0, 0, .08), inset 0 1px 0 rgba(255, 255, 255, .9), inset 0 -1px 0 rgba(0, 0, 0, .04);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
html { background: var(--bg); }
body {
  font-family: var(--font);
  color: var(--fg);
  background: transparent; /* html paints the colour; body must stay clear for the blobs behind it */
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.5;
  overflow-x: hidden;
}
/* soft blobs behind the glass so refraction is visible */
body::before, body::after {
  content: ""; position: fixed; z-index: -1; border-radius: 50%; filter: blur(70px); opacity: .35; pointer-events: none;
  will-change: transform; transform: translateZ(0); /* rasterised once, never re-blurred */
}
body::before { width: 60vmax; height: 60vmax; left: -18vmax; top: -18vmax; background: radial-gradient(circle, var(--accent), transparent 70%); }
body::after  { width: 52vmax; height: 52vmax; right: -16vmax; bottom: -20vmax; background: radial-gradient(circle, #f2b63c, transparent 70%); }

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
.hidden { display: none !important; }

/* ---------- liquid glass primitives ---------- */
.glass {
  position: relative;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  overflow: hidden;
}
.glass::before { /* moving specular highlight */
  content: ""; position: absolute; inset: -60%;
  background: linear-gradient(115deg, transparent 40%, rgba(255,255,255,.55) 50%, transparent 60%);
  transform: translateX(-60%);
  animation: sheen 7s ease-in-out infinite;
  pointer-events: none;
}
@keyframes sheen { 0%, 60% { transform: translateX(-60%); } 100% { transform: translateX(60%); } }

.glass-btn {
  position: relative;
  padding: 10px 24px;
  border-radius: 999px;
  letter-spacing: .02em;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  backdrop-filter: blur(14px) saturate(160%);
  -webkit-backdrop-filter: blur(14px) saturate(160%);
  overflow: hidden;
  transition: transform .25s cubic-bezier(.2,.8,.2,1.4), box-shadow .25s, background .25s;
}
.glass-btn::before {
  content: ""; position: absolute; inset: -60%;
  background: linear-gradient(115deg, transparent 42%, rgba(255,255,255,.7) 50%, transparent 58%);
  transform: translateX(-60%);
  animation: sheen 6s ease-in-out infinite;
  pointer-events: none;
}
.glass-btn:hover { transform: translateY(-1px) scale(1.03); background: rgba(255,255,255,.65); box-shadow: 0 14px 34px rgba(0,0,0,.1), inset 0 1px 0 #fff; }
.glass-btn:active { transform: scale(.97); }
.glass-btn.open { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.glass-btn.small { padding: 7px 18px; font-size: 14px; align-self: flex-start; }
.glass-btn.icon { width: 44px; height: 44px; padding: 0; display: grid; place-items: center; border-radius: 14px; }

.link-btn { color: var(--muted); text-decoration: underline; text-underline-offset: 3px; font-size: 13px; }
.link-btn:hover { color: var(--fg); }

/* ---------- layout ---------- */
.layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr minmax(280px, 480px) 1fr;
  align-items: center;
  padding: 48px;
  padding-left: max(48px, env(safe-area-inset-left));
  padding-right: max(48px, env(safe-area-inset-right));
}
.col { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.col-left { align-items: flex-start; }
.col-right { align-items: flex-end; }

/* ---------- center ---------- */
.col-center { position: relative; gap: 20px; }
.stack {
  position: relative;
  width: 360px; height: 360px;
  --r: 130px; /* orbit radius */
}
/* registered so --a can transition: cans glide to their new slots instead of jumping */
@property --a { syntax: '<angle>'; inherits: false; initial-value: 0deg; }
@property --t { syntax: '<angle>'; inherits: true;  initial-value: 0deg; }
.stack .bottle {
  position: absolute;
  left: 50%; top: 50%;
  width: 40px; height: 100px;
  margin: -50px 0 0 -20px;
  /* --t = shared orbit angle (driven by JS each frame), --a = this can's slot; trailing rotate keeps it upright */
  transform: rotate(calc(var(--t) + var(--a))) translateY(calc(-1 * var(--r))) rotate(calc(-1 * (var(--t) + var(--a))));
  transition: --a .75s cubic-bezier(.3, 1, .3, 1), opacity .4s ease;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,.1));
  will-change: transform;
}
.stack .bottle img { width: 100%; height: 100%; object-fit: contain; display: block; transition: opacity .3s ease; }
.stack .bottle.empty { opacity: .15; filter: grayscale(1); }
.stack .bottle.leave { opacity: 0; }
.stack .bottle.landing img { opacity: 0; transition: none; }
.stack .bottle.pop img { animation: pop .6s cubic-bezier(.2,.8,.3,1); }
@keyframes pop { 0% { transform: scale(.55); } 35% { transform: scale(1.28); } 60% { transform: scale(.9); } 80% { transform: scale(1.06); } 100% { transform: none; } }
/* the can in flight */
.fly {
  position: fixed; left: 0; top: 0; z-index: 200; pointer-events: none;
  object-fit: contain; transform-origin: 0 0; will-change: transform, opacity;
  filter: drop-shadow(0 10px 14px rgba(0,0,0,.18));
}

.today {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%) translateY(-20px);
  width: 170px; height: 170px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-radius: 50%;
  pointer-events: none;
}
.today-label { display: block; font-size: 12px; letter-spacing: .2em; color: var(--muted); }
.today-count { display: block; font-size: 56px; font-weight: 300; line-height: 1; margin-top: 2px; }
.today-count.bump { animation: bump .35s ease; }
@keyframes bump { 40% { transform: scale(1.15); color: var(--accent); } }

.today-flavors {
  list-style: none; margin: 0; padding: 0;
  display: flex; gap: 14px; flex-wrap: wrap; justify-content: center;
  font-size: 13px; color: var(--muted);
  min-height: 20px;
}
.today-flavors li::before {
  content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--c); margin-right: 6px; vertical-align: middle;
}

/* ---------- forms / picker (inside the user glass) ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.form input {
  font: inherit; color: var(--fg);
  border: 0; border-bottom: 1px solid rgba(0,0,0,.12);
  padding: 6px 0; outline: none; background: transparent;
}
.form input:focus { border-bottom-color: var(--accent); }
.error { color: #c0392b; font-size: 13px; margin: 0; min-height: 1em; }

.picker { display: flex; flex-direction: column; gap: 16px; align-items: stretch; }
.flavors { display: flex; justify-content: space-between; width: 100%; overflow: hidden; padding-top: 4px; }
.flavor {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  font-size: 11px; color: var(--muted);
  transform: translateY(-160px); opacity: 0;
  animation: fall .55s cubic-bezier(.2,.9,.3,1.15) forwards;
  animation-delay: var(--d);
  transition: transform .15s, color .15s;
  border-radius: 12px; padding: 6px;
}
.flavor img { width: 40px; height: 100px; object-fit: contain; display: block; filter: drop-shadow(0 6px 8px rgba(0,0,0,.1)); }
.flavor:hover { color: var(--fg); }
.flavor:hover img { transform: translateY(-4px) scale(1.05); transition: transform .15s; }
@keyframes fall { to { transform: translateY(0); opacity: 1; } }

.logged { width: 100%; display: flex; flex-direction: column; gap: 2px; font-size: 13px; color: var(--muted); }
.logged-title { letter-spacing: .15em; font-size: 11px; margin-bottom: 4px; }
.logged-item {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 0; border-bottom: 1px solid rgba(0,0,0,.06); color: var(--fg);
}
.logged-item::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex: none; }
.logged-item span { flex: 1; }
.logged-item small { color: var(--muted); font-size: 11px; }
.remove {
  width: 24px; height: 24px; border-radius: 50%;
  background: rgba(255,255,255,.6); border: 1px solid var(--glass-border);
  display: grid; place-items: center; color: var(--muted); font-size: 15px; line-height: 1;
  transition: transform .2s, color .2s, background .2s;
}
.remove:hover { color: var(--fg); background: #fff; transform: scale(1.1); }

/* ---------- liquid glass component ----------
   .lg-wrap keeps the closed footprint in the layout; .lg is the glass shell.
   Opening is a FLIP: the shell is placed at its FINAL size/position at once, then a
   transform (translate + scale) carries it from the button's rect to identity while the
   label/body are counter-scaled. Only `transform` and `opacity` animate → compositor-only,
   60fps, and the backdrop blur is live throughout.
   Per-instance vars (inline): --w0 closed width, --rad0 closed radius, --wo open width.
   JS sets --h/--left/--top (final geometry) and --tx/--ty/--sx/--sy (FLIP start). */
.lg-wrap { position: relative; width: var(--w0); height: 44px; z-index: 100; }
.lg-wrap.raised { z-index: 101; }

.lg {
  --dur: .58s; --ease: cubic-bezier(.3, 1.06, .4, 1);
  position: absolute; left: var(--left, 0px); top: var(--top, 0px);
  width: var(--w, var(--w0)); height: var(--h, 44px);
  border-radius: var(--rad, var(--rad0));
  z-index: 100;
  transform-origin: var(--o);
  transform: translate(var(--tx, 0px), var(--ty, 0px)) scale(var(--sx, 1), var(--sy, 1));
  will-change: transform;
  background:
    radial-gradient(120% 90% at var(--gx, 18%) 10%, rgba(255,255,255,.7), rgba(255,255,255,0) 55%),
    linear-gradient(135deg, rgba(255,255,255,.55), rgba(255,255,255,.25));
  border: 1px solid rgba(255,255,255,.9);
  box-shadow:
    0 22px 48px -22px rgba(0,0,0,.25),
    inset 0 1px 1px rgba(255,255,255,1),
    inset 0 -10px 20px -14px rgba(0,0,0,.12);
  backdrop-filter: blur(14px) saturate(150%);
  -webkit-backdrop-filter: blur(14px) saturate(150%);
  overflow: hidden;
  contain: paint;
  transition:
    transform var(--dur) var(--ease),
    border-radius var(--dur) var(--ease),
    height .35s ease, top .35s ease; /* only for content re-flow while open */
  cursor: pointer;
}
.lg.notrans, .lg.notrans .lg-label, .lg.notrans .lg-body { transition: none !important; }
.lg--left  { --o: 0 0;    --gx: 18%; }
.lg--right { --o: 100% 0; --gx: 82%; }
.lg.open { --w: var(--wo); cursor: default; }
.lg.sheet { position: fixed; }

/* specular band sweeping across as it opens */
.lg::before {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 1;
  background: linear-gradient(110deg, transparent 30%, rgba(255,255,255,.55) 45%, rgba(255,255,255,.15) 52%, transparent 65%);
  transform: translateX(-110%) skewX(-8deg);
  transition: transform .9s cubic-bezier(.2,.7,.2,1);
}
.lg--right::before { transform: translateX(110%) skewX(8deg); }
.lg--left.go::before  { transform: translateX(110%) skewX(-8deg); }
.lg--right.go::before { transform: translateX(-110%) skewX(8deg); }
/* caustic glow at the origin corner */
.lg::after {
  content: ""; position: absolute; top: -30px; width: 120px; height: 120px; pointer-events: none;
  background: radial-gradient(circle, rgba(255,255,255,.9), rgba(255,255,255,0) 70%);
  opacity: .9; transition: opacity .6s ease;
}
.lg--left::after  { left: -30px; }
.lg--right::after { right: -30px; }
.lg.go::after { opacity: .3; }

/* label and body are counter-scaled so they never stretch */
.lg-label, .lg-body {
  transform-origin: var(--o);
  transform: scale(calc(1 / var(--sx, 1)), calc(1 / var(--sy, 1)));
  transition: transform var(--dur) var(--ease), opacity .28s ease;
}
.lg-label {
  position: absolute; top: 0; height: 44px; width: var(--w0); z-index: 2;
  display: grid; place-items: center; color: var(--fg); letter-spacing: .02em;
}
.lg--left .lg-label { left: 0; }
.lg--right .lg-label { right: 0; }
.lg:hover:not(.open) .lg-label svg, .lg:hover:not(.open) .lg-label { color: var(--accent); }
.lg.go .lg-label { opacity: 0; pointer-events: none; }
.lg.closing .lg-label { opacity: 1; transition-delay: 0s, .3s; }

.lg-body {
  position: relative; z-index: 2;
  width: var(--wo); padding: 26px;
  opacity: 0; pointer-events: none;
  max-height: calc(100vh - 48px); max-height: calc(100dvh - 48px); overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.lg--right .lg-body { margin-left: auto; }
.lg.go .lg-body { opacity: 1; pointer-events: auto; transition-delay: 0s, .18s; transition-duration: var(--dur), .4s; }
.lg.closing .lg-body { opacity: 0; pointer-events: none; transition-delay: 0s, 0s; transition-duration: var(--dur), .2s; }
.lg.sheet .lg-body { max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); }
.lg-body--user { padding: 22px; }
.body-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; letter-spacing: .15em; color: var(--muted); margin-bottom: 14px; }

/* ---------- views inside the left glass (statistics ⇄ calendar) ---------- */
.view.enter-right { animation: viewIn .35s cubic-bezier(.2,.8,.2,1) both; --dx: 16px; }
.view.enter-left  { animation: viewIn .35s cubic-bezier(.2,.8,.2,1) both; --dx: -16px; }
@keyframes viewIn { from { opacity: 0; transform: translateX(var(--dx)); } to { opacity: 1; transform: none; } }
.view-link {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; letter-spacing: .12em; color: var(--muted);
  transition: color .2s;
}
.view-link .arrow { display: inline-block; transition: transform .25s cubic-bezier(.2,.8,.2,1.4); font-size: 14px; }
.view-link:hover { color: var(--fg); }
.view-link[data-view="cal"]:hover .arrow { transform: translateX(3px); }
.view-link[data-view="stats"]:hover .arrow { transform: translateX(-3px); }
.body-head small { font-size: 11px; letter-spacing: 0; text-transform: none; margin-left: 6px; opacity: .8; }

/* ---------- statistics panel ---------- */
.stats { display: flex; flex-direction: column; gap: 18px; }
.stats .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
.stat { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat-label { font-size: 11px; letter-spacing: .15em; color: var(--muted); }
.stat-value { font-size: 26px; font-weight: 300; line-height: 1.1; }
.stat-value small { font-size: 13px; color: var(--muted); font-weight: 400; margin-left: 4px; }
.stat-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-sub.up { color: #2f9e5b; } .stat-sub.down { color: #c0392b; }
.stat.wide { grid-column: 1 / -1; }

/* flavour share: one stacked bar */
.dist { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: rgba(0,0,0,.06); margin-top: 8px; }
.dist span { display: block; height: 100%; background: var(--c); transition: width .6s ease; }
.dist-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.dist-legend li { list-style: none; display: flex; align-items: center; gap: 6px; }
.dist-legend li::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.dist-legend ul { display: contents; margin: 0; padding: 0; }

/* last 30 days */
.spark { width: 100%; height: 56px; display: block; margin-top: 8px; overflow: visible; }
.spark line { stroke: rgba(0,0,0,.1); stroke-width: 1; }
.spark .area { fill: var(--accent); opacity: .08; }
.spark .line { fill: none; stroke: var(--accent); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.spark .pt { fill: #fff; stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.spark .pt-zero { fill: rgba(0,0,0,.15); stroke: none; }
.spark .pt-peak { fill: var(--fg); stroke: var(--fg); }
.spark .pt-now { fill: var(--accent); stroke: var(--accent); }
.spark-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 4px; }
.stats .empty { color: var(--muted); font-size: 14px; }

.cal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-grid .dow { font-size: 11px; color: var(--muted); text-align: center; padding-bottom: 6px; }
.cal-grid .day {
  aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-radius: 10px; font-size: 13px; border: 1px solid transparent; transition: background .15s;
}
.cal-grid .day:hover { background: rgba(255,255,255,.7); }
.cal-grid .day.has { font-weight: 500; }
.cal-grid .day.is-today { border-color: var(--fg); }
.cal-grid .day.selected { background: var(--fg); color: var(--bg); }
.cal-grid .day small { font-size: 10px; color: var(--accent); line-height: 1; }
.cal-grid .day.selected small { color: var(--bg); }
.cal-grid .day.future { color: #ccc; pointer-events: none; }

.day-log { margin: 20px 0 0; padding-top: 16px; border-top: 1px solid rgba(0,0,0,.08); font-size: 14px; min-height: 40px; color: var(--muted); }
.day-log ul { list-style: none; margin: 8px 0 0; padding: 0; color: var(--fg); }
.day-log li { display: flex; justify-content: space-between; padding: 4px 0; }

@media (orientation: portrait) {
  .layout { grid-template-columns: 1fr; gap: 32px; padding: 32px max(24px, env(safe-area-inset-right)) max(32px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left)); }
  .col-left, .col-right { align-items: center; }
  .stack { width: 300px; height: 300px; --r: 115px; }
}

/* page scroll is locked while a sheet is open on mobile — body is pinned at its current
   scroll offset (set by JS) so nothing jumps */
html.lock body { position: fixed; left: 0; right: 0; overflow: hidden; touch-action: none; }

/* phones in landscape: short viewport → compact ring, tighter padding, columns hug the edges */
@media (orientation: landscape) and (max-height: 520px) {
  .layout {
    grid-template-columns: auto 1fr auto; gap: 24px;
    padding: 16px max(20px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  }
  .col-center { gap: 8px; }
  .stack { width: 240px; height: 240px; --r: 88px; }
  .stack .bottle { width: 28px; height: 70px; margin: -35px 0 0 -14px; }
  .today { width: 120px; height: 120px; transform: translate(-50%, -50%) translateY(-14px); }
  .today-count { font-size: 40px; }
  .today-flavors { font-size: 12px; }
}
