:root {
  --bg: #6fbf5a;
  --card: #fffaf0;
  --ink: #4a3220;
  --accent: #ff7a3d;
  --accent-dark: #d95a1f;
  --purple: #7b4fc9;
  --font: 'Fredoka', 'Chalkboard SE', 'Comic Sans MS', system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: radial-gradient(circle at 50% 30%, #9be07f, var(--bg));
  font-family: var(--font);
  color: var(--ink);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#stage {
  position: absolute;
  inset: 0;
  margin: auto;
  width: min(100vw, calc(100vh * 16 / 9));
  height: min(100vh, calc(100vw * 9 / 16));
  container-type: size;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
  outline: none;
  background: #bfe8ff;
}

.screen {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(60, 120, 40, 0.35);
  border-radius: 12px;
  padding: 16px;
}

.screen[hidden] {
  display: none;
}

.card {
  background: var(--card);
  border-radius: 28px;
  padding: clamp(16px, 4cqh, 32px) clamp(20px, 5cqw, 44px);
  text-align: center;
  box-shadow: 0 8px 0 #e3d2b2, 0 16px 40px rgba(0, 0, 0, 0.25);
  max-width: min(520px, 100%);
  max-height: 100%;
  overflow: auto;
}

h1 {
  margin: 0 0 12px;
  font-size: clamp(28px, 7cqh, 46px);
  color: var(--purple);
}

form {
  display: grid;
  gap: 12px;
}

label,
.field {
  display: grid;
  gap: 6px;
  font-size: 20px;
  font-weight: 600;
  text-align: left;
}

input {
  font: inherit;
  font-size: 22px;
  padding: 10px 14px;
  border: 3px solid #e3d2b2;
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  user-select: text;
  -webkit-user-select: text;
}

input:focus {
  outline: none;
  border-color: var(--purple);
}

#swatches {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.swatch {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 4px solid transparent;
  background: linear-gradient(135deg, var(--mane) 0 35%, var(--body) 35%);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  cursor: pointer;
  transition: transform 0.1s;
}

.swatch[aria-pressed='true'] {
  border-color: var(--purple);
  transform: scale(1.15);
}

#level-picker {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
}

.level-btn {
  font: inherit;
  font-weight: 700;
  font-size: 19px;
  line-height: 1.05;
  min-width: 48px;
  padding: 4px 6px 3px;
  border-radius: 12px;
  border: 3px solid #e3d2b2;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

.level-btn small {
  display: block;
  font-size: 10px;
  color: #ffb300;
  letter-spacing: 0;
}

.level-btn[aria-pressed='true'] {
  border-color: var(--purple);
  background: #f1e9ff;
}

.level-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.start-card {
  position: relative;
  max-width: min(600px, 100%);
}

/* Language choice: a small row above the title */
.lang-switch {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin: -6px -10px 2px 0;
}

.lang-btn {
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
  padding: 5px 10px;
  border-radius: 999px;
  border: 2px solid #e3d2b2;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

.lang-btn[aria-pressed='true'] {
  border-color: var(--purple);
  background: #f1e9ff;
  color: var(--purple);
}

.win-card {
  max-width: min(760px, 100%);
}

.win-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 20px;
  align-items: center;
}

#win-time {
  font-size: 24px;
  font-weight: 700;
  color: var(--purple);
  margin: 4px 0;
}

#win-record {
  font-size: 18px;
  margin: 4px 0;
}

.board {
  background: #fff;
  border: 3px solid #e3d2b2;
  border-radius: 18px;
  padding: 10px 14px;
  text-align: left;
}

.board h2 {
  margin: 0 0 6px;
  font-size: 18px;
  color: var(--ink);
  text-align: center;
}

#best-times {
  margin: 0;
  padding-left: 26px;
  font-size: 17px;
}

#best-times li {
  padding: 2px 6px;
  border-radius: 8px;
}

#best-times li > span {
  display: inline-flex;
}

#best-times .who {
  max-width: 13em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

#best-times .time {
  float: right;
  font-weight: 700;
  margin-left: 10px;
  font-variant-numeric: tabular-nums;
}

#best-times .mine {
  background: #fff1b8;
  font-weight: 700;
}

.big-btn {
  font: inherit;
  font-size: 26px;
  font-weight: 700;
  padding: 12px 28px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 6px 0 var(--accent-dark);
  cursor: pointer;
  margin-top: 6px;
}

.big-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--accent-dark);
}

.big-btn.restart {
  background: var(--purple);
  box-shadow: 0 6px 0 #5a3597;
  font-size: 20px;
}

.big-btn.secondary {
  background: #5ac447;
  box-shadow: 0 6px 0 #3f9a30;
}

.link-btn {
  font: inherit;
  font-size: 18px;
  background: none;
  border: none;
  color: var(--purple);
  text-decoration: underline;
  cursor: pointer;
}

.buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: center;
  align-items: center;
}

.buttons [hidden] {
  display: none;
}

.hint {
  font-size: 17px;
  opacity: 0.75;
  margin: 14px 0 0;
}

kbd {
  font-family: inherit;
  background: #fff;
  border: 2px solid #e3d2b2;
  border-radius: 6px;
  padding: 0 6px;
}

#win-text,
#win-carrots {
  font-size: 22px;
  margin: 8px 0;
}

.stars {
  font-size: 64px;
  letter-spacing: 8px;
  color: #ddd;
}

