:root { --top: 70px; --bot: 96px; --side: 220px; --ink: #0b0f1c; --paper: #f4f1ea; --gold: #ffd166; --teal: #35d0b0; --shard: #b48cff; --red: #ff4d5e; --panel: #1b233b; --panel2: #222c48; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: radial-gradient(ellipse at 50% 30%, #222b47 0%, #10152a 70%); color: var(--paper);
  font-family: system-ui, "Segoe UI", Roboto, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; touch-action: none; }
#stage { position: fixed; inset: 0; }
#stage canvas { display: block; }
.i { width: 1.15em; height: 1.15em; vertical-align: -0.2em; flex: none; }
.i.big { width: 44px; height: 44px; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; }

/* HUD */
#hud { position: fixed; z-index: 2; display: flex; align-items: center; gap: 10px; pointer-events: none; }
#hud .hcell { display: flex; align-items: center; gap: 6px; background: rgba(11,15,28,.72); border: 2px solid #2d3a5c; border-radius: 14px; padding: 6px 10px; font-weight: 900; font-size: 20px; position: relative; }
#hud .lbl { font-size: 12px; opacity: .75; text-transform: uppercase; letter-spacing: .04em; }
#hud .bar { position: absolute; left: 8px; right: 8px; bottom: 3px; height: 4px; background: rgba(255,255,255,.12); border-radius: 3px; overflow: hidden; }
#hud .bar i { display: block; height: 100%; width: 0; background: #8fb6ff; }
#hud .bar.hp i { background: var(--red); }
#hud .hbtns { display: flex; gap: 8px; pointer-events: auto; }
#hud .hbtns button { width: 44px; height: 44px; border-radius: 12px; background: rgba(11,15,28,.72); border: 2px solid #2d3a5c; display: grid; place-items: center; font-size: 20px; }
.pulse { animation: pulse .35s ease-out; }
@keyframes pulse { 0% { transform: scale(1.25); border-color: var(--red); } 100% { transform: scale(1); } }

body.portrait #hud { top: 0; left: 0; right: 0; height: var(--top); justify-content: center; padding: 6px 8px; padding-top: max(6px, env(safe-area-inset-top)); }
body.portrait #hud .hbtns { margin-left: auto; }
body.portrait #hud .hcell { font-size: clamp(15px, 4.4vw, 21px); padding: 5px 8px; }
body.landscape #hud { left: 0; top: 0; bottom: 0; width: var(--side); flex-direction: column; justify-content: center; align-items: stretch; padding: 14px; }
body.landscape #hud .hcell { font-size: clamp(16px, 2.6vh, 24px); }
body.landscape #hud .hbtns { position: fixed; right: 12px; top: 12px; }

