:root {
  --ink: #002920;
  --leaf: #2e6a4f;
  --leaf-soft: #8fb07a;
  --mint: #d6e8d2;
  --paper: #fbf8ef;
  --paper-line: #d9e3d6;
  --gold: #d9a93b;
  --tomato: #d9483b;
  --display: "Baloo 2", "Trebuchet MS", system-ui, sans-serif;
  --body: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
body {
  --viewport-height: 100vh;
  --top-gutter: calc(12px + env(safe-area-inset-top, 0px));
  --bottom-gutter: calc(12px + env(safe-area-inset-bottom, 0px));
  box-sizing: border-box;
  height: var(--viewport-height);
  margin: 0;
  background: var(--mint);
  color: var(--ink);
  font: 700 15px/1.4 var(--body);
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  place-items: center;
  padding-block: var(--top-gutter) var(--bottom-gutter);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
@supports (height: 100dvh) {
  body {
    --viewport-height: 100dvh;
  }
}
.stage {
  position: relative;
  /* The canvas uses a 400 × 640 coordinate system. Leave room for the outer ring. */
  width: min(
    100%,
    calc((var(--viewport-height) - var(--top-gutter) - var(--bottom-gutter)) * 5 / 8)
  );
  aspect-ratio: 5 / 8;
  container-type: size;
  border-radius: 22px;
  overflow: hidden;
  background: #e9f3e4;
  box-shadow:
    0 0 0 4px var(--ink),
    0 18px 40px rgba(0, 41, 32, 0.25);
}
canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* HUD */
.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  font-family: var(--display);
}
.hud-top {
  position: absolute;
  left: 3%;
  right: 3%;
  top: 2.2%;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
}
.score {
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 14px;
  padding: 2px 12px 0;
  line-height: 1.05;
  min-width: 74px;
}
.score .lbl {
  display: block;
  font: 800 10px/1 var(--body);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--leaf);
  padding-top: 4px;
}
.score b {
  font-size: clamp(22px, 6.2vw, 30px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.time {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.bar {
  flex: 1;
  height: 14px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 99px;
  overflow: hidden;
}
.bar i {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--leaf-soft);
  transform-origin: left;
  border-radius: 99px;
}
.bar i.low {
  background: var(--tomato);
}
#timeTxt {
  font-size: 18px;
  font-weight: 800;
  min-width: 1.6em;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.lives {
  display: flex;
  gap: 3px;
}
.lives svg {
  width: 24px;
  height: 24px;
  transition: transform 0.2s;
}
.lives .full {
  fill: var(--tomato);
  stroke: var(--ink);
}
.lives .lost {
  fill: #ffffff;
  fill-opacity: 0.55;
  stroke: var(--ink);
  stroke-opacity: 0.35;
  transform: scale(0.82);
}
.lives path {
  stroke-width: 2.4;
  stroke-linejoin: round;
}

.fact {
  position: absolute;
  left: 4%;
  right: 4%;
  top: 11%;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 16px;
  padding: 8px 12px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  align-items: center;
  font-family: var(--body);
  opacity: 0;
  transform: translateY(-8px);
  transition:
    opacity 0.2s,
    transform 0.2s;
}
.fact.show {
  opacity: 0.96;
  transform: none;
}
.fact .em {
  font-size: 28px;
  grid-row: span 2;
  line-height: 1;
}
.fact b {
  font: 800 15px/1.1 var(--display);
}
.fact b.warn {
  color: var(--tomato);
}
.fact span {
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1.3;
}
.combo {
  position: absolute;
  left: 0;
  right: 0;
  top: 22%;
  text-align: center;
  font: 800 clamp(20px, 6vw, 28px) / 1 var(--display);
  color: var(--ink);
  text-shadow:
    0 2px 0 #fff,
    0 0 12px #fff;
  opacity: 0;
  transition: opacity 0.15s;
}
.combo.show {
  opacity: 1;
}

.icon-btn {
  position: absolute;
  right: 3%;
  bottom: 1.6%;
  z-index: 4;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 3px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
}
.icon-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-btn[aria-pressed="true"] .wave {
  display: none;
}
.icon-btn:not([aria-pressed="true"]) .cross {
  display: none;
}

/* Panels */
.panel {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  text-align: center;
  background: linear-gradient(180deg, rgba(251, 248, 239, 0.95), rgba(233, 243, 228, 0.95));
}
[hidden] {
  display: none !important;
}
.panel-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px 7%;
  overflow-y: auto;
}
.panel-content > * {
  flex: none;
}
.panel-content > :first-child {
  margin-top: auto;
}
.panel-content > :last-child {
  margin-bottom: auto;
}
.brand {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: inherit;
}
.panel img.logo {
  width: min(58%, 210px);
  height: auto;
}
.panel img.mascot {
  width: min(46%, 170px);
  height: auto;
  animation: bob 2.4s ease-in-out infinite;
}
@keyframes bob {
  50% {
    transform: translateY(-6px) rotate(-2deg);
  }
}
h1,
h2 {
  font: 800 clamp(32px, 9.5vw, 44px) / 1 var(--display);
  margin: 0;
  letter-spacing: -0.01em;
}
h2 {
  font-size: clamp(28px, 8vw, 38px);
}
.panel p {
  margin: 0;
  max-width: 30ch;
  font-weight: 700;
}
.legend {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.chip {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 3px solid var(--ink);
  border-radius: 99px;
  padding: 3px 12px 3px 10px;
  background: #fff;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}
.chip.good {
  border-color: var(--leaf);
}
.chip.bad {
  border-color: var(--tomato);
}
.chip .e {
  font-size: 18px;
  letter-spacing: 2px;
}
.btn {
  font: 800 20px/1 var(--display);
  color: var(--paper);
  background: var(--ink);
  border: 0;
  border-radius: 16px;
  padding: 14px 30px 12px;
  cursor: pointer;
  box-shadow: 0 5px 0 var(--leaf);
  transition:
    transform 0.08s,
    box-shadow 0.08s;
}
.btn:hover {
  background: #0b3d31;
}
.btn:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--leaf);
}
.btn:focus-visible,
.icon-btn:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}
.hint {
  font-size: 12px;
  font-weight: 700;
  color: var(--leaf);
}
.tagline {
  font: 800 12.5px/1.2 var(--display);
  letter-spacing: 0.01em;
  color: var(--ink);
  margin-top: 2px;
}
.big {
  font: 800 clamp(54px, 17vw, 76px) / 1 var(--display);
  font-variant-numeric: tabular-nums;
}
.badge {
  display: inline-block;
  background: var(--gold);
  border: 3px solid var(--ink);
  border-radius: 99px;
  padding: 6px 18px 3px;
  font: 800 18px/1 var(--display);
  transform: rotate(-2deg);
}
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: 100%;
}
.stats div {
  background: #fff;
  border: 3px solid var(--paper-line);
  border-radius: 14px;
  padding: 6px 4px 4px;
}
.stats b {
  display: block;
  font: 800 24px/1.1 var(--display);
  font-variant-numeric: tabular-nums;
}
.stats span {
  font-size: 11px;
  font-weight: 800;
  color: var(--leaf);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.best {
  font-size: 13px;
  font-weight: 800;
  color: var(--leaf);
}

@container (max-height: 620px) {
  .panel {
    padding-bottom: 50px;
  }
  .panel-content {
    padding-block: 12px;
    gap: 8px;
  }
  .panel img.logo {
    width: min(40%, 150px);
  }
  .panel img.mascot {
    width: min(34%, 120px);
  }
}
@container (max-height: 500px) {
  .brand {
    flex-direction: row;
    justify-content: center;
  }
  .brand img.mascot {
    width: min(25%, 72px);
  }
  h1,
  h2 {
    font-size: 28px;
  }
  .panel-content {
    padding-inline: 4%;
  }
  .legend {
    gap: 4px;
  }
  .chip {
    padding-inline: 6px;
  }
  .hud-top {
    gap: 4px;
  }
  .score {
    min-width: 0;
    padding-inline: 6px;
  }
  .score b {
    font-size: 22px;
  }
  .lives svg {
    width: 18px;
    height: 18px;
  }
}
@media (prefers-reduced-motion: reduce) {
  .panel img.mascot {
    animation: none;
  }
  .fact {
    transition: none;
  }
}