.stars .on {
  color: #ffc928;
  text-shadow: 0 3px 0 #d99a00;
  display: inline-block;
  animation: pop 0.5s ease-out both;
}

.stars .on:nth-child(2) {
  animation-delay: 0.25s;
}

.stars .on:nth-child(3) {
  animation-delay: 0.5s;
}

@keyframes pop {
  from {
    transform: scale(0);
  }
  70% {
    transform: scale(1.3);
  }
  to {
    transform: scale(1);
  }
}

/* The pause button sits next to the sound button, and only while riding */
#pause {
  right: calc(1.5% + 62px);
  display: none;
}

body[data-screen='play'] #pause {
  display: block;
}

.pause-buttons {
  display: grid;
  gap: 14px;
  margin-top: 8px;
}

.pause-card {
  min-width: min(360px, 100%);
}

.icon-btn {
  position: absolute;
  top: 2.5%;
  right: 1.5%;
  width: 52px;
  height: 52px;
  font-size: 26px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.85);
  cursor: pointer;
  z-index: 5;
}

/* Touch controls only on touch devices, only while playing */
#touch-controls {
  display: none;
}

@media (pointer: coarse) {
  body[data-screen='play'] #touch-controls {
    display: flex;
    position: absolute;
    left: 0;
    right: 0;
    bottom: 3%;
    padding: 0 3%;
    justify-content: space-between;
    align-items: flex-end;
    pointer-events: none;
  }

  .hint {
    display: none;
  }
}

#touch-controls button {
  pointer-events: auto;
  font: inherit;
  font-weight: 700;
  font-size: 30px;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.6);
  color: var(--ink);
  touch-action: none;
}

#touch-controls .pad {
  display: flex;
  gap: 18px;
}

#touch-controls #btn-jump {
  width: 110px;
  height: 110px;
  font-size: 26px;
  background: rgba(255, 122, 61, 0.75);
  color: #fff;
}

#touch-controls button.pressed {
  transform: scale(0.92);
  background: rgba(255, 255, 255, 0.9);
}

/* Short screens (phones in landscape): compact menus and smaller touch buttons */
@container (max-height: 480px) {
  .card {
    padding: 12px 22px;
    border-radius: 20px;
  }

  h1 {
    font-size: 26px;
    margin-bottom: 6px;
  }

  form {
    gap: 6px 12px;
    grid-template-columns: 1fr 1fr;
  }

  form .field,
  form .big-btn {
    grid-column: 1 / -1;
  }

  .card {
    max-width: min(560px, 100%);
  }

  label,
  .field {
    font-size: 15px;
    gap: 3px;
  }

  input {
    font-size: 17px;
    padding: 5px 10px;
    border-width: 2px;
  }

  /* wide, short card: the language buttons fit in the corner beside the title */
  .lang-switch {
    position: absolute;
    top: 10px;
    right: 14px;
    margin: 0;
  }

  .lang-btn {
    font-size: 13px;
    padding: 3px 8px;
  }

  #level-picker {
    gap: 4px;
  }

  .level-btn {
    font-size: 16px;
    min-width: 0;
    padding: 2px 3px;
    border-width: 2px;
  }

  .level-btn small {
    font-size: 8px;
  }

  .swatch {
    width: 34px;
    height: 34px;
    border-width: 3px;
  }

  .big-btn {
    font-size: 20px;
    padding: 8px 22px;
  }

  .big-btn.restart {
    font-size: 16px;
  }

  .win-card .buttons {
    gap: 8px 12px;
  }

  .win-card .big-btn {
    padding: 6px 18px;
    margin-top: 2px;
  }

  #win-text,
  #win-carrots {
    font-size: 17px;
    margin: 4px 0;
  }

  .stars {
    font-size: 40px;
  }

  #win-time {
    font-size: 18px;
    margin: 2px 0;
  }

  #win-record {
    font-size: 14px;
    margin: 2px 0;
  }

  .board {
    padding: 6px 10px;
  }

  .board h2 {
    font-size: 15px;
    margin-bottom: 2px;
  }

  #best-times {
    font-size: 14px;
  }

  #best-times li {
    padding: 0 4px;
  }

  .win-card h1 {
    margin-bottom: 0;
  }

  .win-card #win-text {
    margin: 2px 0 6px;
  }

  #touch-controls button {
    width: 62px;
    height: 62px;
    font-size: 22px;
  }

  #touch-controls .pad {
    gap: 10px;
  }

  #touch-controls #btn-jump {
    width: 80px;
    height: 80px;
    font-size: 20px;
  }

  .icon-btn {
    width: 40px;
    height: 40px;
    font-size: 20px;
  }

  #pause {
    right: calc(1.5% + 48px);
  }

  .pause-buttons {
    gap: 8px;
  }
}

/* Very short screens (phones in landscape) with many levels: squeeze the start card a little more */
@container (max-height: 420px) {
  .start-card {
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .start-card h1 {
    font-size: 22px;
    margin-bottom: 2px;
  }

  .start-card form {
    gap: 4px 12px;
  }

  .start-card .swatch {
    width: 30px;
    height: 30px;
  }

  .start-card .level-btn {
    font-size: 14px;
    padding: 1px 3px;
  }

  .start-card .level-btn small {
    font-size: 7px;
  }

  .start-card .big-btn {
    padding: 6px 22px;
  }
}
