/* Laid out like Monkeytype, on the host's flat pine green. No gradients, nothing 3D: every surface is one
   flat colour. Accent: neon green marks "where you are" (caret, timer, chosen setting, your score), the way
   Monkeytype uses its main colour. Right letters pastel green, wrong ones red, as the host asked.
   Typefaces, all chosen by the host: Goozette (title), Roboto Mono (the words, numbers and board, as on
   Monkeytype), Server Mono (labels and the gold bar's stamp), Meyrin (the roasts). Each face ships one
   weight, so nothing here asks for bold. */
@font-face { font-family: 'Goozette'; src: url(fonts/goozette.woff2) format('woff2'); font-display: block; }
@font-face { font-family: 'Server Mono'; src: url(fonts/server-mono.woff2) format('woff2'); font-display: swap; }
@font-face { font-family: 'Meyrin'; src: url(fonts/meyrin.woff2) format('woff2'); font-display: swap; }

:root {
  --bg: #022f28;
  --panel: #0a3b33;
  --panel-up: #0f463d;
  --text: #e9f3ee;
  --sub: #6f9d8f;    /* 4.8:1 on the background: untyped letters, labels */
  --label: #8fb8aa;  /* 5.7:1 on panels */
  --ok: #cdf7d8;
  --bad: #f0587a;    /* wrong letters, which are always large text */
  --extra: #d9577a;
  --warn: #ff7d97;   /* small red text, 6:1 */
  --neon: #3bff8a;
  --title: 'Goozette', 'Arial Black', sans-serif;
  --type: 'Roboto Mono', ui-monospace, Menlo, Consolas, monospace;
  --ui: 'Server Mono', ui-monospace, Menlo, Consolas, monospace;
  --roast: 'Meyrin', 'Comic Sans MS', 'Marker Felt', cursive;
  --words: clamp(24px, 2vw, 32px);
  --u: clamp(26px, 2.1vw, 31px);
  --kgap: 4px;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--bg); -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
body { margin: 0; min-height: 100vh; min-height: 100dvh; font-family: var(--ui); color: var(--text); background: var(--bg); overflow-x: hidden; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--neon); outline-offset: 3px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* Squircle corners (between a square and a round corner) on the panels, keys and the name box. Browsers
   without corner-shape (Safari, Firefox) get plain rounded corners. A squircle reads smaller than a round
   corner of the same radius, so the radius grows with it. */
.config, .key, #name, .caps-chip, kbd, .suggest, .row, .slowest, .face { --r: 8px; border-radius: var(--r); }
@supports (corner-shape: squircle) {
  .config, .key, #name, .caps-chip, kbd, .suggest, .row, .slowest, .face { corner-shape: squircle; border-radius: calc(var(--r) * 1.9); }
}
kbd { --r: 4px; font: 11px var(--ui); padding: 2px 6px 3px; background: var(--panel); color: var(--label); }

/* ---------- frame ---------- */
/* letters in random fonts shed by the mouse, behind everything */
.trail { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; }
.app {
  position: relative; z-index: 1;
  min-height: 100vh; min-height: 100dvh;
  display: grid; grid-template-rows: auto 1fr auto;
  padding: 28px clamp(24px, 5vw, 80px) 18px;
}
.top, .config, .lang, .foot, .board { transition: opacity .3s; }
.logo {
  margin: 0; font: 400 34px/1 var(--title); letter-spacing: .02em; text-transform: uppercase;
  color: var(--text); user-select: none;
}
/* the whole title is a link back to a fresh test; "23" is twice the size, centred on the words beside it */
.home { display: inline-flex; align-items: center; color: inherit; text-decoration: none; }
/* "23" is drawn on a canvas as a grid of tiny cells, each cycling through colours on its own. The real
   digits stay underneath (transparent) for layout and screen readers, and show plainly if the canvas can't. */
.disco { position: relative; top: -.045em; display: inline-block; margin: 0 .17em 0 .09em; font-size: 2em; } /* top: measured so the digits' ink centres on the letters */
.disco.on { color: transparent; }
.disco canvas { position: absolute; left: 0; top: 0; width: 0; height: 0; pointer-events: none; }

.foot { text-align: center; font-size: 12px; color: var(--sub); padding-top: 8px; }

/* While typing, everything but the words steps back (moving the mouse brings it back). */
.focus .top, .focus .config, .focus .lang, .focus .foot { opacity: 0; }
.focus .board { opacity: .12; }
.focus .config:focus-within { opacity: 1; }

