/* ==========================================================================
   beer counter
   Sections: fonts, tokens, base, layout, coaster, fix buttons, unit pills,
             sheets (dialogs), utilities, motion preferences.
   ========================================================================== */

/* --- fonts ---------------------------------------------------------------
   Baloo 2 is a variable font, so one file covers every weight we use.
   Self-hosted on purpose: the app has to look right with no network.
   ----------------------------------------------------------------------- */
@font-face {
  font-family: "Baloo 2";
  src: url("fonts/baloo2-latin.woff2") format("woff2");
  font-weight: 400 800;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Baloo 2";
  src: url("fonts/baloo2-latin-ext.woff2") format("woff2");
  font-weight: 400 800;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* --- tokens --------------------------------------------------------------
   Light values live on :root; the dark block below redefines the same names
   so nothing else in the file needs to know which theme is active.
   ----------------------------------------------------------------------- */
:root {
  color-scheme: light dark;

  --bg: #edeafa;
  --bg-glow: #f8f5ff;
  --surface: #ffffff;
  --ink: #463c5e;
  --ink-soft: #7e73a0;
  --ring: rgba(70, 60, 94, 0.16);

  --coaster-light: #fff4d2;
  --coaster: #ffe4a3;
  --coaster-deep: #f0c87a;
  --coaster-soft: #fff6e2;
  --coaster-ink: #6d5018;

  --mint: #c6ead8;
  --mint-edge: #9fd7bd;
  --mint-ink: #2c6d51;

  --blush: #f9ccd8;
  --blush-edge: #eeaabd;
  --blush-ink: #8d3f58;

  --foam: #ffffff;
  --shadow-soft: 0 8px 20px rgba(70, 60, 94, 0.12);
  --shadow-lift: 0 14px 30px rgba(70, 60, 94, 0.18);

  --radius-button: 1.25rem;
  --radius-sheet: 1.75rem;

  --font: "Baloo 2", "Trebuchet MS", system-ui, sans-serif;
  --font-emoji: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #221d31;
    --bg-glow: #2e2744;
    --surface: #312a47;
    --ink: #f3eefc;
    --ink-soft: #a99cca;
    --ring: rgba(243, 238, 252, 0.18);

    --coaster-light: #e9cd8a;
    --coaster: #d8b86f;
    --coaster-deep: #b9975a;
    --coaster-soft: #3c3353;
    --coaster-ink: #38260a;

    --mint: #2f5c4a;
    --mint-edge: #437c66;
    --mint-ink: #bfe9d5;

    --blush: #5d3344;
    --blush-edge: #7e4760;
    --blush-ink: #f6c8d7;

    --foam: #fdf9ff;
    --shadow-soft: 0 8px 20px rgba(10, 6, 20, 0.45);
    --shadow-lift: 0 14px 30px rgba(10, 6, 20, 0.55);
  }
}

/* --- base --------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Our own classes set `display`, so `hidden` needs to win over them. */
[hidden] {
  display: none !important;
}

html {
  font-size: 17px;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  background:
    radial-gradient(120% 70% at 50% -10%, var(--bg-glow), transparent 70%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-weight: 500;
  line-height: 1.45;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  /* Rapid tapping should never select text, zoom, or flash a grey box. */
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}

/* --- layout ------------------------------------------------------------- */
.app {
  width: 100%;
  max-width: 28rem;
  margin-inline: auto;
  padding:
    calc(0.75rem + env(safe-area-inset-top))
    calc(1.25rem + env(safe-area-inset-right))
    calc(1.25rem + env(safe-area-inset-bottom))
    calc(1.25rem + env(safe-area-inset-left));
  display: grid;
  /* topbar, the part you aim at, drink types. */
  grid-template-rows: auto 1fr auto;
  gap: 1.25rem;
}

/* Coaster and fix buttons move as one block, centred in whatever is left. */
.play {
  display: grid;
  align-content: center;
  gap: 1.75rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.wordmark {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--ink-soft);
}

.icon-button {
  width: 2.75rem;
  height: 2.75rem;
  display: grid;
  place-items: center;
  border: 2px solid var(--ring);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink-soft);
  box-shadow: var(--shadow-soft);
}

.icon-button svg {
  width: 1.5rem;
  height: 1.5rem;
  fill: currentColor;
}

