@property --sweep {
  syntax: "<angle>";
  inherits: false;
  initial-value: 360deg;
}

:root {
  --paper: #fafbf9;
  --grid: #dfe7ee;
  --margin: #ef9f9f;
  --graphite: #34373e;
  --pencil: #6b7079;
  --blue: #2747d1;
  --red: #c93222;
  --cell: 22px;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100dvh;
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: var(--cell) var(--cell);
  color: var(--graphite);
  font-family: "Shantell Sans", ui-rounded, system-ui, sans-serif;
  font-size: 1.0625rem;
  font-weight: 420;
  font-variation-settings: "INFM" 0, "BNCE" 0;
  line-height: 1.5;
}

/* Players write in their own pen; the colour follows their mark in data.json. */
.ink-x { --ink: var(--blue); }
.ink-o { --ink: var(--red); }

/* The notebook page: a red margin line, content written to its right. */
.sheet {
  width: min(42rem, calc(100% - 1.375rem));
  min-height: 100dvh;
  margin-left: max(1.375rem, calc((100% - 42rem) / 2));
  padding: 2.75rem 1rem 5rem 1.125rem;
  border-left: 2px solid var(--margin);
}

/* ---------- Masthead ---------- */

h1 {
  margin: 0;
  font-size: clamp(2.25rem, 9vw, 3rem);
  font-weight: 700;
  font-variation-settings: "INFM" 100, "BNCE" 40;
  line-height: 1.05;
}

.as-of {
  margin: 0.375rem 0 0;
  color: var(--pencil);
  font-size: 0.9375rem;
}

/* ---------- Overall duel ---------- */

.overall {
  margin: 2.25rem 0 3rem;
}

.duel {
  display: flex;
  align-items: flex-end;
  gap: clamp(1.25rem, 6vw, 2.25rem);
  padding-left: 1rem;
}

.side {
  display: flex;
  flex-direction: column;
  align-items: center;
  color: var(--ink);
}

.who {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  font-weight: 600;
}

.side .who {
  font-size: 1.125rem;
}

/* Kiki's name doubles as the door to the hidden ride. */
.egg {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.egg:active {
  transform: rotate(-4deg);
}

.egg:focus-visible {
  outline: 2px dashed var(--ink);
  outline-offset: 4px;
}

.big {
  font-size: clamp(4.75rem, 26vw, 8rem);
  font-weight: 700;
  font-variation-settings: "INFM" 100, "BNCE" 50;
  line-height: 1;
  --rx: 0.24em;
  --ry: 0.06em;
  --stroke: 3.5;
}

.colon {
  padding-bottom: 0.1em;
  color: var(--pencil);
  font-size: clamp(3rem, 16vw, 5rem);
  font-weight: 600;
  line-height: 1;
}

.note {
  max-width: 34ch;
  margin: 1rem 0 0;
  color: var(--pencil);
  font-size: 0.9375rem;
}

/* ---------- Score table ---------- */

.scores {
  width: 100%;
  max-width: 34rem;
  border-collapse: separate;
  border-spacing: 0;
}

.scores thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 0.625rem 0 0.5rem;
  border-bottom: 1.5px solid var(--pencil);
  background: var(--paper);
  font-size: 1rem;
  font-weight: 600;
}

.scores thead th + th {
  width: clamp(5rem, 22vw, 6rem);
  color: var(--ink);
}

.game th {
  padding: 1.75rem 0 0.125rem;
  font-size: 1.375rem;
  font-weight: 650;
  font-variation-settings: "INFM" 80, "BNCE" 30;
  line-height: 1.25;
  text-align: left;
}

.platform {
  margin-left: 0.25rem;
  color: var(--pencil);
  font-size: 0.8125rem;
  font-weight: 500;
  font-variation-settings: "INFM" 0, "BNCE" 0;
  white-space: nowrap;
}

.scores tbody th[scope="row"] {
  padding: 0.5rem 0.75rem 0.5rem 0;
  font-weight: 420;
  text-align: left;
}

.draws {
  display: block;
  color: var(--pencil);
  font-size: 0.8125rem;
}

.scores td {
  padding: 0.5rem 0;
  color: var(--ink);
  font-size: clamp(1.125rem, 5vw, 1.3125rem);
  font-weight: 600;
  font-variation-settings: "INFM" 100, "BNCE" 30;
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
}