/* ---------- settings bar ---------- */
.stage {
  width: 100%; max-width: 1240px; margin: 0 auto;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 8px 0 56px;
}
.config { display: flex; align-items: center; height: 40px; padding: 0 8px; margin-bottom: 6px; background: var(--panel); font-size: 13px; }
.done .config { visibility: hidden; }
.opt {
  display: inline-flex; align-items: center; gap: 6px; height: 100%; padding: 0 9px;
  border: 0; background: none; color: var(--label); transition: color .15s;
}
.opt:hover { color: var(--text); }
.opt[aria-pressed="true"] { color: var(--neon); }
.opt .ic { width: 13px; text-align: center; font-size: 13px; line-height: 1; }
.opt svg.ic { height: 13px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.sep { width: 4px; height: 20px; margin: 0 7px; border-radius: 2px; background: var(--bg); }

/* ---------- typing test ---------- */
.test { width: 100%; }
.test-head { position: relative; display: flex; justify-content: center; align-items: flex-end; height: 40px; margin-bottom: 4px; font-size: var(--words); }
.counter {
  position: absolute; left: .31em; bottom: .05em; font-family: var(--type); line-height: 1;
  color: var(--neon); font-variant-numeric: tabular-nums; opacity: 0;
}
.typing .counter { opacity: 1; }
.lang { font-size: 14px; color: var(--sub); }
.caps-chip { --r: 6px; position: absolute; right: .31em; bottom: .1em; padding: 4px 10px; font-size: 12px; background: var(--bad); color: var(--bg); }

.box { --lh: 1.55em; position: relative; height: calc(var(--lh) * 3); overflow: hidden; font: var(--words) var(--type); }
.lines { position: relative; transition: transform .3s ease-out; }
.words { display: flex; flex-wrap: wrap; }
.word { position: relative; display: flex; height: var(--lh); line-height: var(--lh); margin: 0 .31em; }
.l { color: var(--sub); }
.l.ok { color: var(--ok); }
.l.bad { color: var(--bad); }
.l.extra { color: var(--extra); }
.word.err::after { content: ''; position: absolute; left: 0; right: 0; bottom: .22em; height: 2px; background: var(--bad); }

.caret {
  position: absolute; left: 0; top: 0; width: 2px; height: 1.15em; border-radius: 1px; background: var(--neon);
  transition: transform .1s ease-out; animation: blink 1s step-end infinite;
}
.keying .caret { animation: none; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- on-screen keyboard: small and flat; a pressed key just flashes its colour ---------- */
.keyboard { margin-top: clamp(28px, 6vh, 56px); display: flex; flex-direction: column; gap: var(--kgap); font: 12px var(--type); }
.done .keyboard { display: none; }
.krow { display: flex; gap: var(--kgap); }
.krow.r2 { margin-left: calc((var(--u) + var(--kgap)) * .25); }
.krow.r3 { margin-left: calc((var(--u) + var(--kgap)) * .75); }
.krow.r4 { margin-left: calc((var(--u) + var(--kgap)) * 2.25); }
.key { --r: 6px; position: relative; width: var(--u); height: var(--u); display: grid; place-items: center; background: var(--panel); color: var(--label); }
.key.space { width: calc((var(--u) + var(--kgap)) * 6.25 - var(--kgap)); font-size: 11px; color: var(--sub); }
.key .bump { position: absolute; left: 50%; bottom: 4px; width: 8px; height: 2px; margin-left: -4px; border-radius: 1px; background: currentColor; }
.caps .key:not(.space) { text-transform: uppercase; }

/* ---------- results ---------- */
.results { width: 100%; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 16px; }
.score { display: flex; justify-content: center; gap: clamp(48px, 6vw, 96px); }
.stat { margin: 0; display: grid; justify-items: start; font-family: var(--type); }
.stat .lbl { font-size: 24px; line-height: 1; color: var(--sub); }
.stat .num { font-size: clamp(60px, 5.6vw, 84px); line-height: 1.05; color: var(--neon); font-variant-numeric: tabular-nums; }
.facts { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px 40px; margin: 0; }
.facts div { display: grid; justify-items: start; gap: 2px; }
.facts dt { font-size: 13px; color: var(--sub); }
.facts dd { margin: 0; font: 20px var(--type); font-variant-numeric: tabular-nums; }

/* The name box and, once it's saved, the lines that replace it share one slot, tall enough from the start for a
   two-line jab, a two-line event line and the rank, so the page never grows or shifts after Enter. */
.slot { display: grid; justify-items: center; min-height: 172px; }
.claim, .after { grid-area: 1 / 1; align-self: start; }
.claim { display: grid; justify-items: center; gap: 6px; margin-top: 6px; }
.combo { position: relative; width: 200px; }
#name {
  width: 100%; height: 38px; padding: 0 12px; border: 0; background: var(--panel);
  font-size: 15px; text-align: center; caret-color: var(--neon);
}
#name::placeholder { color: var(--label); opacity: 1; }
#name:focus { outline: none; }
#name:focus-visible { box-shadow: inset 0 0 0 1px var(--sub); }
.claim-msg { margin: 0; min-height: 1.3em; font-size: 13px; color: var(--warn); }
.suggest { position: absolute; z-index: 5; top: calc(100% + 4px); left: 0; right: 0; margin: 0; padding: 4px; list-style: none; background: var(--panel-up); }
.suggest li { padding: 7px 10px; border-radius: 6px; font-size: 14px; text-align: left; color: var(--label); cursor: pointer; }
.suggest li:hover, .suggest li[aria-selected="true"] { background: var(--panel); color: var(--text); }
.suggest mark { background: none; color: var(--neon); }

/* The roast is the loudest thing on the screen. Meyrin ships one weight, so a thin outline in the text's own
   colour, painted under the letters, makes it bolder. */
.roast-line, .after { max-width: 780px; }
.roast-line {
  margin: 4px 0 0; font: clamp(30px, 2.7vw, 42px)/1.25 var(--roast); color: #fff; text-wrap: balance;
  -webkit-text-stroke: 1.6px currentColor; paint-order: stroke fill;
}
.after { display: grid; justify-items: center; gap: 10px; }
/* While the roast types itself out, the rest of the line is already laid out but invisible, so nothing
   re-wraps. The caret is the typed part's right border, which adds no width and no line-break point. */
.roast-line .typed { border-right: 2px solid var(--neon); margin-right: -2px; animation: caret-blink 1s step-end infinite; }
.roast-line .ghost { visibility: hidden; }
@keyframes caret-blink { 50% { border-right-color: transparent; } }
.jab-line { margin: 0; font: 24px/1.3 var(--roast); -webkit-text-stroke: 1.1px currentColor; paint-order: stroke fill; }
.event-line { margin: 0; font: 22px/1.3 var(--roast); -webkit-text-stroke: 1.1px currentColor; paint-order: stroke fill; }
.jab-line.down, .event-line.down { color: var(--warn); }
.jab-line.up, .event-line.up { color: var(--ok); }
.who-line { margin: 6px 0 0; font-size: 14px; color: var(--sub); }
.who-line b { font: 400 16px var(--type); color: var(--text); }
.who-line .fix { display: inline-block; white-space: pre; }

/* ---------- leaderboard: a gold bar for #1, plain rows for everyone else ---------- */
.board { position: fixed; left: clamp(16px, 2.4vw, 40px); bottom: 20px; width: 276px; z-index: 3; }
.board-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; font-size: 13px; color: var(--sub); }
.board-title { margin: 0; font-size: inherit; font-weight: 400; }
.board-empty, .board-note { margin: 0 0 8px; font-size: 13px; line-height: 1.45; color: var(--sub); }
.board-note { color: var(--warn); }
.podium { list-style: none; margin: 0; padding: 0; }
/* A cast bar seen from above: the four bevels are flat facets in four shades of gold, lit from the top
   left, with the name stamped into the face. Every couple of seconds a shine slides across it. */
