/* ============================================================
   RUG RUN — meme-sticker UI over a synthwave trench
   Display face: Impact (the meme font, and it ships on every OS)
   ============================================================ */
:root {
  --bg: #14082b;
  --panel: #1e1040;
  --panel-2: #2a1857;
  --green: #2bff88;
  --gold: #ffd94a;
  --pink: #ff4fa8;
  --cyan: #43e8ff;
  --red: #ff3b57;
  --text: #ffffff;
  --muted: #b9a6e8;
  --display: Impact, 'Arial Black', 'Franklin Gothic Bold', sans-serif;
  --body: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  font-family: var(--body);
  color: var(--text);
}

#wrap { position: fixed; inset: 0; }
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.hidden { display: none !important; }

/* ============ shared meme-text treatment ============ */
.stroke-text, #score, #coins, #title, #rekt, #go-pop, #o-score {
  font-family: var(--display);
  -webkit-text-stroke: 0;
  text-shadow:
    -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000, 2px 2px 0 #000,
    0 4px 0 #000;
  letter-spacing: 0.02em;
}

/* ============ HUD ============ */
#hud {
  position: absolute; inset: 0;
  pointer-events: none;
  z-index: 5;
}
#hud-top {
  position: absolute;
  top: calc(10px + var(--sat));
  left: 12px; right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
#score-box { display: flex; align-items: center; gap: 8px; }
#score {
  font-size: clamp(30px, 8vw, 44px);
  color: #fff;
  line-height: 1;
}
#coin-box {
  display: flex; align-items: center; gap: 7px;
  background: rgba(0,0,0,0.42);
  border: 2px solid #000;
  border-radius: 999px;
  padding: 5px 14px 5px 8px;
  box-shadow: 0 3px 0 rgba(0,0,0,0.6);
}
#coins {
  font-size: clamp(20px, 5.4vw, 28px);
  color: var(--gold);
  line-height: 1;
}
#coin-ico, .mini-coin {
  width: 22px; height: 22px; border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #fff6c9, var(--gold) 46%, #b8860b 100%);
  border: 2px solid #6b4a00;
  display: inline-block;
  flex: none;
}
.mini-coin { width: 13px; height: 13px; vertical-align: -2px; }
#x2badge {
  font-family: var(--display);
  font-size: 18px;
  color: #000;
  background: var(--gold);
  border: 2px solid #000;
  border-radius: 8px;
  padding: 3px 7px 1px;
  box-shadow: 0 3px 0 #000;
  animation: pulse 0.5s ease-in-out infinite alternate;
}
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.12); } }

/* power-up timer bars */
#pw-bars {
  position: absolute;
  left: 12px;
  bottom: calc(16px + var(--sab));
  display: flex; flex-direction: column; gap: 7px;
  width: min(44vw, 190px);
}
.pw-row { display: flex; align-items: center; gap: 7px; }
.pw-ico {
  font-family: var(--display);
  font-size: 15px;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  background: rgba(0,0,0,0.5);
  border: 2px solid #000;
  border-radius: 8px;
  flex: none;
}
.pw-track {
  flex: 1; height: 10px;
  background: rgba(0,0,0,0.5);
  border: 2px solid #000;
  border-radius: 999px;
  overflow: hidden;
}
.pw-fill {
  height: 100%; width: 100%;
  background: var(--c, #fff);
  transform-origin: left center;
}

/* ============ stumble / danger flash ============ */
#flash {
  position: absolute; inset: 0;
  pointer-events: none;
  z-index: 8;
  opacity: 0;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(255,59,87,0.55) 100%);
}
#flash.on { animation: flashkick 0.5s ease-out; }
@keyframes flashkick { 0% { opacity: 1; } 100% { opacity: 0; } }

/* ============ GO! pop ============ */
#go-pop {
  position: absolute;
  top: 34%; left: 50%;
  z-index: 9;
  font-size: clamp(64px, 22vw, 130px);
  color: var(--green);
  pointer-events: none;
  animation: gopop 0.8s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
