:root {
  --bg: #08131f;
  --bg-2: #0d1d2e;
  --line: #1d3247;
  --ink: #eaf2fa;
  --ink-dim: #8aa4bd;
  --coffee: #f0a63c;
  --joint: #7fc66a;
  --radius: 18px;
  --bar-h: 52px;
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

body { overflow: hidden; }

b, strong { font-weight: 800; }

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---- top bar ---- */

.bar {
  height: var(--bar-h);
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
}

.brand {
  font-size: 15px;
  font-weight: 900;
  letter-spacing: .22em;
}

.bar__age {
  flex: 1;
  min-width: 0;
  font-size: 11px;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar__btn {
  flex: none;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink-dim);
  border-radius: 999px;
  padding: 6px 14px;
  font: inherit;
  font-size: 12px;
  letter-spacing: .08em;
  cursor: pointer;
}

.bar__btn:active { background: var(--bg-2); }

/* ---- tiles ---- */

.tiles {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: 10px;
  padding: 0 10px;
}

@media (min-width: 720px) and (orientation: landscape) {
  .tiles { grid-template-rows: 1fr; grid-template-columns: 1fr 1fr; }
}

.tile {
  --heat: 0;
  /* the rendered artwork box, set by placeArt() so overlays can be positioned
     in source-image fractions no matter how the square art is cropped */
  --artx: 0px;
  --arty: 0px;
  --artsize: 100%;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-height: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-2);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: transform .12s ease;
}

.tile:active { transform: scale(.987); }

.tile__art { position: absolute; inset: 0; }

.tile__art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  user-select: none;
  /* goes flat and cold as time passes since the last tap */
  filter: saturate(calc(.4 + .6 * var(--heat))) brightness(calc(.7 + .3 * var(--heat)));
  transition: filter 1.5s linear;
}

.tile__art::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(4,10,17,.94) 0%, rgba(4,10,17,.72) 26%, rgba(4,10,17,.12) 58%, rgba(4,10,17,0) 100%);
}

.tile__body {
  position: relative;
  z-index: 2;
  padding: 14px 16px 16px;
}

.tile__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.tile__name {
  font-size: 12px;
  letter-spacing: .2em;
  text-transform: uppercase;
  font-weight: 700;
}

.tile--coffee .tile__name { color: var(--coffee); }
.tile--joint .tile__name { color: var(--joint); }

.tile__since {
  font-size: 11px;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
}

.tile__count {
  font-size: clamp(54px, 15vh, 92px);
  line-height: .9;
  font-weight: 800;
  letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}

.tile__count.bump { animation: bump .32s ease; }

@keyframes bump {
  0% { transform: scale(1); }
  35% { transform: scale(1.14); }
  100% { transform: scale(1); }
}

.tile__sub {
  font-size: 11px;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin-top: 2px;
}

.tile__periods {
  display: flex;
  gap: 14px;
  margin-top: 10px;
  font-size: 11px;
  color: var(--ink-dim);
  letter-spacing: .04em;
}

.tile__periods b {
  font-size: 14px;
  color: var(--ink);
  margin-right: 5px;
  font-variant-numeric: tabular-nums;
}

.tile__mine {
  margin-top: 8px;
  font-size: 11px;
  color: var(--ink-dim);
  min-height: 14px;
}

.tile__mine em { font-style: normal; color: var(--ink); }

/* tap ripple */
.tile::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 38%;
  width: 40px;
  height: 40px;
  margin: -20px 0 0 -20px;
  border-radius: 50%;
  border: 2px solid currentColor;
  opacity: 0;
  pointer-events: none;
  z-index: 3;
}

.tile--coffee::after { color: var(--coffee); }
.tile--joint::after { color: var(--joint); }
.tile.pop::after { animation: ripple .55s ease-out; }

@keyframes ripple {
  0% { opacity: .75; transform: scale(.4); }
  100% { opacity: 0; transform: scale(7); }
}

/* ---- steam over the coffee ---- */

.steam {
  position: absolute;
  left: calc(var(--artx) + 0.486 * var(--artsize));
  top: calc(var(--arty) + 0.04 * var(--artsize));
  width: calc(0.20 * var(--artsize));
  height: calc(0.27 * var(--artsize));
  margin-left: calc(-0.10 * var(--artsize));
  opacity: var(--heat);
  transition: opacity 1.5s linear;
  pointer-events: none;
}

.steam i {
  position: absolute;
  bottom: 0;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: rgba(233, 244, 255, .5);
  filter: blur(7px);
  animation: rise 3.6s ease-in infinite;
}

.steam i:nth-child(1) { left: 10%; animation-delay: 0s; }
.steam i:nth-child(2) { left: 42%; animation-delay: 1.2s; }
.steam i:nth-child(3) { left: 70%; animation-delay: 2.4s; }

@keyframes rise {
  0% { transform: translate(0, 0) scale(.6); opacity: 0; }
  25% { opacity: .9; }
  100% { transform: translate(-10px, -110px) scale(2.2); opacity: 0; }
}

/* ---- ember on the joint tip ---- */

