:root {
  --ink: #171926;
  --ink-soft: #4a4c63;
  --paper: #ffffff;
  --cream: #fbe8c3;
  --sky: #cfe6ff;
  --blue: #2753f0;
  --blue-deep: #1c22a7;
  --yellow: #f9c730;
  --green: #2fbf71;
  --red: #f03b3b;
  --coral: #f9695f;
  --purple: #7b6cf6;
  --orange: #ff9f43;
  --line: 2.5px;
  --pop: 0 4px 0 var(--ink);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --font: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --gutter: max(16px, env(safe-area-inset-left));
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--sky);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
}

.stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

#playfield {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

[data-screen="title"] #playfield,
[data-screen="paused"] #playfield,
[data-screen="pr"] #playfield,
[data-screen="help"] #playfield {
  cursor: default;
}

.rig-canvas {
  position: absolute;
  left: 0;
  top: 0;
  z-index: -1;
  opacity: 0;
  pointer-events: none;
}

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

.hud {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: var(--gutter);
  right: max(16px, env(safe-area-inset-right));
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 12px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-16px);
  transition:
    opacity 260ms var(--ease-out),
    transform 360ms var(--ease-out);
}

[data-screen="playing"] .hud,
[data-screen="paused"] .hud {
  opacity: 1;
  transform: none;
}

.hud-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.hud-score {
  justify-self: start;
  padding: 6px 14px 7px;
  background: var(--paper);
  border: var(--line) solid var(--ink);
  border-radius: 14px;
  box-shadow: var(--pop);
  min-width: 96px;
}

.hud-score strong {
  display: block;
  font-size: 24px;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}

.hud-score strong.bump {
  animation: bump 260ms var(--ease-spring);
}

.hud-wave {
  justify-self: center;
  width: min(300px, 38vw);
  padding: 6px 14px 8px;
  background: var(--paper);
  border: var(--line) solid var(--ink);
  border-radius: 14px;
  box-shadow: var(--pop);
  text-align: center;
}

.hud-wave .hud-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-transform: none;
  letter-spacing: 0;
  font-size: 13px;
  color: var(--ink);
}

.progress {
  height: 10px;
  margin: 5px 0 3px;
  background: #e8eefc;
  border: 2px solid var(--ink);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--green), #5ee59b);
  border-radius: 999px;
  transition: width 320ms var(--ease-out);
}

.hud-fixes {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.hud-actions {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}

.retries {
  display: flex;
  gap: 3px;
  padding: 7px 10px;
  background: var(--paper);
  border: var(--line) solid var(--ink);
  border-radius: 14px;
  box-shadow: var(--pop);
}

.retry-heart {
  width: 20px;
  height: 20px;
  transition:
    transform 300ms var(--ease-spring),
    opacity 300ms var(--ease-out);
}

.retry-heart path {
  fill: var(--coral);
  stroke: var(--ink);
  stroke-width: 2.2;
  stroke-linejoin: round;
}

.retry-heart.lost {
  opacity: 0.25;
  transform: scale(0.8);
}

.retry-heart.lost path {
  fill: #c9cbd8;
}

.retry-heart.gained {
  animation: bump 420ms var(--ease-spring);
}

.icon-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  padding: 0;
  background: var(--paper);
  border: var(--line) solid var(--ink);
  border-radius: 14px;
  box-shadow: var(--pop);
  cursor: pointer;
  transition:
    transform 120ms var(--ease-out),
    box-shadow 120ms var(--ease-out);
}

.icon-button:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--ink);
}

.icon-button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: var(--ink);
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button .sound-body {
  fill: var(--ink);
}

.icon-button .sound-off,
.icon-button[aria-pressed="true"] .sound-on {
  display: none;
}

.icon-button[aria-pressed="true"] .sound-off {
  display: inline;
}

button:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 3px;
}

/* ---------------------------------------------------------------- combo + powers */

.combo {
  position: absolute;
  top: calc(max(10px, env(safe-area-inset-top)) + 84px);
  left: 50%;
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 4px 14px 10px;
  background: var(--yellow);
  border: var(--line) solid var(--ink);
  border-radius: 999px;
  box-shadow: var(--pop);
  transform: translate(-50%, -8px) scale(0.6);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 200ms var(--ease-out),
    transform 300ms var(--ease-spring);
}

.combo.visible {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

.combo.tier-up {
  animation: tier-up 420ms var(--ease-spring);
}

.combo strong {
  font-size: 22px;
  font-weight: 900;
}

.combo span {
  font-size: 13px;
  font-weight: 800;
}

.combo-timer {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 4px;
  height: 3px;
  background: rgba(23, 25, 38, 0.15);
  border-radius: 999px;
  overflow: hidden;
}

.combo-timer div {
  height: 100%;
  width: 100%;
  background: var(--ink);
  transform-origin: left center;
}

.powers {
  position: absolute;
  left: var(--gutter);
  top: calc(max(10px, env(safe-area-inset-top)) + 76px);
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}

.power {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px 7px 8px;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
  box-shadow: 0 3px 0 var(--ink);
  overflow: hidden;
  animation: pop-in 320ms var(--ease-spring);
}

.power-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--ink);
}