.gold { position: relative; height: 62px; overflow: hidden; }
.gold .bar {
  position: absolute; inset: 0; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px;
  padding: 0 12px; border: 7px solid; border-color: #f7da86 #b9871f #8c6115 #e2b14b; background: #ebbf52;
  color: #5e400b; text-shadow: 0 1px 0 #f8de95;
}
/* the recessed stamp around the lettering: shadowed on the top and left edges, lit on the bottom and right */
.gold .bar::before { content: ''; position: absolute; inset: 3px; border: 1px solid; border-color: #c4952f #f9e3a2 #f9e3a2 #c4952f; pointer-events: none; }
.gold .bar.pic { grid-template-columns: auto 1fr auto; }
.face { --r: 4px; display: block; object-fit: cover; }
.gold .face { width: 36px; height: 36px; box-shadow: 0 0 0 1px #b9871f; }
.gold .who { display: grid; min-width: 0; line-height: 1.2; }
.gold .name { font-size: 15px; letter-spacing: .06em; text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gold .test { font-size: 10.5px; letter-spacing: .04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gold .wpm { font-size: 11px; white-space: nowrap; }
.gold .wpm b { font-size: 21px; font-weight: 400; margin-right: 2px; font-variant-numeric: tabular-nums; }
.gold::after {
  content: ''; position: absolute; top: -20%; bottom: -20%; left: 0; width: 24%; pointer-events: none;
  background: rgba(255, 250, 228, .6); filter: blur(5px);
  transform: translateX(-160%) skewX(-20deg); animation: shine 2s cubic-bezier(.45, 0, .25, 1) infinite;
}
@keyframes shine {
  0% { transform: translateX(-160%) skewX(-20deg); }
  40%, 100% { transform: translateX(520%) skewX(-20deg); }
}
.focus .gold::after { animation-play-state: paused; }

.rest {
  --row: 30px;
  list-style: none; margin: 8px 0 0; padding: 0; font-family: var(--type);
  max-height: calc(var(--row) * 4); overflow-y: auto; /* whole rows only; the count up top says when there are more */ overscroll-behavior: contain; scrollbar-width: none;
}
.rest::-webkit-scrollbar { display: none; }
.row { --r: 6px; height: var(--row); display: grid; grid-template-columns: 24px 1fr auto; align-items: center; gap: 8px; padding: 0 10px; font-size: 13px; }
.row.pic { grid-template-columns: 24px auto 1fr auto; }
.row .face { width: 22px; height: 22px; }
.row:nth-child(odd) { background: var(--panel); }
.row .rank { color: var(--label); }
.row .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .wpm { font-size: 12px; color: var(--label); }
.row .wpm b { font-size: 14px; font-weight: 400; color: var(--text); font-variant-numeric: tabular-nums; }

.slowest {
  position: relative; margin-top: 10px; height: 40px;
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; padding: 0 12px;
  background: var(--panel); font: 13px var(--type);
}
.slow-label { font: 12px var(--ui); color: var(--warn); }
.slow-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slow-wpm { font-size: 12px; color: var(--label); }
.slow-wpm b { font-size: 14px; font-weight: 400; color: var(--text); }
/* Smoke off the right end of the slowest row, beside the board so no score sits behind it: soft blurred
   puffs that swell, drift, turn and thin out as they rise, each on its own path and timing. */
.fumes { position: absolute; left: calc(100% - 18px); bottom: 8px; width: 70px; height: 80px; pointer-events: none; }
.puff {
  position: absolute; left: 50%; bottom: 0; width: var(--s, 18px); height: var(--s, 18px); margin-left: calc(var(--s, 18px) / -2);
  border-radius: 46% 54% 50% 50%; background: rgba(214, 224, 220, .5); filter: blur(4px); opacity: 0;
  animation: fume var(--t, 3.6s) cubic-bezier(.25, .55, .4, 1) var(--d, 0s) infinite;
}
.puff:nth-of-type(1) { --s: 16px; --x1: 6px;   --x2: 14px;  --spin: 40deg;  --t: 3.4s; }
.puff:nth-of-type(2) { --s: 20px; --x1: -8px;  --x2: -18px; --spin: -60deg; --t: 3.9s; --d: .45s; }
.puff:nth-of-type(3) { --s: 14px; --x1: 3px;   --x2: 4px;   --spin: 80deg;  --t: 3.2s; --d: .9s; }
.puff:nth-of-type(4) { --s: 22px; --x1: -4px;  --x2: -10px; --spin: -30deg; --t: 4.2s; --d: 1.35s; }
.puff:nth-of-type(5) { --s: 17px; --x1: 9px;   --x2: 20px;  --spin: 70deg;  --t: 3.6s; --d: 1.8s; }
.puff:nth-of-type(6) { --s: 19px; --x1: -10px; --x2: -22px; --spin: -80deg; --t: 4s;   --d: 2.25s; }
.puff:nth-of-type(7) { --s: 15px; --x1: 5px;   --x2: 9px;   --spin: 50deg;  --t: 3.3s; --d: 2.7s; }
.puff:nth-of-type(8) { --s: 21px; --x1: -6px;  --x2: -4px;  --spin: -45deg; --t: 4.4s; --d: 3.15s; }
@keyframes fume {
  0% { transform: translate(0, 4px) scale(.3) rotate(0deg); opacity: 0; }
  12% { opacity: .75; }
  45% { transform: translate(var(--x1), -26px) scale(1.25) rotate(calc(var(--spin) / 2)); opacity: .5; }
  100% { transform: translate(var(--x2), -68px) scale(2.8) rotate(var(--spin)); opacity: 0; }
}
.focus .puff { animation-play-state: paused; }

/* short windows (a 13-inch Mac with the Dock and bookmarks bar showing): tighter spacing so nothing scrolls */
@media (max-height: 760px) {
  .app { padding-top: 18px; }
  .stage { padding: 4px 0 16px; }
  .results { gap: 12px; }
  .stat .num { font-size: clamp(52px, 4.6vw, 68px); }
  .roast-line { font-size: clamp(28px, 2.4vw, 36px); }
  .jab-line { font-size: 22px; }
  .event-line { font-size: 20px; }
  .slot { min-height: 156px; }
}
/* the board is pinned bottom-left on wide screens: keep the centred roast lines clear of it */
@media (min-width: 1100px) {
  .roast-line, .after { max-width: min(780px, calc(100vw - 2 * (clamp(16px, 2.4vw, 40px) + 300px))); }
}
@media (min-width: 1100px) and (max-height: 780px) {
  .gold { height: 54px; }
  .gold .bar { border-width: 6px; }
  .rest { --row: 28px; max-height: calc(var(--row) * 3); }
  .slowest { height: 36px; }
}
/* narrow desktop windows: the board joins the page flow */
@media (max-width: 1099px) {
  .app { grid-template-rows: auto 1fr auto auto; }
  .board { position: static; width: min(320px, 100%); margin: 28px auto 8px; }
}

/* ---------- photo booth: an Instax Wide print with the camera inside, the countdown on both sides ---------- */
.booth {
  position: fixed; inset: 0; z-index: 20; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 24px; background: var(--bg);
}
.count { justify-self: center; font: 400 clamp(110px, 12vw, 190px)/1 var(--title); color: var(--text); }
/* Instax Wide film is 108 x 86 mm around a 99 x 62 mm picture: thin sides, a thicker top, the wide strip at the
   bottom. Padding percentages are of the width, so the proportions hold at any size. */
.film {
  position: relative; margin: 0; width: min(62vw, calc((100vh - 120px) * 108 / 86), 900px);
  padding: 6% 4.17% 16.2%; background: #f3f0e8; transform: rotate(-1.2deg); container-type: inline-size;
}
.shot { position: relative; aspect-ratio: 99 / 62; overflow: hidden; background: #10201c; }
.shot video, .shot canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.shot video { transform: scaleX(-1); } /* a mirror, like Photo Booth; the photo is saved the same way round */
.film-cap {
  position: absolute; left: 4.17%; right: 4.17%; bottom: 0; height: 16.2%; display: grid; place-items: center;
  font: 6.48cqw/1 var(--roast); color: #26302d; -webkit-text-stroke: .9px currentColor; paint-order: stroke fill; /* 7 mm on the film, as on the saved print */
}
.booth-hint { position: absolute; left: 0; right: 0; bottom: 18px; margin: 0; text-align: center; font-size: 12px; color: var(--sub); }
.flash { position: fixed; inset: 0; z-index: 30; background: #fff; opacity: 0; pointer-events: none; transition: opacity .7s ease-out; }
.flash.on { opacity: 1; transition: none; }

/* ---------- phones: just the message ---------- */
.mobile { display: none; }
@media (hover: none) and (pointer: coarse), (max-width: 599px) {
  .app { display: none; }
  .mobile { display: grid; place-items: center; min-height: 100vh; min-height: 100dvh; padding: 24px; }
}
.mobile-msg { margin: 0; text-align: center; font: clamp(40px, 12vw, 72px)/1.15 var(--title); text-transform: uppercase; color: var(--text); }
.drop .w { white-space: nowrap; }
.drop .w > span { display: inline-block; animation: drop-in .5s ease-out both; animation-delay: calc(var(--i) * 55ms + 150ms); }
.drop .w > .mcaret {
  width: .06em; height: .8em; margin-left: .08em; vertical-align: -.04em; background: var(--neon);
  animation: drop-in .5s ease-out both 1s, blink 1s step-end 1.5s infinite;
}
@keyframes drop-in { from { transform: translateY(-.5em); opacity: 0; } to { transform: none; opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0s !important;
    transition-duration: .001ms !important;
  }
}