.icon-button--danger {
  width: 2.25rem;
  height: 2.25rem;
  border-color: transparent;
  background: transparent;
  box-shadow: none;
  color: var(--ink-soft);
}

.icon-button--danger:hover {
  color: var(--blush-ink);
  background: var(--blush);
}

.icon-button--danger svg {
  width: 1.25rem;
  height: 1.25rem;
  fill: none;
}

/* --- the coaster: the one thing you are meant to hit -------------------- */
.stage {
  position: relative;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 1rem;
}

.coaster {
  position: relative;
  width: min(82vw, 46vh, 21rem);
  aspect-ratio: 1;
  padding: 0;
  border: none;
  border-radius: 50%;
  display: grid;
  place-content: center;
  gap: 0.15rem;
  color: var(--coaster-ink);
  background: radial-gradient(
    circle at 50% 28%,
    var(--coaster-light),
    var(--coaster) 58%,
    var(--coaster-deep)
  );
  box-shadow: var(--shadow-lift), inset 0 -4px 0 rgba(109, 80, 24, 0.12);
  transition: transform 120ms ease-out;
  /* Sizes the count in cqw units below, so it tracks the circle exactly. */
  container-type: inline-size;
}

.coaster::after {
  /* The printed ring on a paper beer mat. */
  content: "";
  position: absolute;
  inset: 7%;
  border: 3px dashed currentColor;
  border-radius: 50%;
  opacity: 0.25;
}

.coaster:active {
  transform: scale(0.96);
}

.coaster__count {
  font-size: 38cqw;
  font-weight: 800;
  line-height: 0.95;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

/* Keep long counts inside the circle. */
.coaster[data-digits="3"] .coaster__count {
  font-size: 30cqw;
}

.coaster[data-digits="4"] .coaster__count {
  font-size: 22cqw;
}

.coaster__unit {
  font-size: 9cqw;
  font-weight: 700;
  opacity: 0.72;
}

.coaster__count--bump {
  animation: bump 260ms ease-out;
}

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

.hint {
  margin: 0;
  min-height: 1.45em;
  font-size: 0.9375rem;
  color: var(--ink-soft);
}

/* Bubbles rise out of the coaster on every tap.
   JS varies --drift, --size and --rise so they never move in lockstep. */
.bubble {
  position: absolute;
  top: 56%;
  left: 50%;
  width: var(--size, 0.75rem);
  height: var(--size, 0.75rem);
  border-radius: 50%;
  background: var(--foam);
  border: 2px solid var(--coaster-deep);
  opacity: 0;
  pointer-events: none;
  animation: float-up var(--rise, 900ms) ease-out forwards;
}

@keyframes float-up {
  0% {
    transform: translate(-50%, 0) scale(0.4);
    opacity: 0.95;
  }
  100% {
    transform: translate(calc(-50% + var(--drift, 0px)), -16rem) scale(1.15);
    opacity: 0;
  }
}

/* --- the quiet fix buttons ---------------------------------------------- */
.fix {
  display: flex;
  /* Wide apart on purpose: a wobbly thumb should not hit the wrong one. */
  justify-content: space-evenly;
  gap: 3rem;
}

.fix__button {
  min-width: 4.75rem;
  min-height: 3.25rem;
  border-radius: var(--radius-button);
  border: 2px solid;
  font-size: 1.1875rem;
  font-weight: 700;
  transition: transform 120ms ease-out;
}

.fix__button:active {
  transform: scale(0.94);
}

.fix__button:disabled {
  cursor: default;
  opacity: 0.4;
}

.fix__button--down {
  background: var(--blush);
  border-color: var(--blush-edge);
  color: var(--blush-ink);
}

.fix__button--up {
  background: var(--mint);
  border-color: var(--mint-edge);
  color: var(--mint-ink);
}

/* --- unit pills --------------------------------------------------------- */
.units {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.25rem;
  overflow-x: auto;
  scrollbar-width: none;
}

.units::-webkit-scrollbar {
  display: none;
}

.pill {
  flex: 0 0 auto;
  min-width: 3.5rem;
  min-height: 3.5rem;
  display: grid;
  place-items: center;
  gap: 0.05rem;
  border: 2px solid var(--ring);
  border-radius: var(--radius-button);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  transition: transform 120ms ease-out;
}

.pill:active {
  transform: scale(0.94);
}

.pill[aria-pressed="true"] {
  border-color: var(--coaster-deep);
  background: var(--coaster-soft);
}

.pill__emoji {
  font-family: var(--font-emoji);
  font-size: 1.25rem;
  line-height: 1.1;
}

.pill__count {
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--ink-soft);
}