.power-ci .power-dot {
  background: var(--green);
}
.power-shield .power-dot {
  background: #3b82f6;
}

.power-bar {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  width: 100%;
  transform-origin: left center;
}

.power-ci .power-bar {
  background: var(--green);
}
.power-shield .power-bar {
  background: #3b82f6;
}

/* ---------------------------------------------------------------- wave banner */

.banner {
  position: absolute;
  left: 50%;
  top: 34%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 14px 30px 16px;
  min-width: min(340px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 22px;
  box-shadow: 0 6px 0 var(--ink);
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -24px) scale(0.92);
  transition:
    opacity 240ms var(--ease-out),
    transform 420ms var(--ease-spring);
}

.banner.visible {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

.banner.leaving {
  opacity: 0;
  transform: translate(-50%, 18px) scale(0.96);
  transition:
    opacity 220ms ease-in,
    transform 260ms ease-in;
}

.banner-step {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--blue);
}

.banner-title {
  font-size: clamp(30px, 7vw, 44px);
  font-weight: 900;
  line-height: 1.05;
}

.banner-subtitle {
  font-family: var(--mono);
  font-size: 14px;
  color: var(--ink-soft);
}

.banner.clear .banner-step {
  color: var(--green);
}

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

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) var(--gutter) max(16px, env(safe-area-inset-bottom));
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity 280ms var(--ease-out),
    visibility 0s linear 280ms;
}

[data-screen="title"] .title-screen,
[data-screen="paused"] .pause-screen,
[data-screen="pr"] #pr-screen,
[data-screen="help"] #help-screen {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition:
    opacity 320ms var(--ease-out),
    visibility 0s;
}

.screen .card,
.title-copy {
  transform: translateY(18px) scale(0.97);
  transition: transform 460ms var(--ease-spring);
}

[data-screen="title"] .title-copy,
[data-screen="paused"] .pause-screen .card,
[data-screen="pr"] #pr-screen .card,
[data-screen="help"] #help-screen .card {
  transform: none;
}

.title-screen {
  flex-direction: column;
  gap: 4px;
  pointer-events: none;
}

[data-screen="title"] .title-screen {
  pointer-events: none;
}

.title-screen .title-copy {
  pointer-events: auto;
}

.bird-slot {
  width: clamp(150px, min(34vh, 52vw), 270px);
  aspect-ratio: 1;
  flex: none;
}

.title-copy {
  max-width: 520px;
  text-align: center;
}

.eyebrow {
  margin: 0 0 4px;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  color: var(--blue);
}

.eyebrow.ok {
  color: #178a4c;
}

.eyebrow.warn {
  color: #c2321f;
}

h1 {
  margin: 0;
  font-size: clamp(44px, 11vw, 76px);
  font-weight: 900;
  line-height: 0.95;
  letter-spacing: -0.02em;
  color: var(--blue);
  -webkit-text-stroke: 2px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 5px 0 var(--ink);
}

.tagline {
  margin: 12px auto 12px;
  max-width: 420px;
  font-size: clamp(15px, 3.8vw, 17px);
  line-height: 1.4;
  color: var(--ink-soft);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 12px;
  margin: 0 0 16px;
  padding: 0;
  list-style: none;
  font-size: 13px;
  font-weight: 700;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 5px;
}

.legend-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--ink);
}

.legend-sentry {
  background: #f0524f;
}
.legend-linear {
  background: var(--purple);
}
.legend-flaky {
  background: #d9cffc;
  border-style: dashed;
}
.legend-regression {
  background: var(--orange);
  width: 18px;
  height: 18px;
}

.legend-chip {
  padding: 1px 7px 2px;
  font-family: var(--mono);
  font-size: 11px;
  color: #ff8a7a;
  background: #2a2236;
  border: 2px solid var(--ink);
  border-radius: 999px;
}

.primary-button {
  min-height: 52px;
  padding: 0 30px;
  font-size: 19px;
  font-weight: 900;
  color: var(--paper);
  background: var(--blue);
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: 0 5px 0 var(--ink);
  cursor: pointer;
  transition:
    transform 120ms var(--ease-out),
    box-shadow 120ms var(--ease-out),
    background 160ms;
}

.primary-button:hover {
  background: #3a63ff;
}

.primary-button:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--ink);
}

.controls {
  margin: 14px 0 0;
  font-size: 13px;
  line-height: 1.8;
  color: var(--ink-soft);
}

kbd {
  display: inline-block;
  padding: 0 6px;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 800;
  line-height: 20px;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 6px;
  box-shadow: 0 2px 0 var(--ink);
}

.best {
  min-height: 18px;
  margin: 8px 0 0;
  font-size: 14px;
  font-weight: 800;
}

