:root {
  --sky: #8fd0f0;
  --ink: #3f5a3a;
  --muted: #7f8b72;
  --paper: #fffdf3;
  --glass: rgb(255 254 245 / 0.82);
  --green: #6a9b52;
  --green-dark: #4f7f3b;
  --carrot: #f09a45;
  --gold: #ffc21f;
  --gold-dark: #d99a00;
  --soft: #e7eddb;
  --soft-dark: #cdd8bb;
  --shadow: 0 6px 20px rgb(52 85 57 / 0.14);
  --edge: max(14px, env(safe-area-inset-left), env(safe-area-inset-right));

  font-family: Nunito, ui-rounded, 'Arial Rounded MT Bold', system-ui, sans-serif;
  color: var(--ink);
  font-synthesis: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-text-size-adjust: 100%;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: linear-gradient(#8fd0f0, #e6f6fb);
}

/* The canvas fills the screen, but never gets taller than 4:3 so portrait
   phones still see enough of the level. */
.stage {
  position: relative;
  height: 100svh;
  display: grid;
  place-items: center;
}

canvas {
  display: block;
  width: 100vw;
  height: min(100svh, 75vw);
  touch-action: none;
}

canvas:focus {
  outline: none;
}

@media (any-pointer: coarse) {
  .stage,
  .share {
    -webkit-user-select: none;
    user-select: none;
  }

  #shareLink {
    -webkit-touch-callout: default;
    -webkit-user-select: text;
    user-select: text;
  }
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: 0;
  background: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid #efab52;
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
}

/* ----- HUD ----- */

.hud {
  position: absolute;
  inset: max(14px, env(safe-area-inset-top)) var(--edge) auto;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
}

.score,
.lives {
  background: var(--glass);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
  border: 1px solid rgb(255 255 255 / 0.7);
}

.score {
  display: grid;
  grid-template-columns: auto auto auto;
  align-items: center;
  column-gap: 8px;
  padding: 8px 16px 10px 12px;
  border-radius: 20px;
}

.score-icon {
  font-size: 24px;
  grid-row: span 2;
}

.score .progress {
  grid-column: 2;
}

/* Lives: a heart each, faded once lost. */
.lives {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 52px;
  padding: 0 12px;
  border-radius: 20px;
}

.heart {
  font-size: 22px;
  line-height: 1;
  color: #e3dcc4;
  transition: color 0.3s ease;
}

.heart.full {
  color: #ef4f5f;
  text-shadow: 0 2px 0 #b8323f;
}

.lives.last .heart.full {
  animation: heart-beat 0.9s ease-in-out infinite;
}

@keyframes heart-beat {
  50% {
    transform: scale(1.25);
  }
}

/* The golden carrot's star: faint until it is found. */
.golden {
  grid-column: 3;
  grid-row: 1 / span 2;
  font-size: 22px;
  line-height: 1;
  color: #d8d2bd;
}

.golden.found {
  color: var(--gold);
  text-shadow: 0 0 10px rgb(255 194 31 / 0.8);
  animation: star-pop 0.6s cubic-bezier(0.2, 1.6, 0.4, 1);
}

.score b {
  font-size: 22px;
  font-weight: 900;
}

.score small {
  font-size: 14px;
  font-weight: 800;
  color: var(--muted);
  margin-left: 2px;
}

.progress {
  height: 5px;
  width: 64px;
  border-radius: 9px;
  background: #e8e3cf;
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--carrot);
  transition: width 0.3s ease;
}

.actions {
  display: flex;
  gap: 18px;
  margin-left: auto;
  pointer-events: auto;
}

/* The top bar in two groups: you, share and install; then the settings. */
.action-group {
  display: flex;
  gap: 10px;
}

/* No changing who you are in the middle of a level. */
.stage[data-screen='game'] #profile,
.stage[data-screen='game'] #install {
  display: none;
}

/* Solid cream squares with a little lip, pressed down when tapped. */
.icon {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 14px;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 4px 0 rgb(52 85 57 / 0.2);
  transition:
    transform 0.1s ease,
    box-shadow 0.1s ease,
    filter 0.15s;
}

.icon:hover {
  filter: brightness(0.97);
}

.icon:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgb(52 85 57 / 0.2);
}

/* Two-state buttons hold both icons; show the one that matches. */
.icon .when-off,
.icon.is-muted .when-on,
.icon.is-paused .when-on {
  display: none;
}

.icon.is-muted .when-off,
.icon.is-paused .when-off {
  display: block;
}

/* ----- Touch controls (touch screens only) ----- */

.touch {
  display: none;
}