/* ---------- Marks and the hand-drawn circle ---------- */

.mark {
  width: 1em;
  height: 1em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.lead {
  position: relative;
  display: inline-block;
  --rx: 0.55em;
  --ry: 0.32em;
  --stroke: 2.25;
}

.big .lead {
  --rx: inherit;
  --ry: inherit;
  --stroke: inherit;
}

/* An ellipse only clears a wide number's corners if it grows with it. */
.ring {
  --w: max(calc(100% + 2 * var(--rx)), calc(130% + var(--rx)));
  position: absolute;
  left: calc((100% - var(--w)) / 2);
  top: calc(-1 * var(--ry));
  width: var(--w);
  height: calc(100% + 2 * var(--ry));
  overflow: visible;
  pointer-events: none;
  fill: none;
  stroke: currentColor;
  stroke-width: var(--stroke);
  stroke-linecap: round;
  transform: rotate(var(--tilt, 0deg));
  -webkit-mask: conic-gradient(from -60deg, #000 var(--sweep), transparent 0);
  mask: conic-gradient(from -60deg, #000 var(--sweep), transparent 0);
  animation: draw 0.5s cubic-bezier(0.6, 0.05, 0.3, 1) both;
  animation-delay: calc(250ms + var(--i, 0) * 45ms);
}

@keyframes draw {
  from { --sweep: 0deg; }
}

@media (prefers-reduced-motion: reduce) {
  .ring { animation: none; }
}

/* ---------- Hidden ride ---------- */

.ride {
  width: min(36rem, calc(100% - 2rem));
  max-width: none;
  padding: 1rem 1.125rem 0.75rem;
  border: 1.5px solid var(--graphite);
  border-radius: 6px;
  background: var(--paper);
  color: var(--graphite);
  touch-action: manipulation;
}

.ride::backdrop {
  background: rgb(52 55 62 / 0.45);
}

.ride-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

.ride h2 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  font-variation-settings: "INFM" 100, "BNCE" 40;
  white-space: nowrap;
}

/* Same-width digits and no wrapping: a changing score must not resize the header
   and make the centred dialog jump. */
.ride-score {
  color: var(--red);
  font-size: 1.5rem;
  font-weight: 700;
  font-variation-settings: "INFM" 100, "BNCE" 30;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.ride-stage {
  position: relative;
  margin-top: 0.625rem;
}

.ride canvas {
  display: block;
  width: 100%;
  aspect-ratio: 13 / 6; /* matches the game's zoom-out, so phones get no empty sky */
  border: 1.5px solid var(--graphite);
  border-radius: 3px;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.ride-msg {
  position: absolute;
  inset: 0 0 3rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.125rem;
  margin: 0;
  padding: 0 1rem;
  pointer-events: none;
  text-align: center;
}

.ride-msg[hidden] {
  display: none;
}

.ride-msg strong {
  font-size: clamp(1.375rem, 6vw, 1.75rem);
  font-weight: 700;
  font-variation-settings: "INFM" 100, "BNCE" 40;
}

.ride-msg span {
  color: var(--pencil);
  font-size: 0.9375rem;
}

.ride-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 0.5rem;
}

.ride-best {
  margin: 0;
  color: var(--pencil);
  font-size: 0.9375rem;
}

.ride-foot form {
  display: flex;
  gap: 0.5rem;
}

.ride-close[hidden] {
  display: none;
}

.ride-close {
  padding: 0.375rem 0.875rem;
  border: 1.5px solid var(--graphite);
  border-radius: 999px;
  background: var(--paper);
  color: var(--graphite);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.ride-close:focus-visible {
  outline: 2px dashed var(--graphite);
  outline-offset: 3px;
}

/* Phones: a tall stage is easier to hit than a thin strip, and keeps Zavřít out of the way.
   The extra height is sky, where the message has room. */
@media (max-width: 40rem) {
  /* Small enough that the title and a four-digit score share one line. */
  .ride h2,
  .ride-score {
    font-size: 1.25rem;
  }

  .ride canvas {
    aspect-ratio: 4 / 5;
    max-height: 60svh;
  }

  .ride-foot {
    margin-top: 1rem;
  }
}

/* ---------- Misc ---------- */

.error {
  color: var(--red);
  font-weight: 600;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
