/* Colours and the page background come from the shared SparkUp UI kit
   (static.sparkup.dev/css/sparkup-ui.css, loaded first); only the demo's own
   shades are defined here. */
:root {
  --panel: #141413;
  --stage: #1c1c1b;
  --text: var(--su-text);
  --muted: var(--su-muted);
  --dim: rgb(168 176 192 / 40%);
  --track: rgb(255 255 255 / 10%);
  --accent: var(--su-accent-2);
  --sure: var(--su-success, #22c55e); /* fallback until the kit with --su-success is deployed */
  --sans: "Helvetica Neue", Helvetica, Arial, system-ui, sans-serif;
  --site-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --cjk: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  --page: 1280px; /* the width the navbar, the intro and the demo share */
  --gutter: 24px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  height: auto;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--text);
  font-family: var(--sans);
  line-height: normal;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--text);
}

h2 {
  margin: 0 0 14px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.button {
  appearance: none;
  border: 1px solid var(--dim);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: 500 14px var(--sans);
  padding: 8px 14px;
  text-decoration: none;
  cursor: pointer;
}

.button:hover {
  border-color: var(--muted);
}

/* Everything lines up on the same column, --page wide at most: the logo, the
   intro and the edge of the demo card. */
.navbar-inner,
.intro {
  width: 100%;
  max-width: var(--page);
  margin-left: auto;
  margin-right: auto;
}

/* --- Navbar, as on the other Sparkup demos --------------------------------- */

/* The page background from the kit shows through. */
.navbar {
  padding: 15px 0;
  border-bottom: 1px solid var(--su-border);
  font-family: var(--site-sans);
}

.navbar-inner {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 var(--gutter);
}

.logo {
  display: flex;
}

.title {
  color: #fff;
  font-size: 22px;
  white-space: nowrap;
}

.title .hanzi {
  margin-left: 4px;
  font-family: var(--cjk);
  color: var(--accent);
}

.actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.nav-link {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: rgb(255 255 255 / 82%);
  font: 17px var(--site-sans);
  line-height: 1;
  padding: 9px 12px;
  text-decoration: none;
  cursor: pointer;
  transition: color 0.12s ease, background 0.12s ease;
}

.nav-link:hover {
  color: #fff;
  background: rgb(255 255 255 / 8%);
}

.languages {
  display: flex;
}

.languages .nav-link {
  font-size: 15px;
  padding: 9px 8px;
}

.languages .nav-link[aria-pressed="true"] {
  color: #fff;
  font-weight: 600;
  cursor: default;
}

.languages .nav-link[aria-pressed="true"]:hover {
  background: transparent;
}

.nav-link--icon {
  padding: 4px 8px;
  border-radius: 999px;
}

.nav-link--icon img {
  filter: brightness(0) invert(1);
}

/* --- Intro and the demo card ------------------------------------------------- */

.intro {
  margin-top: 28px;
  margin-bottom: 0;
  padding: 0 var(--gutter);
  color: var(--muted);
  font: 17px/1.5 var(--site-sans);
}

.demo {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(340px, 1fr);
  gap: 24px;
  width: calc(100% - 2 * var(--gutter));
  max-width: calc(var(--page) - 2 * var(--gutter));
  margin: 20px auto 0;
}

/* --- Camera -------------------------------------------------------------- */

.stage {
  position: relative;
  overflow: hidden;
  border-radius: 14px;
  background: var(--stage);
  aspect-ratio: 4 / 3;
  align-self: start;
}

.stage video {
  display: none;
}

.stage canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.pill {
  position: absolute;
  top: 16px;
  left: 16px;
  padding: 9px 16px;
  border-radius: 10px;
  background: rgb(20 20 19 / 75%);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.02em;
  transition: background 0.3s;
}

.pill.done {
  background: var(--sure);
}

.status {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  text-align: center;
  background: var(--stage);
  color: var(--muted);
  font-size: 16px;
  line-height: 1.5;
}

.status[hidden] {
  display: none;
}

.status p {
  margin: 0;
  max-width: 32em;
}

/* --- Panel --------------------------------------------------------------- */

.panel {
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.reading {
  display: flex;
  align-items: center;
  gap: 24px;
}

/* Fixed heights, so the panel does not move when a number appears. */
.number {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.2ch;
  height: 120px;
  font-size: 120px;
  font-weight: 700;
  line-height: 1;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.number.none {
  color: var(--dim);
}

.number.egg {
  font-size: 96px;
}

.details {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.caption {
  display: flex;
  align-items: center;
  height: 44px;
  font-size: 26px;
  line-height: 1;
  color: var(--muted);
  white-space: nowrap;
}

.caption .char {
  font-family: var(--cjk);
  font-size: 34px;
  margin-right: 10px;
}

.caption.none {
  color: var(--dim);
}

.bar {
  position: relative;
  height: 44px;
  border-radius: 10px;
  background: var(--track);
  overflow: hidden;
}

.bar .fill {
  height: 100%;
  width: 0;
  border-radius: 10px;
  background: var(--accent);
}

.bar .fill.sure {
  background: var(--sure);
}

.bar .percent {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 20px;
  font-weight: 700;
}

.next {
  display: grid;
  grid-template-columns: auto 2ch 1fr 4ch;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 16px;
  font-weight: 500;
}

.next .label {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.next-percent {
  text-align: right;
}

.track {
  height: 8px;
  border-radius: 4px;
  background: var(--track);
  overflow: hidden;
}

.track .fill {
  height: 100%;
  width: 0;
  background: var(--dim);
}

/* --- Hand shapes ----------------------------------------------------------- */

.grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 18px 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.shape {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

/* The hands are drawn with a near-black fill for the video; screen drops the
   fill so only the outlines show on the page background. */
.shape img {
  width: 100%;
  max-width: 64px;
  aspect-ratio: 100 / 130;
  mix-blend-mode: screen;
}

.shape .label {
  position: relative;
  font-size: 17px;
  font-weight: 500;
  color: var(--dim);
}

.shape.counted .label {
  color: var(--text);
}

.shape.current .label {
  color: var(--accent);
}

.shape .tick {
  position: absolute;
  left: 100%;
  margin-left: 4px;
  color: var(--su-accent);
  font-size: 15px;
  visibility: hidden;
}

.shape.counted .tick {
  visibility: visible;
}

.badge {
  display: grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  border-radius: 12px;
  border: 2px solid var(--track);
  background: transparent; /* the kit has its own .badge */
  color: var(--dim);
  font-size: 13px;
  font-weight: 700;
}

.badge.on {
  border-color: var(--text);
  background: var(--text);
  color: var(--panel);
}

.badge.bump {
  animation: bump 0.35s ease-out;
}

@keyframes bump {
  40% {
    transform: scale(1.35);
  }
}

/* --- Easter eggs ----------------------------------------------------------- */

.eggs {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.eggs .toast {
  position: absolute;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  padding: 12px 20px;
  border-radius: 12px;
  background: rgb(20 20 19 / 85%);
  font-size: 20px;
  font-weight: 700;
  white-space: nowrap;
  animation: toast 2.8s ease-out forwards;
}

/* Emoji reactions rising up the whole screen, as in a video call. Each one pops
   in, rises while its inner span sways from side to side, and fades out near
   the top. */
.reactions {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  overflow: hidden;
}

.reaction {
  position: absolute;
  bottom: -1.2em;
  line-height: 1;
  animation: float-up var(--duration) cubic-bezier(0.25, 0.6, 0.45, 1) var(--delay) both;
}

.reaction span {
  display: inline-block;
  animation: sway var(--sway-duration) ease-in-out var(--delay) infinite alternate;
}

@keyframes float-up {
  0% {
    opacity: 0;
    transform: translateY(0) scale(0.3);
  }
  8% {
    opacity: 1;
    transform: translateY(-6vh) scale(1);
  }
  70% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateY(calc(-100vh - 1.2em)) scale(1);
  }
}

@keyframes sway {
  from {
    transform: translateX(calc(-1 * var(--sway))) rotate(-10deg);
  }
  to {
    transform: translateX(var(--sway)) rotate(10deg);
  }
}

@keyframes toast {
  0% {
    opacity: 0;
    transform: translate(-50%, 12px);
  }
  12%,
  80% {
    opacity: 1;
    transform: translate(-50%, 0);
  }
  100% {
    opacity: 0;
  }
}

/* --- Footer, as on the other Sparkup demos -------------------------------- */

.site-footer {
  margin-top: auto;
  padding: 36px var(--gutter) 30px;
  text-align: center;
  font: 14px/1.4 var(--site-sans);
  color: var(--muted);
}

.site-footer p {
  margin: 0;
}

.made {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.heart {
  width: 18px;
  height: 18px;
  fill: #7c5cff;
}

.rights {
  margin-top: 6px !important;
}

/* --- Phones ---------------------------------------------------------------- */

@media (max-width: 860px) {
  :root {
    --gutter: 16px;
  }

  /* Phones ignore or mishandle fixed backgrounds; let the gradient scroll. */
  body {
    background-attachment: scroll;
  }

  .navbar {
    padding: 10px 0;
  }

  .navbar-inner {
    gap: 10px;
  }

  .title {
    font-size: 19px;
  }

  .nav-link {
    font-size: 15px;
    padding: 8px;
  }

  .intro {
    margin-top: 16px;
    font-size: 15px;
  }

  .demo {
    grid-template-columns: minmax(0, 1fr);
    gap: 20px;
    margin-top: 14px;
  }

  .stage {
    aspect-ratio: 1 / 1;
  }

  .panel {
    gap: 22px;
  }

  .number {
    height: 84px;
    font-size: 84px;
  }

  .number.egg {
    font-size: 64px;
  }

  .caption {
    height: 34px;
    font-size: 20px;
  }

  .caption .char {
    font-size: 26px;
  }

  .bar {
    height: 36px;
  }

  .bar .percent {
    font-size: 17px;
  }

  .shape .label {
    font-size: 15px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .badge.bump {
    animation-duration: 0.01s;
  }

  /* No flying emojis; the toast still says what happened. */
  .reactions {
    display: none;
  }
}

@media (max-width: 400px) {
  .title .hanzi {
    display: none;
  }
}