@media (any-pointer: coarse) {
  .touch {
    position: absolute;
    inset: auto var(--edge) max(18px, env(safe-area-inset-bottom));
    display: flex;
    align-items: end;
    gap: 6px;
    pointer-events: none;
  }

  .touch button {
    position: relative;
    pointer-events: auto;
    width: clamp(56px, 25vw, 106px);
    height: clamp(76px, 22vw, 88px);
    border-radius: 26px;
    font-size: 32px;
    color: var(--green-dark);
    background: rgb(255 255 255 / 0.82);
    border: 3px solid #fff;
    box-shadow:
      0 5px 0 rgb(79 127 59 / 0.35),
      0 10px 20px rgb(52 85 57 / 0.18);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    touch-action: none;
    transition:
      transform 0.08s ease,
      box-shadow 0.08s ease;
  }

  .touch .jump {
    margin-left: auto;
    width: clamp(68px, 29vw, 112px);
    height: clamp(92px, 26vw, 104px);
    border-radius: 50%;
    color: #7a4f00;
    background: linear-gradient(rgb(255 224 130 / 0.95), rgb(255 194 31 / 0.92));
    box-shadow:
      0 5px 0 var(--gold-dark),
      0 10px 20px rgb(217 154 0 / 0.25);
  }

  .touch button.held {
    transform: translateY(4px);
    background: var(--paper);
    box-shadow: 0 1px 0 rgb(79 127 59 / 0.35);
  }

  .touch .jump.held {
    background: #ffe082;
    box-shadow: 0 1px 0 var(--gold-dark);
  }

  /* Small thumbs miss: each button catches touches a little outside its edge,
     and the two arrows meet in the middle of the gap between them. */
  .touch button::before {
    content: '';
    position: absolute;
    inset: -28px -14px -14px;
  }

  .touch .jump::before {
    inset: -40px -24px -14px -40px;
  }

  .touch [data-control='left']::before {
    right: -3px;
  }

  .touch [data-control='right']::before {
    left: -3px;
  }

  /* A blur behind every button and badge is redrawn each frame over the
     moving game, which costs phones and older iPads smoothness. */
  .touch button,
  .score,
  .lives,
  .icon,
  .level-badge {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}

/* Phones in landscape: low, wide buttons that stay in the ground strip under
   the bunny, so they do not hide it or what is coming. */
@media (any-pointer: coarse) and (max-height: 520px) {
  .touch {
    bottom: max(6px, calc(env(safe-area-inset-bottom) - 12px));
    gap: 10px;
  }

  .touch button {
    width: clamp(84px, 13vw, 120px);
    height: 58px;
    border-radius: 20px;
    font-size: 26px;
    background: rgb(255 255 255 / 0.68);
  }

  .touch .jump {
    width: clamp(100px, 15vw, 132px);
    height: 64px;
    border-radius: 32px;
    background: linear-gradient(rgb(255 224 130 / 0.85), rgb(255 194 31 / 0.82));
  }
}

/* iPad: bigger buttons, further in from the edges where hands rest. */
@media (any-pointer: coarse) and (min-width: 700px) and (min-height: 700px) {
  .touch {
    inset: auto max(28px, var(--edge)) max(28px, env(safe-area-inset-bottom));
    gap: 14px;
  }

  .touch button {
    width: 120px;
    height: 104px;
    font-size: 36px;
  }

  .touch .jump {
    width: 136px;
    height: 136px;
  }
}

/* ----- Title / pause / win card ----- */

.overlay {
  position: absolute;
  inset: 0;
  /* Flex + auto margins: centered when the card fits, scrollable from the top when it does not. */
  display: flex;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 16px;
  background: rgb(200 229 226 / 0.35);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fade-in 0.2s ease;
}

.overlay.hidden {
  display: none;
}

.card {
  margin: auto;
  flex-shrink: 0;
}

.card,
.share {
  width: min(380px, 100%);
  padding: 30px 28px 24px;
  text-align: center;
  background: var(--paper);
  border: 4px solid #fff;
  border-radius: 32px;
  box-shadow: 0 24px 70px rgb(52 85 57 / 0.25);
  animation: pop-in 0.3s cubic-bezier(0.2, 1.4, 0.4, 1);
}

.hero {
  display: block;
  width: 140px;
  height: 140px;
  margin: -12px auto -4px;
}

h1,
h2 {
  margin: 12px 0 6px;
  font-weight: 900;
  letter-spacing: -0.5px;
}

h1 {
  font-size: 30px;
}

h2 {
  font-size: 22px;
}

.card p,
.share p {
  margin: 0 0 22px;
  color: var(--muted);
  font-weight: 700;
}

.card p:empty {
  display: none;
}

.card-actions {
  display: grid;
  gap: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 22px;
  border-radius: 18px;
  font-size: 17px;
  font-weight: 900;
  transition: transform 0.1s ease;
}

.btn:active {
  transform: translateY(3px);
}

.btn svg {
  width: 20px;
  height: 20px;
}

.primary {
  color: #fff;
  background: var(--green);
  box-shadow: 0 5px 0 var(--green-dark);
}

.primary:active {
  box-shadow: 0 2px 0 var(--green-dark);
}

.secondary {
  background: var(--soft);
  box-shadow: 0 5px 0 var(--soft-dark);
}

.secondary:active {
  box-shadow: 0 2px 0 var(--soft-dark);
}

.small {
  padding: 10px 16px;
  font-size: 15px;
}

.keys {
  margin: 18px 0 0 !important;
  font-size: 13px;
}

kbd {
  display: inline-block;
  min-width: 24px;
  padding: 2px 6px;
  margin: 0 2px;
  font: inherit;
  font-weight: 800;
  border: 1px solid #dce0cf;
  border-bottom-width: 3px;
  border-radius: 7px;
  background: #fff;
}

@media (pointer: coarse) {
  .keys {
    display: none;
  }
}

/* ----- Share dialog ----- */

.share {
  position: relative;
  color: var(--ink);
  padding-top: 26px;
}

.share::backdrop {
  background: rgb(52 85 57 / 0.3);
  backdrop-filter: blur(4px);
}

.share .close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 40px;
  height: 40px;
  box-shadow: none;
  border: 0;
  background: var(--soft);
}

.share h2 {
  margin-top: 4px;
}

.qr {
  width: min(220px, 70vw);
  margin: 0 auto 18px;
  padding: 10px;
  background: #fff;
  border-radius: 20px;
  box-shadow: inset 0 0 0 2px var(--soft);
}

.qr svg {
  display: block;
  width: 100%;
  height: auto;
  stroke: none;
}

.link-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.link-row input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  background: #fff;
  border: 2px solid var(--soft);
  border-radius: 14px;
}

.share > .btn {
  width: 100%;
}

