/* Ziggy Dash. The game draws itself on the canvas; this styles the cards and HUD in the
   Ziggy Games print-shop look: cream stock, ink outlines, overprinted red and blue. */
:root {
  --paper: #f2ead8;
  --paper-2: #e9dfc8;
  --ink: #1b1f1c;
  --ink-2: #4a4f47;
  --green: #1f6b4a;
  --red: #e5452c;
  --blue: #2e63c9;
  --yellow: #f1bd2c;
  --display: 'Fraunces', Georgia, serif;
  --mono: 'IBM Plex Mono', ui-monospace, Menlo, monospace;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #62b1e6;
  color: var(--ink);
  font: 500 15px/1.5 var(--mono);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

.zd {
  position: fixed;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

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

/* ---- HUD ------------------------------------------------------------------------ */
.hud {
  position: absolute;
  top: calc(12px + var(--safe-t));
  left: calc(16px + var(--safe-l));
  right: calc(16px + var(--safe-r));
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  z-index: 5;
}
.hud[hidden] {
  display: none;
}
.hud-score {
  display: flex;
  align-items: baseline;
  gap: 18px;
  font-family: var(--display);
  font-variation-settings: 'SOFT' 100, 'WONK' 1, 'opsz' 72;
  color: #fffaf0;
  -webkit-text-stroke: 6px var(--ink);
  paint-order: stroke fill;
  text-shadow: 3px 3px 0 rgba(46, 99, 201, 0.7);
}
.hud-dist b {
  font-weight: 900;
  font-size: clamp(34px, 5vw, 52px);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.hud-dist .unit {
  font-weight: 800;
  font-size: clamp(18px, 2.4vw, 26px);
  margin-left: 4px;
}
.hud-bones {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 900;
  font-size: clamp(22px, 3vw, 32px);
}
.hud-bones svg {
  width: 1.3em;
  height: 0.65em;
  fill: #fff6d8;
  stroke: var(--ink);
  stroke-width: 2.5;
  stroke-linejoin: round;
  overflow: visible;
}
.hud-bones.pop {
  animation: pop 260ms cubic-bezier(0.3, 1.6, 0.5, 1);
}
@keyframes pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.22); }
  100% { transform: scale(1); }
}
.hud-actions {
  display: flex;
  gap: 10px;
  pointer-events: auto;
}
.icon-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 3px solid var(--ink);
  background: var(--paper);
  box-shadow: 3px 3px 0 var(--ink);
  display: grid;
  place-items: center;
  padding: 0;
  transition: transform 80ms ease, box-shadow 80ms ease;
}
.icon-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--ink);
}
.icon-btn svg {
  width: 24px;
  height: 24px;
  fill: var(--ink);
}
.icon-btn .wave {
  fill: none;
  stroke: var(--ink);
  stroke-width: 2.2;
  stroke-linecap: round;
}
[data-mute] .off,
[data-mute].muted .on {
  display: none;
}
[data-mute].muted .off {
  display: inline;
}
.icon-btn.muted .off {
  display: block;
}

/* ---- Speed-level banner and the splat layer ---------------------------------------- */
.banner {
  position: absolute;
  left: 50%;
  top: 24%;
  z-index: 5;
  display: grid;
  justify-items: center;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%);
  font-family: var(--display);
  font-variation-settings: 'SOFT' 100, 'WONK' 1, 'opsz' 144;
  color: var(--red);
  -webkit-text-stroke: 7px #fffaf0;
  paint-order: stroke fill;
  text-shadow: 4px 4px 0 rgba(46, 99, 201, 0.75);
  white-space: nowrap;
}
.banner b {
  font-style: italic;
  font-weight: 900;
  font-size: clamp(46px, 9vw, 96px);
  line-height: 1;
  letter-spacing: -0.02em;
}
.banner span {
  margin-top: 4px;
  font-weight: 800;
  font-size: clamp(18px, 2.6vw, 28px);
  color: var(--ink);
  text-shadow: none;
  -webkit-text-stroke: 5px #fffaf0;
}
.banner.show {
  animation: banner 1.7s cubic-bezier(0.2, 0.9, 0.3, 1) both;
}
@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6) rotate(-4deg); }
  14% { opacity: 1; transform: translate(-50%, -50%) scale(1.1) rotate(2deg); }
  24% { transform: translate(-50%, -50%) scale(1) rotate(0deg); }
  78% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -62%) scale(0.96); }
}
/* Poop that hits the screen sits over the HUD but under the cards. */
#splat {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 5;
  pointer-events: none;
}