.ember {
  position: absolute;
  left: calc(var(--artx) + 0.772 * var(--artsize));
  top: calc(var(--arty) + 0.285 * var(--artsize));
  width: calc(0.15 * var(--artsize));
  height: calc(0.15 * var(--artsize));
  margin: calc(-0.075 * var(--artsize)) 0 0 calc(-0.075 * var(--artsize));
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,150,46,.95) 0%, rgba(255,92,26,.42) 36%, rgba(255,80,20,0) 68%);
  opacity: var(--heat);
  transition: opacity 1.5s linear;
  animation: glow 2.4s ease-in-out infinite;
  pointer-events: none;
}

@keyframes glow {
  0%, 100% { transform: scale(.82); }
  50% { transform: scale(1.12); }
}

/* ---- pace strip ---- */

.pace {
  flex: none;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 2px 16px;
  padding: 8px 14px calc(8px + env(safe-area-inset-bottom));
  font-size: 12px;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.pace span { white-space: nowrap; }
.pace .up { color: var(--coffee); }
.pace .down { color: var(--ink-dim); }
.pace .who { color: var(--ink); font-weight: 700; }

/* ---- stats ---- */

.stats {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
  animation: slideup .22s ease;
}

@keyframes slideup { from { transform: translateY(16px); opacity: 0; } }

.stats[hidden] { display: none; }

.stats__scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 0 12px calc(30px + env(safe-area-inset-bottom));
}

.card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg-2);
  padding: 14px 15px;
  margin-bottom: 10px;
}

.card h2 {
  margin: 0 0 12px;
  font-size: 11px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--ink-dim);
  font-weight: 700;
}

.card .empty { color: var(--ink-dim); font-size: 13px; }

.row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 0;
  border-top: 1px solid rgba(29,50,71,.55);
  font-size: 13px;
}

.row:first-of-type { border-top: 0; }
.row__k { color: var(--ink-dim); }
.row__v { font-variant-numeric: tabular-nums; font-weight: 700; }
.row--now .row__k, .row--now .row__v { color: var(--coffee); }

.rank { display: flex; align-items: baseline; gap: 10px; }
.rank__n { width: 18px; color: var(--ink-dim); font-size: 11px; font-variant-numeric: tabular-nums; }

.tag { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; }
.tag--coffee { color: var(--coffee); }
.tag--joint { color: var(--joint); }

.big {
  display: flex;
  gap: 22px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.big div { min-width: 64px; }
.big .n { font-size: 30px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.big .l { font-size: 11px; color: var(--ink-dim); margin-top: 4px; letter-spacing: .06em; }
.big .d { font-size: 11px; margin-top: 3px; font-variant-numeric: tabular-nums; }
.big .d.up { color: var(--joint); }
.big .d.down { color: #e2735f; }

/* balance beam */
.beam {
  display: flex;
  height: 26px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg);
  margin-bottom: 8px;
}

.beam__c { background: var(--coffee); }
.beam__j { background: var(--joint); }
.beam__c, .beam__j { transition: width .4s ease; }

.beam__legend { display: flex; justify-content: space-between; font-size: 12px; }
.beam__legend .c { color: var(--coffee); }
.beam__legend .j { color: var(--joint); }

/* heatmap */
.heat { margin-bottom: 14px; }
.heat:last-child { margin-bottom: 0; }

.heat__grid {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7, auto);
  /* minmax(0, 1fr) and min-width on the cells: without both, the square cells'
     automatic minimum size makes the grid wider than the card it sits in */
  grid-auto-columns: minmax(0, 1fr);
  gap: 3px;
  margin-top: 8px;
}

.heat__cell {
  aspect-ratio: 1;
  min-width: 0;
  border-radius: 2px;
  background: rgba(29,50,71,.5);
}

.heat__cell.future { background: transparent; }

/* hours */
.hours { display: flex; align-items: flex-end; gap: 2px; height: 76px; margin-top: 6px; }
.hours__bar { flex: 1; border-radius: 2px 2px 0 0; min-height: 2px; background: rgba(29,50,71,.8); }
.hours__axis { display: flex; justify-content: space-between; font-size: 10px; color: var(--ink-dim); margin-top: 5px; font-variant-numeric: tabular-nums; }

/* footer */
.stats__foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px 0;
  font-size: 12px;
  color: var(--ink-dim);
}

.linkbtn {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--ink-dim);
  text-decoration: underline;
  cursor: pointer;
}

.sync { margin-left: auto; font-size: 11px; }
.sync.bad { color: #e2735f; }

/* ---- toast ---- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 14px;
  background: #16293c;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 9px 9px 18px;
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
  animation: slideup .18s ease;
  max-width: calc(100vw - 28px);
}

.toast[hidden] { display: none; }

.toast button {
  background: var(--ink);
  color: #0b1a29;
  border: 0;
  border-radius: 999px;
  padding: 6px 14px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

/* ---- milestone takeover ---- */

.milestone {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 45%, rgba(20,44,68,.97), rgba(4,10,17,.98));
  animation: slideup .2s ease;
}

.milestone[hidden] { display: none; }
.milestone__inner { text-align: center; animation: bump .6s ease; }

.milestone__n {
  font-size: clamp(76px, 26vw, 190px);
  font-weight: 900;
  line-height: .85;
  letter-spacing: -.04em;
  font-variant-numeric: tabular-nums;
}

.milestone__label {
  margin-top: 16px;
  font-size: 13px;
  letter-spacing: .26em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
