/* Kirk Run — KRKR runner. Local / Pages. Pixel field, crisp type. */
:root {
  --bg: #05070a;
  --paper: #e8eee9;
  --mute: rgba(232, 238, 233, .56);
  --faint: rgba(232, 238, 233, .32);
  --hair: rgba(232, 238, 233, .12);
  --link: #8fbfb0;
  --shot: #c45c4a;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  width: 100%;
  height: 100%;
  height: 100svh;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  background: #000;
  color: var(--paper);
  font-family: Manrope, system-ui, sans-serif;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }

#app {
  width: 100%;
  height: 100%;
  height: 100svh;
  height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  background: #000;
  overscroll-behavior: none;
}

/* Desktop / fine pointer: cinematic 16:9 (landscape) or 9:16 (portrait) letterbox. */
#stage {
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  width: min(100vw, calc(100dvh * 16 / 9));
  height: min(100dvh, calc(100vw * 9 / 16));
  max-width: 100vw;
  max-height: 100dvh;
  box-shadow: 0 0 0 1px var(--hair), 0 24px 80px rgba(0, 0, 0, .7);
}
@supports not (height: 100dvh) {
  #stage {
    width: min(100vw, calc(100vh * 16 / 9));
    height: min(100vh, calc(100vw * 9 / 16));
  }
}
@media (orientation: portrait) {
  #stage {
    width: min(100vw, calc(100dvh * 9 / 16));
    height: min(100dvh, calc(100vw * 16 / 9));
  }
  @supports not (height: 100dvh) {
    #stage {
      width: min(100vw, calc(100vh * 9 / 16));
      height: min(100vh, calc(100vw * 16 / 9));
    }
  }
}

/* Phones & tablets (coarse / no hover): fill the viewport — pad always usable. */
@media (hover: none), (pointer: coarse) {
  #stage {
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    box-shadow: none;
  }
}
@media (max-width: 900px) and (orientation: portrait) {
  #stage {
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    box-shadow: none;
  }
}

#field {
  position: relative;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
}
#view {
  display: block;
  width: 100%;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 16 / 9;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: var(--bg);
  touch-action: none;
}

header.play-head {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 6;
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(6px + env(safe-area-inset-top, 0px)) 12px 6px;
  background: linear-gradient(180deg, rgba(5, 7, 10, .8), transparent);
  pointer-events: none;
}
header.play-head a { pointer-events: auto; }
.logo {
  font-family: Syne, sans-serif;
  letter-spacing: .34em;
  font-size: 11px;
  min-height: 40px;
  display: inline-flex; align-items: center;
}
header nav {
  display: flex; gap: .7rem;
  font-size: 10px; letter-spacing: .2em; text-transform: uppercase;
  color: var(--mute);
}
header nav a {
  min-height: 40px; min-width: 40px;
  display: inline-flex; align-items: center; justify-content: center;
}
header nav a:hover { color: var(--paper); }
@media (max-width: 420px) {
  header nav { display: none; }
  .logo { letter-spacing: .28em; font-size: 10px; }
}
@media (max-width: 520px) and (min-width: 421px) {
  header nav a { font-size: 9px; letter-spacing: .12em; min-width: 36px; padding: 0 4px; }
}

.hud {
  position: absolute;
  top: 8px; right: 14px;
  z-index: 5;
  display: flex; gap: .85rem; align-items: baseline;
  font-size: 11px; letter-spacing: .22em;
  color: var(--mute);
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}
.hud .hi b { color: var(--paper); font-weight: 500; }
.hud .sc {
  font-family: Syne, sans-serif;
  font-size: 15px; letter-spacing: .16em;
  color: var(--paper);
}
.hud.hidden { display: none; }

