/* Sip Sensei -- dark purple, pixel-art forward. */

:root {
  --surface:      #1c0f2b;   /* app + chart surface */
  --surface-2:    #261539;   /* cards */
  --surface-3:    #331f4a;   /* inputs, tracks */
  --ink:          #f3ecfa;   /* primary text */
  --ink-2:        #bfa8d4;   /* secondary text */
  --ink-3:        #8a76a3;   /* muted text, axes */
  --accent:       #a260cc;   /* brand purple */
  --accent-lt:    #c58cf0;
  --bar:          #b07ade;   /* the one series colour, validated vs --surface */
  --gold:         #e6ba4e;
  --water:        #def6ff;
  --radius:       16px;
  --safe-top:     env(safe-area-inset-top, 0px);
  --safe-bottom:  env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Several of these elements set `display: flex`, which outranks the user-agent
   `[hidden] { display: none }`. Without this they all render at once. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: radial-gradient(120% 80% at 50% 0%, #2a1642 0%, var(--surface) 60%);
  background-attachment: fixed;
  color: var(--ink);
  font: 16px/1.5 ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
  min-height: 100dvh;
  overscroll-behavior-y: contain;
}

.muted { color: var(--ink-3); }
code { background: var(--surface-3); padding: 1px 5px; border-radius: 5px; }

/* Pixel art must never be smoothed. */
img[src*="avatar"], img[src*="icon"] { image-rendering: pixelated; }

/* ---------------------------------------------------------------- screens */
.screen {
  min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 32px 28px; text-align: center;
}
.screen h1 { margin: 0; font-size: 1.6rem; letter-spacing: .2px; }
.screen p  { margin: 0; max-width: 34ch; }
.steps { text-align: left; max-width: 34ch; color: var(--ink-2); padding-left: 22px; margin: 4px 0 0; }
.steps li { margin: 8px 0; }

/* ---------------------------------------------------------------- layout */
main {
  max-width: 460px; margin: 0 auto;
  padding: calc(var(--safe-top) + 10px) 18px calc(var(--safe-bottom) + 32px);
  display: flex; flex-direction: column; gap: 18px;
}
.topbar { display: flex; align-items: center; justify-content: space-between; min-height: 34px; }
.streak { font-weight: 700; color: var(--gold); font-size: .95rem; }
.icon-btn {
  background: none; border: 0; color: var(--ink-2);
  font-size: 1.35rem; line-height: 1; padding: 6px 8px; cursor: pointer;
}
.icon-btn:active { color: var(--ink); }

/* ------------------------------------------------------------ progress ring */
.ring-wrap { position: relative; width: 232px; height: 232px; margin: 4px auto 0; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--surface-3); stroke-width: 10; }
.ring-fill {
  fill: none; stroke: var(--accent-lt); stroke-width: 10; stroke-linecap: round;
  stroke-dasharray: 553; stroke-dashoffset: 553;
  transition: stroke-dashoffset .7s cubic-bezier(.2,.8,.3,1);
  filter: drop-shadow(0 0 6px rgba(197,140,240,.45));
}
.avatar {
  position: absolute; inset: 0; margin: auto;
  width: 152px; height: 152px; display: block;
}
/* reset the ring avatar's absolute positioning, incl. the auto margins
   that would otherwise absorb all the free space in a flex column */
.avatar.lg { position: static; inset: auto; margin: 0; width: 128px; height: 128px; }
#avatar { transition: transform .3s cubic-bezier(.3,1.6,.5,1); }
#avatar.bounce { animation: bounce .55s cubic-bezier(.3,1.4,.4,1); }
@keyframes bounce {
  0%   { transform: scale(1) translateY(0); }
  35%  { transform: scale(1.09) translateY(-10px); }
  100% { transform: scale(1) translateY(0); }
}

/* ---------------------------------------------------------------- readout */
.readout { text-align: center; margin-top: -4px; }
.total { margin: 0; font-size: 2.9rem; font-weight: 800; letter-spacing: -1px; line-height: 1; }
.total .unit { font-size: 1.05rem; font-weight: 600; color: var(--ink-2); margin-left: 7px; }
.goal { margin: 6px 0 0; font-size: .92rem; }
.line { margin: 10px 0 0; color: var(--ink-2); font-size: .95rem; min-height: 1.5em; }