@keyframes gopop {
  0%   { transform: translate(-50%, -50%) scale(0.2) rotate(-8deg); opacity: 0; }
  35%  { transform: translate(-50%, -50%) scale(1.15) rotate(2deg); opacity: 1; }
  70%  { transform: translate(-50%, -50%) scale(1) rotate(0deg); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1.4); opacity: 0; }
}

/* ============ toast ============ */
#toast {
  position: absolute;
  top: 22%; left: 50%;
  transform: translateX(-50%);
  z-index: 9;
  font-family: var(--display);
  font-size: clamp(22px, 6.5vw, 34px);
  color: var(--c, var(--cyan));
  text-shadow: -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000, 2px 2px 0 #000, 0 4px 0 #000;
  pointer-events: none;
  white-space: nowrap;
}
#toast.show { animation: toastpop 1.2s cubic-bezier(0.16, 1, 0.3, 1) forwards; }
@keyframes toastpop {
  0%   { transform: translateX(-50%) translateY(14px) scale(0.5); opacity: 0; }
  20%  { transform: translateX(-50%) translateY(0) scale(1.06); opacity: 1; }
  75%  { transform: translateX(-50%) translateY(-6px) scale(1); opacity: 1; }
  100% { transform: translateX(-50%) translateY(-26px) scale(0.94); opacity: 0; }
}

/* ============ MENU ============ */
#menu {
  position: absolute; inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: calc(26px + var(--sat)) 18px calc(20px + var(--sab));
  background:
    radial-gradient(at 50% 0%, rgba(67, 232, 255, 0.10) 0, transparent 42%),
    linear-gradient(180deg, rgba(20, 8, 43, 0.55) 0%, transparent 30%, transparent 55%, rgba(20, 8, 43, 0.88) 88%);
}

