:root {
  --font: "Arial Black", "Trebuchet MS", system-ui, sans-serif;
  --gold: #ffcf6b;
  --ink: #1a0f2e;
  --crimson: #e8394d;
}
html, body { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; background: #120a24; }
body { font-family: var(--font); color: #fff; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; }
#app { position: fixed; inset: 0; overflow: hidden; }
#stage { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

.out { text-shadow: 2px 0 0 var(--ink), -2px 0 0 var(--ink), 0 2px 0 var(--ink), 0 -2px 0 var(--ink), 1.5px 1.5px 0 var(--ink), -1.5px 1.5px 0 var(--ink), 1.5px -1.5px 0 var(--ink), -1.5px -1.5px 0 var(--ink), 0 4px 0 rgba(0,0,0,.45); }
.num, .gbtn, #countdown, #title-prompt, .panel h2, .row, #toast, #howto, #subtitle, #video-sub { font-family: var(--font); font-weight: 900; }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 10; }
#hud-left { position: absolute; left: calc(12px + env(safe-area-inset-left, 0px)); top: calc(10px + env(safe-area-inset-top, 0px)); display: flex; flex-direction: column; gap: 2px; }
#hearts { display: flex; gap: 4px; height: 30px; }
.heart { width: 28px; height: 28px; filter: drop-shadow(0 2px 0 var(--ink)) drop-shadow(0 0 1px var(--ink)); transition: transform .2s; }
.heart.lost { opacity: .28; transform: scale(.8); filter: grayscale(1); }
.heart.pop { animation: heartpop .4s; }
@keyframes heartpop { 0% { transform: scale(1.6); } 100% { transform: scale(.8); } }
#score { font-size: 34px; line-height: 1.05; color: #fff; }
#dist { font-size: 16px; color: #d9d0ff; }
.num { text-shadow: 2px 0 0 var(--ink), -2px 0 0 var(--ink), 0 2px 0 var(--ink), 0 -2px 0 var(--ink), 1.5px 1.5px 0 var(--ink), -1.5px 1.5px 0 var(--ink), 1.5px -1.5px 0 var(--ink), -1.5px -1.5px 0 var(--ink), 0 4px 0 rgba(0,0,0,.45); }
#hud-center { position: absolute; left: 50%; top: calc(12px + env(safe-area-inset-top, 0px)); transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; }
#coinbox { display: flex; align-items: center; gap: 6px; padding: 4px 14px 4px 6px; border-radius: 22px; background: rgba(26, 15, 46, .55); border: 2px solid rgba(255, 207, 107, .6); }
.coin-ico { width: 24px; height: 24px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff6c4 0 15%, #ffd34d 30%, #c98a12 80%); box-shadow: 0 0 0 2px var(--ink), inset 0 0 0 3px rgba(150, 90, 0, .5); position: relative; }
.coin-ico::after { content: ""; position: absolute; left: 8px; top: 8px; width: 8px; height: 8px; background: #7a4a00; }
#coins { font-size: 22px; color: var(--gold); }
#racebox { display: flex; gap: 10px; align-items: center; }
#timer { font-size: 26px; color: #fff; min-width: 2.2em; text-align: center; padding: 2px 10px; border-radius: 14px; background: rgba(26, 15, 46, .55); border: 2px solid rgba(255,255,255,.35); }
#timer.low { color: #ff6b7d; animation: pulse .5s infinite alternate; }
#place { font-size: 24px; color: var(--gold); }
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.12); } }

#popups { position: absolute; inset: 0; pointer-events: none; z-index: 11; overflow: hidden; }
.popup { position: absolute; font-family: var(--font); font-weight: 900; font-size: 26px; color: var(--gold); transform: translate(-50%, -50%); animation: popup 0.9s ease-out forwards; white-space: nowrap; }
@keyframes popup { 0% { opacity: 0; transform: translate(-50%, -20%) scale(.6); } 15% { opacity: 1; transform: translate(-50%, -50%) scale(1.2); } 30% { transform: translate(-50%, -60%) scale(1); } 100% { opacity: 0; transform: translate(-50%, -160%) scale(1); } }

#howto { position: absolute; left: 50%; top: 24%; transform: translateX(-50%); width: min(88%, 520px); box-sizing: border-box; text-align: center; font-size: 16px; line-height: 1.5; padding: 10px 14px; border-radius: 14px; background: rgba(26, 15, 46, .6); z-index: 12; pointer-events: none; }
#countdown { position: absolute; left: 0; right: 0; top: 38%; text-align: center; font-size: 96px; color: var(--gold); z-index: 13; pointer-events: none; }
#countdown.go { color: #fff; }
#countdown.anim { animation: cd .7s cubic-bezier(.34, 1.56, .64, 1); }
@keyframes cd { 0% { transform: scale(2.4); opacity: 0; } 60% { transform: scale(.9); opacity: 1; } 100% { transform: scale(1); } }
#subtitle { position: absolute; left: 50%; top: 17%; transform: translateX(-50%); max-width: 86%; width: max-content; box-sizing: border-box; text-align: center; font-size: 17px; padding: 8px 16px; border-radius: 12px; background: rgba(10, 5, 25, .7); z-index: 45; pointer-events: none; color: #fff; }
/* while a panel (results, leaderboard…) is open the subtitle sits under it instead of behind it */
#app:has(#panel-wrap:not(.hidden)) #subtitle { top: auto; bottom: calc(3% + env(safe-area-inset-bottom, 0px)); }
#flash { position: absolute; inset: 0; pointer-events: none; z-index: 15; background: radial-gradient(ellipse at center, rgba(255,40,60,0) 30%, rgba(255,30,50,.75) 100%); opacity: 0; transition: opacity .35s; }

/* ---------- buttons & panels (9-slice art with transparent margins: outset hides them) ---------- */
.gbtn {
  position: relative; display: block; box-sizing: border-box; min-height: 52px; padding: 0 12px;
  border-style: solid; border-color: transparent; border-width: 12px 18px;
  border-image-source: url("../assets/ui-button.png");
  border-image-slice: 45% 11% 47% 11% fill;
  border-image-width: 104px 25px 108px 25px;
  border-image-outset: 76px 3.5px 80px 3.5px;
  border-image-repeat: stretch;
  background: transparent; color: #fff; font-size: 19px; cursor: pointer; outline: none;
  transition: transform .09s ease-out, filter .12s;
  text-shadow: 2px 0 0 #4a0a14, -2px 0 0 #4a0a14, 0 2px 0 #4a0a14, 0 -2px 0 #4a0a14, 1.5px 1.5px 0 #4a0a14, -1.5px -1.5px 0 #4a0a14, 0 4px 0 rgba(0,0,0,.4);
  white-space: nowrap; -webkit-tap-highlight-color: transparent;
}
.gbtn.big { width: min(78vw, 330px); min-height: 62px; font-size: 22px; }
.gbtn.alt { filter: hue-rotate(215deg) saturate(.7) brightness(.95); }
.gbtn.focus { filter: brightness(1.25) saturate(1.15); transform: translateY(-2px) scale(1.04); }
.gbtn.alt.focus { filter: hue-rotate(215deg) saturate(.9) brightness(1.3); }
.gbtn:active, .gbtn.press { transform: translateY(2px) scale(.96); }
.gbtn[disabled] { opacity: .45; filter: grayscale(.8); }
.gbtn span { display: inline-block; }

/* the shared pause menu wears the same art */
body > div[role="dialog"] > div {
  border-image-slice: 31% 9% 33% 9% fill !important;
  border-image-width: 119px 35px 127px 35px !important;
  border-image-outset: 87px 4px 96px 4px !important;
}
body > div[role="dialog"] > div > button {
  border-image-slice: 45% 11% 47% 11% fill !important;
  border-image-width: 104px 25px 108px 25px !important;
  border-image-outset: 76px 3.5px 80px 3.5px !important;
}

.screen { position: absolute; inset: 0; z-index: 30; }
#title { overflow: hidden; background: #1b1238; }
.title-art { position: absolute; inset: -3%; background: url("../assets/cover-bg.png") center / cover no-repeat; animation: drift 16s ease-in-out infinite alternate; }
@keyframes drift { from { transform: scale(1.04) translateY(0); } to { transform: scale(1.1) translateY(-1.5%); } }
#title::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to bottom, rgba(18,10,36,.15) 0%, rgba(18,10,36,0) 30%, rgba(18,10,36,0) 50%, rgba(18,10,36,.7) 100%); pointer-events: none; }
#logo { position: absolute; left: 50%; top: 5%; width: 82%; max-height: 30%; object-fit: contain; transform: translateX(-50%); z-index: 2; filter: drop-shadow(0 6px 10px rgba(0,0,0,.5)); }
#logo.enter { animation: logoIn .7s cubic-bezier(.34, 1.56, .64, 1) both, logoFloat 3.2s ease-in-out .7s infinite alternate; }
@keyframes logoIn { 0% { transform: translateX(-50%) translateY(-60px) scale(.6); opacity: 0; } 100% { transform: translateX(-50%) translateY(0) scale(1); opacity: 1; } }
@keyframes logoFloat { from { transform: translateX(-50%) translateY(0); } to { transform: translateX(-50%) translateY(-8px); } }
#title-buttons { position: absolute; left: 0; right: 0; top: 60%; display: flex; flex-direction: column; align-items: center; gap: 16px; z-index: 3; }
#title-buttons .gbtn { animation: btnIn .45s cubic-bezier(.34, 1.56, .64, 1) both; }
#title-buttons .gbtn:nth-child(2) { animation-delay: .08s; }
#title-buttons .gbtn:nth-child(3) { animation-delay: .16s; }
@keyframes btnIn { from { opacity: 0; transform: translateY(30px) scale(.8); } to { opacity: 1; transform: none; } }
#title-prompt { position: absolute; left: 0; right: 0; bottom: calc(4% + env(safe-area-inset-bottom, 0px)); text-align: center; font-size: 16px; color: #ffe9b8; z-index: 3; animation: breathe 1.6s ease-in-out infinite; padding: 0 16px; text-shadow: 0 2px 0 var(--ink), 0 0 6px var(--ink); }
@keyframes breathe { 0%, 100% { opacity: .6; } 50% { opacity: 1; } }

#panel-wrap { position: absolute; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; background: rgba(10, 5, 25, .45); }
.panel {
  width: min(86vw, 400px); max-height: 80%; overflow: visible; box-sizing: border-box;
  border-style: solid; border-color: transparent; border-width: 30px 28px;
  border-image-source: url("../assets/ui-panel.png");
  border-image-slice: 31% 9% 33% 9% fill;
  border-image-width: 119px 35px 127px 35px;
  border-image-outset: 87px 4px 96px 4px;
  border-image-repeat: stretch;
  padding: 6px 4px; display: flex; flex-direction: column; align-items: center; gap: 10px;
  filter: drop-shadow(0 12px 24px rgba(0,0,0,.5));
}
.panel.enter { animation: panelIn .28s cubic-bezier(.34, 1.56, .64, 1); }
@keyframes panelIn { from { transform: scale(.7); opacity: 0; } to { transform: none; opacity: 1; } }
.panel h2 { margin: 0 0 2px; font-size: 28px; color: var(--gold); text-align: center; }
.panel .sub { font-family: var(--font); font-weight: 700; font-size: 15px; color: #d9d0ff; text-align: center; line-height: 1.4; }
.panel .bigscore { font-size: 54px; color: #fff; line-height: 1; }
.panel .stats { display: flex; gap: 8px; width: 100%; justify-content: center; }
.panel .stat { flex: 1; min-width: 0; text-align: center; padding: 6px 2px; border-radius: 12px; background: rgba(255,255,255,.07); }
.panel .stat .k { font-family: var(--font); font-weight: 700; font-size: 13px; color: #c9bff0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.panel .stat .v { font-size: 21px; color: var(--gold); white-space: nowrap; }
.panel .badge { font-size: 22px; color: #fff; padding: 4px 16px; border-radius: 20px; background: linear-gradient(#ff5468, #b81c32); animation: slam .5s cubic-bezier(.34, 1.56, .64, 1); transform: rotate(-3deg); }
@keyframes slam { from { transform: scale(2.5) rotate(-8deg); opacity: 0; } to { transform: rotate(-3deg); opacity: 1; } }
.panel .rank { font-size: 18px; color: var(--gold); min-height: 24px; }
.panel .btns { display: flex; flex-direction: column; gap: 14px; width: 100%; align-items: center; margin-top: 6px; }
.panel .btns .gbtn { width: 94%; }
.list { width: 100%; display: flex; flex-direction: column; gap: 4px; overflow: hidden; }
.row { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 10px; background: rgba(255,255,255,.06); font-size: 16px; }
.row.me { background: rgba(255, 207, 107, .25); box-shadow: inset 0 0 0 2px var(--gold); }
.row .r { min-width: 2.2em; color: var(--gold); text-align: center; }
.row .n { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.row .s { color: #fff; }
.row .dot { width: 14px; height: 14px; border-radius: 50%; box-shadow: 0 0 0 2px var(--ink); flex: none; }
.row .tag { font-size: 12px; padding: 2px 6px; border-radius: 8px; background: rgba(255,207,107,.3); color: #fff; }
.nameinput { width: 92%; box-sizing: border-box; font-family: var(--font); font-weight: 900; font-size: 22px; text-align: center; color: #fff; background: rgba(0,0,0,.35); border: 3px solid var(--gold); border-radius: 14px; padding: 10px; outline: none; user-select: text; -webkit-user-select: text; }
.spinner { width: 40px; height: 40px; border-radius: 50%; border: 5px solid rgba(255,255,255,.2); border-top-color: var(--gold); animation: spin 0.9s linear infinite; margin: 8px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

#video-wrap { position: absolute; inset: 0; z-index: 50; background: #000 url("../assets/cover-bg.png") center / cover no-repeat; }
#intro { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#skip { position: absolute; top: calc(14px + env(safe-area-inset-top, 0px)); right: 14px; min-width: 110px; font-size: 17px; }
#video-sub { position: absolute; left: 6%; right: 6%; bottom: 10%; text-align: center; font-size: 20px; color: #fff; text-shadow: 0 2px 4px #000, 0 0 2px #000, 0 0 8px #000; }

#toast { position: absolute; left: 50%; top: 40%; transform: translateX(-50%); z-index: 60; padding: 12px 20px; border-radius: 14px; background: rgba(26, 15, 46, .92); border: 2px solid var(--gold); font-size: 17px; text-align: center; max-width: 80%; width: max-content; box-sizing: border-box; pointer-events: none; }
#fade { position: absolute; inset: 0; z-index: 70; background: #0b0618; opacity: 0; pointer-events: none; transition: opacity .3s; }
#fade.on { opacity: 1; }