.card {
  position: relative;
  width: min(440px, 100%);
  padding: 22px 24px 24px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 24px;
  box-shadow: 0 7px 0 var(--ink);
  text-align: center;
}

.small-card {
  width: min(340px, 100%);
}

.card h2 {
  margin: 0;
  font-size: clamp(24px, 6vw, 30px);
  font-weight: 900;
  line-height: 1.15;
}

.card-copy {
  margin: 8px 0 18px;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink-soft);
}

.result-screen {
  align-items: flex-end;
  padding-bottom: max(24px, env(safe-area-inset-bottom), 7vh);
}

.result-card {
  margin-top: 0;
}

.bird-slot.perch {
  position: absolute;
  left: 50%;
  bottom: 100%;
  width: clamp(130px, min(26vh, 40vw), 200px);
  transform: translate(-50%, 9%);
  pointer-events: none;
}

.pr-meta {
  margin: 6px 0 12px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-soft);
}

.checks {
  margin: 0 0 14px;
  padding: 10px 14px;
  list-style: none;
  text-align: left;
  background: #f3fbf6;
  border: 2px solid var(--ink);
  border-radius: 14px;
  font-size: 14px;
  font-weight: 700;
}

.checks li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
}

.checks li::before {
  content: "";
  flex: none;
  width: 16px;
  height: 16px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--green)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4.5 8.2l2.2 2.2 4.8-4.8' fill='none' stroke='white' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")
    center / 14px no-repeat;
}

.checks li.check-warn::before {
  background: var(--yellow)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 4.5v4.2M8 11.3v.2' fill='none' stroke='%23171926' stroke-width='2.2' stroke-linecap='round'/%3E%3C/svg%3E")
    center / 14px no-repeat;
}

[data-screen="pr"] .checks li {
  animation: check-in 420ms var(--ease-spring) both;
}

[data-screen="pr"] .checks li:nth-child(2) {
  animation-delay: 120ms;
}
[data-screen="pr"] .checks li:nth-child(3) {
  animation-delay: 240ms;
}
[data-screen="pr"] .checks li:nth-child(4) {
  animation-delay: 360ms;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0 0 14px;
}

.stats div {
  padding: 8px 4px;
  background: #f4f6ff;
  border: 2px solid var(--ink);
  border-radius: 12px;
}

.stats dt {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
}

.stats dd {
  margin: 2px 0 0;
  font-size: 20px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.new-best {
  display: none;
  margin: -4px 0 12px;
  font-weight: 900;
  color: var(--blue);
}

.new-best.visible {
  display: block;
  animation: bump 500ms var(--ease-spring);
}

.help-card .stats div {
  background: #fff5f3;
}

.loading {
  position: absolute;
  inset: auto 0 45% 0;
  margin: 0;
  text-align: center;
  font-weight: 800;
  color: var(--ink-soft);
  transition: opacity 240ms var(--ease-out);
}

.stage:not([data-screen="loading"]) .loading {
  opacity: 0;
  pointer-events: none;
}

/* ---------------------------------------------------------------- motion */

@keyframes bump {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.18);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes tier-up {
  0% {
    transform: translate(-50%, 0) scale(1);
  }
  40% {
    transform: translate(-50%, 0) scale(1.25) rotate(-3deg);
  }
  100% {
    transform: translate(-50%, 0) scale(1);
  }
}

@keyframes pop-in {
  from {
    transform: scale(0.6);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes check-in {
  from {
    transform: translateX(-10px);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

/* ---------------------------------------------------------------- small screens */

@media (max-width: 560px) {
  .hud {
    grid-template-columns: auto 1fr;
    grid-template-areas:
      "score actions"
      "wave wave";
    gap: 8px;
  }

  .hud-score {
    grid-area: score;
    min-width: 0;
    padding: 4px 10px 5px;
  }
  .hud-score strong {
    font-size: 20px;
  }
  .hud-actions {
    grid-area: actions;
    gap: 6px;
  }
  .hud-wave {
    grid-area: wave;
    width: 100%;
    padding: 4px 12px 6px;
  }
  .retries {
    padding: 6px 8px;
  }
  .retry-heart {
    width: 17px;
    height: 17px;
  }
  .icon-button {
    width: 38px;
    height: 38px;
  }

  .combo,
  .powers {
    top: calc(max(10px, env(safe-area-inset-top)) + 124px);
  }

  .combo {
    left: auto;
    right: max(16px, env(safe-area-inset-right));
    transform: translate(0, -8px) scale(0.6);
    transform-origin: right center;
  }

  .combo.visible {
    transform: none;
  }

  @keyframes tier-up {
    0% {
      transform: scale(1);
    }
    40% {
      transform: scale(1.25) rotate(-3deg);
    }
    100% {
      transform: scale(1);
    }
  }
}

@media (max-height: 640px) {
  .legend {
    display: none;
  }
  .tagline {
    margin: 8px auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-delay: 0ms !important;
    transition-duration: 1ms !important;
  }
}