#title-wrap { text-align: center; }
#title-tag {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--cyan);
  margin-bottom: 6px;
  animation: rise 0.6s cubic-bezier(0.16, 1, 0.3, 1) both;
}
#title {
  font-size: clamp(46px, 15.5vw, 96px);
  line-height: 0.82;
  color: var(--gold);
  text-shadow:
    -3px -3px 0 #000, 3px -3px 0 #000, -3px 3px 0 #000, 3px 3px 0 #000,
    0 7px 0 #000,
    -6px 8px 0 var(--pink),
    6px 10px 22px rgba(255, 79, 168, 0.45);
  transform: rotate(-2deg);
}
#title span { display: block; animation: rise 0.65s cubic-bezier(0.16, 1, 0.3, 1) both; }
#title span:nth-child(2) { animation-delay: 0.08s; color: var(--green); }
#subtitle {
  margin-top: 12px;
  font-size: clamp(13px, 3.8vw, 16px);
  font-weight: 600;
  color: var(--muted);
  animation: rise 0.6s cubic-bezier(0.16, 1, 0.3, 1) 0.18s both;
}
@keyframes rise {
  from { transform: translateY(22px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

#menu-bottom {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 11px;
}

#chars {
  display: flex;
  gap: 10px;
  width: 100%;
  justify-content: center;
  animation: rise 0.6s cubic-bezier(0.16, 1, 0.3, 1) 0.26s both;
}
.char-card {
  flex: 1;
  max-width: 116px;
  background: var(--panel);
  border: 3px solid #000;
  border-radius: 16px;
  padding: 10px 6px 8px;
  cursor: pointer;
  box-shadow: 0 4px 0 #000;
  transition: transform 0.15s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.char-card:hover { transform: translateY(-3px); }
.char-card:active { transform: translateY(1px); box-shadow: 0 2px 0 #000; }
.char-card:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }
.char-card.sel {
  background: var(--panel-2);
  border-color: var(--green);
  box-shadow: 0 4px 0 #000, 0 0 18px rgba(43, 255, 136, 0.4);
  transform: translateY(-4px);
}
.cc-name {
  font-family: var(--display);
  font-size: 17px;
  letter-spacing: 0.06em;
  color: #fff;
}
.char-card.sel .cc-name { color: var(--green); }

/* tiny CSS face avatars */
.cc-face {
  position: relative;
  width: 52px; height: 44px;
  border-radius: 46% 46% 42% 42%;
  border: 2.5px solid #000;
  display: block;
}
.cc-pepe  { background: #4a9e57; }
.cc-peng  { background: #23242e; }
.cc-bully { background: #8a4b2f; }
.cc-eye {
  position: absolute; top: 8px;
  width: 13px; height: 13px;
  background: #fff; border: 2px solid #000; border-radius: 50%;
}
.cc-eye::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 4px; height: 4px; background: #000; border-radius: 50%;
}
.cc-eye:nth-child(1) { left: 7px; }
.cc-eye:nth-child(2) { right: 7px; }
.cc-mouth {
  position: absolute; bottom: 7px; left: 50%;
  transform: translateX(-50%);
  width: 26px; height: 5px;
  background: #7a3b47; border: 2px solid #000; border-radius: 4px;
}
.cc-stache {
  position: absolute; bottom: 6px; left: 50%;
  transform: translateX(-50%);
  width: 30px; height: 9px;
  background: #d8d8d8; border: 2px solid #000;
  border-radius: 3px 3px 8px 8px;
}
.cc-snout {
  position: absolute; bottom: 4px; left: 50%;
  transform: translateX(-50%);
  width: 26px; height: 13px;
  background: #c98a5e; border: 2px solid #000; border-radius: 8px;
}
.cc-snout::before, .cc-snout::after {
  content: ''; position: absolute; top: 4px;
  width: 3px; height: 4px; background: #000; border-radius: 50%;
}
.cc-snout::before { left: 6px; }
.cc-snout::after { right: 6px; }
.cc-horn {
  position: absolute; top: -7px;
  width: 8px; height: 13px;
  background: #efe6d8; border: 2px solid #000;
  border-radius: 6px 6px 0 0;
}
.cc-horn.l { left: 3px; transform: rotate(-24deg); }
.cc-horn.r { right: 3px; transform: rotate(24deg); }

#char-tag {
  font-size: 13px;
  font-weight: 600;
  font-style: italic;
  color: var(--muted);
  min-height: 18px;
  animation: rise 0.6s cubic-bezier(0.16, 1, 0.3, 1) 0.3s both;
}

#play-btn, #retry-btn, #menu-btn {
  font-family: var(--display);
  border: 3px solid #000;
  border-radius: 16px;
  cursor: pointer;
  color: #062b14;
  letter-spacing: 0.05em;
  transition: transform 0.15s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.15s;
}
#play-btn {
  width: 100%;
  font-size: clamp(26px, 8vw, 36px);
  padding: 14px 0 12px;
  background: linear-gradient(180deg, #6dffb0 0%, var(--green) 55%, #12c95e 100%);
  box-shadow: 0 6px 0 #000, 0 10px 24px rgba(43, 255, 136, 0.35);
  animation: rise 0.6s cubic-bezier(0.16, 1, 0.3, 1) 0.36s both;
}
#play-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 0 #000, 0 14px 28px rgba(43, 255, 136, 0.45); }
#play-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #000; }
#play-btn:focus-visible, #retry-btn:focus-visible, #menu-btn:focus-visible, #mute-btn:focus-visible {
  outline: 3px solid var(--cyan); outline-offset: 3px;
}

#menu-stats {
  font-family: var(--display);
  font-size: 15px;
  letter-spacing: 0.08em;
  color: var(--muted);
  animation: rise 0.6s cubic-bezier(0.16, 1, 0.3, 1) 0.42s both;
}
#menu-stats b { color: var(--gold); font-weight: 400; }
#menu-stats .dot { margin: 0 10px; color: var(--pink); }
#menu-hint {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(185, 166, 232, 0.6);
  animation: rise 0.6s cubic-bezier(0.16, 1, 0.3, 1) 0.48s both;
}

#mute-btn {
  position: absolute;
  top: calc(12px + var(--sat));
  right: 12px;
  width: 44px; height: 44px;
  font-size: 20px;
  background: var(--panel);
  border: 3px solid #000;
  border-radius: 12px;
  box-shadow: 0 3px 0 #000;
  cursor: pointer;
  transition: transform 0.15s;
}
#mute-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #000; }

/* ============ GAME OVER ============ */
#over {
  position: absolute; inset: 0;
  z-index: 12;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(10, 4, 24, 0.62);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