.flash {
  position: absolute; inset: 0;
  z-index: 7;
  background: var(--shot);
  opacity: 0;
  pointer-events: none;
  transition: opacity .1s linear;
}
.flash.on { opacity: .34; }
.flash.shield { background: var(--link); opacity: .28; }
.flash.glitch {
  background:
    linear-gradient(90deg, rgba(196,92,74,.55), transparent 40%, rgba(80,180,255,.45)),
    repeating-linear-gradient(0deg, rgba(232,238,233,.12) 0 1px, transparent 1px 3px);
  opacity: .42;
  animation: shieldGlitchFlash .32s steps(4, end) both;
}
@keyframes shieldGlitchFlash {
  0% { opacity: .55; transform: translateX(-3px); }
  25% { opacity: .2; transform: translateX(4px); }
  50% { opacity: .48; transform: translateX(-2px); }
  100% { opacity: 0; transform: none; }
}
.lifechip.glitchout {
  animation: lifeChipGlitch .52s steps(3, end) both;
  color: var(--paper) !important;
  background: transparent !important;
  border-color: var(--shot) !important;
  text-shadow: 2px 0 #c45c4a, -2px 0 #50b4ff;
}
@keyframes lifeChipGlitch {
  0% { opacity: 1; transform: translateX(0) skewX(0); letter-spacing: .28em; }
  20% { opacity: 1; transform: translateX(-4px) skewX(-8deg); letter-spacing: .4em; }
  40% { opacity: .4; transform: translateX(5px) skewX(6deg); filter: hue-rotate(90deg); }
  60% { opacity: 1; transform: translateX(-2px); }
  100% { opacity: 0; transform: translateX(8px) scaleX(1.2); }
}

.lifechip {
  margin-top: 4px;
  font-size: 9px;
  letter-spacing: .28em;
  text-transform: uppercase;
  color: var(--mute);
  border: 1px solid var(--hair);
  padding: 2px 8px 3px;
  background: rgba(5,7,10,.62);
}
.lifechip.on {
  color: var(--bg);
  background: var(--link);
  border-color: var(--link);
}
.lifechip.hidden { display: none; }

.pause {
  position: absolute;
  left: 0; right: 0; bottom: 14px;
  z-index: 6;
  text-align: center;
  font-size: 10px; letter-spacing: .24em; text-transform: uppercase;
  color: var(--faint);
  pointer-events: none;
}
.pause.hidden { display: none; }

/* screens */
.screen {
  position: absolute; inset: 0;
  z-index: 8;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 54px 18px 16px;
  text-align: center;
  background: rgba(5, 7, 10, .94);
  overflow: hidden;
}
.screen.hidden { display: none; }
.eyebrow {
  font-size: 10px; letter-spacing: .28em; text-transform: uppercase;
  color: var(--mute); margin-bottom: .55rem;
}
h1 {
  font-family: Syne, sans-serif;
  font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  font-size: clamp(22px, 5.6vmin, 34px); line-height: .92;
}
h1 span {
  display: block;
  font-size: .58em; letter-spacing: .18em; font-weight: 500;
  color: var(--link); margin-bottom: 5px;
}
.lede {
  color: var(--mute);
  margin: .6rem 0 .8rem;
  max-width: 30ch; line-height: 1.45;
  font-size: 13px;
}
.picks { display: flex; gap: 12px; margin: .2rem 0 .7rem; }
.pick {
  background: transparent;
  border: 1px solid var(--hair);
  padding: 4px 4px 6px;
  cursor: pointer;
  color: var(--mute);
  font-family: inherit;
  display: block;
  transition: border-color .16s ease, color .16s ease, transform .16s ease;
}
.pick img {
  display: block;
  width: clamp(56px, 13vmin, 88px);
  aspect-ratio: 1 / 1;
  object-fit: cover;
  object-position: 50% 26%;
  background: #05070a;
  filter: saturate(.85) brightness(.8);
}
.pick .cap {
  display: block;
  margin-top: 5px;
  font-size: 9px; letter-spacing: .22em; text-transform: uppercase;
}
.pick.on { border-color: var(--link); color: var(--paper); }
.pick.on img { filter: none; }
.pick:hover { border-color: var(--link); }

input[type=text] {
  background: transparent;
  border: 0; border-bottom: 1px solid var(--hair);
  color: var(--paper);
  font-family: Syne, sans-serif;
  font-size: 1rem; text-align: center;
  padding: .4rem .2rem;
  margin-bottom: .85rem;
  width: 13rem;
  outline: none;
  min-height: 40px;
}
@media (hover: none), (pointer: coarse), (max-width: 900px) {
  #name, input[type=text] {
    font-size: 16px;
    min-height: 44px;
  }
}
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid rgba(232, 238, 233, .5);
  border-radius: 999px;
  padding: .8em 1.6em;
  font-size: 12px; min-height: 44px; min-width: 44px;
  letter-spacing: .2em; text-transform: uppercase;
  color: var(--paper); background: transparent;
  cursor: pointer;
  font-family: Manrope, system-ui, sans-serif;
}
.btn:hover { background: var(--paper); color: var(--bg); }
.hint {
  color: var(--faint); font-size: 11px; margin-top: .8rem;
  line-height: 1.4; max-width: 32ch;
  letter-spacing: .04em;
}
.hint a { color: var(--paper); border-bottom: 1px solid var(--hair); }
.save { margin-top: .7rem; color: var(--link); font-size: 12px; min-height: 1.2em; letter-spacing: .06em; }
.score-big {
  display: flex; align-items: baseline; gap: .8rem;
  margin: .5rem 0 .1rem;
  font-variant-numeric: tabular-nums;
}
.score-big b {
  font-family: Syne, sans-serif; font-weight: 600;
  font-size: clamp(30px, 8vmin, 46px); letter-spacing: .08em;
}
.score-big i {
  font-style: normal; color: var(--mute);
  font-size: 11px; letter-spacing: .22em;
}
#dead.hard { background: rgba(26, 8, 8, .95); }