/* ---- Panels --------------------------------------------------------------------- */
.panel {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(16px + var(--safe-t)) calc(16px + var(--safe-r)) calc(16px + var(--safe-b)) calc(16px + var(--safe-l));
}
.panel[hidden] {
  display: none;
}
.panel.pause,
.panel.over {
  background: rgba(27, 31, 28, 0.28);
}
.title {
  justify-content: flex-end;
  padding-right: calc(clamp(16px, 6vw, 96px) + var(--safe-r));
}
.card {
  position: relative;
  width: min(440px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: 22px 24px 20px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 20px;
  box-shadow: 8px 8px 0 var(--ink);
  text-align: center;
}
.card::before {
  /* Offset blue plate behind the card, like a misregistered second ink. */
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 20px;
  background: var(--blue);
  transform: translate(-10px, 9px) rotate(-1deg);
  z-index: -1;
  opacity: 0.85;
}
h1,
h2 {
  margin: 0;
  font-family: var(--display);
  font-variation-settings: 'SOFT' 100, 'WONK' 1, 'opsz' 144;
  letter-spacing: -0.03em;
}
h1 {
  font-weight: 900;
  font-size: clamp(44px, 6.2vw, 68px);
  line-height: 0.92;
  white-space: nowrap;
}
h1 em {
  font-style: italic;
  font-weight: 700;
  color: var(--red);
  text-shadow: 3px 3px 0 rgba(46, 99, 201, 0.55);
}
h2 {
  font-weight: 800;
  font-size: clamp(28px, 4.2vw, 40px);
  line-height: 1.02;
}
.over h2 {
  color: #6b3f22;
}
.tag {
  margin: 10px 0 16px;
  color: var(--ink-2);
  font-size: 14px;
}
.worlds {
  display: inline-flex;
  gap: 0;
  border: 3px solid var(--ink);
  border-radius: 999px;
  padding: 3px;
  background: var(--paper-2);
  margin-bottom: 14px;
}
.world {
  border: 0;
  background: transparent;
  padding: 9px 16px;
  min-height: 44px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.world.on {
  background: var(--ink);
  color: var(--paper);
}
.run {
  display: block;
  width: 100%;
  min-height: 60px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--yellow);
  box-shadow: 5px 5px 0 var(--ink);
  font: 900 28px/1 var(--display);
  font-variation-settings: 'SOFT' 100, 'WONK' 1, 'opsz' 72;
  letter-spacing: -0.01em;
  transition: transform 80ms ease, box-shadow 80ms ease;
}
.run:hover {
  background: #f5c947;
}
.run:active {
  transform: translate(3px, 3px);
  box-shadow: 2px 2px 0 var(--ink);
}
.ghost {
  min-height: 60px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
  padding: 0 22px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 13px;
}
.row {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}
.row .run {
  flex: 1;
}
.how {
  margin: 14px 0 0;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--ink-2);
}
.k {
  display: inline-block;
  padding: 0 6px;
  border: 2px solid var(--ink);
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 600;
  background: #fffaf0;
}
.stats {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px 18px;
  margin: 14px 0 0;
  padding-top: 12px;
  border-top: 2px dashed rgba(27, 31, 28, 0.25);
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.stats b {
  font-family: var(--display);
  font-size: 17px;
  letter-spacing: 0;
  text-transform: none;
}
.home {
  position: absolute;
  top: calc(14px + var(--safe-t));
  left: calc(16px + var(--safe-l));
  padding: 8px 14px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
  box-shadow: 3px 3px 0 var(--ink);
  text-decoration: none;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.04em;
}
.foot {
  position: absolute;
  bottom: calc(10px + var(--safe-b));
  right: calc(16px + var(--safe-r));
  margin: 0;
  display: flex;
  gap: 10px;
  align-items: center;
  font-size: 12px;
  color: #fffaf0;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}
.foot a,
.link {
  color: #fffaf0;
  background: none;
  border: 0;
  padding: 10px 4px;
  text-decoration: underline;
  text-underline-offset: 3px;
  font-size: 12px;
}
.result {
  display: flex;
  justify-content: center;
  gap: 28px;
  margin: 18px 0 6px;
}
.result div {
  display: grid;
}
.result b {
  font: 900 clamp(40px, 6vw, 58px) / 1 var(--display);
  font-variation-settings: 'SOFT' 100, 'WONK' 1, 'opsz' 144;
  font-variant-numeric: tabular-nums;
}
.result span {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.newbest {
  display: inline-block;
  margin: 6px 0 0;
  padding: 4px 12px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--yellow);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-size: 12px;
  transform: rotate(-3deg);
}
.newbest[hidden] {
  display: none;
}
.best-line {
  margin: 8px 0 0;
  font-size: 12.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.noscript {
  position: absolute;
  inset: auto 16px 16px;
  padding: 12px;
  background: var(--paper);
  border: 3px solid var(--ink);
}

/* Tall screens (phones held upright): cards sit high over the sky, the run stays below. */
body.tall .title {
  justify-content: center;
  align-items: flex-start;
  padding-top: calc(64px + var(--safe-t));
  padding-right: calc(16px + var(--safe-r));
}
body.tall .panel.over,
body.tall .panel.pause {
  align-items: flex-start;
  padding-top: calc(76px + var(--safe-t));
}
body.tall .card {
  padding: 18px 18px 16px;
}
body.tall .foot {
  left: calc(16px + var(--safe-l));
  justify-content: center;
}

@media (max-height: 520px) and (min-aspect-ratio: 1/1) {
  /* Phones on their side: compact cards that leave Ziggy and Pam in view. */
  .title {
    padding-right: calc(20px + var(--safe-r));
  }
  .card {
    padding: 12px 16px 12px;
    width: min(360px, 100%);
    box-shadow: 5px 5px 0 var(--ink);
  }
  .card::before {
    transform: translate(-6px, 6px) rotate(-1deg);
  }
  h1 {
    font-size: 38px;
  }
  h2 {
    font-size: 26px;
  }
  .title .tag {
    display: none;
  }
  .tag {
    margin: 6px 0 8px;
    font-size: 12.5px;
  }
  .worlds {
    margin: 10px 0 8px;
  }
  .world {
    min-height: 38px;
    padding: 6px 14px;
  }
  .run,
  .ghost {
    min-height: 48px;
  }
  .run {
    font-size: 23px;
  }
  .how {
    margin-top: 8px;
    font-size: 11.5px;
  }
  .stats {
    margin-top: 8px;
    padding-top: 8px;
    font-size: 11px;
  }
  .result {
    margin: 8px 0 0;
  }
  .result b {
    font-size: 38px;
  }
  .row {
    margin-top: 10px;
  }
  .home {
    padding: 6px 12px;
  }
  .foot {
    left: calc(16px + var(--safe-l));
    right: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .hud-bones.pop {
    animation: none;
  }
  .banner.show {
    animation: banner-calm 1.7s linear both;
  }
  @keyframes banner-calm {
    0%, 100% { opacity: 0; }
    10%, 80% { opacity: 1; }
  }
}