#over-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 3px solid #000;
  border-radius: 22px;
  box-shadow: 0 8px 0 #000, 0 22px 50px rgba(0, 0, 0, 0.6);
  padding: 24px 22px calc(20px + var(--sab) / 2);
  text-align: center;
  animation: slam 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
}
@keyframes slam {
  0%   { transform: scale(1.5) rotate(4deg);  opacity: 0; }
  60%  { transform: scale(0.96) rotate(-1deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
#rekt {
  font-size: clamp(56px, 17vw, 84px);
  line-height: 1;
  color: var(--red);
  text-shadow:
    -3px -3px 0 #000, 3px -3px 0 #000, -3px 3px 0 #000, 3px 3px 0 #000,
    0 6px 0 #000, -5px 7px 0 rgba(255, 217, 74, 0.9);
  transform: rotate(-2deg);
}
#death-line {
  margin: 10px 0 16px;
  font-size: 14px;
  font-weight: 600;
  font-style: italic;
  color: var(--muted);
}
#over-stats {
  background: rgba(0, 0, 0, 0.32);
  border: 2px solid #000;
  border-radius: 14px;
  padding: 12px 16px;
  margin-bottom: 16px;
  display: flex; flex-direction: column; gap: 8px;
}
.os-row {
  display: flex; align-items: baseline; justify-content: space-between;
  font-family: var(--display);
  font-size: 17px;
  color: #fff;
}
.os-label { font-size: 12px; letter-spacing: 0.18em; color: var(--muted); }
.os-big #o-score { font-size: clamp(34px, 10vw, 46px); color: var(--gold); }
#o-coins { color: var(--gold); }
#new-best {
  font-size: 12px;
  color: #000;
  background: var(--green);
  border: 2px solid #000;
  border-radius: 6px;
  padding: 2px 6px 0;
  margin-left: 8px;
  animation: pulse 0.45s ease-in-out infinite alternate;
}
#retry-btn {
  width: 100%;
  font-size: clamp(22px, 6.5vw, 28px);
  padding: 12px 0 10px;
  background: linear-gradient(180deg, #6dffb0 0%, var(--green) 55%, #12c95e 100%);
  box-shadow: 0 5px 0 #000;
  margin-bottom: 10px;
}
#retry-btn:hover { transform: translateY(-2px); }
#retry-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #000; }
#menu-btn {
  width: 100%;
  font-size: 16px;
  padding: 10px 0 8px;
  color: var(--muted);
  background: var(--panel-2);
  box-shadow: 0 4px 0 #000;
}
#menu-btn:hover { transform: translateY(-1px); color: #fff; }
#menu-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #000; }

/* ============ PAUSED ============ */
#paused {
  position: absolute; inset: 0;
  z-index: 11;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 8px;
  background: rgba(10, 4, 24, 0.7);
  font-family: var(--display);
  font-size: clamp(38px, 12vw, 60px);
  color: #fff;
  text-shadow: -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000, 2px 2px 0 #000, 0 4px 0 #000;
}
#paused small {
  font-size: 14px;
  font-family: var(--body);
  font-weight: 600;
  color: var(--muted);
  text-shadow: none;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

/* ============ BAG button on menu ============ */
#bag-btn {
  width: 100%;
  margin-top: 2px;
  font-family: var(--display);
  font-size: clamp(16px, 4.6vw, 20px);
  letter-spacing: 0.06em;
  color: #3a2a00;
  background: linear-gradient(180deg, #ffe57a 0%, var(--gold) 60%, #d19a00 100%);
  border: 3px solid #000;
  border-radius: 14px;
  padding: 9px 14px 7px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 9px;
  box-shadow: 0 5px 0 #000, 0 8px 20px rgba(255, 217, 74, 0.3);
  transition: transform 0.15s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.15s;
  animation: rise 0.6s cubic-bezier(0.16, 1, 0.3, 1) 0.4s both;
}
#bag-btn:hover { transform: translateY(-2px); box-shadow: 0 7px 0 #000, 0 12px 24px rgba(255, 217, 74, 0.4); }
#bag-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #000; }
#bag-btn:focus-visible { outline: 3px solid var(--cyan); outline-offset: 3px; }
#bag-btn b { font-weight: 400; }
.bag-ico {
  width: 20px; height: 20px; border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #fff6c9, #fff 20%, #ffcf3a 55%, #a8790b 100%);
  border: 2px solid #6b4a00; flex: none;
}

