:root {
  --bg: #1c1528;
  --panel: rgba(33, 24, 48, 0.78);
  --line: rgba(255, 255, 255, 0.1);
  --text: #fff7ef;
  --muted: rgba(255, 247, 239, 0.62);
  --pink: #ff5c8a;
  --gold: #ffc83d;
  --green: #5fe37c;
  --blue: #4fb4ff;
  --purple: #c77dff;
  --red: #ff5d5d;
  --r: 16px;
  --font: Fredoka, 'Segoe UI', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: var(--font); -webkit-tap-highlight-color: transparent; }
body { user-select: none; -webkit-user-select: none; touch-action: manipulation; }
#app, #app canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#app canvas { touch-action: none; }
a { color: inherit; }
.hidden { display: none !important; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 40px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.08); color: var(--text); font: 600 15px var(--font);
  cursor: pointer; text-decoration: none; backdrop-filter: blur(8px); transition: transform .12s, background .2s;
}
.btn:hover { background: rgba(255, 255, 255, 0.16); transform: translateY(-1px); }
.btn:active { transform: scale(.96); }
.btn.primary { background: linear-gradient(180deg, #ff7aa0, #ff4f7e); border-color: transparent; box-shadow: 0 6px 20px rgba(255, 79, 126, .35); }
.btn.primary:hover { background: linear-gradient(180deg, #ff8fb0, #ff5f8a); }
.btn.icon { width: 40px; padding: 0; font-size: 17px; }
.btn.icon.on { background: rgba(255, 92, 138, .35); }
.btn.ghost { background: transparent; }
.link { background: none; border: 0; color: var(--muted); font: 500 14px var(--font); cursor: pointer; text-decoration: underline; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); backdrop-filter: blur(10px); }
.ph { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px 8px; font-size: 14px; letter-spacing: .06em; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 10px var(--green); animation: blink 1.6s infinite; }
@keyframes blink { 50% { opacity: .35; } }

/* brand */
#brand { position: fixed; top: 14px; left: 16px; z-index: 5; width: 290px; }
.logo { display: flex; align-items: center; gap: 8px; font-size: 26px; letter-spacing: .02em; }
.logo img { width: 36px; height: 36px; border-radius: 10px; }
.logo .tick { font-size: 14px; font-weight: 600; color: var(--gold); background: rgba(255, 200, 61, .14); padding: 2px 8px; border-radius: 999px; }
.tag { color: var(--muted); font-size: 14px; margin: 2px 0 10px 44px; }
#coin { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; }
.coin-row { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); gap: 8px; }
#coinMc { color: var(--text); font-weight: 600; }
.bar { height: 6px; border-radius: 6px; background: rgba(255, 255, 255, .1); margin-top: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--pink), var(--gold)); border-radius: 6px; transition: width .6s; }

/* pops */
#pops { position: fixed; top: 10px; left: 50%; transform: translateX(-50%); text-align: center; z-index: 4; pointer-events: none; }
#pops .big { font-size: 58px; font-weight: 700; line-height: 1; text-shadow: 0 4px 30px rgba(255, 92, 138, .45); font-variant-numeric: tabular-nums; }
#pops .big.bump { animation: bump .18s; }
@keyframes bump { 40% { transform: scale(1.06); } }
#pops .sub { font-size: 13px; color: var(--muted); letter-spacing: .08em; margin-top: 4px; }
#pops .mine { font-size: 14px; margin-top: 4px; color: var(--gold); }
#pops .mine img { width: 18px; vertical-align: -3px; border-radius: 2px; margin-left: 4px; }

/* actions */
#actions { position: fixed; top: 14px; right: 16px; display: flex; gap: 8px; z-index: 6; }

