:root {
  --gold: #ffd23f;
  --gold-dark: #b8860b;
  --ink: #1b1030;
  --panel: rgba(20, 14, 40, 0.86);
  --font: 'Lilita One', 'Arial Rounded MT Bold', 'Trebuchet MS', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #000;
  font-family: var(--font); color: #fff;
  user-select: none; -webkit-user-select: none; touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
canvas#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }
button { font-family: var(--font); cursor: pointer; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
.iconBtn {
  width: 50px; height: 50px; border-radius: 14px; border: 3px solid #fff;
  background: rgba(10, 20, 40, 0.45); color: #fff; font-size: 18px; line-height: 1;
  box-shadow: 0 3px 0 rgba(0,0,0,.35); pointer-events: auto;
}
#pauseBtn { position: absolute; top: calc(12px + env(safe-area-inset-top)); left: 14px; }
#stageLabel {
  position: absolute; top: calc(18px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  font-size: 15px; letter-spacing: .5px; padding: 6px 14px; border-radius: 20px;
  background: rgba(10, 20, 40, 0.45); white-space: nowrap; text-shadow: 0 2px 0 rgba(0,0,0,.5);
  max-width: calc(100vw - 260px); overflow: hidden; text-overflow: ellipsis;
}
#topRight {
  position: absolute; top: calc(10px + env(safe-area-inset-top)); right: 14px;
  display: flex; flex-direction: column; align-items: flex-end; gap: 6px;
}
.pill {
  display: flex; align-items: center; gap: 8px; border-radius: 14px;
  background: rgba(10, 20, 40, 0.55); padding: 3px 14px 3px 4px;
  font-size: 30px; text-shadow: 0 3px 0 #000; min-height: 42px;
}
.scorePill { font-size: 34px; }
.coinPill.bump { animation: bump .22s ease-out; }
@keyframes bump { 40% { transform: scale(1.14); } }
#multi {
  background: linear-gradient(#ffe066, #f4b400); color: #6a3500; border-radius: 10px;
  padding: 2px 9px; font-size: 22px; text-shadow: none; border: 2px solid #fff3b0;
}
#multi.boost { background: linear-gradient(#7ef0ff, #18a7d8); color: #053248; }
.coinIcon { width: 30px; height: 30px; border-radius: 50%; display: inline-block; flex: none; }
.coinIcon[data-item=coin] {
  background: radial-gradient(circle at 35% 35%, #fff6b0, #ffd23f 45%, #c98a00 100%);
  border: 2px solid #8a5a00;
}
.coinIcon[data-item=stone] {
  background: radial-gradient(circle at 35% 35%, #fff, #e4e0d6 50%, #a8a294 100%);
  border-radius: 50% 50% 46% 54%; border: 2px solid #8a8476;
}
.coinIcon[data-item=fish] {
  background: radial-gradient(ellipse at 40% 40%, #fff, #c8dae6 50%, #6a8aa0 100%);
  border-radius: 50% / 35%; border: 2px solid #4a6a80; width: 36px;
}
.coinIcon[data-item=manna] {
  background: radial-gradient(circle at 35% 35%, #fff, #f6efd8 50%, #d8c9a0 100%);
  border-radius: 45% 55% 50% 50%; border: 2px solid #b9a777;
  box-shadow: 0 0 10px rgba(255, 250, 220, .9);
}
#powers { position: absolute; left: 14px; top: 40%; display: flex; flex-direction: column; gap: 10px; }
.pw { display: flex; align-items: center; gap: 8px; background: rgba(10,20,40,.55); padding: 4px 10px 4px 4px; border-radius: 12px; }
.pw .ic { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-size: 20px; border: 2px solid #fff; }
.pw .bar { width: 70px; height: 10px; border-radius: 5px; background: rgba(255,255,255,.25); overflow: hidden; }
.pw .bar i { display: block; height: 100%; background: #fff; border-radius: 5px; }
#hint {
  position: absolute; bottom: calc(26px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  font-size: 17px; padding: 8px 16px; border-radius: 20px; background: rgba(0,0,0,.45);
  white-space: nowrap; transition: opacity .6s;
}
#toast {
  position: absolute; top: 34%; left: 50%; transform: translate(-50%, -50%); font-size: 26px;
  text-shadow: 0 3px 0 #000, 0 0 12px rgba(0,0,0,.6); opacity: 0; transition: opacity .3s; white-space: nowrap;
}
#toast.show { opacity: 1; }

/* ---------- Banner / transitions ---------- */
#banner {
  position: fixed; left: 50%; top: 20%; transform: translate(-50%, -50%) scale(.6);
  text-align: center; opacity: 0; pointer-events: none; width: min(92vw, 720px);
}
#banner.show { animation: bannerPop 3.6s ease forwards; }
#bannerTitle {
  font-size: clamp(30px, 7vw, 58px); color: var(--gold);
  -webkit-text-stroke: 2px #4a2600; text-shadow: 0 5px 0 #4a2600, 0 0 24px rgba(0,0,0,.5);
}
#bannerSub { font-size: clamp(15px, 3.2vw, 22px); margin-top: 6px; text-shadow: 0 2px 0 #000, 0 0 10px #000; }
@keyframes bannerPop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.5); }
  10% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  16% { transform: translate(-50%, -50%) scale(1); }
  82% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(.95); }
}
#flash { position: fixed; inset: 0; pointer-events: none; opacity: 0; transition: opacity .5s ease-out; }
#iris { position: fixed; inset: 0; pointer-events: none; display: none; place-items: center; }
#iris span {
  font-size: clamp(50px, 12vw, 110px); color: #ff9db0; -webkit-text-stroke: 3px #3a0010;
  text-shadow: 0 6px 0 #3a0010; opacity: 0; transition: opacity .15s;
}

