*{box-sizing:border-box}
html{background:#181425}
body{margin:0;min-height:100dvh;background:#181425;color:#f4f4f4;font-family:ui-monospace,Menlo,Consolas,monospace;-webkit-user-select:none;user-select:none;touch-action:manipulation;-webkit-tap-highlight-color:transparent;
 padding:env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left)}
button{font-family:inherit;cursor:pointer;touch-action:manipulation}
#app{max-width:640px;margin:0 auto;padding:10px 12px 24px;text-align:center}
.hud{display:flex;justify-content:space-between;align-items:center;gap:8px;font-size:15px;font-weight:700;padding:6px 2px}
#snd{background:#3a4466;border:2px solid #5a6988;border-radius:20px;color:#fff;font-size:15px;padding:2px 10px}
canvas{image-rendering:pixelated;image-rendering:crisp-edges}
/* Map: as wide as the column allows, but never so tall that the D-pad falls off screen */
#c{display:block;margin:0 auto;width:min(100%,calc((100dvh - 250px) * 72 / 88));aspect-ratio:72/88;border:3px solid #3a4466;border-radius:6px;background:#181425}
.pad{display:grid;grid-template-columns:repeat(3,64px);grid-template-areas:". up ." "lf dn rt";gap:8px;justify-content:center;margin-top:12px}
.pad button{height:56px;font-size:22px;background:#3a4466;color:#f4f4f4;border:0;border-bottom:4px solid #262b44;border-radius:10px}
.pad button:active{transform:translateY(2px);border-bottom-width:2px}
.up{grid-area:up}.lf{grid-area:lf}.dn{grid-area:dn}.rt{grid-area:rt}
.hint,.small{font-size:12px;opacity:.75}
.ov{position:fixed;inset:0;background:rgba(24,20,37,.9);display:flex;align-items:center;justify-content:center;padding:max(16px,env(safe-area-inset-top)) 16px max(16px,env(safe-area-inset-bottom));z-index:5}
.hidden{display:none!important}
.box{background:#262b44;border:3px solid #5a6988;border-radius:12px;padding:18px 16px;width:100%;max-width:380px;max-height:100%;overflow-y:auto;text-align:center}
.box h1{margin:0 0 10px;font-size:24px;color:#feae34}
.box h2{margin:6px 0 4px;font-size:18px}
.box canvas{width:128px;height:128px}
.box>button,#again,#next{display:block;width:100%;margin:10px 0 0;padding:14px;font-weight:700;font-size:17px;background:#0099db;color:#fff;border:0;border-bottom:4px solid #124e89;border-radius:10px}
#next{background:#3e8948;border-bottom-color:#265c42}
#mhp{color:#e43b44;font-size:18px;letter-spacing:3px;min-height:22px}
.tag{display:inline-block;margin-top:6px;padding:3px 10px;border-radius:20px;background:#5a6988;font-size:12px}
#q{font-size:20px;font-weight:700;margin:10px 0 14px;white-space:pre-line}
/* Reading-comprehension passages: smaller, left-aligned text */
#q.read{font-size:16px;font-weight:400;text-align:left;line-height:1.45}
/* Long answer options get a full row each */
#opts.long{grid-template-columns:1fr}
#pic{font-size:32px;line-height:1.25;margin-top:8px;min-height:4px}
#spk{background:#3a4466;border:2px solid #5a6988;border-radius:20px;color:#fff;font-size:16px;padding:2px 10px;margin-left:4px}
#opts{display:grid;grid-template-columns:1fr 1fr;gap:8px}
#opts.free{display:block}
#opts button{padding:14px 6px;font-size:16px;font-weight:700;background:#3a4466;color:#f4f4f4;border:2px solid #5a6988;border-radius:10px;min-height:52px}
#opts button.ok{background:#3e8948;border-color:#63c74d}
#opts button.bad{background:#a22633;border-color:#e43b44}
#opts button:disabled{opacity:.45}
#opts button.ok,#opts button.bad{opacity:1}
#opts .go{background:#3e8948;border-color:#63c74d}
.y1 #opts{grid-template-columns:1fr}
.y1 #opts button{font-size:22px;padding:14px}
.y1 #q{font-size:22px}
.ansbox{font-size:26px;font-weight:700;letter-spacing:4px;background:#181425;border:2px solid #5a6988;border-radius:10px;padding:10px;min-height:52px;margin-bottom:10px;word-break:break-word}
.ansbox.small{font-size:15px;letter-spacing:0}
.keys{display:grid;grid-template-columns:repeat(3,1fr);gap:8px}
.tiles{display:flex;flex-wrap:wrap;gap:8px;justify-content:center}
.tiles button{min-width:48px}
.ctl{display:grid;grid-template-columns:1fr 1fr;gap:8px;margin-top:10px}
#fb{min-height:22px;font-weight:700;margin:12px 0 0}
#fb.ok{color:#63c74d}#fb.bad{color:#ff8a7a}
#statl{text-align:left;margin:10px auto;max-width:240px;line-height:1.7}
#statl .gap{margin-top:12px}
#toast{position:fixed;left:50%;top:calc(14px + env(safe-area-inset-top));transform:translateX(-50%);background:#feae34;color:#181425;font-weight:700;padding:8px 14px;border-radius:20px;opacity:0;transition:opacity .25s;z-index:9;pointer-events:none;white-space:nowrap}
#toast.on{opacity:1}

/* Feedback animations */
.shake{animation:shake .35s}
@keyframes shake{20%{transform:translateX(-8px)}40%{transform:translateX(7px)}60%{transform:translateX(-5px)}80%{transform:translateX(3px)}}
.hit{animation:hit .4s}
@keyframes hit{0%{filter:brightness(3)}30%{transform:scale(.9) rotate(-6deg)}60%{transform:scale(1.05)}100%{filter:none;transform:none}}
@media (prefers-reduced-motion:reduce){.shake,.hit{animation:none}}

/* Tablets (iPad portrait, big phones): bigger touch targets and text */
@media (min-width:600px){
 .hud{font-size:20px}
 .pad{grid-template-columns:repeat(3,88px);gap:10px}
 .pad button{height:76px;font-size:30px}
 .hint{font-size:14px}
 .box{max-width:540px;padding:24px 22px}
 .box h1{font-size:32px}.box h2{font-size:22px}
 .box canvas{width:160px;height:160px}
 #q{font-size:26px}.y1 #q{font-size:28px}
 #pic{font-size:44px}
 #opts button{font-size:20px;padding:18px 8px}
 .y1 #opts button{font-size:28px}
 .ansbox{font-size:32px}
 .tiles button{min-width:60px}
 .box>button,#again,#next{font-size:20px;padding:18px}
 #c{width:min(100%,calc((100dvh - 300px) * 72 / 88))}
}

/* Landscape (iPad landscape, phones on their side): map on the left, controls on the right */
@media (orientation:landscape) and (min-width:640px){
 #app{max-width:none;height:100dvh;padding:12px 20px;display:grid;grid-template-columns:auto minmax(220px,340px);grid-template-rows:1fr auto auto auto 1fr;grid-template-areas:"map ." "map hud" "map pad" "map hint" "map .";justify-content:center;align-content:center;column-gap:clamp(16px,4vw,56px)}
 #c{grid-area:map;width:auto;height:calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));max-height:calc(100dvh - 24px)}
 .hud{grid-area:hud;flex-wrap:wrap;justify-content:center}
 .pad{grid-area:pad;margin-top:20px}
 .hint{grid-area:hint;align-self:start;margin-top:20px}
 .keys{grid-template-columns:repeat(6,1fr)}
}
/* Small phones: tighten the battle screen so the number pad and big Year 1 buttons fit without scrolling */
@media (max-height:720px){
 .box{padding:12px 14px}
 .box canvas{width:88px;height:88px}
 .box h2{margin:2px 0}
 #pic{font-size:28px;margin-top:4px}
 #q{margin:6px 0 10px}
 #opts button,.y1 #opts button{padding:10px 6px;min-height:44px}
 .keys button{padding:10px 4px!important}
 .ansbox{padding:6px;min-height:44px;margin-bottom:8px}
 #fb{margin-top:8px}
}
/* Short screens (phone landscape): shrink the battle monster so questions fit */
@media (max-height:520px){
 .box{padding:12px 14px}
 .box canvas{width:64px;height:64px}
 #q{margin:6px 0 10px}
 .pad button{height:52px}
}
/* Phone landscape battles: monster on the left, question + answers on the right */
@media (max-height:520px) and (orientation:landscape){
 #battle .box{max-width:780px;display:grid;grid-template-columns:150px 1fr;column-gap:16px;align-content:start}
 #battle .box>*{grid-column:2}
 #battle .box>.mon{grid-column:1;grid-row:1 / span 6;align-self:center}
 #battle .mon canvas{width:72px;height:72px}
 .y1 #opts{grid-template-columns:repeat(auto-fit,minmax(150px,1fr))}
 .keys{grid-template-columns:repeat(6,1fr)}
 #pic{font-size:22px;margin-top:0}
 #fb{min-height:0}
 #pic{font-size:26px}
 #q{font-size:18px}
 #opts button{padding:10px 6px;min-height:44px}
}

/* Character canvases are 20×21 sprites: keep that shape whatever width a layout gives them */
.box canvas{aspect-ratio:20/21;height:auto!important;margin:0 auto;display:block}

/* Title: small "change hero" button under the hero */
.box>button.mini{display:inline-block;width:auto;margin:4px auto 0;padding:6px 14px;font-size:13px;background:#3a4466;border-bottom:3px solid #262b44}

/* Hero creator */
#heroEd .box{max-width:460px}
#heroEd h3{font-size:11px;text-transform:uppercase;letter-spacing:1px;opacity:.75;margin:12px 0 6px;text-align:left}
#hopts{margin-top:6px}
.chips{display:flex;flex-wrap:wrap;gap:6px}
.chip{background:#3a4466;color:#f4f4f4;border:2px solid #5a6988;border-radius:20px;padding:7px 12px;font-size:14px;font-weight:700}
.chip.on{border-color:#feae34;color:#feae34;background:#262b44}
.sw{width:34px;height:34px;border-radius:9px;border:3px solid #262b44;padding:0;box-shadow:0 0 0 2px #3a4466}
.sw.on{border-color:#fff}
.duo{display:grid;grid-template-columns:1fr 1fr;gap:8px;margin-top:14px}
.duo button{padding:14px;font-weight:700;font-size:16px;color:#fff;border:0;border-radius:10px;background:#3e8948;border-bottom:4px solid #265c42}
.duo button.alt{background:#3a4466;border-bottom-color:#262b44}
:is(.chip,.sw,.duo button,#edhero):focus-visible{outline:3px solid #feae34;outline-offset:2px}
/* keep the hero preview in view while scrolling through the options on small screens */
#heroEd .box{padding-top:0}
#heroEd .hhead{position:sticky;top:0;z-index:1;background:#262b44;padding:14px 0 8px;border-bottom:2px solid #3a4466}
#heroEd .hhead h2{margin:0 0 6px}
@media (max-height:720px){#heroEd .hhead canvas{width:88px}}
/* Battle monster size on in-between heights (older iPads in landscape, small phones) */
@media (min-width:600px) and (min-height:521px) and (max-height:820px){#battle .box canvas{width:112px}}
@media (max-width:599px) and (max-height:660px){#battle .box canvas{width:72px}}

/* Taming + pets in battle */
#battle .box>#tame{background:#b55088;border-bottom-color:#68386c}
#pethelp{background:#feae34;color:#181425;border:0;border-radius:20px;font-weight:700;font-size:14px;padding:3px 10px;margin-left:4px}
#opts button.zapped{opacity:.15;text-decoration:line-through}

/* Monster Book */
#book .box{max-width:640px;text-align:center}
#book h3{font-size:12px;text-align:left;margin:16px 0 6px;color:#feae34;letter-spacing:.5px}
.brow{display:grid;grid-template-columns:78px 1fr;gap:8px;align-items:center;margin:4px 0}
.blabel{font-size:12px;text-align:left;opacity:.85}
.bslots{display:grid;grid-template-columns:repeat(auto-fill,minmax(36px,1fr));gap:4px}
.bslot{aspect-ratio:1;background:#181425;border:2px solid #3a4466;border-radius:8px;padding:1px;color:#5a6988;font-weight:700;font-size:14px;display:flex;align-items:center;justify-content:center}
#book .bslot canvas{width:100%!important;height:auto!important;margin:0}
.bslot.got{border-color:#63c74d;background:#262b44}
.bslot.gold{border-style:dashed;border-color:#b86f50}
.bslot.got.gold{border-style:solid;border-color:#feae34}
.bslot.pet{box-shadow:0 0 0 3px #feae34}
#bdetail{position:sticky;top:-18px;z-index:2;display:grid;grid-template-columns:96px 1fr;gap:12px;align-items:center;text-align:left;background:#181425;border:2px solid #3a4466;border-radius:12px;padding:10px;margin:10px 0}
#book #bdetail canvas{width:96px!important;margin:0}
#bname{font-size:16px;color:#feae34}
#binfo{margin:4px 0 0;opacity:.9}
#bpet{margin-top:8px;padding:10px 12px;border:0;border-radius:10px;background:#3e8948;color:#fff;font-weight:700;font-size:14px;border-bottom:3px solid #265c42}
@media (max-width:420px){.brow{grid-template-columns:1fr}.blabel{margin-top:4px}}

/* Players */
#hi{margin:0 0 4px;font-weight:700;color:#63c74d}
#title .box>button.last{box-shadow:0 0 0 3px #feae34}
#plist{display:grid;grid-template-columns:repeat(auto-fill,minmax(130px,1fr));gap:10px;margin:12px 0 4px}
.pcard{position:relative}
.pgo{width:100%;display:flex;flex-direction:column;align-items:center;gap:2px;background:#181425;border:2px solid #3a4466;border-radius:12px;padding:10px 6px;color:#f4f4f4}
.pgo:hover{border-color:#5a6988}
#who .pgo canvas{width:72px!important;margin:0}
.pgo b{font-size:17px;margin-top:2px}
.pedit{position:absolute;top:6px;right:6px;background:#3a4466;border:0;border-radius:8px;width:30px;height:30px;font-size:14px;padding:0}
#pname{display:block;width:100%;margin:6px 0 2px;padding:12px;font:inherit;font-size:22px;font-weight:700;text-align:center;background:#181425;color:#f4f4f4;border:2px solid #5a6988;border-radius:10px;user-select:text;-webkit-user-select:text}
#pname:focus{outline:3px solid #feae34;outline-offset:1px}
#perr{min-height:18px;margin:4px 0 0;color:#ff8a7a;font-size:13px;font-weight:700}
#pedit .box>#pdel{background:#a22633;border-bottom-color:#3e2731}
#pedit .box>#pcancel{background:#3a4466;border-bottom-color:#262b44}
:is(.pgo,.pedit):focus-visible{outline:3px solid #feae34;outline-offset:2px}

/* Family sync */
#syncstate{margin:8px 0 0}
#sync .box{max-width:440px}
#sync .or{margin:18px 0 0}
#syncCode{display:block;width:100%;margin:6px 0 0;padding:12px;font:inherit;font-size:24px;font-weight:700;letter-spacing:3px;text-align:center;text-transform:uppercase;background:#181425;color:#f4f4f4;border:2px solid #5a6988;border-radius:10px;user-select:text;-webkit-user-select:text}
#syncCode:focus{outline:3px solid #feae34;outline-offset:1px}
#syncShow{font-size:32px;font-weight:700;letter-spacing:4px;color:#feae34;background:#181425;border-radius:12px;padding:14px;margin:8px 0;user-select:text;-webkit-user-select:text}
#syncMsg{min-height:20px;margin:12px 0 0;font-weight:700;color:#63c74d}
#sync .box>button.alt{background:#3a4466;border-bottom-color:#262b44}
#syncOff>button,#syncOn>button{display:block;width:100%;margin:10px 0 0;padding:14px;font-weight:700;font-size:17px;color:#fff;border:0;border-radius:10px;background:#0099db;border-bottom:4px solid #124e89}
#syncOff>button.alt,#syncOn>button.alt{background:#3a4466;border-bottom-color:#262b44}
@media (min-width:600px){#syncOff>button,#syncOn>button{font-size:20px;padding:18px}}

/* Team of pets */
.herorow{display:flex;align-items:flex-end;justify-content:center;gap:6px}
#tteam{display:flex;gap:2px;cursor:pointer}
#title #tteam canvas{width:48px!important;margin:0}
#tteam.empty{display:none}
#opts .tp-add,#opts .tp-in,#bteam .tp-add,#bteam .tp-in{display:block;width:100%;margin-top:6px;padding:12px;border:0;border-radius:10px;font-weight:700;font-size:15px;color:#fff;background:#3e8948;border-bottom:3px solid #265c42}
#opts .tp-in,#bteam .tp-in{background:#3a4466;border-bottom-color:#262b44}
.tp-note{margin:6px 0;font-size:13px;font-weight:700;color:#feae34}
.tp-row{display:flex;gap:8px;justify-content:center}
#opts .tp-swap,#bteam .tp-swap{display:flex;flex-direction:column;align-items:center;gap:2px;padding:6px;background:#181425;border:2px solid #5a6988;border-radius:10px;color:#f4f4f4;min-height:0}
.tp-swap canvas{width:48px!important;height:auto!important;margin:0}
.bteamrow{display:flex;gap:6px}
.bteamrow .tslot{width:56px;flex:none}
#bdetail .tp-row{justify-content:flex-start}
