:root {
  color-scheme: light;
  --bg: #f6efe4;
  --ink: #3b2a1e;
  --muted: #8a7462;
  --brick: #c8553d;
  --brick-dark: #9f3f2b;
  --open: #fffaf2;
  --open-line: #d9c6b0;
  --select: #2f6fd6;
  --good: #3f9b5a;
  --good-dark: #2d7442;
  --bad: #d64545;
  --key: #ffffff;
  --key-line: #e3d5c3;
  --brick-w: clamp(84px, 24vmin, 190px);
  --brick-h: calc(var(--brick-w) * 0.56);
  --gap: clamp(5px, 1vmin, 8px);
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overflow-x: hidden;
}

button {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
  cursor: pointer;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

h1 {
  margin: 0;
  font-size: clamp(24px, 4vmin, 34px);
  font-weight: 800;
  letter-spacing: -0.01em;
}

.stars {
  display: flex;
  gap: clamp(8px, 1.6vmin, 14px);
  font-size: clamp(18px, 3vmin, 24px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: #fff;
  border: 2px solid var(--key-line);
  border-radius: 999px;
  padding: 6px 14px;
}

.tally {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.tally.pop {
  animation: pop 0.5s ease-out 2;
}

.star {
  width: 1.25em;
  height: 1.25em;
  stroke-width: 1.4;
  stroke-linejoin: round;
}

.star-bronze {
  fill: #d4884a;
  stroke: #94531f;
}

.star-silver {
  fill: #d3dae2;
  stroke: #7d8a98;
}

.star-gold {
  fill: #ffc21a;
  stroke: #c48a00;
}

/* ---------------------------------------------------------------- dino */

.dino {
  position: fixed;
  left: 0;
  z-index: 5;
  pointer-events: none;
}

.dino svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.dino-kick-leg {
  transform-box: fill-box;
  transform-origin: 50% 10%;
}

.dino-back-leg {
  transform-box: fill-box;
  transform-origin: 50% 10%;
}

.dino.running .dino-kick-leg {
  animation: stride 0.22s ease-in-out infinite alternate;
}

.dino.running .dino-back-leg {
  animation: stride 0.22s ease-in-out infinite alternate-reverse;
}

.dino.running svg {
  animation: bob 0.22s ease-in-out infinite alternate;
}

@keyframes stride {
  from {
    transform: rotate(-28deg);
  }
  to {
    transform: rotate(28deg);
  }
}

@keyframes bob {
  to {
    transform: translateY(-5%);
  }
}

.wall {
  transform-origin: 50% 50%;
}

.reward {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 17px;
  font-weight: 700;
  color: var(--muted);
  padding: 0 4px;
}

.reward .star {
  width: 28px;
  height: 28px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.refresh {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 2px solid var(--key-line);
  background: #fff;
  font-size: 30px;
  font-weight: 800;
  line-height: 1;
  display: grid;
  place-items: center;
  padding: 0 0 3px;
  box-shadow: 0 3px 0 var(--key-line);
}

.refresh:active {
  transform: translateY(2px) rotate(90deg);
  box-shadow: 0 1px 0 var(--key-line);
}

.confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
}

.settings {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.segmented {
  display: inline-flex;
  background: #ebdfcf;
  border-radius: 14px;
  padding: 4px;
  gap: 4px;
}

.segmented button {
  border: 0;
  background: transparent;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 17px;
  font-weight: 700;
  color: var(--muted);
  min-height: 44px;
}

.segmented button[aria-checked="true"] {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.12);
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(20px, 4vmin, 40px);
}

@media (orientation: landscape) and (min-width: 700px) {
  main {
    flex-direction: row;
    justify-content: space-evenly;
  }
}

/* ---------------------------------------------------------------- wall */

.play {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.wall {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--gap);
}

.row {
  display: flex;
  gap: var(--gap);
}

.brick {
  width: var(--brick-w);
  height: var(--brick-h);
  border-radius: 8px;
  font-size: calc(var(--brick-h) * 0.5);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  display: grid;
  place-items: center;
  padding: 0;
  border: 3px solid transparent;
}

.brick.given {
  background: var(--brick);
  border-color: var(--brick-dark);
  color: #fff;
  box-shadow: inset 0 -5px 0 rgb(0 0 0 / 0.14);
  cursor: default;
}

.brick.open {
  background: var(--open);
  border: 3px dashed var(--open-line);
  color: var(--select);
}

.brick.selected {
  border: 4px solid var(--select);
  box-shadow: 0 0 0 5px rgb(47 111 214 / 0.18);
}

.brick.selected:empty::after {
  content: "";
  width: 3px;
  height: 45%;
  background: var(--select);
  animation: blink 1s steps(1) infinite;
}

.brick.solved {
  background: var(--good);
  border-color: var(--good-dark);
  color: #fff;
  box-shadow: inset 0 -5px 0 rgb(0 0 0 / 0.14);
  cursor: default;
}

.brick.wrong {
  border-color: var(--bad);
  color: var(--bad);
  animation: shake 0.4s;
}

.brick.pop {
  animation: pop 0.35s ease-out;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

@keyframes shake {
  20%, 60% {
    transform: translateX(-8px);
  }
  40%, 80% {
    transform: translateX(8px);
  }
}

@keyframes pop {
  50% {
    transform: scale(1.12);
  }
}

/* ---------------------------------------------------------------- keypad */

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: min(100%, 340px);
}

.keypad button {
  aspect-ratio: 1.35;
  border: 2px solid var(--key-line);
  border-radius: 16px;
  background: var(--key);
  font-size: clamp(26px, 4.5vmin, 36px);
  font-weight: 800;
  box-shadow: 0 3px 0 var(--key-line);
}

.keypad button:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--key-line);
}

.keypad .key-back {
  color: var(--muted);
  font-size: clamp(32px, 5.5vmin, 44px);
}

.keypad .key-ok {
  background: var(--good);
  border-color: var(--good-dark);
  box-shadow: 0 3px 0 var(--good-dark);
  color: #fff;
}

.hint {
  margin: 0;
  min-height: 1.5em;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  color: var(--bad);
}

/* ---------------------------------------------------------------- done */

/* Takes the keypad's place, so the finished wall stays in view. */
.done {
  width: min(100%, 340px);
  background: #fff;
  border: 2px solid var(--key-line);
  border-radius: 24px;
  padding: 32px 24px;
  text-align: center;
  animation: pop 0.4s ease-out;
}

.done[hidden],
.keypad[hidden] {
  display: none;
}

.done-star {
  line-height: 0;
  animation: spin 1.2s ease-out;
}

.done-star .star {
  width: 96px;
  height: 96px;
  stroke-width: 1;
}

@keyframes spin {
  from {
    transform: rotate(-180deg) scale(0.3);
  }
}

.done-text {
  font-size: 30px;
  font-weight: 800;
  margin: 12px 0 4px;
}

.done-earned {
  font-size: 20px;
  font-weight: 700;
  color: var(--muted);
  margin: 0 0 24px;
}

#next {
  border: 0;
  border-radius: 16px;
  background: var(--good);
  color: #fff;
  font-size: 24px;
  font-weight: 800;
  padding: 16px 32px;
  box-shadow: 0 4px 0 var(--good-dark);
}

#next:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 var(--good-dark);
}

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