/* touch pad — big hit areas, quiet on desktop fine-pointer landscape */
#pad {
  flex: 0 0 auto;
  display: flex; gap: 10px;
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--hair);
  background: #04060a;
  touch-action: none;
  z-index: 9;
}
.padbtn {
  flex: 1 1 0;
  min-height: 64px;
  border: 1px solid var(--hair);
  background: transparent;
  color: var(--mute);
  font-family: Manrope, system-ui, sans-serif;
  font-size: 12px; letter-spacing: .26em; text-transform: uppercase;
  cursor: pointer;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.padbtn.wide { flex: 1.6 1 0; color: var(--paper); border-color: rgba(143, 191, 176, .35); }
.padbtn:active, .padbtn.held { background: rgba(143, 191, 176, .14); color: var(--paper); }
@media (hover: none), (pointer: coarse) {
  #pad { padding: 12px 14px calc(14px + env(safe-area-inset-bottom, 0px)); gap: 12px; }
  .padbtn { min-height: 68px; font-size: 13px; }
}
@media (orientation: landscape) and (hover: hover) and (pointer: fine) {
  #pad { display: none; }
}

/* ---- Title / death screens ---- */
.screen.cardy {
  background: linear-gradient(180deg, rgba(5,7,10,.55), rgba(5,7,10,.88));
  justify-content: flex-start;
  padding-top: 48px;
  gap: 0;
}
.screen.cardy h1 {
  text-shadow: 3px 3px 0 #000;
  animation: titleIn .5s cubic-bezier(.2,1.4,.3,1) both;
}
.glitch { position: relative; }
.glitch::before, .glitch::after {
  content: attr(data-text);
  position: absolute; left: 0; right: 0; top: 0;
  pointer-events: none;
  overflow: hidden;
}
.glitch::before { color: #c45c4a; clip-path: inset(0 0 55% 0); transform: translate(-2px, 0); animation: glitchA 2.4s infinite; }
.glitch::after { color: #8fbfb0; clip-path: inset(55% 0 0 0); transform: translate(2px, 0); animation: glitchB 2.4s infinite; }
@keyframes glitchA {
  0%, 88%, 100% { transform: translate(-1px, 0); opacity: .0; }
  90% { transform: translate(-3px, 1px); opacity: .7; }
  93% { transform: translate(2px, -1px); opacity: .4; }
}
@keyframes glitchB {
  0%, 88%, 100% { transform: translate(1px, 0); opacity: .0; }
  91% { transform: translate(3px, -1px); opacity: .7; }
  94% { transform: translate(-2px, 1px); opacity: .4; }
}
@keyframes titleIn {
  from { transform: scale(.86) translateY(10px); opacity: 0; }
  to { transform: none; opacity: 1; }
}
.blink { animation: blink 1.4s steps(2, end) infinite; }
@keyframes blink { 50% { opacity: .25; } }

.runners {
  display: flex; gap: 28px; align-items: flex-end; justify-content: center;
  height: 72px; margin: .2rem 0 .35rem;
  pointer-events: none;
}
.runbob {
  height: 68px; width: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  animation: runbob .28s steps(2, end) infinite;
  filter: drop-shadow(2px 2px 0 #000);
}
.erikabob { animation-delay: .14s; height: 64px; }
@keyframes runbob {
  0% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.xp-tease {
  font-size: 11px; letter-spacing: .22em; text-transform: uppercase;
  color: var(--link); margin: .15rem 0 .2rem;
}
.best-line {
  font-size: 11px; letter-spacing: .18em; color: var(--mute);
  font-variant-numeric: tabular-nums;
  margin-bottom: .35rem;
}
.joke { min-height: 2.8em; transition: opacity .25s ease; }
.joke.swap { opacity: 0; }

.btn.pulse {
  animation: pulse 1.6s ease-in-out infinite;
  border-color: var(--link);
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(143,191,176,.35); }
  50% { box-shadow: 0 0 0 7px rgba(143,191,176,0); }
}

.hud {
  top: auto; right: auto; left: 50%;
  transform: translateX(-50%);
  top: calc(8px + env(safe-area-inset-top, 0px));
  flex-direction: column; align-items: center; gap: 2px;
}
.xpchip {
  display: flex; align-items: baseline; gap: .45rem;
  background: rgba(5,7,10,.72);
  border: 1px solid var(--hair);
  padding: 4px 12px 5px;
}
.xpchip .xp-lab {
  font-size: 9px; letter-spacing: .28em; color: var(--link);
}
.xpchip b {
  font-family: Syne, sans-serif;
  font-size: 22px; letter-spacing: .12em; font-weight: 600;
  color: var(--paper);
}
.xpchip i {
  font-style: normal; font-size: 9px; letter-spacing: .16em; color: var(--mute);
}
.hud .hi { font-size: 10px; }

.death-hero {
  display: flex; gap: 12px; align-items: center;
  text-align: left;
  margin: .4rem 0 .5rem;
  max-width: 340px;
  animation: deathIn .45s cubic-bezier(.2,1.3,.3,1) both;
}
@keyframes deathIn {
  from { transform: translateY(16px) scale(.96); opacity: 0; }
  to { transform: none; opacity: 1; }
}
.portrait-panel.death {
  width: 72px; height: 88px;
  border: 2px solid var(--shot);
  box-shadow: 4px 4px 0 #000;
  overflow: hidden;
  background: #120808;
  flex: 0 0 auto;
  animation: portShake .5s ease-out both;
}
.portrait-panel.death img {
  width: 100%; height: 100%;
  object-fit: cover; object-position: 50% 20%;
  image-rendering: pixelated;
  filter: saturate(.7) contrast(1.1);
}
@keyframes portShake {
  0% { transform: translate(-6px, 2px) rotate(-4deg); }
  30% { transform: translate(5px, -2px) rotate(3deg); }
  100% { transform: none; }
}
.death-stats { min-width: 0; }
.death-stats .xp-lab {
  font-size: 9px; letter-spacing: .28em; color: var(--shot);
}
.huge b {
  font-family: Syne, sans-serif;
  font-size: clamp(34px, 9vmin, 52px);
  letter-spacing: .06em; font-weight: 600;
  text-shadow: 3px 3px 0 #000;
  display: block; line-height: .9;
}
.km-line {
  margin-top: 6px;
  font-size: 12px; color: var(--link); line-height: 1.3;
}
.shot-kicker { color: var(--shot); }
#dead.cardy { background: linear-gradient(180deg, rgba(28,8,8,.62), rgba(5,7,10,.92)); }

/* ---- Ghost PB toggle ---- */
.ghost-tog {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0.15rem 0 0.45rem;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--mute);
  cursor: pointer;
  user-select: none;
}
.ghost-tog input {
  accent-color: #8fbfb0;
  width: 14px;
  height: 14px;
}
.ghost-chip {
  border: 1px solid rgba(143, 191, 176, 0.35);
  background: rgba(5, 7, 10, 0.72);
  color: var(--mute);
  font: inherit;
  font-size: 9px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  padding: 3px 8px;
  cursor: pointer;
  margin-top: 2px;
}
.ghost-chip.on {
  color: var(--link);
  border-color: rgba(143, 191, 176, 0.65);
  box-shadow: 0 0 0 1px rgba(143, 191, 176, 0.2);
}
.ghost-chip.hidden { display: none; }

/* ---- Share card ---- */
.share-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  margin: 0.55rem 0 0.35rem;
  width: min(340px, 92%);
}
.share-preview {
  width: 100%;
  height: auto;
  border: 1px solid rgba(143, 191, 176, 0.25);
  border-radius: 8px;
  background: #070b10;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.share-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: center;
  width: 100%;
}
.btn-share {
  padding: 0.55em 1em;
  font-size: 10px;
  letter-spacing: 0.14em;
  min-height: 36px;
  border-color: rgba(143, 191, 176, 0.4);
}
.btn-share:hover {
  background: rgba(143, 191, 176, 0.18);
  color: var(--paper);
}