/* ============ BAG modal ============ */
#bag {
  position: absolute; inset: 0;
  z-index: 14;
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
  background: rgba(10, 4, 24, 0.72);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
#bag-card {
  position: relative;
  width: 100%; max-width: 380px;
  background: var(--panel);
  border: 3px solid #000;
  border-radius: 22px;
  box-shadow: 0 8px 0 #000, 0 22px 50px rgba(0, 0, 0, 0.6);
  padding: 24px 22px calc(20px + var(--sab) / 2);
  text-align: center;
  animation: slam 0.42s cubic-bezier(0.16, 1, 0.3, 1) both;
}
#bag-close {
  position: absolute; top: 10px; right: 12px;
  width: 34px; height: 34px;
  font-size: 16px; font-weight: 700;
  color: var(--muted);
  background: var(--panel-2);
  border: 2px solid #000; border-radius: 9px;
  cursor: pointer;
}
#bag-close:active { transform: translateY(2px); }
#bag-title {
  font-family: var(--display);
  font-size: clamp(30px, 9vw, 42px);
  color: var(--gold);
  letter-spacing: 0.04em;
  text-shadow: -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000, 2px 2px 0 #000, 0 4px 0 #000;
}
#bag-balance {
  margin-top: 12px;
  font-family: var(--display);
  font-size: clamp(40px, 12vw, 58px);
  color: #fff;
  line-height: 1;
}
#bag-balance-n { color: var(--green); }
.bag-unit { font-size: 0.42em; color: var(--muted); letter-spacing: 0.06em; }
#bag-sub { margin-top: 4px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
#bag-wallet-label {
  display: block; text-align: left;
  margin: 18px 0 6px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.16em;
  color: var(--cyan); text-transform: uppercase;
}
#bag-wallet {
  width: 100%;
  font-family: 'Courier New', ui-monospace, monospace;
  font-size: 13px;
  color: #fff;
  background: rgba(0, 0, 0, 0.4);
  border: 2px solid #000;
  border-radius: 11px;
  padding: 12px 13px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
#bag-wallet::placeholder { color: rgba(185, 166, 232, 0.5); }
#bag-wallet:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(67, 232, 255, 0.25); }
#bag-wallet.good { border-color: var(--green); box-shadow: 0 0 0 3px rgba(43, 255, 136, 0.25); }
#bag-wallet.bad { border-color: var(--red); box-shadow: 0 0 0 3px rgba(255, 59, 87, 0.25); }
#bag-wallet-msg { min-height: 15px; margin-top: 6px; font-size: 11.5px; font-weight: 600; text-align: left; }
#bag-wallet-msg.good { color: var(--green); }
#bag-wallet-msg.bad { color: var(--red); }
#payout-btn {
  width: 100%; margin-top: 14px;
  font-family: var(--display);
  font-size: clamp(22px, 6.5vw, 28px);
  color: #062b14;
  background: linear-gradient(180deg, #6dffb0 0%, var(--green) 55%, #12c95e 100%);
  border: 3px solid #000; border-radius: 15px;
  padding: 12px 0 10px;
  cursor: pointer;
  box-shadow: 0 5px 0 #000;
  transition: transform 0.15s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.15s, filter 0.15s;
}
#payout-btn:hover { transform: translateY(-2px); }
#payout-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #000; }
#payout-btn:focus-visible { outline: 3px solid var(--cyan); outline-offset: 3px; }
#payout-btn:disabled { filter: grayscale(0.7) brightness(0.8); cursor: not-allowed; box-shadow: 0 5px 0 #000; transform: none; }
#bag-status { min-height: 16px; margin-top: 12px; font-size: 13px; font-weight: 700; color: var(--gold); white-space: pre-line; }
#bag-note { margin-top: 14px; font-size: 10.5px; line-height: 1.5; color: rgba(185, 166, 232, 0.65); }

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