:root {
  --ink: #3a2618;
  --ink-soft: #6d5442;
  --paper: #fff6e3;
  --accent: #d8452b;
  --slab: Rockwell, "Roboto Slab", "Rockwell Nova", Georgia, serif;
  --sans: "Avenir Next", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #8ed1e6;
  color: var(--ink);
  font-family: var(--sans);
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: pointer;
}

[hidden] { display: none !important; }

kbd {
  display: inline-block;
  padding: 0 .45em;
  border: 1.5px solid currentColor;
  border-bottom-width: 3px;
  border-radius: 5px;
  font: inherit;
  font-weight: 700;
  line-height: 1.35;
}

/* --- In-game display --- */

#hud {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 8px;
  pointer-events: none;
}

.tag {
  justify-self: start;
  padding: 7px 12px;
  border-radius: 10px;
  background: var(--paper);
  box-shadow: 0 2px 0 rgba(58, 38, 24, .25);
  white-space: nowrap;
}

.tag.right {
  justify-self: end;
  margin-right: 48px;
  font-size: 15px;
}

.best b {
  font-family: var(--slab);
  font-size: 18px;
}

#lives {
  display: flex;
  gap: 5px;
  align-items: center;
  min-height: 36px;
}

#lives svg { display: block; transition: opacity .25s, transform .25s; }
#lives svg.spent { opacity: .2; transform: rotate(35deg) translateY(2px); }

.tag.score {
  justify-self: center;
  min-width: 92px;
  padding: 9px 16px 7px;
  text-align: center;
  line-height: 1;
}

#score {
  display: block;
  font-family: var(--slab);
  font-size: 40px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

#score.bump { animation: bump .28s ease-out; }

@keyframes bump {
  40% { transform: scale(1.28); color: var(--accent); }
}

#height {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
}

#mute {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  right: 12px;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: var(--paper);
  box-shadow: 0 2px 0 rgba(58, 38, 24, .25);
  color: var(--ink);
  cursor: pointer;
}

#mute:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
#mute .cross { display: none; }
#mute[aria-pressed="true"] .waves { display: none; }
#mute[aria-pressed="true"] .cross { display: inline; }

#toast {
  position: fixed;
  top: calc(84px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  padding: 7px 16px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--slab);
  font-size: 18px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
}

#toast.show { animation: toast 2.6s ease-out; }

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

#hint {
  position: fixed;
  bottom: calc(22px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  padding: 7px 14px;
  border-radius: 10px;
  background: var(--paper);
  box-shadow: 0 2px 0 rgba(58, 38, 24, .25);
  font-size: 15px;
  white-space: nowrap;
  pointer-events: none;
}

/* --- Title and game over cards --- */

.card {
  position: fixed;
  top: max(4vh, 64px); /* Clears the mute button on small screens. */
  left: 50%;
  transform: translateX(-50%);
  width: min(440px, calc(100vw - 32px));
  padding: 22px 28px 20px;
  border-radius: 16px;
  background: var(--paper);
  box-shadow: 0 5px 0 rgba(58, 38, 24, .28);
  text-align: center;
  cursor: pointer;
}

.card h1 {
  margin: 0;
  font-family: var(--slab);
  font-size: clamp(42px, 9vw, 58px);
  font-weight: 700;
  line-height: 1.02;
  letter-spacing: -.01em;
  color: var(--accent);
}

.card h2 {
  margin: 0;
  font-family: var(--slab);
  font-size: 30px;
  font-weight: 700;
  color: var(--accent);
}

.lead {
  margin: 8px 0 12px;
  font-size: 17px;
  font-weight: 600;
}

.card ul {
  margin: 0 0 14px;
  padding: 0;
  list-style: none;
  font-size: 15px;
  line-height: 1.4;
  color: var(--ink-soft);
}

.card li + li { margin-top: 3px; }

.cta {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  animation: pulse 1.7s ease-in-out infinite;
}

@keyframes pulse {
  50% { opacity: .55; }
}

.final {
  margin: 6px 0 0;
  font-size: 20px;
  font-weight: 600;
}

#final-score {
  font-family: var(--slab);
  font-size: 68px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.sub {
  margin: 2px 0 0;
  font-size: 15px;
  color: var(--ink-soft);
}

#final-best.new {
  margin-top: 6px;
  font-family: var(--slab);
  font-size: 19px;
  font-weight: 700;
  color: var(--accent);
}

#over-card .cta { margin-top: 14px; }

/* Leave the fallen tower in view: the camera moves it to the right on wide screens. */
@media (min-width: 760px) {
  #over-card {
    top: 50%;
    left: max(5vw, 28px);
    transform: translateY(-50%);
    width: 340px;
  }
}

@media (max-height: 560px) {
  .card ul { display: none; }
  .card { padding: 14px 20px; }
}

@media (prefers-reduced-motion: reduce) {
  .cta, #score.bump { animation: none; }
}