/* ----- Motion ----- */

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(10px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* Share dialog on short screens (phones in landscape): QR beside the text. */
.share {
  max-height: calc(100svh - 24px);
  overflow: auto;
}

@media (max-height: 520px) {
  .share {
    width: min(560px, 100%);
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: 20px;
    align-items: center;
    text-align: left;
    padding: 20px;
  }

  .share .qr {
    grid-row: 1 / span 5;
    grid-column: 1;
    width: min(180px, 40svh);
    margin: 0;
  }

  .share > :not(.qr, .close) {
    grid-column: 2;
  }

  .share p {
    margin-bottom: 14px;
  }
}

/* ----- Level badge, language button, level banner ----- */

.hud-left {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.level-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 52px;
  padding: 0 14px 0 12px;
  border-radius: 20px;
  background: var(--glass);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
  border: 1px solid rgb(255 255 255 / 0.7);
  font-size: 22px;
  font-weight: 900;
}

.level-badge svg {
  color: var(--cap, #e5484d);
}

/* The level number takes the color of its difficulty. */
.level-badge[data-tier='easy'] b {
  color: #4f7f3b;
}

.level-badge[data-tier='medium'] b {
  color: #c5751d;
}

.level-badge[data-tier='hard'] b {
  color: #b23a33;
}

.icon.lang {
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0.5px;
}

.banner {
  position: absolute;
  top: 22%;
  left: 50%;
  translate: -50% 0;
  padding: 12px 26px;
  border-radius: 999px;
  background: var(--paper);
  box-shadow: var(--shadow);
  font-size: clamp(18px, 3vw, 26px);
  font-weight: 900;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
}

.banner.show {
  animation: banner 2.6s ease both;
}

@keyframes banner {
  0% {
    opacity: 0;
    transform: translateY(-12px) scale(0.9);
  }
  12%,
  80% {
    opacity: 1;
    transform: none;
  }
  100% {
    opacity: 0;
    transform: translateY(-8px);
  }
}

/* ----- Your animal: the picker dialog ----- */

.character-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.character-option {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 6px 4px 8px;
  border-radius: 18px;
  font-size: 14px;
  font-weight: 900;
  color: var(--ink);
  background: var(--soft);
  box-shadow: 0 3px 0 var(--soft-dark);
}

.character-option canvas {
  width: 64px;
  height: 64px;
}

.character-option[aria-checked='true'] {
  background: #fff;
  box-shadow:
    0 0 0 3px var(--green),
    0 3px 0 3px var(--green-dark);
}

.profile-label {
  margin: 12px 0 6px !important;
  font-weight: 900;
  text-align: left;
}

.color-list {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 14px;
}

.color-option {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid #fff;
  background: var(--swatch);
  box-shadow: 0 0 0 2px var(--soft-dark);
}

.color-option[aria-checked='true'] {
  box-shadow: 0 0 0 3px var(--green-dark);
  transform: scale(1.12);
}

.profile-form label {
  display: block;
  margin-bottom: 6px;
  font-weight: 900;
  text-align: left;
}

.profile-form input {
  font-weight: 900;
}

/* Short screens: six bunnies in one row, the name below. */
@media (max-height: 520px) {
  .share.profile {
    display: block;
    width: min(620px, 100%);
  }

  .share.install,
  .share.scan {
    display: block;
    text-align: center;
  }

  .character-list {
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
  }

  .profile-label {
    margin: 6px 0 4px !important;
  }

  .color-list {
    margin-bottom: 8px;
  }

  .character-option canvas {
    width: 52px;
    height: 52px;
  }
}

/* ----- Stars on the win card ----- */

.stars {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin: 2px 0 10px;
}

.stars[hidden] {
  display: none;
}

.star {
  font-size: 40px;
  line-height: 1;
  color: #e3dcc4;
}

.star.earned {
  color: var(--gold);
  text-shadow:
    0 3px 0 var(--gold-dark),
    0 0 14px rgb(255 194 31 / 0.6);
  animation: star-pop 0.5s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}

.star:nth-child(2) {
  transform: translateY(-8px);
  font-size: 48px;
}

.star.earned:nth-child(2) {
  animation-name: star-pop-middle;
}

@keyframes star-pop {
  from {
    transform: scale(0) rotate(-40deg);
    opacity: 0;
  }
}

@keyframes star-pop-middle {
  from {
    transform: translateY(-8px) scale(0) rotate(-40deg);
    opacity: 0;
  }
}

/* Short screens (phones in landscape): keep the card on screen. */
@media (max-height: 520px) {
  .card {
    padding: 14px 22px 16px;
  }

  .hero {
    width: 90px;
    height: 90px;
    margin: -8px auto -6px;
  }

  .card p {
    margin-bottom: 12px;
  }

  .star {
    font-size: 30px;
  }

  .star:nth-child(2) {
    font-size: 36px;
  }

  .level-badge {
    height: 46px;
  }
}

/* Phones, upright or sideways: a compact HUD so every button fits and the
   level stays visible. */
@media (max-width: 600px), (max-height: 520px) {
  .hud-left,
  .action-group {
    gap: 5px;
  }

  .actions {
    gap: 10px;
  }

  .level-badge,
  .lives {
    height: 38px;
    padding: 0 8px;
    border-radius: 14px;
    font-size: 17px;
  }

  .level-badge svg {
    width: 16px;
    height: 16px;
  }

  .heart {
    font-size: 15px;
  }

  .score {
    column-gap: 5px;
    padding: 4px 9px 6px 7px;
    border-radius: 14px;
  }

  .score-icon {
    font-size: 17px;
  }

  .score b {
    font-size: 17px;
  }

  .score small {
    font-size: 11px;
  }

  /* The carrot count says it already; the bar needs the room. */
  .score .progress {
    display: none;
  }

  .score-icon {
    grid-row: auto;
  }

  .golden {
    grid-row: auto;
    font-size: 16px;
  }

  .icon {
    width: 34px;
    height: 34px;
    border-radius: 12px;
  }

  .icon svg {
    width: 18px;
    height: 18px;
  }

  .icon.lang {
    font-size: 11px;
  }
}

/* Phones held upright: the counters on one row, the buttons on the next. */
@media (max-width: 600px) {
  .hud {
    flex-wrap: wrap;
    row-gap: 6px;
  }

  .actions {
    margin-left: auto;
  }
}

/* Short screens: a smaller level banner, so it does not cover the level. */
@media (max-height: 520px) {
  .banner {
    top: 20%;
    padding: 8px 18px;
    font-size: 17px;
  }
}

/* "Turn the phone sideways" on the home screen, only on upright phones. */
.rotate-hint {
  display: none;
}

@media (any-pointer: coarse) and (orientation: portrait) and (max-width: 600px) {
  .home .rotate-hint {
    display: block;
    margin: 14px 0 0 !important;
    font-size: 14px;
  }

  .rotate-hint::before {
    content: '📱↻ ';
  }
}

/* ----- First steps on level 1: a finger on the button to press ----- */

@media (any-pointer: coarse) {
  .touch[data-hint='right'] [data-control='right'],
  .touch[data-hint='jump'] .jump {
    animation: hint-pulse 1.1s ease-in-out infinite;
  }

  .touch[data-hint='right'] [data-control='right']::after,
  .touch[data-hint='jump'] .jump::after {
    content: '👆';
    position: absolute;
    left: 50%;
    bottom: calc(100% + 6px);
    translate: -50% 0;
    font-size: 40px;
    line-height: 1;
    filter: drop-shadow(0 3px 4px rgb(52 85 57 / 0.3));
    animation: hint-tap 1.1s ease-in-out infinite;
    pointer-events: none;
  }
}

@keyframes hint-pulse {
  50% {
    box-shadow:
      0 0 0 8px rgb(255 194 31 / 0.55),
      var(--shadow);
  }
}

@keyframes hint-tap {
  50% {
    transform: translateY(10px);
  }
}

/* ----- Screens: the menu (home, levels) or the game ----- */

.hud-left,
.actions {
  position: relative;
  z-index: 3;
}

.banner {
  z-index: 3;
}

.overlay {
  z-index: 4;
}

.stage[data-screen='menu'] .hud-left,
.stage[data-screen='menu'] .touch,
.stage[data-screen='game'] .menu {
  display: none;
}

.menu {
  --top: calc(max(14px, env(safe-area-inset-top)) + 66px);

  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  padding: var(--top) var(--edge) max(16px, env(safe-area-inset-bottom));
  overflow-y: auto;
  /* The level drifting by behind stays visible, a little softer at the bottom. */
  background: linear-gradient(rgb(255 253 243 / 0) 35%, rgb(255 253 243 / 0.45));
}

.menu[data-view='home'] .levels,
.menu[data-view='home'] .room-screen,
.menu[data-view='levels'] .home,
.menu[data-view='levels'] .room-screen,
.menu[data-view='room'] .home,
.menu[data-view='room'] .levels {
  display: none;
}

/* ----- Home ----- */

.home {
  margin: auto;
  width: min(820px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 0.9fr);
  align-items: center;
  gap: 22px;
  padding: 18px 22px 18px 18px;
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 3px solid #fff;
  border-radius: 30px;
  box-shadow: 0 24px 60px rgb(52 85 57 / 0.22);
  animation: rise-in 0.35s ease both;
}

/* Who you play, the title and what to do, on a soft panel of their own. */
.home-brand {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 16px 14px 18px;
  text-align: center;
  border-radius: 24px;
  background: linear-gradient(rgb(255 255 255 / 0.75), rgb(255 243 207 / 0.8));
  box-shadow: inset 0 0 0 2px rgb(255 255 255 / 0.9);
}

/* Who you play, hopping above the title: tap it to change. */
.hero-button {
  position: relative;
  margin-bottom: -22px;
  padding: 0;
  border-radius: 50%;
  background: none;
}

.home-hero {
  display: block;
  width: 150px;
  height: 150px;
  filter: drop-shadow(0 10px 8px rgb(52 85 57 / 0.18));
}

.hero-pencil {
  position: absolute;
  top: 20px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: var(--green-dark);
  background: #fff;
  box-shadow: var(--shadow);
}

.hero-pencil svg {
  width: 18px;
  height: 18px;
}

.logo {
  margin: 0;
  font-size: clamp(40px, 6.4vw, 60px);
  line-height: 1;
  letter-spacing: -1px;
  color: #fff;
  /* A thick outline and a chunky drop, like a sticker. */
  text-shadow:
    3px 0 0 var(--green-dark),
    -3px 0 0 var(--green-dark),
    0 3px 0 var(--green-dark),
    0 -3px 0 var(--green-dark),
    2px 2px 0 var(--green-dark),
    -2px 2px 0 var(--green-dark),
    2px -2px 0 var(--green-dark),
    -2px -2px 0 var(--green-dark),
    0 8px 0 var(--green-dark),
    0 14px 22px rgb(52 85 57 / 0.3);
}

.logo-mario {
  color: #ffb24d;
}

.home-text {
  max-width: 30ch;
  margin: 10px 0 0;
  font-weight: 800;
  color: var(--muted);
}

/* The buttons: one line each, Play the biggest. */
.home-panel {
  display: grid;
  gap: 12px;
}

.home-buttons,
.join-form {
  display: grid;
  gap: 12px;
}

.home-buttons[hidden],
.join-form[hidden] {
  display: none;
}

.home-button {
  --top: #ffe08a;
  --bot: #f5c13c;
  --lip: var(--gold-dark);
  --ink: #6b4300;

  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 56px;
  padding: 8px 14px;
  border-radius: 18px;
  font-size: 20px;
  font-weight: 900;
  line-height: 1.1;
  color: var(--ink);
  background: linear-gradient(var(--top), var(--bot));
  box-shadow: 0 5px 0 var(--lip);
  transition: transform 0.1s ease;
}

.home-button:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 var(--lip);
}

.home-button svg {
  flex: none;
  width: 24px;
  height: 24px;
}

.home-button.play {
  --top: #80b862;
  --bot: var(--green);
  --lip: var(--green-dark);
  --ink: #fff;

  min-height: 70px;
  font-size: 28px;
}

.home-button.play svg {
  width: 30px;
  height: 30px;
}

.home-button.rejoin {
  --top: #7cc2ef;
  --bot: #3f92d2;
  --lip: #2d6fa6;
  --ink: #fff;
}

.home-button.join {
  --top: #f1f8ec;
  --bot: #d9ebd3;
  --lip: #a9c4a0;
  --ink: var(--green-dark);
}

.play-button {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 20px 12px 12px;
  border-radius: 24px;
  color: #fff;
  text-align: left;
  background: linear-gradient(#80b862, var(--green));
  box-shadow:
    0 6px 0 var(--green-dark),
    0 14px 26px rgb(79 127 59 / 0.3);
  transition: transform 0.1s ease;
}

.play-button:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--green-dark);
}

