:root {
  /* Pastel daylight palette. Ink colours are deliberately deep enough to stay
     readable on the soft fills. */
  --bg-a: #fdf3fb;
  --bg-b: #eef4ff;
  --surface: #ffffff;
  --surface-2: #f5f0fc;
  --line: #ece4f6;
  --text: #4b4360;
  --muted: #9d94b3;

  --lilac: #cdb8f7;
  --pink: #ffc3dc;
  --mint: #b4ebd6;
  --peach: #ffd2b0;
  --ink-accent: #4a3a72;
  --ink-warm: #7a4a4f;
  --ink-mint: #2f7a63;

  --radius: 20px;
  --wheel-item: 44px;
  --wheel-visible: 5;

  --shadow-soft: 0 10px 26px rgba(140, 118, 180, .20);
  --shadow-card: 0 6px 20px rgba(150, 130, 190, .13);
}

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

html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: linear-gradient(165deg, var(--bg-a) 0%, var(--bg-b) 100%);
  background-attachment: fixed;
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior: none;
  min-height: 100vh;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.app, .btn, .units, .sheet__actions, .counter { -webkit-user-select: none; user-select: none; }

.app {
  max-width: 460px;
  min-height: 100%;
  margin: 0 auto;
  padding: 26px 20px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.app__head {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.app__title {
  margin: 0;
  font-size: 19px;
  letter-spacing: .01em;
  color: #7a6a99;
  font-weight: 700;
}

.install {
  border: 1px solid var(--line);
  background: var(--surface);
  color: #6f5f92;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: var(--shadow-card);
}
.install.is-hidden { display: none; }

/* ---- Counter, wrapped in the timer's progress ring ---- */
.counter {
  position: relative;
  width: min(280px, 72vw);
  aspect-ratio: 1;
  margin: 0 auto;
  display: grid;
  place-items: center;
  text-align: center;
}
.counter__value {
  font-size: clamp(70px, 24vw, 124px);
  font-weight: 300;
  line-height: 1;
  color: #5b4c7d;
  font-variant-numeric: tabular-nums;
  transition: transform .18s ease;
  grid-area: 1 / 1;
}
.counter__value.is-bumped { transform: scale(1.08); }
.counter__value { cursor: pointer; touch-action: manipulation; outline: none; }
.counter__value.is-pressing { transform: scale(.95); opacity: .8; }

/* Remaining time, tucked under the number inside the ring. */
.counter__time {
  grid-area: 1 / 1;
  pointer-events: none;
  align-self: end;
  margin-bottom: 14%;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  letter-spacing: .04em;
  color: #9184ad;
  opacity: 0;
  transition: opacity .3s ease, color .3s ease;
}
.counter.is-timing .counter__time { opacity: 1; }
.counter.is-done .counter__time { color: var(--ink-mint); }

.ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg); /* start the sweep at twelve o'clock */
  overflow: visible;
  pointer-events: none; /* decorative: never intercept the counter's long-press */
}
.ring__track {
  fill: none;
  stroke: #ffffff;
  stroke-width: 7;
  opacity: 0;
  transition: opacity .3s ease;
}
.ring__fill {
  fill: none;
  stroke: url(#ringFill);
  stroke-width: 7;
  stroke-linecap: round;
  stroke-dasharray: 100;
  stroke-dashoffset: 100;
  opacity: 0;
  transition: stroke-dashoffset .3s linear, opacity .3s ease;
}
.counter.is-timing .ring__track,
.counter.is-timing .ring__fill { opacity: 1; }
.counter.is-done .ring__fill { stroke: url(#ringDone); }

/* ---- Buttons ---- */
.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  min-height: 96px;
  transition: min-height .3s ease;
}
.controls.is-collapsed { min-height: 0; }

.btn {
  border: 0;
  font-weight: 400;
  cursor: pointer;
  display: grid;
  place-items: center;
  border-radius: 50%;
  transition: transform .12s ease, opacity .2s ease, width .2s ease, height .2s ease;
  touch-action: manipulation;
  user-select: none;
}
.btn:active { transform: scale(.94); }

.btn--plus {
  width: 96px; height: 96px;
  font-size: 46px;
  color: var(--ink-accent);
  background: linear-gradient(155deg, #e2d3ff 0%, var(--lilac) 55%, #b9e5f7 100%);
  box-shadow: var(--shadow-soft);
}
.btn--plus.is-pressing { transform: scale(.92); box-shadow: 0 5px 14px rgba(140, 118, 180, .22); }

.btn--minus {
  width: 66px; height: 66px;
  font-size: 34px;
  color: var(--ink-warm);
  background: linear-gradient(155deg, #ffe0cf 0%, var(--pink) 100%);
  box-shadow: 0 8px 20px rgba(214, 140, 168, .26);
}

/* Collapsed away entirely: min-width/min-height must be zeroed too, or the
   flex item floors at the glyph's min-content size and leaves a sliver. */
.btn.is-hidden {
  opacity: 0;
  width: 0; height: 0;
  min-width: 0; min-height: 0;
  margin: 0;
  padding: 0;
  overflow: hidden;
  visibility: hidden;
  pointer-events: none;
  box-shadow: none;
}

/* ---- The pal, and the little chase ---- */
.pal {
  position: relative;
  height: 210px;
  transition: opacity .35s ease, height .35s ease;
}
.pal.is-away { opacity: 0; height: 0; pointer-events: none; overflow: hidden; }

.pal__pos {
  position: absolute;
  left: 50%; top: 46px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: left .42s cubic-bezier(.34, 1.4, .5, 1), top .42s cubic-bezier(.34, 1.4, .5, 1);
}

.pal__stage {
  position: relative;
  border: 0;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  border-radius: 50%;
  /* A soft halo so pale animals still read against the pastel ground. */
  background: radial-gradient(circle at 50% 58%, #ffffff 0%, #fbf3ff 52%, rgba(251, 243, 255, 0) 72%);
}
.pal__svg { width: 132px; height: 132px; display: block; overflow: visible; }
.pal__stage.is-pressing .pal__svg { transform: scale(.94); transition: transform .2s ease; }

/* Caught! A quick spin-and-shrink as it scampers off. */
.pal.is-caught .pal__stage { animation: pal-scamper .42s ease-in-out; }
@keyframes pal-scamper {
  0%   { transform: scale(1) rotate(0deg); }
  40%  { transform: scale(.7) rotate(-16deg); }
  100% { transform: scale(1) rotate(0deg); }
}

.pal__shadow { fill: rgba(120, 96, 160, .16); }

.pal__wave, .pal__ear { transform-box: view-box; }
.pal__eye { transform-box: fill-box; transform-origin: center; }

.pal__bob {
  transform-box: view-box;
  transform-origin: 100px 180px;
  animation: pal-bob 3.4s ease-in-out infinite;
}
@keyframes pal-bob {
  0%, 100% { transform: translateY(0) scale(1, 1); }
  50%      { transform: translateY(-4px) scale(1.015, .985); }
}

.pal.is-blinking .pal__eye { transform: scaleY(.1); }
.pal__eye { transition: transform .09s ease; }

.pal.is-greeting .pal__wave { animation: pal-wave .5s ease-in-out 4; }
@keyframes pal-wave {
  0%, 100% { transform: rotate(0deg); }
  30%      { transform: rotate(-26deg); }
  70%      { transform: rotate(14deg); }
}

.pal.is-greeting .pal__bob { animation: pal-hop .55s ease-in-out 3; }
@keyframes pal-hop {
  0%, 100% { transform: translateY(0) scale(1, 1); }
  25%      { transform: translateY(-14px) scale(.97, 1.03); }
  60%      { transform: translateY(0) scale(1.04, .96); }
}

.pal.is-greeting .pal__ear { animation: pal-ear .6s ease-in-out 3; }
.pal.is-greeting .pal__ear--r { animation-direction: alternate-reverse; }
@keyframes pal-ear {
  0%, 100% { transform: rotate(0deg); }
  50%      { transform: rotate(-13deg); }
}

.pal__bubble {
  position: relative;
  max-width: 220px;
  margin-bottom: 6px;
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  font-size: 13px;
  color: #5f5280;
  text-align: center;
  box-shadow: var(--shadow-card);
  opacity: 0;
  transform: translateY(6px) scale(.94);
  transition: opacity .25s ease, transform .25s ease;
  pointer-events: none;
  white-space: nowrap;
}
.pal__bubble::after {
  content: '';
  position: absolute;
  left: 50%; bottom: -6px;
  width: 10px; height: 10px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  transform: translateX(-50%) rotate(45deg);
}
.pal__bubble.is-shown { opacity: 1; transform: translateY(0) scale(1); }

/* ---- Sheets ---- */
.sheet { position: fixed; inset: 0; display: grid; place-items: end center; z-index: 20; }
.sheet[hidden] { display: none; }
.sheet__backdrop { position: absolute; inset: 0; background: rgba(90, 70, 120, .28); animation: fade .18s ease; }
.sheet__panel {
  position: relative;
  width: 100%;
  max-width: 460px;
  background: var(--surface);
  border-radius: 28px 28px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 40px rgba(120, 96, 160, .18);
  animation: rise .22s cubic-bezier(.2,.8,.3,1);
}
@keyframes fade { from { opacity: 0 } }
@keyframes rise { from { transform: translateY(24px); opacity: 0 } }

.sheet__title { margin: 0 0 14px; font-size: 17px; text-align: center; font-weight: 700; color: #5b4c7d; }

.units { display: flex; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 14px; }
.units__tab {
  flex: 1; border: 0; background: transparent; color: var(--muted);
  padding: 9px 0; border-radius: 11px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.units__tab.is-active { background: linear-gradient(150deg, #e2d3ff, var(--lilac)); color: var(--ink-accent); }

.wheel {
  position: relative;
  height: calc(var(--wheel-item) * var(--wheel-visible));
  margin: 14px 0 4px;
  overflow: hidden;
}
.wheel__list {
  list-style: none; margin: 0;
  height: 100%;
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
  padding: calc(var(--wheel-item) * ((var(--wheel-visible) - 1) / 2)) 0;
  outline: none;
}
.wheel__list::-webkit-scrollbar { display: none; }
.wheel__opt {
  height: var(--wheel-item);
  scroll-snap-align: center;
  display: grid; place-items: center;
  font-size: 20px;
  color: var(--muted);
  opacity: .5;
  transform: scale(.86);
  transition: opacity .15s ease, transform .15s ease, color .15s ease;
  cursor: pointer;
}
.wheel__opt.is-near { opacity: .75; transform: scale(.93); }
.wheel__opt.is-selected { color: #5b4c7d; opacity: 1; transform: scale(1.06); font-weight: 600; }
.wheel__highlight {
  position: absolute; left: 0; right: 0; top: 50%; height: var(--wheel-item);
  transform: translateY(-50%);
  border-radius: 12px;
  background: var(--surface-2);
  pointer-events: none;
}
.wheel__fade { position: absolute; left: 0; right: 0; height: 62px; pointer-events: none; }
.wheel__fade--top { top: 0; background: linear-gradient(var(--surface), rgba(255,255,255,0)); }
.wheel__fade--bottom { bottom: 0; background: linear-gradient(rgba(255,255,255,0), var(--surface)); }

.sheet__preview { margin: 4px 0 16px; text-align: center; color: var(--muted); font-size: 13px; }

.sheet__actions { display: flex; gap: 10px; }
.btn-flat {
  flex: 1; border: 0; border-radius: 16px; padding: 14px 0;
  background: var(--surface-2); color: #6f5f92;
  font-size: 15px; font-weight: 700; cursor: pointer;
}
.btn-flat--primary {
  background: linear-gradient(150deg, #e2d3ff, var(--lilac));
  color: var(--ink-accent);
}
.btn-flat:active { transform: scale(.98); }

/* ---- Companion picker grid ---- */
.pals {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.pals__item {
  background: var(--surface-2);
  border: 2px solid transparent;
  border-radius: 18px;
  padding: 10px 6px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.pals__item svg { width: 56px; height: 56px; overflow: visible; }
.pals__item .pal__bob { animation: none; }
.pals__item.is-chosen { border-color: var(--lilac); color: #5b4c7d; background: #faf6ff; }
.pals__item:active { transform: scale(.97); }

/* ---- Small screens ---- */
@media (max-height: 700px) {
  .app { gap: 10px; padding-top: 18px; }
  .controls { min-height: 84px; }
  .btn--plus { width: 84px; height: 84px; font-size: 40px; }
  .btn--minus { width: 60px; height: 60px; font-size: 30px; }
  .counter { width: min(230px, 62vw); }
  .pal { height: 186px; }
  .pal__svg { width: 108px; height: 108px; }
  :root { --wheel-visible: 3; }
}

@media (display-mode: standalone) {
  .install { display: none; }
}

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

/* ---- The Why Gauntlet ---- */
.quiz__q {
  margin-top: 4px;
  margin-bottom: 16px;
  line-height: 1.35;
}

.quiz__choices {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.quiz__choice {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: #5f5280;
  border-radius: 14px;
  padding: 13px 16px;
  font-size: 15px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}
.quiz__choice:active { transform: scale(.99); background: var(--surface-2); }
.quiz__choice--final {
  text-align: center;
  font-weight: 700;
  border-color: transparent;
  color: var(--ink-accent);
  background: linear-gradient(150deg, #e2d3ff, var(--lilac));
}

/* ---- History ---- */
.clock {
  position: fixed;
  right: calc(16px + env(safe-area-inset-right));
  bottom: calc(16px + env(safe-area-inset-bottom));
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow-card);
  cursor: pointer;
  z-index: 10;
}
.clock svg {
  width: 21px; height: 21px;
  fill: none;
  stroke: #9b8fbb;
  stroke-width: 1.7;
  stroke-linecap: round;
}
.clock:active { transform: scale(.94); }

.log__total {
  text-align: center;
  font-size: 30px;
  font-weight: 300;
  color: #5b4c7d;
  font-variant-numeric: tabular-nums;
  margin-bottom: 4px;
}
.log__sub {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 16px;
}

.log {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  max-height: 42vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.log__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface-2);
  border-radius: 14px;
  padding: 11px 14px;
}
.log__len { font-size: 15px; font-weight: 600; color: #5f5280; }
.log__at { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.log__empty { text-align: center; color: var(--muted); font-size: 14px; padding: 10px 0 4px; }
