/* Shared base: tokens, controls, photo wells, the reference/camera pair, solo and source pages. */
:root {
  --sun: #ffd426;
  --ink: #000;
  --paper: #fff;
  --punch: #ff4d8d;
  --font: 'Roboto Condensed', 'Arial Narrow', Arial, sans-serif;
  --line: 3px solid var(--ink);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--sun); color: var(--ink); font: 500 17px/1.3 var(--font); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
h1, h2, p, figure, ol, ul { margin: 0; padding: 0; }
ol, ul { list-style: none; }
img, video, svg { display: block; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; }
a { color: inherit; }
a, button { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
::selection { background: var(--punch); }

/* One phone-width column on every screen size. */
.app { width: min(100%, 460px); min-height: 100vh; min-height: 100dvh; margin: 0 auto; padding: max(12px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 14px; }
.screen { flex: 1; display: flex; flex-direction: column; gap: 14px; min-height: 0; }

.title { font-size: 30px; font-weight: 900; line-height: 1.04; text-transform: uppercase; text-wrap: balance; overflow-wrap: anywhere; }
.title.sm { font-size: 18px; }
.hint { font-size: 16px; font-weight: 600; line-height: 1.25; color: #000000b8; }
.hint:empty { display: none; }
.center { text-align: center; }
.link { padding: 8px; border: 0; background: none; font-size: 16px; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }

/* Meme caption: white heavy capitals with a black outline. */
.cap {
  --o: 2px;
  font-weight: 900; line-height: 1; text-transform: uppercase; text-align: center; color: #fff; overflow-wrap: anywhere;
  text-shadow:
    var(--o) 0 #000, calc(var(--o) * -1) 0 #000, 0 var(--o) #000, 0 calc(var(--o) * -1) #000,
    calc(var(--o) * .71) calc(var(--o) * .71) #000, calc(var(--o) * -.71) calc(var(--o) * .71) #000,
    calc(var(--o) * .71) calc(var(--o) * -.71) #000, calc(var(--o) * -.71) calc(var(--o) * -.71) #000,
    calc(var(--o) * .92) calc(var(--o) * .38) #000, calc(var(--o) * -.92) calc(var(--o) * .38) #000,
    calc(var(--o) * .92) calc(var(--o) * -.38) #000, calc(var(--o) * -.92) calc(var(--o) * -.38) #000,
    calc(var(--o) * .38) calc(var(--o) * .92) #000, calc(var(--o) * -.38) calc(var(--o) * .92) #000,
    calc(var(--o) * .38) calc(var(--o) * -.92) #000, calc(var(--o) * -.38) calc(var(--o) * -.92) #000;
}

/* A ledge under a control means it can be pressed. */
.btn { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; min-height: 56px; padding: 0 20px; border: var(--line); border-radius: 16px; background: var(--paper); color: var(--ink); box-shadow: 0 4px 0 var(--ink); font-size: 19px; font-weight: 800; line-height: 1.1; text-transform: uppercase; text-decoration: none; text-align: center; transition: transform .06s, box-shadow .06s; }
.btn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 0 0 var(--ink); }
.btn.go { background: var(--punch); }
.btn.small { flex: none; width: auto; padding: 0 18px; }
.btn:disabled { background: transparent; border-color: #00000059; color: #00000073; box-shadow: none; }
.btn svg, .icon-btn svg { flex: none; width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn { flex: none; display: grid; place-items: center; width: 46px; height: 46px; padding: 0; border: var(--line); border-radius: 50%; background: var(--paper); color: var(--ink); box-shadow: 0 3px 0 var(--ink); transition: transform .06s, box-shadow .06s; }
.icon-btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }
.field { width: 100%; min-width: 0; min-height: 56px; padding: 0 16px; border: var(--line); border-radius: 16px; background: var(--paper); font-size: 19px; font-weight: 700; }
.field::placeholder { color: #00000073; font-weight: 600; }
.row { display: flex; gap: 10px; }
.row > .go { flex: 1; }
.stack { display: grid; gap: 12px; }
.dock { margin-top: auto; display: grid; gap: 10px; }

.toast { padding: 12px 16px; border-radius: 14px; background: var(--ink); color: #fff; font-size: 16px; font-weight: 600; line-height: 1.3; text-align: center; cursor: pointer; }

/* Top bar: leave, round pips, clock or score. */
.bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; min-height: 49px; }
.bar > :first-child { justify-self: start; }
.bar > :nth-child(3) { justify-self: end; }
.pips { display: flex; align-items: center; gap: 6px; }
.pips li { width: 14px; height: 14px; border: var(--line); border-radius: 7px; }
.pips .done { background: var(--ink); }
.pips .now, .pips .current { width: 30px; background: var(--paper); }
.clock { display: grid; place-items: center; min-width: 60px; height: 46px; padding: 0 12px; border: var(--line); border-radius: 23px; background: var(--paper); font-size: 26px; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.clock.low { background: var(--punch); animation: beat .5s ease-in-out infinite alternate; }

/* The meme above, the player's camera below. The camera takes the height that is left. */
.duel { flex: 1; display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.well { position: relative; overflow: hidden; border: var(--line); border-radius: 20px; background: var(--ink); }
.well > img, .well > video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.well .cap, .shot .cap { position: absolute; left: 10px; right: 10px; font-size: 22px; pointer-events: none; }
.cap.top { top: 10px; }
.cap.bottom { bottom: 10px; }
.ref { flex: none; width: 100%; aspect-ratio: 3 / 2; max-height: 30vh; max-height: 30dvh; }
/* A pixel flex-basis is required: with a percentage basis Chrome resolves cqh to 0 here. */
.cam-fit { flex: 1 1 190px; display: grid; place-items: start center; min-height: 190px; container-type: size; }
.cam { width: 100%; aspect-ratio: 1; }
@supports (width: 1cqh) { .cam { width: min(100cqw, 100cqh); } }
.cam > img, .cam > video { object-fit: cover; }
.cam > video { transform: scaleX(-1); }
.cam > video.unmirrored { transform: none; }
.cam-empty { position: absolute; inset: 0; display: grid; place-items: center; color: #ffffff80; }
.cam-empty svg { width: 76px; height: 76px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.cam.flash::after { content: ''; position: absolute; inset: 0; background: #fff; pointer-events: none; animation: flash .4s ease-out forwards; }
.cam .icon-btn { position: absolute; z-index: 3; right: 10px; }

/* Pink sticker for the winner and the solo total. */
.trophy { display: grid; gap: 8px; margin: 10px 6px 6px; padding: 26px 16px; border: var(--line); border-radius: 24px; background: var(--punch); box-shadow: 6px 6px 0 var(--ink); text-align: center; transform: rotate(-1.5deg); animation: pop .5s cubic-bezier(.2, 1.4, .4, 1) both; }
.trophy .cap { --o: 3px; font-size: clamp(34px, 11vw, 50px); }
.trophy .hint { color: var(--ink); }

/* Solo: the meme and the camera share the height. Swipe the meme to change it. */
.solo .ref { flex: 1 1 190px; aspect-ratio: auto; max-height: none; min-height: 160px; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.solo .ref img { -webkit-user-drag: none; pointer-events: none; }
.solo .ref .cap { bottom: 12px; }
.swipe-btn { position: absolute; z-index: 3; top: 50%; margin-top: -23px; }
#prev-meme { left: 10px; }
#next-meme { right: 10px; }
.from-right { animation: from-right .22s ease-out; }
.from-left { animation: from-left .22s ease-out; }
@keyframes from-right { from { opacity: 0; transform: translateX(30%); } }
@keyframes from-left { from { opacity: 0; transform: translateX(-30%); } }
#stop-camera { top: 10px; }
#flip-camera { bottom: 10px; }
#face-guides { position: absolute; inset: 10% 20%; border: 3px dashed #ffffffb3; border-radius: 50%; pointer-events: none; }
#face-guides.detected { border: 4px solid var(--punch); }
.count { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.count .cap { position: static; --o: 5px; font-size: 130px; }
.count.tick .cap { animation: tick .45s cubic-bezier(.2, 1.4, .4, 1); }
.score-box { position: absolute; left: 10px; right: 10px; bottom: 10px; display: grid; gap: 6px; pointer-events: none; }
.score-box .cap { position: static; }
#round-score { --o: 4px; font-size: 68px; }
#round-score span { font-size: 24px; }
.bars { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; }
.score-item > div:first-child { display: flex; justify-content: space-between; margin-bottom: 4px; font-size: 15px; font-weight: 700; }
.score-bar { height: 11px; overflow: hidden; border: 2px solid var(--ink); border-radius: 6px; background: var(--paper); }
.score-bar span { display: block; height: 100%; background: var(--punch); }
#status.error { padding: 10px 14px; border-radius: 14px; background: var(--ink); color: #fff; }
.rounds { display: grid; gap: 8px; }
.rounds li { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 7px 14px 7px 7px; border: var(--line); border-radius: 16px; background: var(--paper); }
.round-result-pair { display: flex; gap: 4px; }
.round-result-pair img { width: 50px; height: 50px; object-fit: cover; border-radius: 9px; }
.rounds p { overflow: hidden; font-weight: 700; white-space: nowrap; text-overflow: ellipsis; }
.rounds strong { font-size: 26px; font-weight: 900; font-variant-numeric: tabular-nums; }
.rounds strong span { font-size: 14px; font-weight: 700; }
.app:has(#summary:not([hidden])) :is(.duel, #result-details) { display: none; }

/* Source list */
.sources-page { width: min(100%, 720px); margin: 0 auto; padding: max(12px, env(safe-area-inset-top)) 16px 48px; line-height: 1.5; }
.sources-page p { margin: 12px 0; }
.sources-page ol { margin: 0; padding-left: 24px; list-style: decimal; }
.sources-page li { margin: 10px 0; }
.sources-page a { font-weight: 700; text-underline-offset: 3px; }

@keyframes beat { to { transform: scale(1.12); } }
@keyframes flash { to { opacity: 0; } }
@keyframes tick { from { transform: scale(1.5); } }
@keyframes pop { from { opacity: 0; transform: rotate(-9deg) scale(.6); } }
@media (max-width: 340px) {
  .app { padding-left: 12px; padding-right: 12px; }
  .title { font-size: 26px; }
  .btn { font-size: 17px; padding: 0 14px; }
  .btn.small { padding: 0 14px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