.play-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: rgb(255 255 255 / 0.25);
  animation: play-pulse 1.6s ease-in-out infinite;
}

.play-icon svg {
  width: 32px;
  height: 32px;
  margin-left: 4px;
}

.play-words {
  display: grid;
  min-width: 0;
}

.play-words b {
  font-size: 30px;
  line-height: 1.05;
}

.play-words small {
  overflow: hidden;
  font-size: 15px;
  font-weight: 800;
  white-space: nowrap;
  text-overflow: ellipsis;
  opacity: 0.95;
}

.star-pill {
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 900;
  white-space: nowrap;
  color: var(--gold-dark);
  background: #fff3c9;
}

.home .keys,
.home .rotate-hint {
  margin: 0 !important;
  text-align: center;
  font-weight: 800;
  color: var(--muted);
}

.home .keys {
  font-size: 13px;
}

/* Join a room: the panel that takes the buttons' place. */
.join-title {
  margin: 0;
  font-size: 22px;
  text-align: center;
}

.join-or {
  margin: 0;
  font-weight: 800;
  text-align: center;
  color: var(--muted);
}

.join-code {
  display: flex;
  gap: 8px;
}

.join-code input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  font: inherit;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 4px;
  text-align: center;
  text-transform: uppercase;
  color: var(--ink);
  background: #fff;
  border: 2px solid var(--soft-dark);
  border-radius: 14px;
}

.join-code input::placeholder {
  font-size: 15px;
  letter-spacing: 0;
  text-transform: none;
  color: var(--muted);
}

.join-back {
  justify-self: center;
}

.join-error {
  flex-basis: 100%;
  margin: 0 !important;
  font-size: 14px;
  font-weight: 800;
  text-align: center;
  color: #c2453d;
}

.join-error:empty {
  display: none;
}

.join-retry {
  margin: 0 auto;
}

/* ----- The room ----- */

.room-screen {
  margin: auto;
  width: min(820px, 100%);
  display: grid;
  gap: 14px;
  padding: 20px;
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 3px solid #fff;
  border-radius: 30px;
  box-shadow: 0 24px 60px rgb(52 85 57 / 0.22);
  animation: rise-in 0.35s ease both;
}

/* The title and, big in the middle, the code friends type. */
.room-head {
  display: grid;
  justify-items: center;
  gap: 2px;
  text-align: center;
}

.room-head h2 {
  margin: 0;
  font-size: 30px;
}

.room-code-label {
  margin-top: 4px;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--muted);
}

.room-code {
  padding: 2px 26px 4px 34px;
  border: 3px dashed var(--soft-dark);
  border-radius: 20px;
  font-size: 48px;
  line-height: 1.15;
  letter-spacing: 10px;
  color: var(--green-dark);
  background: rgb(255 255 255 / 0.7);
}

.room-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.85fr) minmax(0, 1fr);
  gap: 14px;
}

.room-panel {
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 16px;
  border-radius: 24px;
  background: #fff;
  box-shadow: 0 4px 0 var(--soft);
}

.room-panel h3 {
  margin: 0;
  font-size: 20px;
  font-weight: 900;
  text-align: center;
}

.room-invite {
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
  text-align: center;
}

.room-invite .qr {
  width: min(190px, 100%);
  padding: 8px;
  border: 3px solid var(--ink);
  border-radius: 18px;
  box-shadow: none;
}

.room-invite p {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
}

.room-invite .link-row {
  width: 100%;
  margin: 0;
}

.room-invite .link-row input {
  font-size: 13px;
}

.room-share {
  width: auto;
  min-width: 200px;
  min-height: 52px;
  font-size: 21px;
}

