:root {
  color-scheme: light;
  --page: #f6f4ef;
  --surface: #fffdf9;
  --ink: #1b1a17;
  --ink-2: #57544c;
  --muted: #8d897e;
  --ring: rgba(27, 26, 23, 0.12);
  --glass: rgba(27, 26, 23, 0.55);
  --glass-fill: rgba(27, 26, 23, 0.03);
  --wood: #8a5a33;
  --good: #1f9d55;
  --ok: #d39a00;
  --meh: #e5772e;
  --bad: #d23f3f;
  --button: #1b1a17;
  --button-ink: #fffdf9;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #121210;
    --surface: #1c1b19;
    --ink: #f2f0ea;
    --ink-2: #c6c2b8;
    --muted: #8d897e;
    --ring: rgba(255, 255, 255, 0.12);
    --glass: rgba(242, 240, 234, 0.6);
    --glass-fill: rgba(242, 240, 234, 0.04);
    --wood: #6e4526;
    --button: #f2f0ea;
    --button-ink: #121210;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 16px/1.5 "Petrov Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}
main {
  max-width: 560px;
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 16px max(32px, env(safe-area-inset-bottom));
}
button { font: inherit; cursor: pointer; }
/* Mobile browsers paint a highlight box over a pressed button, which stays
   up for the whole of a held pour; the glasses and taps show their own state. */
button, .glass, .tap { -webkit-tap-highlight-color: transparent; }

header { display: flex; justify-content: space-between; align-items: flex-start; }
h1 { font-size: 34px; line-height: 1; margin: 0; letter-spacing: -0.03em; font-weight: 800; }
.sub { margin: 6px 0 0; color: var(--ink-2); font-size: 14px; }
.icon {
  width: 36px; height: 36px; border-radius: 50%; border: 0;
  background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--ring); font-weight: 700;
}