/* summon */
#ctl { position: fixed; z-index: 2; display: flex; align-items: center; justify-content: center; gap: 10px; }
body.portrait #ctl { left: 0; right: 0; bottom: 0; height: var(--bot); padding-bottom: env(safe-area-inset-bottom); }
body.landscape #ctl { right: 0; top: 0; bottom: 0; width: var(--side); flex-direction: column; }
#bSummon { display: flex; align-items: center; gap: 10px; padding: 12px 26px; min-height: 60px; border-radius: 20px; font-weight: 900; font-size: 24px;
  background: linear-gradient(#ffe08a, #ffbf3f); color: #3a2400; box-shadow: 0 6px 0 #b57a12, 0 10px 20px rgba(0,0,0,.35); transition: transform .06s; }
#bSummon:active { transform: translateY(4px); box-shadow: 0 2px 0 #b57a12; }
#bSummon .i { width: 30px; height: 30px; }
#bSummon .cost { display: flex; align-items: center; gap: 4px; background: rgba(0,0,0,.18); border-radius: 12px; padding: 4px 10px; font-size: 20px; }
#bSummon.off { filter: grayscale(.7) brightness(.75); }
#bSummon.hint { animation: hint 1s ease-in-out infinite; }
#bSummon.nope { animation: nope .25s; }
@keyframes hint { 50% { transform: scale(1.08); box-shadow: 0 6px 0 #b57a12, 0 0 0 10px rgba(255,209,102,.35); } }
@keyframes nope { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.keyhint { font-size: 12px; opacity: .45; font-weight: 700; border: 1px solid rgba(255,255,255,.3); border-radius: 6px; padding: 2px 6px; }
body.portrait .keyhint { display: none; }
@media (hover: none) { .keyhint { display: none; } }
body.landscape #bSummon { flex-direction: column; padding: 16px 18px; font-size: clamp(18px, 3vh, 26px); }

/* overlays */
#ov { position: fixed; inset: 0; z-index: 5; display: none; align-items: center; justify-content: center; background: rgba(8,11,22,.72); padding: 12px; overflow-y: auto; touch-action: pan-y; }
#ov.show { display: flex; }
#ov.homeov { background: rgba(10,14,28,.94); align-items: flex-start; }
.card { background: var(--panel); border: 3px solid #34426a; border-radius: 22px; padding: 22px 20px; width: min(420px, 94vw); text-align: center; box-shadow: 0 20px 50px rgba(0,0,0,.5); animation: pop .25s ease-out; }
@keyframes pop { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.card h2 { margin: 0 0 6px; font-size: 28px; }
.card h2.bad { color: var(--red); }
.card .sub { margin: 0 0 16px; opacity: .8; font-size: 15px; }
.col { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 10px; justify-content: center; }
.row > .btn { flex: 1 1 0; }
.row.tight { gap: 6px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; padding: 10px 14px; border-radius: 16px; font-weight: 900; font-size: 18px;
  background: #2c3960; color: #fff; border: 2px solid #4a5b8e; box-shadow: 0 4px 0 #17203a; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #17203a; }
.btn.primary { background: linear-gradient(#ffe08a, #ffbf3f); color: #3a2400; border-color: #ffe9a8; box-shadow: 0 4px 0 #b57a12; }
.btn.small { min-height: 42px; font-size: 15px; padding: 6px 10px; border-radius: 12px; }
.btn.done { background: #1f3a33; border-color: var(--teal); box-shadow: none; }
.kicker { opacity: .7; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; font-size: 13px; }
.big { font-size: 46px; font-weight: 900; line-height: 1.1; }
.best { margin: 4px 0 12px; opacity: .85; font-weight: 800; }
.nb { color: var(--gold); font-size: 20px; animation: hint 1s infinite; display: inline-block; }
.stats { display: flex; justify-content: center; gap: 18px; margin-bottom: 14px; }
.stats div { display: flex; flex-direction: column; } .stats b { font-size: 22px; } .stats span { font-size: 12px; opacity: .7; }
.reward { font-size: 26px; font-weight: 900; margin-bottom: 16px; color: #e3d4ff; display: flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: wrap; }
.tag { font-size: 12px; background: var(--gold); color: #3a2400; border-radius: 8px; padding: 2px 6px; }
.keys { opacity: .5; font-size: 12px; margin: 14px 0 0; }

/* home */
.home { width: min(560px, 100%); margin: 0 auto; padding-bottom: 92px; }
.hhead { display: flex; align-items: center; justify-content: space-between; }
.hhead h1 { margin: 4px 0; font-size: 28px; letter-spacing: .01em; }
.wallet { display: flex; align-items: center; gap: 6px; font-size: 24px; font-weight: 900; background: #241c3d; border: 2px solid #5a3f99; border-radius: 14px; padding: 6px 12px; }
.hsub { opacity: .8; font-size: 13px; margin: 2px 0 8px; }
.daily { background: #3a2e10; border: 2px solid #8a6a1a; color: #ffe08a; border-radius: 12px; padding: 6px 10px; font-size: 13px; font-weight: 800; margin-bottom: 8px; }
.crate { display: flex; align-items: center; gap: 10px; background: var(--panel2); border: 2px solid #3a4870; border-radius: 16px; padding: 8px 10px; flex-wrap: wrap; }
.crate .ctext { display: flex; flex-direction: column; flex: 1; min-width: 120px; } .crate .ctext span { opacity: .85; font-size: 14px; }
.crate .row { flex: 1 1 220px; }
.home h3 { margin: 12px 0 6px; font-size: 16px; opacity: .9; }
.tree { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.branch { display: flex; flex-direction: column; gap: 14px; position: relative; }
.branch h4 { margin: 0; font-size: 13px; display: flex; gap: 4px; align-items: center; opacity: .9; }
.node { position: relative; display: flex; flex-direction: column; align-items: flex-start; text-align: left; gap: 1px; padding: 8px; border-radius: 12px; background: #202a46; border: 2px solid #34426a; min-height: 86px; }
.node + .node::before { content: ''; position: absolute; left: 50%; top: -16px; width: 3px; height: 14px; background: #34426a; }
.node .nname { font-weight: 900; font-size: 13px; line-height: 1.15; }
.node .nlv { font-size: 11px; opacity: .7; font-weight: 800; }
.node .neff { font-size: 11px; opacity: .85; line-height: 1.2; }
.node .ncost { margin-top: auto; font-weight: 900; font-size: 14px; color: #e3d4ff; display: flex; align-items: center; gap: 3px; }
.node .nreq { margin-top: auto; font-size: 10.5px; opacity: .75; }
.node .nmax { margin-top: auto; font-weight: 900; color: var(--gold); font-size: 13px; }
.node.can { border-color: var(--shard); box-shadow: 0 0 0 2px rgba(180,140,255,.25), 0 3px 0 #3b2b66; }
.node.can::after { content: ''; position: absolute; right: 7px; top: 7px; width: 9px; height: 9px; border-radius: 50%; background: var(--shard); box-shadow: 0 0 8px var(--shard); }
.node.locked { opacity: .5; } .node.poor { opacity: .8; } .node.max { border-color: #8a6a1a; }
.node.bought { animation: bought .45s ease-out; }
@keyframes bought { 0% { transform: scale(1.12); background: #4a3a80; } 100% { transform: scale(1); } }
.playbar { position: fixed; left: 0; right: 0; bottom: 0; padding: 10px 12px max(12px, env(safe-area-inset-bottom)); display: flex; justify-content: center; background: linear-gradient(transparent, rgba(10,14,28,.95) 35%); }
.btn.play { width: min(420px, 92vw); min-height: 62px; font-size: 26px; }

/* blocking spinner during ad requests */
#block { position: fixed; inset: 0; z-index: 20; display: none; place-items: center; background: rgba(0,0,0,.45); }
#block.on { display: grid; }
#block.playing { background: rgba(0,0,0,.2); }
.spin { width: 46px; height: 46px; border-radius: 50%; border: 5px solid rgba(255,255,255,.2); border-top-color: #fff; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#mockad { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: #05070e; }
.mockad-box { text-align: center; width: min(360px, 90vw); }
.mockad-tag { font-size: 13px; opacity: .7; } .mockad-kind { font-size: 30px; font-weight: 900; margin: 8px 0; letter-spacing: .1em; }
.mockad-count b { font-size: 50px; } .mockad-bar { height: 6px; background: #222; border-radius: 4px; margin: 10px 0 16px; overflow: hidden; } .mockad-bar i { display: block; height: 100%; width: 0; background: var(--gold); }

#toast { position: fixed; left: 50%; top: 18%; transform: translateX(-50%); z-index: 40; background: rgba(11,15,28,.92); border: 2px solid #4a5b8e; border-radius: 14px; padding: 10px 16px; font-weight: 800; opacity: 0; pointer-events: none; max-width: 90vw; text-align: center; }
#toast.on { animation: toast 2.2s ease-out; }
@keyframes toast { 0% { opacity: 0; transform: translate(-50%, 10px); } 10%, 80% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; } }
#loading { position: fixed; inset: 0; z-index: 50; display: grid; place-content: center; gap: 14px; background: #151b2e; text-align: center; }
.ld-title { font-size: 34px; font-weight: 900; } .ld-bar { width: 220px; height: 8px; background: #2a3354; border-radius: 6px; overflow: hidden; } .ld-bar i { display: block; height: 100%; width: 40%; background: var(--gold); animation: ld 1s ease-in-out infinite alternate; }
@keyframes ld { to { margin-left: 60%; } }

/* landscape (desktop iframe 16:9): side panels get the HUD and the summon button */
body.landscape #ov.homeov { align-items: flex-start; }
@media (max-height: 560px) and (orientation: landscape) {
  .home { width: min(760px, 100%); padding-bottom: 76px; }
  .node { min-height: 64px; padding: 6px; } .branch { gap: 10px; } .node + .node::before { top: -12px; height: 10px; }
  .hhead h1 { font-size: 22px; } .btn.play { min-height: 52px; font-size: 22px; }
  .card { padding: 14px; } .big { font-size: 36px; }
}