/* ---------- Menu ---------- */
#menu {
  position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center;
  padding: calc(14px + env(safe-area-inset-top)) 16px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(rgba(20,10,40,.75), rgba(20,10,40,.05) 32%, rgba(20,10,40,.05) 52%, rgba(20,10,40,.85));
  overflow-y: auto; touch-action: pan-y;
}
.menuTop { width: 100%; max-width: 900px; display: flex; justify-content: space-between; align-items: flex-start; }
.pill.small { font-size: 22px; min-height: 36px; padding-right: 12px; }
.pill.small .coinIcon { width: 24px; height: 24px; }
.logo {
  margin: 0; text-align: center; font-size: clamp(38px, 9vw, 74px); line-height: .9; font-weight: normal;
  color: var(--gold); -webkit-text-stroke: 2px #4a2600; text-shadow: 0 6px 0 #4a2600, 0 10px 20px rgba(0,0,0,.5);
  transform: rotate(-3deg);
}
.menuSpacer { flex: 1 0 22vh; }
.pickTitle .keys { font-size: 14px; opacity: .75; }
@media (hover: none) { .pickTitle .keys { display: none; } }
@media (hover: hover) { .touchOnly { display: none; } }
.pickTitle { margin-top: 10px; font-size: 20px; text-shadow: 0 2px 0 #000; }
#cards {
  display: flex; gap: 12px; margin-top: 8px; width: 100%; max-width: 1180px; padding: 6px 4px 10px;
  overflow-x: auto; scroll-snap-type: x mandatory; touch-action: pan-x; scrollbar-width: thin; flex-shrink: 0;
}
#cards > .card:first-child { margin-left: auto; }
#cards > .card:last-child { margin-right: auto; }
.card {
  flex: 0 0 210px; scroll-snap-align: center; border-radius: 18px; padding: 9px; color: #fff; text-align: left;
  border: 4px solid rgba(255,255,255,.35); background: rgba(20, 14, 40, .78);
  box-shadow: 0 6px 0 rgba(0,0,0,.4); transition: transform .15s, border-color .15s;
}
.card.sel { border-color: var(--gold); transform: translateY(-4px); box-shadow: 0 10px 0 rgba(0,0,0,.4), 0 0 24px rgba(255,210,63,.45); }
.cardArt { overflow: hidden; height: 56px; border-radius: 12px; display: grid; place-items: center; font-size: 42px; }
.exodusArt { background: linear-gradient(90deg, #1565c0 0 22%, #f2d39b 22% 78%, #1565c0 78%); }
.jonahArt { background: linear-gradient(#5aa9e6, #1d4f7a 60%, #0d2b45); }
.cardName { font-size: 20px; margin-top: 8px; color: var(--gold); text-shadow: 0 2px 0 #000; }
.cardHero { font-size: 14px; opacity: .85; }
.stages { margin: 6px 0 4px; padding-left: 20px; font-size: 12.5px; line-height: 1.45; font-family: system-ui, sans-serif; font-weight: 600; }
.stages .special { color: #8fd8ff; }
.cardBest { font-size: 15px; }
.cardBest b { color: var(--gold); font-weight: normal; }
.bigBtn {
  margin-top: 10px; font-size: 26px; padding: 12px 34px; border-radius: 16px; border: 3px solid #fff;
  color: #3a1d00; background: linear-gradient(#ffe36e, #f5b301); box-shadow: 0 6px 0 #9a6400;
  pointer-events: auto;
}
.bigBtn:active { transform: translateY(4px); box-shadow: 0 2px 0 #9a6400; }
.bigBtn.alt { color: #fff; background: linear-gradient(#5cc8ff, #1c86d1); box-shadow: 0 6px 0 #0d4d7c; }
#playBtn { animation: pulse 1.3s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }
.controls { margin-top: 12px; font-size: 13px; text-align: center; opacity: .85; font-family: system-ui, sans-serif; line-height: 1.5; }
.textBtn {
  font-size: 14px; padding: 9px 14px; border-radius: 12px; border: 2px solid rgba(255,255,255,.7);
  background: rgba(10, 20, 40, 0.5); color: #fff; pointer-events: auto; margin-top: 12px;
}
.textBtn.corner.left { position: absolute; left: 14px; top: calc(62px + env(safe-area-inset-top)); margin: 0; font-size: 12px; padding: 6px 10px; }
.iconBtn.corner { position: absolute; right: 14px; top: calc(62px + env(safe-area-inset-top)); font-size: 18px; width: 40px; height: 40px; }
@media (max-height: 680px) {
  .menuSpacer { flex-basis: 6vh; }
  .logo { font-size: 44px; }
  .stages { display: none; }
  .cardArt { height: 44px; }
}

/* ---------- Overlays ---------- */
.overlay { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(10, 5, 25, .55); padding: 16px; }
.panel {
  width: min(420px, 100%); background: var(--panel); border: 4px solid rgba(255,255,255,.4); border-radius: 22px;
  padding: 18px 20px 22px; text-align: center; display: flex; flex-direction: column; align-items: center;
}
.panel h2 { margin: 0; font-weight: normal; font-size: 46px; color: var(--gold); -webkit-text-stroke: 1.5px #4a2600; text-shadow: 0 4px 0 #4a2600; }
#overReason { font-size: 16px; margin-top: 4px; opacity: .9; font-family: system-ui, sans-serif; }
.stats { width: 100%; margin-top: 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stats div { background: rgba(255,255,255,.08); border-radius: 12px; padding: 8px; display: flex; flex-direction: column; }
.stats span { font-size: 13px; opacity: .8; font-family: system-ui, sans-serif; }
.stats b { font-weight: normal; font-size: 26px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#oBest { margin-top: 10px; font-size: 20px; color: var(--gold); min-height: 24px; }
.panel .bigBtn { width: 100%; }

@media (max-width: 560px) {
  #cards { gap: 8px; }
  .card { padding: 8px; flex-basis: 64vw; }
  .cardArt { height: 54px; font-size: 32px; }
  .cardName { font-size: 19px; }
  .stages { font-size: 12px; padding-left: 18px; }
  .pill { font-size: 24px; min-height: 36px; }
  .scorePill { font-size: 27px; }
  #multi { font-size: 18px; }
  #stageLabel { top: calc(70px + env(safe-area-inset-top)); left: 14px; transform: none; max-width: calc(100vw - 28px); font-size: 13px; }
  #hint { font-size: 14px; }
}

/* ---------- menu animation ---------- */
.cardArt svg { width: 100%; height: 100%; display: block; }
.pw .ic img { width: 28px; height: 28px; display: block; }
#menu.enter .card { animation: cardIn .55s cubic-bezier(.2, 1.4, .4, 1) both; animation-delay: calc(var(--i) * 70ms + 120ms); }
#menu.enter .logo { animation: logoIn .7s cubic-bezier(.2, 1.5, .4, 1) both; }
#menu.enter #playBtn { animation: cardIn .5s .5s both, pulse 1.3s 1.1s ease-in-out infinite; }
@keyframes cardIn { from { opacity: 0; transform: translateY(40px) scale(.9); } }
@keyframes logoIn { from { opacity: 0; transform: rotate(-3deg) scale(.4); } }
.logo { animation: none; }
#menu:not(.enter) .logo, #menu.enter .logo { will-change: transform; }
.card { transition: transform .18s, border-color .18s, box-shadow .18s; }
@media (hover: hover) { .card:hover { transform: translateY(-6px) rotate(-1deg); } }
.card.sel { animation: selGlow 1.8s ease-in-out infinite; }
#menu.enter .card.sel { animation: cardIn .55s cubic-bezier(.2, 1.4, .4, 1) both, selGlow 1.8s 1s ease-in-out infinite; animation-delay: calc(var(--i) * 70ms + 120ms), 1s; }
.card.sel .cardArt svg { animation: artZoom 3s ease-in-out infinite; }
@keyframes selGlow { 50% { box-shadow: 0 10px 0 rgba(0,0,0,.4), 0 0 34px rgba(255,210,63,.75); } }
@keyframes artZoom { 50% { transform: scale(1.08); } }
@media (prefers-reduced-motion: reduce) { #menu.enter .card, #menu.enter .logo, .card.sel, .card.sel .cardArt svg, #playBtn { animation: none !important; } }