.timer { margin: 28px 0 8px; text-align: center; position: relative; }
/* Done sits beside the clock so it never needs a scroll past the glasses. */
.timer #done { position: absolute; right: 0; top: 8px; }
.clock { font-size: 56px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.clock small { font-size: 22px; color: var(--muted); margin-left: 2px; font-weight: 600; }
.timer.low .clock { color: var(--bad); }
.track { height: 6px; border-radius: 3px; background: var(--ring); margin: 14px auto 0; max-width: 320px; overflow: hidden; }
.track .fill { height: 100%; width: 100%; background: var(--ink); border-radius: 3px; transform-origin: left; }
.timer.low .track .fill { background: var(--bad); }
.hint { color: var(--ink-2); font-size: 14px; margin: 12px 0 0; min-height: 21px; }
.hint.ready { color: var(--ink); font-weight: 700; font-size: 16px; }

/* The patron and their order */
.bar-scene { display: flex; align-items: center; gap: 12px; margin: 20px 0 0; min-height: 150px; }
.patron { margin: 0; flex: none; text-align: center; animation: walk-in 0.7s cubic-bezier(0.2, 0.8, 0.3, 1) both; }
.patron pre { margin: 0; font: 13px/1.15 ui-monospace, "SF Mono", Menlo, Consolas, monospace; color: var(--ink); }
.patron figcaption { color: var(--muted); font-size: 12px; margin-top: 4px; }
.bubble {
  position: relative; flex: 1; background: var(--surface); border-radius: 16px; padding: 14px 16px;
  box-shadow: 0 0 0 1px var(--ring); animation: pop 0.35s 0.55s cubic-bezier(0.2, 0.9, 0.3, 1.3) both;
}
.bubble::before {
  content: ""; position: absolute; left: -8px; top: 50%; width: 16px; height: 16px; margin-top: -8px;
  background: var(--surface); box-shadow: -1px 1px 0 0 var(--ring); transform: rotate(45deg);
}
.bubble p { margin: 0; font-size: 17px; font-weight: 600; position: relative; min-height: 3em; }
.bubble.typing p::after {
  content: ""; display: inline-block; width: 2px; height: 1.1em; margin-left: 2px; vertical-align: -0.15em;
  background: var(--ink); animation: caret 0.8s steps(1) infinite;
}
@keyframes caret { 50% { opacity: 0; } }
@keyframes walk-in { from { transform: translateX(80px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes pop { from { transform: scale(0.85); opacity: 0; } to { transform: none; opacity: 1; } }

/* Taps */
.taps { display: flex; justify-content: center; gap: clamp(6px, 3vw, 20px); margin: 4px 0 0; }
.tap {
  touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  flex: 0 1 64px; display: flex; flex-direction: column; align-items: center; gap: 4px;
  border: 0; background: none; padding: 4px 0; color: inherit; border-radius: 12px;
  animation: rise 0.45s calc(0.9s + var(--delay, 0ms)) cubic-bezier(0.2, 0.8, 0.3, 1) both;
}
.tap svg { width: 100%; max-width: 54px; height: auto; display: block; overflow: visible; }
.tap .tap-body { fill: #b9b6ad; stroke: #8d897e; stroke-width: 1.5; }
.tap .handle { transform-origin: 30px 96px; transition: transform 0.15s; }
.tap .handle-face { stroke: rgba(0, 0, 0, 0.25); stroke-width: 1.5; }
.tap text { font-family: "Petrov Sans", system-ui, -apple-system, "Segoe UI", sans-serif; font-weight: 800; letter-spacing: 0.04em; }
.tap .mini path { fill: none; stroke: var(--ink-2); stroke-width: 7; }
.tap .name { font-size: 11px; color: var(--ink-2); line-height: 1.2; text-align: center; min-height: 26px; }
.tap.selected { background: var(--surface); box-shadow: 0 0 0 2px var(--ink); }
.tap.selected .handle { transform: rotate(-16deg); }
.tap:not([disabled]):hover .handle-face { filter: brightness(1.08); }
.tap:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.tap[disabled] { cursor: default; opacity: 0.6; }
.taps.nudge { animation: nudge 0.35s; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes nudge { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* Glasses */
.glasses {
  --gap: clamp(2px, 1.5vw, 12px);
  display: flex; justify-content: center; align-items: flex-start; gap: var(--gap);
  margin: 12px 0 8px; padding-bottom: 6px; position: relative;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.glass {
  flex: 0 1 92px; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 6px;
  border: 0; background: none; padding: 0; color: inherit; touch-action: none; outline: none;
}
/* Once the round's over, a finger on a glass scrolls the page like anywhere else. */
.glass[disabled] { touch-action: auto; }
/* Each glass's wood strip reaches into the gaps either side, so the bar top
   runs unbroken under all of them. */
.glass svg {
  width: 100%; height: auto; display: block; overflow: visible; box-sizing: content-box;
  padding: 0 calc(var(--gap) / 2); margin: 0 calc(var(--gap) / -2); border-bottom: 8px solid var(--wood);
}

.glass .outline { fill: var(--glass-fill); stroke: var(--glass); stroke-width: 2.5; stroke-linejoin: round; }
.glass .facets { fill: none; stroke: var(--glass); stroke-width: 1; opacity: 0.5; }
.glass .stand { fill: none; stroke: var(--wood); stroke-width: 5; stroke-linecap: round; }
.glass .stream { opacity: 0; transition: opacity 80ms; }
.glass.pouring .stream { opacity: 1; }
.glass .drip { opacity: 0; }
.glass.overflowing .drip { animation: drip 1.1s ease-in infinite; }
.glass.overflowing .drip + .drip { animation-delay: 0.5s; }
.glass.spilled .outline { stroke: var(--bad); }
.glass:not([disabled]):hover .outline { stroke: var(--ink); }
.glass:focus-visible .outline { stroke: var(--ink); stroke-width: 3.5; }
.glass[disabled] { cursor: default; }
@keyframes drip { from { transform: translateY(0); opacity: 1; } to { transform: translateY(40px); opacity: 0; } }

.glass .key, .tap .key {
  font-size: 13px; font-weight: 700; color: var(--ink-2); min-width: 26px; height: 26px; line-height: 24px;
  border-radius: 6px; box-shadow: 0 0 0 1px var(--ring); background: var(--surface); text-align: center;
}
.glass .out { text-align: center; line-height: 1.2; min-height: 34px; }
.glass .pct, .glass .beer-name { display: block; font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.glass .beer-name { color: var(--muted); font-size: 11px; }
.glass .pts { display: block; font-weight: 700; font-variant-numeric: tabular-nums; }
.glass .pts.good { color: var(--good); }
.glass .pts.ok { color: var(--ok); }
.glass .pts.meh { color: var(--meh); }
.glass .pts.bad { color: var(--bad); }

body.served .patron, body.served .bubble, body.served .tap { animation: none; }
@media (max-width: 480px) {
  .bar-scene { gap: 8px; }
  .patron pre { font-size: 10px; }
  .bubble p { font-size: 15px; }
  .tap .name { display: none; }
  main { padding-top: max(14px, env(safe-area-inset-top)); }
  h1 { font-size: 28px; }
  .sub { margin-top: 4px; font-size: 13px; }
  .bar-scene { margin-top: 10px; min-height: 0; }
  .patron pre { font-size: 9px; }
  .bubble { padding: 10px 14px; }
  .timer { margin: 12px 0 4px; }
  .clock { font-size: 44px; }
  .clock small { font-size: 18px; }
  .track { margin-top: 10px; }
  .hint { margin-top: 8px; }
  .timer #done { top: 2px; padding: 8px 18px; }
  .glasses { margin-top: 4px; }
  .glass .out:empty { display: none; }
}
/* Touch screens have no keyboard to press 1–5 or Q–T on. */
@media (hover: none) and (pointer: coarse) {
  .glass .key, .tap .key { display: none; }
}

.primary, .secondary {
  border: 0; border-radius: 999px; padding: 10px 24px; font-weight: 700;
}
.primary { background: var(--button); color: var(--button-ink); }
.secondary { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--ring); }

.result {
  background: var(--surface); border-radius: 18px; box-shadow: 0 0 0 1px var(--ring);
  padding: 24px 20px; text-align: center; margin-top: 8px;
}
.score { font-size: 52px; font-weight: 800; margin: 0; line-height: 1; letter-spacing: -0.02em; }
.score small { font-size: 20px; color: var(--muted); font-weight: 600; }
.squares { font-size: 28px; letter-spacing: 4px; margin: 12px 0 4px; }
.verdict { color: var(--ink-2); margin: 0 0 16px; }
.toast { color: var(--ink-2); font-size: 14px; min-height: 21px; margin: 8px 0 0; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 16px 0 0; }
.stats div { padding: 8px 0; }
.stats dt { color: var(--muted); font-size: 12px; }
.stats dd { margin: 0; font-size: 20px; font-weight: 700; }
.next { color: var(--muted); font-size: 14px; margin: 12px 0 0; }
.next span { font-variant-numeric: tabular-nums; color: var(--ink-2); }

dialog {
  border: 0; border-radius: 18px; padding: 24px; max-width: min(440px, calc(100vw - 32px));
  background: var(--surface); color: var(--ink); box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
dialog h2 { margin: 0 0 8px; font-size: 22px; }
dialog ol { padding-left: 20px; margin: 0 0 20px; color: var(--ink-2); }
dialog li { margin-bottom: 8px; }
dialog strong { color: var(--ink); }
dialog form { text-align: right; }

@media (prefers-reduced-motion: reduce) {
  .glass.overflowing .drip, .patron, .bubble, .tap, .taps.nudge { animation: none; }
  .glass.overflowing .drip { opacity: 1; transform: translateY(8px); }
}