.pill[aria-pressed="true"] .pill__count {
  color: var(--ink);
}

.pill--add {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--ink-soft);
  border-style: dashed;
  background: transparent;
  box-shadow: none;
}

/* --- sheets (both dialogs) ---------------------------------------------- */
.sheet {
  width: 100%;
  max-width: 26rem;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--ink);
  /* Sits at the bottom of the screen, inside thumb reach. */
  margin: auto auto 0;
}

.sheet::backdrop {
  background: rgba(34, 29, 49, 0.55);
}

.sheet__body {
  display: grid;
  gap: 1.25rem;
  padding: 1.5rem 1.25rem calc(1.5rem + env(safe-area-inset-bottom));
  border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  background: var(--surface);
  box-shadow: var(--shadow-lift);
}

.sheet[open] .sheet__body {
  animation: sheet-in 220ms ease-out;
}

@keyframes sheet-in {
  from { transform: translateY(1.5rem); }
  to { transform: translateY(0); }
}

@media (min-width: 30rem) {
  .sheet {
    margin: auto;
  }

  .sheet__body {
    border-radius: var(--radius-sheet);
  }
}

.sheet__title {
  margin: 0;
  font-size: 1.375rem;
  font-weight: 700;
}

.sheet__foot {
  margin: 0;
  font-size: 0.875rem;
  color: var(--ink-soft);
}

.sheet__actions {
  display: flex;
  gap: 0.75rem;
  margin: 0;
  padding: 0;
}

.sheet__actions > .button {
  flex: 1;
}

.button {
  min-height: 3rem;
  padding-inline: 1.25rem;
  border: 2px solid var(--ring);
  border-radius: var(--radius-button);
  background: var(--surface);
  font-weight: 700;
}

.button--primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--surface);
}

/* Destructive, so it looks like a button rather than a line of text, but
   stays quieter than the primary action next to it. */
.button--quiet {
  border-color: var(--blush-edge);
  background: transparent;
  color: var(--blush-ink);
}

.button--danger {
  background: var(--blush);
  border-color: var(--blush-edge);
  color: var(--blush-ink);
}

/* --- form bits inside the sheets ---------------------------------------- */
.field {
  display: grid;
  gap: 0.375rem;
}

.field__label {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--ink-soft);
}

.field__input {
  min-height: 3.25rem;
  padding-inline: 1rem;
  border: 2px solid var(--ring);
  border-radius: var(--radius-button);
  background: var(--bg);
  color: inherit;
  font: inherit;
  font-size: 1.125rem;
}

.picker {
  margin: 0;
  padding: 0;
  border: none;
  display: grid;
  gap: 0.5rem;
}

.picker__options {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
}

.picker__option {
  position: relative;
  display: grid;
}

.picker__option input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.picker__option > span[aria-hidden] {
  min-height: 3rem;
  display: grid;
  place-items: center;
  border: 2px solid var(--ring);
  border-radius: var(--radius-button);
  background: var(--bg);
  font-family: var(--font-emoji);
  font-size: 1.375rem;
  cursor: pointer;
}

.picker__option input:checked + span {
  border-color: var(--coaster-deep);
  background: var(--coaster-soft);
}

.picker__option input:focus-visible + span {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}

/* --- unit list in settings ---------------------------------------------- */
.unit-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.25rem;
}

.unit-list__row {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 0.75rem;
  padding: 0.375rem 0.25rem;
}

.unit-list__row + .unit-list__row {
  border-top: 1px solid var(--ring);
}

.unit-list__emoji {
  font-family: var(--font-emoji);
  font-size: 1.25rem;
}

.unit-list__count {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
}

.danger {
  display: grid;
  gap: 0.75rem;
}

.danger__confirm {
  display: grid;
  gap: 0.75rem;
  padding: 1rem;
  border-radius: var(--radius-button);
  background: var(--bg);
}

.danger__text {
  margin: 0;
  font-size: 0.9375rem;
  color: var(--ink-soft);
}

.danger__actions {
  display: flex;
  gap: 0.75rem;
}

.danger__actions > .button {
  flex: 1;
}

/* --- utilities ---------------------------------------------------------- */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* --- motion preferences ------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
