/* Pear Presser — Pear Expedition (js/minigames/expedition.js).
 * Builds on the .mg-* shell and the sticker look in style.css. Everything here is prefixed .xp-
 * (the tap-test button also keeps the older .ex-tap class). */

/* four stat tiles must stay on one row on a 320px phone */
#mg-root:has(.xp-wrap) .mg-stats { gap: 5px; flex-wrap: nowrap; }
#mg-root:has(.xp-wrap) .mg-stat { min-width: 0; flex: 1 1 0; max-width: 110px; padding: 2px 4px 3px; white-space: nowrap; }

.xp-wrap { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 6px; padding: 8px; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; -webkit-user-select: none; user-select: none; color: var(--ink); }
.xp-wrap::before { content: ""; position: absolute; inset: 0; z-index: 0; pointer-events: none; }
.xp-wrap > * { position: relative; z-index: 1; flex: none; }
/* region backdrops */
.xp-r0 { background: radial-gradient(120% 60% at 20% 108%, #5fb83a 0 55%, transparent 56%), radial-gradient(120% 55% at 85% 112%, #7fd04a 0 55%, transparent 56%), linear-gradient(180deg, #a9e4ff 0%, #e2f8c8 55%, #b6e67a 100%); }
.xp-r0::before { background: radial-gradient(circle at 84% 9%, rgba(255,244,170,.95) 0 22px, rgba(255,244,170,.35) 23px 40px, transparent 41px); }
.xp-r1 { background: radial-gradient(90% 50% at 15% 108%, #1b1440 0 55%, transparent 56%), radial-gradient(100% 50% at 90% 110%, #241a55 0 55%, transparent 56%), linear-gradient(180deg, #2b1f63 0%, #51349a 50%, #1f6d80 100%); }
.xp-r1::before { background: radial-gradient(circle at 12% 14%, rgba(160,240,255,.5) 0 3px, transparent 4px), radial-gradient(circle at 78% 8%, rgba(255,190,255,.55) 0 4px, transparent 5px), radial-gradient(circle at 92% 46%, rgba(160,240,255,.45) 0 3px, transparent 4px), radial-gradient(circle at 6% 62%, rgba(255,220,255,.4) 0 3px, transparent 4px), radial-gradient(circle at 55% 96%, rgba(140,255,230,.4) 0 4px, transparent 5px); }
.xp-r2 { background: linear-gradient(180deg, #ffc48a 0%, #f08a78 38%, #7a4a8e 100%); }
.xp-r2::before { background: linear-gradient(180deg, #6a4590, #47306a); opacity: .6; clip-path: polygon(0 100%, 0 74%, 16% 58%, 27% 69%, 46% 47%, 60% 66%, 77% 52%, 100% 72%, 100% 100%); }

/* map: region, pack and trail */
.xp-map { background: var(--cream); border: 2.5px solid var(--ink); border-radius: 14px; box-shadow: 0 3px 0 var(--ink); padding: 4px 8px 6px; display: flex; flex-direction: column; gap: 4px; }
.xp-reg { display: flex; align-items: center; gap: 6px; font-family: var(--display); font-weight: 600; font-size: 13.5px; line-height: 1.2; min-width: 0; }
.xp-reg > b { font-weight: 600; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xp-pips { display: flex; gap: 3px; flex: none; }
.xp-pips i { width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--ink); background: #fff; }
.xp-pips i.on { background: var(--ink); } .xp-pips i.now { background: #ffb81f; }
.xp-bag { display: flex; gap: 3px; flex: none; }
.xp-it { display: inline-flex; align-items: center; gap: 1px; font-size: 13px; line-height: 1; padding: 2px 4px; border-radius: 8px; border: 2px solid var(--ink); background: #fff3a8; }
.xp-it b { font-weight: 600; font-size: 12px; }
.xp-it.none { background: transparent; border-color: rgba(35,52,26,.25); opacity: .45; filter: grayscale(1); }
.xp-trail { display: flex; align-items: center; height: 22px; }
.xp-trail u { flex: 1; height: 0; border-top: 3px dotted rgba(35,52,26,.35); margin: 0 2px; text-decoration: none; }
.xp-trail u.on { border-top: 3px solid var(--ink); }
.xp-trail i { flex: none; width: 13px; height: 13px; border-radius: 50%; border: 2.5px solid var(--ink); background: #fff; font-style: normal; font-size: 13px; line-height: 1; display: grid; place-items: center; }
.xp-trail i:not(.n-fork) { width: 22px; height: 22px; background: var(--paper); }
.xp-trail i.done { background: #9fdc34; }
.xp-trail i:not(.n-fork).done { background: #d9f29a; filter: saturate(.6); }
.xp-trail i.now { width: 22px; height: 22px; background: #ffe873; box-shadow: 0 0 0 3px rgba(255,184,31,.5); animation: xp-now 1s ease-in-out infinite alternate; }
@keyframes xp-now { to { box-shadow: 0 0 0 5px rgba(255,184,31,.15); transform: translateY(-1.5px); } }

/* what just happened */
.xp-log { display: flex; align-items: center; gap: 8px; background: #eaffc4; border: 2.5px solid var(--ink); border-radius: 14px; padding: 4px 9px; animation: xp-drop .32s cubic-bezier(.3,1.5,.5,1) both; }
.xp-log.bad { background: #ffd9d2; } .xp-log.info { background: #e4f1ff; }
.xp-lem { font-size: 24px; line-height: 1; flex: none; }
.xp-lt { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.xp-lt > b { font-size: 12.5px; font-weight: 800; line-height: 1.2; }
.xp-parts, .xp-tags { display: flex; flex-wrap: wrap; gap: 3px; }
@keyframes xp-drop { from { transform: translateY(-10px) scale(.94); opacity: 0; } }
.xp-chip { display: inline-flex; align-items: center; font-family: var(--display); font-weight: 600; font-size: 11.5px; line-height: 1.2; padding: 1px 6px; border-radius: 999px; border: 1.5px solid var(--ink); background: #fff; white-space: nowrap; }
.xp-chip.gain { background: #c9f27a; } .xp-chip.bad { background: #ff9a8a; } .xp-chip.ok { background: #ffe873; }
.xp-chip.dim { background: transparent; border-style: dashed; color: var(--ink-soft); }

/* the scene */
.xp-scene { display: flex; align-items: center; gap: 9px; background: var(--cream); border: 2.5px solid var(--ink); border-radius: 16px; box-shadow: 0 3px 0 var(--ink); padding: 5px 10px 6px 6px; }
.xp-ava { flex: none; width: 48px; height: 48px; display: grid; place-items: center; animation: xp-bob 2.2s ease-in-out infinite; }
.xp-scene.big .xp-ava { width: 72px; height: 72px; }
.xp-ava canvas { display: block; width: 100%; height: 100%; }
@keyframes xp-bob { 50% { transform: translateY(-3px) rotate(-2deg); } }
.xp-st { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.xp-st h3 { font-family: var(--display); font-weight: 600; font-size: 16.5px; line-height: 1.15; margin: 0; }
.xp-st p { font-size: 12.5px; font-weight: 700; line-height: 1.3; color: var(--ink-soft); margin: 0; text-wrap: pretty; }
.xp-warn { color: #c2261a; } .xp-gain { color: #2f8a12; }
.xp-hp { display: flex; gap: 2px; font-size: 15px; line-height: 1.1; }
.xp-hp i { font-style: normal; opacity: .22; filter: grayscale(1); transition: opacity .2s; }
.xp-hp i.on { opacity: 1; filter: none; }
.xp-hp b { font-family: var(--display); font-weight: 600; font-size: 13px; margin-left: 6px; padding: 0 7px; border-radius: 999px; border: 2px solid var(--ink); background: #ffd9d2; white-space: nowrap; }
.xp-tip { display: block; margin-top: 2px; color: var(--ink); }

/* choices */
.xp-body { flex: 1 0 auto !important; display: flex; flex-direction: column; justify-content: center; min-height: 0; transition: opacity .18s, transform .18s; }
.xp-wrap.is-walking .xp-body { opacity: .35; transform: translateX(10px); pointer-events: none; }
.xp-choices { display: flex; flex-direction: column; gap: 6px; }
.xp-card, .xp-opt { display: grid; grid-template-columns: 40px 1fr; gap: 8px; align-items: center; text-align: left; width: 100%; padding: 5px 8px 6px 6px; color: var(--ink); font: inherit; border-radius: 15px; border: 2.5px solid var(--ink); background: var(--cream); box-shadow: 0 4px 0 var(--ink); cursor: pointer; transition: transform .06s, box-shadow .06s; animation: xp-in .3s cubic-bezier(.3,1.3,.5,1) backwards; animation-delay: calc(var(--n, 0) * 60ms); }
@keyframes xp-in { from { transform: translateY(12px); opacity: 0; } }
.xp-card:active, .xp-opt:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.xp-card:focus-visible, .xp-opt:focus-visible, .xp-gem:focus-visible { outline: 3px solid #fff; outline-offset: 1px; }
.xp-em { width: 40px; height: 40px; border-radius: 12px; border: 2.5px solid var(--ink); display: grid; place-items: center; font-size: 22px; line-height: 1; background: linear-gradient(160deg, var(--e1, #fff6c2), var(--e2, #ffd45a)); }
.xp-card.safe { --e1: #dfffb0; --e2: #8fd62a; } .xp-card.mid { --e1: #ffeaa0; --e2: #ffb81f; } .xp-card.wild { --e1: #ffb4a8; --e2: #f0483a; }
.xp-ct { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.xp-h { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.xp-h b, .xp-opt b { font-family: var(--display); font-weight: 600; font-size: 14.5px; line-height: 1.15; min-width: 0; }
.xp-h b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xp-risk { flex: none; font-family: var(--display); font-weight: 600; font-size: 11px; line-height: 1.2; padding: 1px 7px; border-radius: 999px; border: 2px solid var(--ink); background: #9fdc34; white-space: nowrap; }
.xp-risk.mid { background: #ffc23d; } .xp-risk.wild { background: #f0483a; color: #fff; } .xp-risk.skill { background: #8fd3ff; } .xp-risk.skillw { background: #c9a8ff; }
.xp-desc { display: none; font-size: 12px; font-weight: 700; color: var(--ink-soft); line-height: 1.25; }
.xp-opt small { font-size: 12px; font-weight: 700; color: var(--ink-soft); line-height: 1.25; }
.xp-opt .xp-ct { gap: 1px; }
.xp-opt b { display: flex; justify-content: space-between; gap: 6px; align-items: baseline; }
.xp-opt.go { background: #fff3a8; } .xp-opt.go .xp-em { --e1: #fffbd0; --e2: #ffb81f; }
.xp-opt.home .xp-em { --e1: #c8efff; --e2: #57bfff; }
.xp-opt:disabled { opacity: .55; filter: saturate(.3); cursor: default; box-shadow: 0 2px 0 var(--ink); }
.xp-price { font-style: normal; font-size: 12.5px; background: #ffe873; border: 1.5px solid var(--ink); border-radius: 999px; padding: 0 6px; white-space: nowrap; }
.xp-two { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.xp-opt.sm { grid-template-columns: 32px 1fr; gap: 6px; padding: 4px 6px 5px 5px; }
.xp-opt.sm .xp-em { width: 32px; height: 32px; font-size: 17px; border-radius: 10px; }
.xp-opt.sm small { font-size: 11px; white-space: nowrap; }
.xp-hint { font-size: 12.5px; font-weight: 800; text-align: center; background: rgba(255,255,255,.85); border: 2px dashed var(--ink); border-radius: 12px; padding: 4px 8px; }
.xp-end { animation: xp-in .3s backwards; }
.xp-cap { font-family: var(--display); font-weight: 600; font-size: 12px; line-height: 1.2; text-align: center; align-self: center; background: rgba(255,255,255,.85); border: 2px solid var(--ink); border-radius: 999px; padding: 1px 10px; margin-bottom: -2px; }
/* the end-of-trip card */
.xp-sum { background: var(--cream); border: 2.5px solid var(--ink); border-radius: 16px; box-shadow: 0 3px 0 var(--ink); padding: 4px 10px; margin-bottom: 9px; animation: xp-in .3s backwards; }
.xp-srow { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 5px 0; font-size: 13.5px; font-weight: 700; color: var(--ink-soft); }
.xp-srow + .xp-srow { border-top: 2px dotted rgba(35,52,26,.25); }
.xp-srow span { white-space: nowrap; }
.xp-srow b { font-family: var(--display); font-weight: 600; font-size: 15px; color: var(--ink); text-align: right; }
.xp-srow.good b { color: #2f8a12; font-size: 18px; } .xp-srow.bad b { color: #c2261a; font-size: 18px; }

/* skill tests */
.xp-skill { display: flex; flex-direction: column; align-items: center; gap: 9px; touch-action: none; position: relative; padding-top: 26px; }
.xp-verdict { position: absolute; top: 0; left: 0; right: 0; text-align: center; font-family: var(--display); font-weight: 700; font-size: 23px; line-height: 1; color: #fff; -webkit-text-stroke: 4.5px var(--ink); paint-order: stroke fill; opacity: 0; pointer-events: none; }
.xp-verdict.show { opacity: 1; animation: xp-pop .3s cubic-bezier(.3,1.8,.5,1); }
.xp-verdict.perfect { color: #ffe66b; } .xp-verdict.good { color: #b8f58a; } .xp-verdict.fail { color: #ff8a7a; }
@keyframes xp-pop { from { transform: scale(.4); opacity: 0; } }
.xp-wrap .ex-tap { width: min(132px, 22vh); height: min(132px, 22vh); border-radius: 50%; font-size: min(54px, 9vh); padding: 0; touch-action: none; align-self: center; }
.xp-prog { width: min(100%, 260px); height: 14px; border-radius: 999px; border: 2.5px solid var(--ink); background: rgba(255,255,255,.7); overflow: hidden; }
.xp-prog i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #c5f24f, #7cc91f); transition: width .08s; }
.xp-row { display: flex; align-items: center; justify-content: center; gap: 8px; width: min(100%, 260px); }
.xp-row.wide { width: 100%; max-width: 400px; }
.xp-row.wide .xp-cnt { padding: 0 6px; font-size: 12px; }
.xp-cnt { font-family: var(--display); font-weight: 600; font-size: 14px; background: var(--cream); border: 2px solid var(--ink); border-radius: 999px; padding: 1px 10px; white-space: nowrap; }
.xp-time { flex: 1; height: 9px; border-radius: 999px; border: 2px solid var(--ink); background: rgba(16,30,10,.3); overflow: hidden; }
.xp-time i { display: block; height: 100%; background: #fff; transform-origin: left center; }
.xp-meter { position: relative; width: 100%; max-width: 400px; height: 46px; border-radius: 14px; border: 3px solid var(--ink); box-shadow: 0 4px 0 var(--ink); overflow: hidden; background: linear-gradient(90deg, #ff6b5a, #ffb03d 25%, #ffd95a 50%, #ffb03d 75%, #ff6b5a); }
.xp-zone { position: absolute; top: 0; bottom: 0; background: #57d94a; border-left: 2.5px solid var(--ink); border-right: 2.5px solid var(--ink); box-sizing: border-box; }
.xp-zone i { position: absolute; top: 0; bottom: 0; left: 32.5%; width: 35%; background: #ffe66b; box-shadow: 0 0 0 1.5px rgba(35,52,26,.5); }
.xp-needle { position: absolute; top: -2px; bottom: -2px; left: 0; width: 8px; margin-left: -4px; background: var(--ink); border: 2px solid #fff; border-radius: 4px; box-shadow: 0 0 0 1.5px var(--ink); will-change: left; }
.xp-big { width: 100%; max-width: 400px; min-height: 60px; font-size: 24px; touch-action: none; }
.xp-gems { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: min(100%, 250px, 33vh); }
.xp-gem { aspect-ratio: 1; border-radius: 16px; border: 2.5px solid var(--ink); box-shadow: 0 4px 0 var(--ink); background: linear-gradient(150deg, #cfe9ff, #7fa8e6 60%, #5a6cc8); position: relative; cursor: pointer; padding: 0; transition: transform .08s, filter .15s; }
.xp-gem::after { content: ""; position: absolute; inset: 22%; background: linear-gradient(140deg, rgba(255,255,255,.75), rgba(255,255,255,.08)); clip-path: polygon(50% 0, 100% 38%, 78% 100%, 22% 100%, 0 38%); }
.xp-gem:disabled { cursor: default; }
.xp-gem:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.xp-gem.lit { background: linear-gradient(150deg, #fffbd0, #ffd23d 60%, #ff9a1f); box-shadow: 0 4px 0 var(--ink), 0 0 0 3px #fff, 0 0 16px 4px rgba(255,230,120,.9); transform: scale(1.04); }
.xp-gem.ok { background: linear-gradient(150deg, #e2ffb0, #7fd62a 60%, #3f9a2c); }
.xp-gem.no { background: linear-gradient(150deg, #ffc4b8, #f0483a 60%, #a81a12); }

/* roomier phones show each path's flavour line */
@media (min-height: 700px) {
  .xp-wrap { gap: 9px; padding: 10px; }
  .xp-desc { display: block; }
  .xp-choices { gap: 9px; }
  .xp-scene { padding: 9px 12px 10px 8px; gap: 11px; }
  .xp-ava { width: 60px; height: 60px; }
  .xp-scene.big .xp-ava { width: 84px; height: 84px; }
  .xp-st h3 { font-size: 19px; }
  .xp-st p { font-size: 13.5px; }
  .xp-log { padding: 6px 10px; }
  .xp-lt > b { font-size: 13.5px; }
  .xp-card, .xp-opt { grid-template-columns: 46px 1fr; gap: 10px; padding: 9px 10px 10px 8px; }
  .xp-em { width: 46px; height: 46px; font-size: 25px; }
  .xp-h b, .xp-opt b { font-size: 16px; }
  .xp-opt small { font-size: 13px; }
  .xp-chip { font-size: 12.5px; padding: 1px 7px; }
  .xp-risk { font-size: 12px; }
  .xp-skill { gap: 12px; }
  .xp-meter { height: 54px; }
}
@media (max-height: 600px) {
  .xp-st p { font-size: 12px; }
  .xp-meter { height: 40px; }
  .xp-big { min-height: 52px; font-size: 21px; }
}
@media (max-width: 350px) {
  .xp-ri { display: none; }
  .xp-reg { font-size: 12.5px; gap: 5px; }
  .xp-it { padding: 2px 3px; font-size: 12px; }
}
/* set by the game when a screen would not fit: tighten instead of scrolling */
.xp-tight { gap: 4px; padding: 6px; }
.xp-tight .xp-choices, .xp-tight .xp-two { gap: 4px; }
.xp-tight .xp-card, .xp-tight .xp-opt { padding: 3px 8px 4px 5px; box-shadow: 0 3px 0 var(--ink); }
.xp-tight .xp-map { padding: 3px 8px 4px; gap: 2px; }
.xp-tight .xp-log { padding: 2px 8px; }
.xp-tight .xp-lem { font-size: 19px; }
.xp-tight .xp-lt { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 2px 6px; }
.xp-tight .xp-scene { padding: 3px 9px 4px 5px; }
.xp-tight .xp-scene:not(.big) .xp-ava { width: 38px; height: 38px; }
.xp-tight .xp-scene.big .xp-ava { width: 58px; height: 58px; }
.xp-tight .xp-desc { display: none; }
.xp-tight .xp-skill { gap: 6px; }
.xp-wrap.xp-tighter { gap: 3px; padding: 5px; }
.xp-tighter .xp-opt small { font-size: 11px; line-height: 1.15; }
.xp-tighter .xp-h b, .xp-tighter .xp-opt b { font-size: 13.5px; }
.xp-tighter .xp-cap { font-size: 11px; padding: 0 8px; }
.xp-tighter .xp-srow { padding: 3px 0; font-size: 12.5px; }
.xp-tighter .xp-sum { margin-bottom: 5px; }
.xp-tighter .xp-opt:not(.sm) .xp-em, .xp-tighter .xp-card .xp-em { width: 34px; height: 34px; font-size: 19px; }
.xp-tighter .xp-chip { font-size: 10.5px; padding: 1px 4px; }
.xp-tighter .xp-st p { font-size: 11.5px; line-height: 1.25; }
/* reduced effects */
.xp-low *, .xp-low .xp-body { animation: none !important; transition: none !important; }
@media (prefers-reduced-motion: reduce) {
  .xp-wrap *, .xp-trail i.now { animation: none !important; }
  .xp-body { transition: none; }
}
@media (hover: hover) and (pointer: fine) {
  .xp-card:hover, .xp-opt:not(:disabled):hover, .xp-gem:not(:disabled):hover { filter: brightness(1.06); }
}
/* browsers without aspect-ratio (iOS 14): the memory crystals still need a height */
@supports not (aspect-ratio: 1) { .xp-gem { height: 72px; } }