/* side panels */
#tree { position: fixed; left: 16px; top: 190px; bottom: 150px; width: 290px; z-index: 4; display: flex; flex-direction: column; }
#world { position: fixed; right: 16px; top: 72px; width: 250px; z-index: 4; }
.tabs { display: flex; gap: 6px; padding: 0 12px 8px; }
.tabs button { flex: 1; height: 30px; border-radius: 999px; border: 1px solid var(--line); background: transparent; color: var(--muted); font: 600 13px var(--font); cursor: pointer; }
.tabs button.on { background: rgba(255, 255, 255, .12); color: var(--text); }
.list { overflow-y: auto; padding: 0 8px 10px; scrollbar-width: thin; }
#tree .list { flex: 1; }
.row-i { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 12px; text-decoration: none; cursor: pointer; }
.row-i:hover { background: rgba(255, 255, 255, .07); }
.row-i.fresh { animation: fresh 2.4s; }
@keyframes fresh { 0% { background: rgba(95, 227, 124, .35); } 100% { background: transparent; } }
.av { width: 34px; height: 34px; border-radius: 10px; object-fit: cover; flex: none; background: #3a2d4d; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 15px; }
.ri { flex: 1; min-width: 0; }
.ri .l1 { display: flex; justify-content: space-between; gap: 6px; font-size: 14px; font-weight: 600; }
.ri .l1 span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ri .l2 { display: flex; justify-content: space-between; gap: 6px; font-size: 12px; color: var(--muted); }
.ri .l2 span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up { color: var(--green); } .down { color: var(--red); }
.mini { height: 4px; border-radius: 4px; background: rgba(255, 255, 255, .1); margin-top: 4px; overflow: hidden; }
.mini i { display: block; height: 100%; background: linear-gradient(90deg, var(--pink), var(--gold)); }
.badge { font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 999px; background: var(--green); color: #10301a; margin-left: 4px; }
.badge.bonded { background: var(--gold); color: #3a2a00; }
.empty { color: var(--muted); font-size: 13px; padding: 14px; text-align: center; }
.country { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 10px; font-size: 14px; }
.country.me { background: rgba(255, 200, 61, .14); }
.country .rk { width: 18px; color: var(--muted); font-size: 12px; text-align: right; }
.country img, .country .globe { width: 24px; height: 18px; border-radius: 3px; flex: none; object-fit: cover; }
.country .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.country .n { font-weight: 600; font-variant-numeric: tabular-nums; }

/* bottom */
#bottom { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 5; display: flex; flex-direction: column; align-items: center; gap: 10px; width: min(760px, calc(100vw - 660px)); min-width: 520px; }
.cta { height: 54px; padding: 0 28px; border-radius: 999px; border: 0; cursor: pointer; font: 700 19px var(--font); color: #2a1a00; background: linear-gradient(180deg, #ffe07a, #ffb82e); box-shadow: 0 8px 30px rgba(255, 184, 46, .45), inset 0 -3px 0 rgba(0, 0, 0, .12); animation: wiggle 4s infinite; }
.cta:hover { filter: brightness(1.06); }
@keyframes wiggle { 0%, 88%, 100% { transform: rotate(0); } 91% { transform: rotate(-3deg); } 94% { transform: rotate(3deg); } 97% { transform: rotate(-1.5deg); } }
#road { display: flex; width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; gap: 4px; backdrop-filter: blur(10px); }
.node { flex: 1; text-align: center; font-size: 11px; color: var(--muted); position: relative; padding-top: 16px; cursor: default; }
.node::before { content: ''; position: absolute; top: 4px; left: 50%; width: 10px; height: 10px; border-radius: 50%; transform: translateX(-50%); background: rgba(255, 255, 255, .18); }
.node.done { color: var(--text); }
.node.done::before { background: var(--green); box-shadow: 0 0 10px var(--green); }
.node.next { color: var(--gold); }
.node.next::before { background: var(--gold); box-shadow: 0 0 12px var(--gold); animation: blink 1.2s infinite; }
.node b { display: block; font-size: 12px; letter-spacing: .03em; }
.node[data-play] { cursor: pointer; }
.node .play { display: inline-block; margin-top: 2px; font-size: 11px; color: var(--pink); cursor: pointer; text-decoration: underline; }
.node.sealed b { letter-spacing: .15em; }
#mobileTabs { display: none; }

#hint { position: fixed; left: 50%; bottom: 200px; white-space: nowrap; transform: translateX(-50%); z-index: 3; pointer-events: none; font-size: 20px; font-weight: 700; letter-spacing: .08em; padding: 8px 18px; border-radius: 999px; background: rgba(0, 0, 0, .35); animation: pulse 1.3s infinite; transition: opacity .4s; }
#hint.gone { opacity: 0; }
@keyframes pulse { 50% { transform: translateX(-50%) scale(1.08); } }

#tape { position: fixed; left: 320px; bottom: 150px; z-index: 3; display: flex; flex-direction: column; gap: 4px; pointer-events: none; font-size: 13px; }
#tape div { background: rgba(0, 0, 0, .35); padding: 4px 10px; border-radius: 999px; animation: tapeIn .3s; white-space: nowrap; }
#tape .buy b { color: var(--green); } #tape .sell b { color: var(--red); } #tape .cat b { color: var(--gold); }
@keyframes tapeIn { from { opacity: 0; transform: translateX(-10px); } }

/* floaters: +1, +SOL */
#floaters, #tags { position: fixed; inset: 0; pointer-events: none; z-index: 3; }
.fl { position: absolute; font-weight: 700; font-size: 26px; transform: translate(-50%, -50%); animation: floatUp .9s forwards; text-shadow: 0 2px 8px rgba(0, 0, 0, .5); }
.fl.sol { font-size: 22px; }
@keyframes floatUp { to { transform: translate(-50%, -160%) scale(1.2); opacity: 0; } }
.ctag { position: absolute; transform: translate(-50%, -100%); font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; background: rgba(0, 0, 0, .55); white-space: nowrap; }
.ctag.gold { background: var(--gold); color: #2a1a00; }
.ctag.you { background: var(--pink); }

#title { position: fixed; left: 50%; top: 30%; transform: translate(-50%, -50%); text-align: center; z-index: 7; pointer-events: none; opacity: 0; transition: opacity .35s; }
#title.on { opacity: 1; }
#title .t1 { font-size: clamp(40px, 8vw, 96px); font-weight: 700; line-height: 1; text-shadow: 0 6px 40px rgba(255, 92, 138, .8); }
#title .t2 { font-size: clamp(15px, 2vw, 22px); color: var(--gold); margin-top: 10px; }
#flash { position: fixed; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 8; transition: opacity .6s; }

#tip { position: fixed; z-index: 9; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; font-size: 14px; min-width: 220px; backdrop-filter: blur(10px); }
#tip .row { display: flex; gap: 6px; margin-top: 8px; }
#tip .btn { height: 32px; font-size: 13px; padding: 0 12px; }

/* modal */
.modal { position: fixed; inset: 0; z-index: 20; background: rgba(10, 6, 18, .66); display: flex; align-items: center; justify-content: center; padding: 16px; backdrop-filter: blur(4px); }
.sheet { position: relative; background: #2a1f3b; border: 1px solid var(--line); border-radius: 22px; padding: 24px; width: min(860px, 100%); max-height: 100%; overflow-y: auto; box-shadow: 0 30px 80px rgba(0, 0, 0, .5); }
.sheet.narrow { width: min(520px, 100%); }
.sheet h2 { margin: 0 0 6px; font-size: 28px; }
.sheet p { color: var(--muted); margin: 6px 0 14px; }
.close { position: absolute; right: 14px; top: 12px; background: none; border: 0; color: var(--muted); font-size: 20px; cursor: pointer; z-index: 2; }
#walletIn { width: 100%; height: 50px; border-radius: 14px; border: 1px solid var(--line); background: rgba(0, 0, 0, .3); color: var(--text); font: 500 16px var(--font); padding: 0 16px; outline: none; user-select: text; -webkit-user-select: text; }
#walletIn:focus { border-color: var(--pink); }
.row { display: flex; gap: 10px; margin-top: 12px; }
.row.wrap { flex-wrap: wrap; }
.err { color: var(--red) !important; min-height: 1em; }
.fine { font-size: 12px; }
#stageAsk { max-width: 520px; margin: 0 auto; text-align: center; }
#stageAsk .row { justify-content: center; }
#stageCat { display: flex; gap: 24px; align-items: center; }
.catview { position: relative; width: 380px; height: 380px; flex: none; border-radius: 18px; overflow: hidden; }
#catCanvas { width: 100%; height: 100%; display: block; cursor: pointer; }
#rollBox { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 120px; font-weight: 700; color: rgba(255, 255, 255, .8); pointer-events: none; }
#rollBox.shake { animation: shake .12s infinite; }
@keyframes shake { 25% { transform: translate(-4px, 2px) rotate(-3deg); } 75% { transform: translate(4px, -2px) rotate(3deg); } }
.info { flex: 1; min-width: 0; }
.tier { display: inline-block; font-weight: 700; font-size: 13px; letter-spacing: .1em; padding: 4px 12px; border-radius: 999px; color: #1c1528; }
#catName { font-size: 32px; margin-top: 10px; line-height: 1.1; }
.muted { color: var(--muted); font-size: 14px; margin: 4px 0; }
.traits { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px 0; }
.trait { background: rgba(255, 255, 255, .06); border-radius: 12px; padding: 8px 12px; }
.trait small { display: block; color: var(--muted); font-size: 11px; letter-spacing: .08em; }
.trait b { font-size: 15px; }
.trait.rare b { color: var(--gold); }
ul.how { padding-left: 18px; line-height: 1.5; color: var(--muted); }
ul.how b { color: var(--text); }

#demo { position: fixed; left: 16px; bottom: 16px; z-index: 6; display: flex; flex-wrap: wrap; gap: 4px; width: 290px; background: var(--panel); border: 1px dashed var(--line); border-radius: 12px; padding: 8px; font-size: 11px; }
#demo b { width: 100%; color: var(--muted); letter-spacing: .1em; }
#demo button { font: 600 12px var(--font); background: rgba(255, 255, 255, .08); color: var(--text); border: 0; border-radius: 8px; padding: 5px 8px; cursor: pointer; }
body.demo #tree { bottom: 110px; }

#loader { position: fixed; inset: 0; z-index: 30; background: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; color: var(--muted); transition: opacity .5s; }
#loader .lcat { font-size: 64px; animation: pulse2 1s infinite; }
@keyframes pulse2 { 50% { transform: scale(1.12); } }
#loader.gone { opacity: 0; pointer-events: none; }

/* ---------- medium screens: drop the side panels into sheets */
@media (max-width: 1180px) {
  #bottom { width: calc(100vw - 32px); min-width: 0; }
  #tree, #world { display: none; }
  #tree.open, #world.open { display: flex; flex-direction: column; position: fixed; left: 12px; right: 12px; top: auto; bottom: 150px; width: auto; max-height: 50vh; z-index: 12; }
  #mobileTabs { display: flex; gap: 8px; }
  #mobileTabs button { height: 34px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font: 600 13px var(--font); cursor: pointer; }
  #mobileTabs button.on { background: rgba(255, 92, 138, .35); }
  #tape { left: 16px; bottom: 210px; }
  #demo { bottom: auto; top: 200px; }
}

/* ---------- phones */
@media (max-width: 760px) {
  #brand { width: auto; top: 10px; left: 12px; }
  .logo { font-size: 20px; }
  .logo img { width: 30px; height: 30px; }
  .tag { display: none; }
  #coin { position: fixed; top: 52px; left: 12px; right: 12px; padding: 6px 10px; }
  #actions { top: 10px; right: 12px; gap: 6px; }
  #actions .btn { height: 36px; font-size: 14px; padding: 0 12px; }
  #actions .btn.icon { width: 36px; padding: 0; }
  .desk { display: none !important; }
  #pops { top: 104px; }
  #pops .big { font-size: 44px; }
  #pops .sub { font-size: 11px; }
  #bottom { bottom: calc(10px + env(safe-area-inset-bottom)); gap: 8px; }
  .cta { height: 50px; font-size: 17px; padding: 0 22px; }
  #road { padding: 8px 8px; }
  .node { font-size: 0; padding-top: 12px; }
  .node b { font-size: 9px; }
  .node .play { display: none; }
  .node.next b { font-size: 10px; }
  #tape { bottom: 196px; font-size: 12px; left: 12px; }
  #tape div:nth-child(n+3) { display: none; }
  body.hinting #tape { display: none; }
  #hint { bottom: 190px; font-size: 16px; }
  #stageCat { flex-direction: column; gap: 12px; }
  .catview { width: 100%; height: auto; aspect-ratio: 1; max-width: 340px; }
  .sheet { padding: 18px; }
  #catName { font-size: 24px; }
  .sheet h2 { font-size: 22px; }
  #tree.open, #world.open { bottom: 140px; }
}

/* share-image mode (?og) */
body.og #tree, body.og #world, body.og #tape, body.og #demo, body.og #bottom, body.og #hint, body.og #actions, body.og #coin, body.og #pops, body.og .tag, body.og #floaters, body.og #tags { display: none !important; }
#ogText { position: fixed; left: 40px; bottom: 44px; z-index: 9; text-shadow: 0 4px 30px rgba(0,0,0,.6); }
#ogText b { display: block; font-size: 76px; line-height: .98; }
#ogText span { display: block; font-size: 28px; color: var(--gold); margin-top: 12px; }
