:root{--gold:#f2c14e;--ink:#14102b;--panel:#241c4aee;--house:#7f0909;--house2:#d3a625}
*{box-sizing:border-box}
html,body{margin:0;min-height:100%;background:var(--ink);color:#fff8e7;font-family:Georgia,"Palatino Linotype",serif;-webkit-text-size-adjust:100%}
#bg{position:fixed;inset:0;background:radial-gradient(ellipse at 50% 0,#3b2d7a,#14102b 70%);z-index:-1}
#bg::after{content:"";position:absolute;inset:0;background-image:radial-gradient(2px 2px at 20px 30px,#fff8,transparent),radial-gradient(2px 2px at 140px 90px,#fff6,transparent),radial-gradient(1.5px 1.5px at 80px 160px,#fffa,transparent);background-size:200px 200px;opacity:.7}
#app{width:100%;min-height:100vh;min-height:100dvh;display:flex;align-items:center;justify-content:center;padding:12px}
.screen{text-align:center}
.screen:not([hidden]){display:flex;flex-direction:column;align-items:center;justify-content:center;width:100%;max-width:1500px;min-height:calc(100dvh - 24px)}
.screen.game:not([hidden]){justify-content:flex-start;height:calc(100dvh - 24px)}
.screen > *{max-width:100%}
[hidden]{display:none!important}
h1{font-size:clamp(3rem,11vw,7rem);margin:.4em 0 0;color:var(--gold);text-shadow:0 0 24px #f2c14e88,0 3px 0 #5a3b00;line-height:1}
h2{color:var(--gold);font-size:clamp(1.8rem,6vw,2.6rem);margin:.4em 0}
h3{color:var(--gold);margin:.4em 0}
.sub{font-size:1.4rem;margin:.4em 0 1.4em}
.small{opacity:.85;max-width:34em;margin:1.2em auto}
.say{font-size:1.25rem;max-width:34em;margin:.8em auto}
button{font:inherit;color:inherit;cursor:pointer}
.big{background:linear-gradient(#f7d77a,#d9a52b);color:#2a1d00;border:0;border-radius:14px;padding:.8em 1.6em;font-size:1.3rem;font-weight:bold;margin:.5em;box-shadow:0 4px 0 #7a5600;min-height:52px}
.big:active{transform:translateY(3px);box-shadow:0 1px 0 #7a5600}
.big:disabled{opacity:.4;cursor:not-allowed}
.big.alt{background:linear-gradient(#cfc3ff,#8e7fe0);box-shadow:0 4px 0 #3c2f8a;color:#150d4a}
.btns{display:flex;flex-wrap:wrap;justify-content:center}
#mute{position:fixed;top:10px;right:10px;z-index:50;background:#0008;border:1px solid #fff4;border-radius:50%;width:44px;height:44px;font-size:1.3rem}
.tabs{display:flex;gap:8px;justify-content:center;margin:.6em 0}
.tab{background:#ffffff14;border:2px solid #ffffff30;border-radius:10px;padding:.5em 1em;font-size:1.05rem}
.tab.on{background:var(--gold);color:#2a1d00;font-weight:bold}
#own{width:100%;display:flex;flex-wrap:wrap;gap:20px;justify-content:center;align-items:flex-start}
#avatar svg{width:min(340px,60vw,38dvh);height:auto;background:#ffffff10;border-radius:18px}
.opts{display:flex;flex-direction:column;gap:12px;text-align:left;min-width:260px}
.opts input[type=text],#name{font:inherit;font-size:1.2rem;padding:.4em .6em;border-radius:8px;border:2px solid var(--gold);background:#0006;color:#fff;width:100%}
.chk{display:flex;gap:8px;align-items:center;font-size:1.1rem}
.chk input{width:22px;height:22px}
.sw{display:flex;gap:8px;flex-wrap:wrap;margin-top:6px}
.sw button{width:44px;height:44px;border-radius:50%;border:3px solid transparent;padding:0;background:#ffffff18;font-size:.8rem}
.sw button.on{border-color:#fff;box-shadow:0 0 10px var(--gold)}
.sw button.txt{border-radius:10px;width:auto;padding:0 12px}
.grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:12px;margin:12px 0;width:100%;max-width:1100px}
.card{background:#ffffff12;border:3px solid #ffffff30;border-radius:14px;padding:8px;font-size:1rem;display:flex;flex-direction:column;align-items:center;gap:6px}
.card img{width:100%;aspect-ratio:1;object-fit:cover;border-radius:10px}
.card.on{border-color:var(--gold);box-shadow:0 0 16px #f2c14e88;background:#f2c14e22}
.card.locked{opacity:.45;filter:grayscale(1);cursor:not-allowed}
.card small{opacity:.85}
img.round{width:min(340px,60vw,38dvh);border-radius:50%;border:4px solid var(--gold);box-shadow:0 0 30px #f2c14e66}
.answers{display:grid;grid-template-columns:repeat(auto-fit,minmax(210px,1fr));gap:10px;margin:12px 0}
.ans{background:#ffffff18;border:3px solid #ffffff40;border-radius:12px;padding:.8em;font-size:1.2rem;min-height:56px}
.ans:hover{background:#ffffff28}
.ans.right{background:#2e9b4f;border-color:#8dffae}
.ans.wrong{background:#a12b3b;border-color:#ff9aa8}
.ans.gone{visibility:hidden}
#crest{width:130px;height:150px;margin:10px auto;clip-path:polygon(0 0,100% 0,100% 62%,50% 100%,0 62%);background:linear-gradient(135deg,var(--house) 50%,var(--house2) 50%);display:flex;align-items:center;justify-content:center;font-size:4rem}
.row{display:flex;flex-wrap:wrap;gap:10px;justify-content:center;margin:10px 0}
/* game screen */
.hud{width:100%;padding-right:60px!important;display:flex;align-items:center;gap:12px;background:#0007;padding:8px 12px;border-radius:12px;margin-bottom:8px;flex-wrap:wrap}
#lvl-label{font-weight:bold;color:var(--gold);font-size:1.1rem;text-align:left;flex:1 1 200px}
#bosshp{flex:1 1 140px;height:16px;border-radius:8px;background:#000a;border:2px solid #fff4;overflow:hidden}
#bosshp i{display:block;height:100%;width:100%;background:linear-gradient(90deg,#3de07a,#1a9d4c);transition:width .8s}
#pet-hud{display:flex;align-items:center;gap:6px}
#pet-hud img{width:38px;height:38px;border-radius:50%;object-fit:cover;border:2px solid var(--gold)}
#stage{position:relative;flex:1 1 auto;min-height:180px;width:100%;border-radius:16px;overflow:hidden;border:3px solid var(--gold);background:#000}
#stage-img{position:absolute;inset:0;width:100%;height:100%;object-fit:cover;transition:filter 1s}
#boss-img{position:absolute;right:2%;top:4%;height:70%;aspect-ratio:3/2;object-fit:cover;border-radius:50%;mask-image:radial-gradient(closest-side,#000 55%,transparent);-webkit-mask-image:radial-gradient(closest-side,#000 55%,transparent);opacity:.95;transition:opacity 1.2s,transform .3s,filter .6s}
#hero{position:absolute;left:3%;bottom:3%;height:34%;aspect-ratio:1;object-fit:cover;border-radius:50%;border:3px solid var(--gold);background:#fff2}
#hero.svg{border:0;background:none;border-radius:0}
#fx{position:absolute;inset:0;width:100%;height:100%;pointer-events:none}
#stage-banner{position:absolute;left:0;right:0;top:40%;text-align:center;font-size:clamp(1.4rem,6vw,3rem);font-weight:bold;color:#fff;text-shadow:0 0 14px #000,0 0 30px var(--gold);opacity:0;transition:opacity .4s;pointer-events:none}
#stage-banner.show{opacity:1}
#boss-img.shake{animation:shake .5s}
#boss-img.gone{opacity:0}
#boss-img.grey{filter:grayscale(1) brightness(.8)}
#boss-img.ice{filter:hue-rotate(160deg) saturate(2) brightness(1.2)}
#boss-img.pink{filter:hue-rotate(280deg) saturate(2)}
#boss-img.lift{animation:lift 1.4s}
#stage.dark #stage-img{filter:brightness(.35) sepia(1) hue-rotate(300deg) saturate(3)}
@keyframes shake{0%,100%{transform:translate(0)}20%{transform:translate(-14px,6px)}40%{transform:translate(12px,-8px)}60%{transform:translate(-10px,4px)}80%{transform:translate(8px,-4px)}}
@keyframes lift{0%{transform:translateY(0) rotate(0)}50%{transform:translateY(-60px) rotate(180deg)}100%{transform:translateY(0) rotate(360deg)}}
#panel{background:var(--panel);border-radius:16px;margin-top:10px;padding:14px;width:100%;flex:0 0 auto;max-height:46dvh;overflow:auto}
#story{font-size:1.15rem;margin:.2em 0 .6em}
.subj{background:#ffffff18;border:3px solid #ffffff40;border-radius:12px;padding:.6em 1em;font-size:1.15rem;min-width:120px}
.subj:hover{border-color:var(--gold)}
.spells{grid-template-columns:repeat(auto-fill,minmax(130px,1fr))}
.spell{background:#ffffff14;border:3px solid #ffffff30;border-radius:12px;padding:8px;font-size:.95rem}
.spell b{display:block;color:var(--gold);font-size:1.05rem}
.spell span{font-size:1.8rem;display:block}
.spell:hover{border-color:var(--gold)}
.qhead{display:flex;justify-content:space-between;align-items:center;gap:8px}
#q-sub{background:var(--gold);color:#2a1d00;border-radius:8px;padding:.1em .6em;font-weight:bold}
#b-say{background:#ffffff18;border:2px solid #ffffff40;border-radius:8px;padding:.3em .7em}
#q-text{font-size:clamp(1.3rem,4.5vw,1.8rem);margin:.6em 0}
.pow{background:#ffffff14;border:2px dashed var(--gold);border-radius:10px;padding:.4em .9em}
.pow:disabled{opacity:.35}
#msg{font-size:1.25rem}
#cert-wrap{max-width:min(100%,calc((100dvh - 200px) * 1.414));overflow:hidden}
#cert{width:100%;height:auto;border-radius:6px;box-shadow:0 0 30px #000a}
@media print{
  body *{visibility:hidden}
  #cert-wrap,#cert-wrap *{visibility:visible}
  #cert-wrap{position:absolute;left:0;top:0;width:100%}
  @page{size:A4 landscape;margin:0}
  html,body{background:#fff}
}
@media(max-width:700px){
  #app{padding:8px}
  .screen.game:not([hidden]){height:auto;min-height:calc(100dvh - 16px);justify-content:flex-start}
  .hud{padding:6px 10px 6px 10px!important;padding-right:56px!important;gap:8px}
  #lvl-label{flex-basis:100%;font-size:1rem}
  #stage{flex:0 0 auto;height:26dvh;min-height:150px}
  #boss-img{height:70%}#hero{height:36%}
  #panel{max-height:none;overflow:visible;padding:14px 12px 20px;margin-top:8px}
  .qhead{flex-wrap:wrap}
  #q-text{line-height:1.35;text-align:left;margin:.8em 0 1em}
  .answers{grid-template-columns:1fr;gap:12px}
  .ans{text-align:left;font-size:1.15rem;padding:.9em 1em;min-height:60px}
  .ans.gone{display:none}
}
@media(prefers-reduced-motion:reduce){#boss-img.shake,#boss-img.lift{animation:none}}