/* ---------------------------------------------------------------- log grid */
.log-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.log-btn {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 14px 4px 11px;
  background: var(--surface-2); color: var(--ink);
  border: 1px solid #ffffff14; border-radius: var(--radius);
  font: inherit; cursor: pointer;
  transition: transform .12s, background .12s;
}
.log-btn:active { transform: scale(.94); background: var(--surface-3); }
.log-btn .emoji { font-size: 1.45rem; line-height: 1; }
.log-btn .lbl   { font-size: .78rem; font-weight: 600; }
.log-btn .amt   { font-size: .68rem; color: var(--ink-3); }
.log-btn.snapple { background: linear-gradient(160deg, #3a1c52, #2a1440); border-color: #e6ba4e33; }

.row { display: flex; gap: 10px; }
/* scoped so it outranks the `.ghost, .primary { flex: 1 }` rule below */
.screen .wide { flex: 0 0 auto; width: 100%; max-width: 300px; padding: 14px; }
.fineprint { font-size: .75rem; margin-top: 2px; }

/* Recovery path when the first-run prompt was dismissed. */
.banner {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; padding: 11px 15px; margin: -4px 0 -2px;
  background: linear-gradient(160deg, #3a1c52, #2a1440);
  border: 1px solid #e6ba4e33; border-radius: 12px;
  color: var(--ink); font: inherit; font-size: .88rem; text-align: left;
  cursor: pointer;
}
.banner:active { transform: scale(.985); }
.banner-cta { color: var(--gold); font-weight: 700; white-space: nowrap; }
.ghost, .primary {
  flex: 1; padding: 11px 14px; border-radius: 12px; font: inherit; font-weight: 600;
  cursor: pointer; border: 1px solid #ffffff1f; background: transparent; color: var(--ink-2);
}
.primary { background: var(--accent); border-color: transparent; color: #fff; }
.ghost:active, .primary:active { transform: scale(.97); }

/* ---------------------------------------------------------------- cards */
.card {
  background: var(--surface-2); border: 1px solid #ffffff10;
  border-radius: var(--radius); padding: 16px;
}
.card-title { margin: 0 0 14px; font-size: .82rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-2); }
.card-title .muted { text-transform: none; letter-spacing: 0; font-weight: 500; }

/* ---------------------------------------------------------------- chart
   One series, one hue. "Met the goal" is carried by the dashed goal line and
   a check mark, not by a second colour -- two purples that far apart in
   lightness fail the CVD floor. */
.chart {
  position: relative;
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 2px;                       /* 2px surface gap between adjacent bars */
  height: 152px; align-items: end;
}
.bar-col { position: relative; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 5px; cursor: default; }
.bar {
  width: 68%; min-height: 3px;
  background: var(--bar);
  border-radius: 4px 4px 0 0;     /* rounded data-end, square on the baseline */
  transition: height .5s cubic-bezier(.2,.8,.3,1);
}
.bar-col.empty .bar { background: var(--surface-3); }
.bar-col.today .bar { outline: 2px solid var(--accent-lt); outline-offset: 2px; }
.bar-tick { font-size: .72rem; line-height: 1; color: var(--ink-2); min-height: 1em; }
.bar-lbl  { font-size: .68rem; color: var(--ink-3); letter-spacing: .02em; }
.goal-line {
  position: absolute; left: 0; right: 0;
  border-top: 1px dashed #ffffff40; pointer-events: none;
}
.goal-line::after {
  content: "goal"; position: absolute; left: 0; top: -14px;
  font-size: .62rem; color: var(--ink-3); letter-spacing: .04em;
}
.chart-note { margin: 12px 0 0; font-size: .7rem; }

/* ---------------------------------------------------------------- entries */
.entries { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.entries li { display: flex; align-items: center; gap: 10px; font-size: .9rem; }
.entries .when { margin-left: auto; color: var(--ink-3); font-size: .8rem; font-variant-numeric: tabular-nums; }

.footer { text-align: center; font-size: .75rem; margin: 2px 0 0; }

/* ---------------------------------------------------------------- celebrate */
.celebrate {
  position: fixed; inset: 0; z-index: 40;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; padding: 32px; text-align: center;
  background: rgba(20, 9, 32, .93); backdrop-filter: blur(6px);
  animation: fade .25s ease;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
.avatar.cheer { position: static; width: 168px; height: 168px; animation: cheer .6s cubic-bezier(.3,1.5,.4,1); }
@keyframes cheer {
  0%   { transform: scale(.5) rotate(-8deg); opacity: 0 }
  60%  { transform: scale(1.12) rotate(4deg); opacity: 1 }
  100% { transform: scale(1) rotate(0); opacity: 1 }
}
.congrats {
  margin: 0; font-weight: 800; line-height: 1.1;
  /* the o's are randomised, so the type has to shrink rather than hyphenate */
  font-size: clamp(1.25rem, 6.2vw, 2rem); letter-spacing: -.5px;
  color: var(--accent-lt); text-shadow: 0 0 24px rgba(197,140,240,.55);
  overflow-wrap: break-word; max-width: 100%;
}
.fact { margin: 0; max-width: 32ch; color: var(--ink-2); font-size: .92rem; }
.confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.confetti i {
  position: absolute; top: -14px; width: 7px; height: 12px; border-radius: 2px;
  animation: fall linear forwards;
}
@keyframes fall {
  to { transform: translateY(110vh) rotate(540deg); opacity: .1; }
}

/* ---------------------------------------------------------------- sheet */
.sheet-scrim { position: fixed; inset: 0; background: #0009; z-index: 50; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51;
  max-height: 88dvh; overflow-y: auto;
  background: var(--surface-2); border-radius: 22px 22px 0 0;
  padding: 20px 20px calc(var(--safe-bottom) + 24px);
  display: flex; flex-direction: column; gap: 15px;
  animation: rise .28s cubic-bezier(.2,.9,.3,1);
}
@keyframes rise { from { transform: translateY(100%) } to { transform: translateY(0) } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { margin: 0; font-size: 1.1rem; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; border: 0; padding: 0; margin: 0; font-size: .95rem; }
.field legend { padding: 0; font-size: .95rem; }
.input-row { display: flex; align-items: center; gap: 7px; }
.input-row em { font-style: normal; color: var(--ink-3); font-size: .85rem; }
input[type=number], select {
  background: var(--surface-3); color: var(--ink); border: 1px solid #ffffff14;
  border-radius: 10px; padding: 8px 10px; font: inherit; font-size: .95rem;
  max-width: 8.5em;
}
input[type=number] { width: 5.5em; }
.switch input { width: 22px; height: 22px; accent-color: var(--accent); }
.sheet-actions { display: flex; gap: 10px; margin-top: 4px; }
.sheet-note { font-size: .75rem; margin: 0; min-height: 1.4em; }

/* ---------------------------------------------------------------- toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 24px);
  transform: translateX(-50%);
  background: var(--surface-3); color: var(--ink);
  padding: 11px 18px; border-radius: 999px; font-size: .88rem;
  border: 1px solid #ffffff1a; z-index: 60; animation: fade .2s ease;
  max-width: 90vw; text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