.room-players {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.room-player {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 60px;
  padding: 4px 12px 4px 6px;
  border-radius: 18px;
  background: var(--soft);
}

.room-player canvas,
.room-player-slot {
  flex: none;
  width: 48px;
  height: 48px;
}

.room-player.is-me {
  background: #fff6d6;
  box-shadow: inset 0 0 0 2px var(--gold);
}

.room-player.is-ready {
  box-shadow: inset 0 0 0 3px var(--green);
}

.room-player.is-away canvas,
.room-player.is-away .room-player-name {
  opacity: 0.45;
}

.room-player.is-empty {
  background: none;
  border: 2px dashed var(--soft-dark);
}

.room-player-slot {
  border: 2px dashed var(--soft-dark);
  border-radius: 12px;
  background: var(--paper);
}

.room-player.is-empty .room-player-name {
  font-size: 15px;
  font-weight: 800;
  color: var(--muted);
}

.room-player-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-size: 17px;
  font-weight: 900;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.room-tags {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
}

.tag {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
  color: #fff;
  background: var(--muted);
}

.tag.host {
  background: var(--carrot);
}

.tag.you {
  background: #7b68c8;
}

.tag.ready {
  background: var(--green);
}

.tag.away {
  background: #b3ac9e;
}

/* Your character, picked right in the room. */
.room-me .character-list {
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.room-me .character-option canvas {
  width: 56px;
  height: 56px;
}

.room-me .color-list {
  flex-wrap: wrap;
  justify-content: flex-start;
  margin: 0;
}

.room-me-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.room-me-label {
  flex: none;
  min-width: 84px;
  font-weight: 900;
}

.room-me-row input {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  font: inherit;
  font-size: 17px;
  font-weight: 800;
  color: var(--ink);
  background: #fff;
  border: 2px solid var(--soft-dark);
  border-radius: 14px;
}

.room-status {
  min-height: 1.4em;
  margin: 0;
  font-weight: 800;
  text-align: center;
  color: var(--muted);
}

/* The level everyone will play: its picture, number and name, and Change level for the host. */
.room-level {
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 10px 14px 10px 10px;
  box-shadow:
    0 0 0 4px var(--tier),
    0 6px 0 4px var(--tier-dark);
}

.room-level[hidden] {
  display: none;
}

.room-level-picture {
  display: block;
  width: 150px;
  height: auto;
  aspect-ratio: 860 / 460;
  border-radius: 14px;
  background: linear-gradient(#cfeaf6, #eef8f2);
}

.room-level-words {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.room-level-number {
  justify-self: start;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 900;
  color: #fff;
  background: var(--tier);
}

.room-level-name {
  overflow: hidden;
  font-size: 22px;
  font-weight: 900;
  line-height: 1.2;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.room-level .room-change {
  width: auto;
  min-height: 48px;
  padding: 8px 16px;
  font-size: 18px;
  white-space: nowrap;
}

.room-level .room-change[hidden] {
  display: none;
}

/* Pick a level (or Ready), and Leave beside it. */
.room-actions {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
  gap: 14px;
}

.room-actions .home-button {
  min-height: 64px;
  font-size: 24px;
}

.room-actions .home-button.leave {
  --top: #b5aef7;
  --bot: #7d72e0;
  --lip: #5548b5;
  --ink: #fff;
}

/* Ready: a calm mint button that says how to undo it. */
.ready-button.is-ready {
  --top: #f1f8ec;
  --bot: #d9ebd3;
  --lip: #a9c4a0;
  --ink: var(--green-dark);

  font-size: 19px;
}

.room-screen button:disabled {
  opacity: 0.5;
  pointer-events: none;
}

/* ----- Room notes (toasts) ----- */

.toasts {
  position: absolute;
  top: calc(max(14px, env(safe-area-inset-top)) + 58px);
  left: 50%;
  z-index: 5;
  display: grid;
  justify-items: center;
  gap: 6px;
  width: min(440px, calc(100% - 32px));
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  padding: 8px 16px;
  border-radius: 16px;
  font-weight: 800;
  text-align: center;
  background: var(--paper);
  border: 2px solid #fff;
  box-shadow: 0 8px 24px rgb(52 85 57 / 0.2);
  animation: pop-in 0.25s ease;
  transition:
    opacity 0.4s,
    transform 0.4s;
}

.toast.out {
  opacity: 0;
  transform: translateY(-8px);
}

/* ----- Install guide and QR scanner ----- */

.install-steps {
  display: grid;
  gap: 10px;
  margin: 6px 0 16px;
  padding: 0;
  list-style: none;
  text-align: left;
  counter-reset: step;
}

.install-steps li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-weight: 800;
  counter-increment: step;
}

.install-steps li::before {
  content: counter(step);
  flex: none;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-weight: 900;
  color: #fff;
  background: var(--green);
}

.scan-box {
  position: relative;
  width: min(300px, 70vw, 55svh);
  aspect-ratio: 1;
  margin: 6px auto 14px;
  overflow: hidden;
  border-radius: 22px;
  background: #2b3a2c;
}

.scan-box video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scan-frame {
  position: absolute;
  inset: 16%;
  border: 4px solid rgb(255 255 255 / 0.9);
  border-radius: 18px;
  box-shadow: 0 0 0 999px rgb(0 0 0 / 0.25);
}

.scan p,
.install p {
  margin-bottom: 0;
}

.install .btn {
  margin-top: 14px;
}

/* Phones held upright: one column; friends join with the Share button. */
@media (max-width: 600px) {
  .room-screen {
    padding: 12px;
    border-radius: 24px;
  }

  .room-code {
    font-size: 38px;
  }

  .room-grid {
    grid-template-columns: 1fr;
  }

  .room-invite .qr,
  .room-invite p,
  .room-invite .link-row {
    display: none;
  }

  .room-invite {
    padding: 10px;
  }

  .room-me .character-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .room-me-label {
    min-width: 0;
  }

  .room-actions {
    grid-template-columns: 1fr;
  }

  .room-level {
    gap: 10px;
  }

  .room-level-picture {
    width: 96px;
  }

  .room-level-name {
    font-size: 17px;
    white-space: normal;
  }

  .room-level .room-change {
    min-height: 42px;
    padding: 6px 10px;
    font-size: 15px;
  }
}

/* ----- Level picker ----- */

.levels {
  width: min(1060px, 100%);
  height: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 3px solid #fff;
  border-radius: 30px;
  box-shadow: 0 24px 60px rgb(52 85 57 / 0.22);
  animation: rise-in 0.3s ease both;
}

.levels-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.levels-head h2 {
  flex: 1;
  margin: 0;
  font-size: 26px;
}

.tier-tabs {
  display: flex;
  gap: 10px;
}

.tier-tab,
.level-card,
.level-grid,
.room-level {
  --tier: var(--green);
  --tier-dark: var(--green-dark);
  --tier-soft: #e4f0d8;
}

[data-tier='medium'] {
  --tier: #ec9a3c;
  --tier-dark: #c5751d;
  --tier-soft: #fcebd4;
}

[data-tier='hard'] {
  --tier: #e0574f;
  --tier-dark: #b23a33;
  --tier-soft: #fadcd8;
}

.tier-tab {
  flex: 1;
  display: grid;
  justify-items: center;
  gap: 1px;
  padding: 9px 8px 10px;
  border-radius: 18px;
  font-size: 18px;
  font-weight: 900;
  color: var(--tier-dark);
  background: var(--tier-soft);
  box-shadow: 0 4px 0 color-mix(in srgb, var(--tier-soft) 70%, var(--tier-dark));
  transition: transform 0.1s ease;
}

.tier-tab[aria-selected='true'] {
  color: #fff;
  background: var(--tier);
  box-shadow: 0 4px 0 var(--tier-dark);
}

.tier-tab:active {
  transform: translateY(2px);
}

.tier-stars {
  font-size: 13px;
  opacity: 0.9;
}

.level-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(176px, 1fr));
  align-content: start;
  gap: 16px 14px;
  margin: 0 -6px;
  padding: 8px 6px 18px;
  overflow-y: auto;
}

.level-card {
  position: relative;
  display: grid;
  padding: 7px 7px 9px;
  text-align: left;
  border-radius: 22px;
  background: #fff;
  box-shadow:
    0 5px 0 var(--soft-dark),
    0 10px 22px rgb(52 85 57 / 0.12);
  transition: transform 0.12s ease;
  animation: rise-in 0.3s ease both;
}

.level-card:hover {
  transform: translateY(-3px);
}

.level-card:active {
  transform: translateY(2px);
}

.level-card:nth-child(4n + 2) {
  animation-delay: 0.04s;
}

.level-card:nth-child(4n + 3) {
  animation-delay: 0.08s;
}

.level-card:nth-child(4n) {
  animation-delay: 0.12s;
}

.level-picture {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 860 / 460;
  border-radius: 16px;
  background: linear-gradient(#cfeaf6, #eef8f2);
}

.level-number {
  position: absolute;
  top: -4px;
  left: -4px;
  display: grid;
  place-items: center;
  min-width: 40px;
  height: 40px;
  padding: 0 8px;
  border: 3px solid #fff;
  border-radius: 15px;
  font-size: 19px;
  font-weight: 900;
  color: #fff;
  background: var(--tier);
  box-shadow: 0 3px 0 var(--tier-dark);
}

.level-next {
  position: absolute;
  top: 13px;
  right: 13px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 900;
  color: #6b4700;
  background: var(--gold);
  box-shadow: 0 2px 0 var(--gold-dark);
}

.level-next:empty {
  display: none;
}

.level-name {
  margin: 8px 4px 0;
  overflow: hidden;
  font-size: 16px;
  font-weight: 900;
  line-height: 1.2;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.level-stars {
  margin: 1px 4px 0;
  font-size: 21px;
  line-height: 1.1;
  letter-spacing: 1px;
  color: #e6e3d3;
}

.level-stars .earned {
  color: var(--gold);
  text-shadow: 0 1px 0 var(--gold-dark);
}

.level-card.is-current {
  box-shadow:
    0 0 0 4px var(--gold),
    0 5px 0 4px var(--gold-dark),
    0 12px 26px rgb(217 154 0 / 0.3);
}

/* The picked level: a thick ring in its tier color with a tick, lifted a little. */
.level-card.is-selected {
  transform: translateY(-3px);
  box-shadow:
    0 0 0 5px var(--tier),
    0 6px 0 5px var(--tier-dark),
    0 14px 28px rgb(52 85 57 / 0.25);
}

.level-card.is-selected::after {
  content: '✓';
  position: absolute;
  top: -10px;
  right: -10px;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 3px solid #fff;
  border-radius: 50%;
  font-size: 20px;
  font-weight: 900;
  color: #fff;
  background: var(--tier);
  box-shadow: 0 3px 0 var(--tier-dark);
}

/* Back (or Back to room) and Play for the picked level, side by side. */
.levels-foot {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr);
  gap: 14px;
}

.levels-foot .home-button {
  min-height: 62px;
  font-size: 22px;
  white-space: nowrap;
}

.levels-foot .home-button.play {
  font-size: 26px;
}

/* In a room a tap on a card picks the level, so there is only Back to room. */
.levels-foot:has(.play[hidden]) {
  grid-template-columns: 1fr;
}

.levels-foot .home-button[hidden] {
  display: none;
}

.levels-foot .home-button.back {
  --top: #7cc2ef;
  --bot: #3f92d2;
  --lip: #2d6fa6;
  --ink: #fff;
}

/* ----- Pause, win and out-of-lives card ----- */

.card-title {
  font-size: 26px;
}

.card .card-actions {
  margin-top: 10px;
}

.ghost {
  padding: 8px 16px;
  font-size: 16px;
  color: var(--muted);
}

.ghost:active {
  transform: translateY(2px);
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
}

@keyframes play-pulse {
  50% {
    transform: scale(1.08);
  }
}

/* Phones held upright: two level cards per row, and the home card in one column. */
@media (max-width: 600px) {
  .menu {
    --top: calc(max(14px, env(safe-area-inset-top)) + 52px);
  }

  .home {
    width: min(440px, 100%);
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
    padding: 12px;
    border-radius: 24px;
  }

  .home-brand {
    padding: 10px 12px 14px;
  }

  .levels {
    padding: 12px;
    border-radius: 24px;
  }

  .levels-head h2 {
    font-size: 21px;
  }

  .tier-tab {
    font-size: 16px;
  }

  .level-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px 10px;
  }

  .level-name {
    font-size: 14px;
  }

  .levels-foot {
    gap: 10px;
  }

  .levels-foot {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr);
  }

  .levels-foot .home-button {
    gap: 6px;
    min-height: 54px;
    padding: 8px 10px;
    font-size: 17px;
  }

  .levels-foot .home-button.play {
    font-size: 21px;
  }
}

/* Short screens (phones held sideways): side by side, so nothing scrolls on
   the home screen and the level cards get the most room. */
@media (max-height: 520px) {
  .menu {
    --top: calc(max(10px, env(safe-area-inset-top)) + 50px);

    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  .home {
    gap: 16px;
    padding: 12px 16px 12px 12px;
    border-radius: 24px;
  }

  .home-brand {
    padding: 10px 12px 12px;
  }

  .home-panel,
  .home-buttons,
  .join-form {
    gap: 9px;
  }

  .home-button {
    min-height: 44px;
    font-size: 17px;
  }

  .home-button.play {
    min-height: 54px;
    font-size: 24px;
  }

  .hero-button {
    margin-bottom: -14px;
  }

  .home-hero {
    width: 104px;
    height: 104px;
  }

  .hero-pencil {
    top: 10px;
    right: 0;
    width: 28px;
    height: 28px;
  }

  .join-code input {
    font-size: 18px;
  }

  .room-screen {
    gap: 8px;
    padding: 10px 12px;
    border-radius: 22px;
  }

  .room-head h2 {
    font-size: 22px;
  }

  .room-code {
    font-size: 30px;
  }

  .room-panel {
    padding: 10px;
  }

  .room-invite .qr {
    width: 130px;
  }

  .room-share {
    min-height: 44px;
    font-size: 18px;
  }

  .room-player {
    min-height: 44px;
  }

  .room-player canvas,
  .room-player-slot {
    width: 36px;
    height: 36px;
  }

  .room-player-name {
    font-size: 15px;
  }

  .room-me .character-option canvas {
    width: 44px;
    height: 44px;
  }

  .room-actions .home-button {
    min-height: 50px;
    font-size: 20px;
  }

  .logo {
    font-size: clamp(36px, 6.4vw, 52px);
  }

  .home-text {
    margin-top: 10px;
    font-size: 14px;
  }

  .home-panel {
    gap: 9px;
    padding: 12px;
    border-radius: 24px;
  }

  .play-button {
    padding: 8px 16px 8px 8px;
    border-radius: 20px;
  }

  .play-icon {
    width: 46px;
    height: 46px;
  }

  .play-icon svg {
    width: 26px;
    height: 26px;
  }

  .play-words b {
    font-size: 24px;
  }

  .levels {
    display: grid;
    grid-template-columns: 190px minmax(0, 1fr);
    grid-template-rows: auto 1fr auto;
    gap: 10px 14px;
    padding: 10px;
    border-radius: 22px;
  }

  .levels-head {
    flex-wrap: wrap;
    gap: 4px 8px;
  }

  .levels-head {
    justify-content: space-between;
  }

  .levels-head h2 {
    flex: none;
    font-size: 19px;
    line-height: 1.1;
  }

  .tier-tabs {
    grid-column: 1;
    flex-direction: column;
    align-self: start;
  }

  .tier-tabs {
    gap: 8px;
  }

  /* Name and stars on one line, so the tabs stay short. */
  .tier-tab {
    flex: none;
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 7px 8px 8px;
    border-radius: 14px;
    font-size: 16px;
  }

  .level-grid {
    grid-column: 2;
    grid-row: 1 / -1;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px 10px;
    margin: 0;
    padding: 6px 4px 10px;
  }

  .level-name {
    font-size: 14px;
  }

  .level-stars {
    font-size: 16px;
  }

  /* Play over Back in the left column, under the tabs. */
  .levels-foot {
    grid-column: 1;
    grid-row: 3;
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .levels-foot .play {
    order: -1;
  }

  .levels-foot .home-button {
    min-height: 44px;
    padding: 6px 10px;
    border-radius: 14px;
    font-size: 17px;
  }

  .levels-foot .home-button.play {
    font-size: 20px;
  }
}

/* ----- Livelier screens ----- */

/* While playing, the top bar keeps only sound and pause; share and language
   come back on the pause card, above its blur. */
.stage[data-state='playing'] #share,
.stage[data-state='playing'] #language {
  display: none;
}

.stage[data-screen='game']:not([data-state='playing']) .actions {
  z-index: 5;
}

/* The counters drop in, one after another, when a level starts. */
.stage[data-screen='game'] .hud-left > * {
  animation: drop-in 0.45s cubic-bezier(0.2, 1.4, 0.4, 1) backwards;
}

.stage[data-screen='game'] .hud-left > :nth-child(2) {
  animation-delay: 0.08s;
}

.stage[data-screen='game'] .hud-left > :nth-child(3) {
  animation-delay: 0.16s;
}

@keyframes drop-in {
  from {
    opacity: 0;
    transform: translateY(-24px) scale(0.9);
  }
}

/* A carrot picked: the carrot and the number jump. */
.score.bump .score-icon {
  animation: carrot-bump 0.35s ease;
}

.score.bump b {
  display: inline-block;
  animation: number-bump 0.35s ease;
}

@keyframes carrot-bump {
  40% {
    transform: scale(1.35) rotate(-14deg);
  }
}

@keyframes number-bump {
  40% {
    transform: scale(1.3);
    color: var(--carrot);
  }
}

/* A life lost: the hearts shake. */
.lives.lost {
  animation: shake 0.5s ease;
}

@keyframes shake {
  20%,
  60% {
    transform: translateX(-5px) rotate(-3deg);
  }
  40%,
  80% {
    transform: translateX(5px) rotate(3deg);
  }
}

.banner {
  border: 3px solid #fff;
  background: linear-gradient(var(--paper), #fff6d9);
  box-shadow:
    0 5px 0 rgb(217 154 0 / 0.25),
    var(--shadow);
}

/* ----- Home: a bobbing title, sparkles and a shiny Play button ----- */

.home-brand {
  position: relative;
}

.home-brand::before,
.home-brand::after {
  content: '✦';
  position: absolute;
  color: #fff;
  text-shadow: 0 0 12px rgb(255 194 31 / 0.9);
  pointer-events: none;
  animation: twinkle 2.4s ease-in-out infinite;
}

.home-brand::before {
  top: 34%;
  left: -6%;
  font-size: 28px;
}

.home-brand::after {
  top: 18%;
  right: -2%;
  font-size: 20px;
  animation-delay: 1.1s;
}

@keyframes twinkle {
  0%,
  100% {
    opacity: 0.2;
    transform: scale(0.6) rotate(0deg);
  }
  50% {
    opacity: 1;
    transform: scale(1.1) rotate(45deg);
  }
}

.logo span {
  display: inline-block;
  animation:
    logo-in 0.6s cubic-bezier(0.2, 1.5, 0.4, 1) backwards,
    logo-bob 3.2s ease-in-out 0.6s infinite;
}

.logo .logo-mario {
  animation-delay: 0.12s, 1.2s;
}

@keyframes logo-in {
  from {
    opacity: 0;
    transform: scale(0.4) rotate(-8deg);
  }
}

@keyframes logo-bob {
  0%,
  100% {
    transform: translateY(0) rotate(-1.5deg);
  }
  50% {
    transform: translateY(-6px) rotate(1.5deg);
  }
}

/* The menu buttons rise in one after another. */
.home-buttons > * {
  animation: rise-in 0.4s ease backwards;
}

.home-buttons > :nth-child(2) {
  animation-delay: 0.06s;
}

.home-buttons > :nth-child(3) {
  animation-delay: 0.12s;
}

.home-buttons > :nth-child(4) {
  animation-delay: 0.18s;
}

.home-buttons > :nth-child(n + 5) {
  animation-delay: 0.24s;
}

/* A light sweeps across Play now and then. */
.play-button {
  position: relative;
  overflow: hidden;
}

.play-button::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    105deg,
    transparent 35%,
    rgb(255 255 255 / 0.35) 50%,
    transparent 65%
  );
  transform: translateX(-100%);
  animation: shine 3.6s ease-in-out 1s infinite;
  pointer-events: none;
}

@keyframes shine {
  0% {
    transform: translateX(-100%);
  }
  35%,
  100% {
    transform: translateX(100%);
  }
}

@media (hover: hover) {
  .play-button,
  .home-button,
  .btn.primary,
  .btn.secondary {
    transition:
      transform 0.12s ease,
      filter 0.12s ease;
  }

  .play-button:hover,
  .home-button:hover,
  .btn.primary:hover,
  .btn.secondary:hover {
    transform: translateY(-2px);
    filter: brightness(1.05);
  }
}

/* ----- Level picker: tier icons, done marks, a glowing next level ----- */

.tier-name::before {
  margin-right: 4px;
}

.tier-tab[data-tier='easy'] .tier-name::before {
  content: '🌱';
}

.tier-tab[data-tier='medium'] .tier-name::before {
  content: '🌼';
}

.tier-tab[data-tier='hard'] .tier-name::before {
  content: '⛰️';
}

.tier-tab:not([aria-selected='true']):hover {
  filter: brightness(0.97);
}

.level-card {
  transition:
    transform 0.12s ease,
    box-shadow 0.12s ease;
}

@media (hover: hover) {
  .level-card:hover {
    box-shadow:
      0 7px 0 var(--soft-dark),
      0 16px 28px rgb(52 85 57 / 0.18);
  }
}

/* A green tick on levels already finished; a gold one with every star. */
.level-card.is-done::after {
  content: '✓';
  position: absolute;
  top: 13px;
  right: 13px;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 3px solid #fff;
  border-radius: 50%;
  font-size: 16px;
  font-weight: 900;
  color: #fff;
  background: var(--green);
  box-shadow: 0 2px 0 var(--green-dark);
}

.level-card.is-perfect {
  background: linear-gradient(#fff 60%, #fff4cf);
}

.level-card.is-perfect::after {
  content: '★';
  background: var(--gold);
  box-shadow: 0 2px 0 var(--gold-dark);
}

/* The next level: its "Next" tag takes the tick's corner. */
.level-card.is-current::after {
  display: none;
}

.level-card.is-current {
  animation:
    rise-in 0.3s ease both,
    next-glow 1.8s ease-in-out 0.4s infinite;
}

.level-next {
  animation: next-bob 1.8s ease-in-out infinite;
}

@keyframes next-glow {
  50% {
    box-shadow:
      0 0 0 6px var(--gold),
      0 5px 0 6px var(--gold-dark),
      0 14px 34px rgb(255 194 31 / 0.55);
  }
}

@keyframes next-bob {
  50% {
    transform: translateY(-3px);
  }
}

/* ----- Pause, win and out-of-lives card ----- */

.card {
  position: relative;
}

.card > :not(.confetti) {
  position: relative;
}

/* Sun rays turning slowly behind the hero when a level is won. */
.overlay[data-state='won'] .card::before {
  content: '';
  position: absolute;
  top: -20px;
  left: 50%;
  width: 260px;
  height: 260px;
  margin-left: -130px;
  border-radius: 50%;
  background: repeating-conic-gradient(rgb(255 194 31 / 0.22) 0 12deg, transparent 12deg 30deg);
  mask: radial-gradient(closest-side, #000 40%, transparent);
  animation: rays 14s linear infinite;
  pointer-events: none;
}

@keyframes rays {
  to {
    transform: rotate(1turn);
  }
}

.overlay[data-state='won'] .card-title {
  color: var(--green-dark);
}

.overlay[data-state='out'] .card-title {
  color: #c5751d;
}

.confetti {
  position: absolute;
  top: 210px;
  left: 50%;
  width: 0;
  height: 0;
  z-index: 2;
  pointer-events: none;
}

.confetti i {
  position: absolute;
  width: 9px;
  height: 14px;
  margin: -7px 0 0 -4px;
  border-radius: 3px;
  opacity: 0;
  animation: confetti 1.3s cubic-bezier(0.15, 0.7, 0.3, 1) both;
}

@keyframes confetti {
  0% {
    opacity: 1;
    transform: translate(0, 0) scale(0.3) rotate(0deg);
  }
  70% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(var(--x), calc(var(--y) + 60px)) scale(1) rotate(var(--spin));
  }
}

@media (max-height: 520px) {
  .confetti {
    top: 130px;
  }

  .overlay[data-state='won'] .card::before {
    top: -50px;
    width: 200px;
    height: 200px;
    margin-left: -100px;
  }

  .level-card.is-done::after {
    width: 26px;
    height: 26px;
    font-size: 14px;
  }
}

/* ----- Greeting card after the last level ----- */

.overlay.finale .card {
  width: min(400px, 100%);
  padding-top: 38px;
  border: 0;
  /* A card with a stitched golden edge. */
  background:
    radial-gradient(circle at 12% 8%, rgb(255 194 31 / 0.18), transparent 40%),
    radial-gradient(circle at 88% 92%, rgb(240 154 69 / 0.16), transparent 40%), var(--paper);
  box-shadow:
    0 0 0 4px #fff,
    0 0 0 8px var(--gold),
    0 24px 70px rgb(52 85 57 / 0.3);
}

.overlay.finale .card::after {
  content: '';
  position: absolute;
  inset: 8px;
  border: 2px dashed rgb(217 154 0 / 0.45);
  border-radius: 24px;
  pointer-events: none;
}

.overlay.finale .card::before {
  display: none;
}

.ribbon {
  position: absolute;
  top: -18px;
  left: 50%;
  z-index: 3;
  padding: 7px 26px;
  transform: translateX(-50%);
  color: #fff;
  font-size: 15px;
  font-weight: 900;
  white-space: nowrap;
  background: #e35d4f;
  border-radius: 10px;
  box-shadow: 0 4px 0 #b23a33;
}

.overlay.finale .card > .ribbon {
  position: absolute;
}

.finale-scene {
  display: block;
  width: min(100%, 300px);
  height: auto;
  aspect-ratio: 300 / 170;
  margin: 0 auto 4px;
  border-radius: 18px;
  box-shadow:
    0 0 0 3px #fff,
    0 6px 16px rgb(52 85 57 / 0.18);
}

.finale-scene[hidden],
.hero[hidden] {
  display: none;
}

.overlay.finale .card p {
  white-space: pre-line;
}

.overlay.finale .confetti {
  top: 120px;
}

/* Room above the card for its ribbon. */
.overlay.finale {
  padding-top: 30px;
}

@media (max-height: 520px) {
  .overlay.finale .card {
    padding-top: 24px;
  }

  .finale-scene {
    width: min(100%, 180px);
  }
}

.feedback-link {
  display: block;
  width: fit-content;
  margin: 0.4rem auto 0;
  padding: 0.45rem 0.6rem;
  color: inherit;
  font-size: 0.875rem;
  text-align: center;
  text-decoration: underline;
  text-underline-offset: 0.18em;
}
.feedback-link [lang="vi"],
html:lang(vi) .feedback-link [lang="en"] { display: none; }
html:lang(vi) .feedback-link [lang="vi"] { display: inline; }
