/* ==========================================================================
   Mythlings — "Bold Cartoon" theme
   Thick ink outlines, hard offset shadows, chunky outlined display type,
   saturated flat colors. Matches the outlined monster art.
   ========================================================================== */
:root {
  --ink: #1b1534;
  --cream: #fff4d8;
  --cream2: #f3e3bb;
  --paper: #fffbf2;
  --blue: #2f8cff;
  --blue2: #1f6fe0;
  --sky: #3fb0ff;
  --sky2: #1f78d0;
  --yellow: #ffd23d;
  --yellow2: #e8a10c;
  --orange: #ff8a2b;
  --orange2: #d9600d;
  --red: #ff4d5e;
  --red2: #c42a3a;
  --green: #4fd15a;
  --green2: #2a9a35;
  --purple: #8a5cff;
  --purple2: #5f37d0;
  --muted: #6b5d3c; /* 5.9:1 on cream (WCAG AA) */
  --dim: #b3a47f;
  --text: var(--ink);
  --good: #146624; /* 6.4:1 on cream, >= 5:1 on the tinted cards (was #1a7f2c: 4.1:1 there, audit) */
  --bad: #c42536; /* 5.2:1 on cream */
  --gold-text: #b34d00; /* orange text, 4.8:1 on cream; --orange2 stays for button shading */
  --blue-text: #1a5fc4; /* blue text, 5.5:1 on cream (--blue2 was 4.35:1, 3.9:1 on the pink wave banner: audit) */
  --gold: #ffb800;
  --fh: 'Lilita One', 'Rubik', 'Segoe UI', sans-serif;
  --fb: 'Rubik', 'Segoe UI', system-ui, sans-serif;
  --ol: 2px 2px 0 var(--ink), -2px 2px 0 var(--ink), 2px -2px 0 var(--ink), -2px -2px 0 var(--ink), 0 2px 0 var(--ink), 0 -2px 0 var(--ink), 2px 0 0 var(--ink), -2px 0 0 var(--ink), 0 4px 0 var(--ink);
  --ols: 1.5px 1.5px 0 var(--ink), -1.5px 1.5px 0 var(--ink), 1.5px -1.5px 0 var(--ink), -1.5px -1.5px 0 var(--ink), 0 1.5px 0 var(--ink), 0 -1.5px 0 var(--ink), 1.5px 0 0 var(--ink), -1.5px 0 0 var(--ink), 0 3px 0 var(--ink);
  --hard: 0 5px 0 var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background-color: var(--blue);
  background-image:
    radial-gradient(ellipse at 50% -10%, rgba(255, 255, 255, .28), transparent 55%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='90' height='90' viewBox='0 0 90 90'%3E%3Cg fill='%23ffffff' fill-opacity='.09'%3E%3Cpath transform='translate(8 8) rotate(-15 12 12)' d='M12 1.5 C16 6 19.5 9.5 19.5 14 A7.5 7.5 0 0 1 4.5 14 C4.5 9.5 8 6 12 1.5Z'/%3E%3Cpath transform='translate(52 50) rotate(20 12 12)' d='M12 1.5 C16 6 19.5 9.5 19.5 14 A7.5 7.5 0 0 1 4.5 14 C4.5 9.5 8 6 12 1.5Z'/%3E%3C/g%3E%3C/svg%3E");
  color: var(--ink);
  font-family: var(--fb);
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
}
button { font-family: inherit; color: inherit; }
h1, h2, h3, h4 { font-family: var(--fh); font-weight: 400; margin: 0; letter-spacing: .3px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.good { color: var(--good); }
.bad { color: var(--bad); }
.gold { color: var(--gold-text); }
b, strong { font-weight: 700; }
.ol { font-family: var(--fh); color: #fff; text-shadow: var(--ol); }
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-thumb { background: var(--sky); border: 3px solid var(--ink); border-radius: 10px; }
::-webkit-scrollbar-track { background: transparent; }

#app { display: flex; flex-direction: column; height: 100vh; }
#app.booting #layout { opacity: 0; }

/* ---------- top bar ---------- */
#topbar { height: 62px; flex: none; display: flex; align-items: center; gap: 16px; padding: 0 16px; position: relative; z-index: 5; }
.logo { display: flex; align-items: center; gap: 6px; background: none; border: 0; cursor: pointer; padding: 4px 6px; }
.logo-mark { width: 34px; height: 34px; display: inline-block; filter: drop-shadow(0 3px 0 var(--ink)); }
.logo-mark svg { width: 100%; height: 100%; }
.logo-text { font-family: var(--fh); font-size: 34px; color: var(--yellow); text-shadow: var(--ol); transform: rotate(-3deg); display: inline-block; letter-spacing: .5px; transition: transform .15s; }
.logo:hover .logo-text { transform: rotate(-3deg) scale(1.04); }
.news { flex: 1; overflow: hidden; height: 38px; border-radius: 12px; background: var(--blue2); border: 3px solid var(--ink); box-shadow: inset 0 3px 0 rgba(0, 0, 0, .18); position: relative; }
.news-text { position: absolute; white-space: nowrap; top: 0; line-height: 32px; padding-left: 100%; color: #e9f3ff; font-weight: 700; font-size: 14px; }
.news-text.run { animation: newsScroll linear forwards; }
@keyframes newsScroll { from { transform: translateX(0); } to { transform: translateX(-100%); } }
.top-res { display: flex; align-items: center; gap: 10px; }
.res-chip { display: flex; align-items: center; gap: 6px; height: 38px; padding: 0 14px 0 2px; border-radius: 12px; background: var(--ink); border: 3px solid var(--ink); cursor: default; }
.res-chip .res-num { font-family: var(--fh); font-size: 19px; color: #fff; text-shadow: var(--ols); } /* a class, not :last-child: the hidden unit text comes last (UI-23) */
.res-ico svg { display: block; width: 30px; height: 30px; margin-left: -12px; filter: drop-shadow(0 2px 0 var(--ink)); }
.icon-btn { width: 40px; height: 38px; border-radius: 12px; border: 3px solid var(--ink); background: var(--yellow); cursor: pointer; display: grid; place-items: center; box-shadow: inset 0 -4px 0 var(--yellow2), 0 3px 0 var(--ink); padding: 0; }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:active { transform: translateY(2px); box-shadow: inset 0 -2px 0 var(--yellow2), 0 1px 0 var(--ink); }

/* ---------- layout ---------- */
#layout { flex: 1; display: grid; grid-template-columns: minmax(280px, 27%) minmax(400px, 1fr) minmax(300px, 340px); gap: 14px; padding: 2px 14px 16px; min-height: 0; transition: opacity .4s; }
.col { min-height: 0; position: relative; }

/* ---------- left column (partner) ---------- */
#left { overflow: hidden; border: 4px solid var(--ink); border-radius: 22px; box-shadow: 0 7px 0 var(--ink); background: #9fe3ff; }
#left::after { content: ''; position: absolute; inset: 0; border-radius: 18px; box-shadow: inset 0 0 0 4px rgba(255, 255, 255, .35); pointer-events: none; }
#scene-bg { position: absolute; inset: 0; transition: opacity .8s; }
#scene-bg svg { width: 100%; height: 100%; display: block; }
.scene-shade { position: absolute; inset: 0; background: linear-gradient(180deg, rgba(27, 21, 52, .32) 0%, rgba(27, 21, 52, 0) 38%, rgba(27, 21, 52, 0) 72%, rgba(27, 21, 52, .22) 100%); pointer-events: none; }
.left-inner { position: relative; height: 100%; display: flex; flex-direction: column; align-items: center; padding: 14px 12px 12px; }
.den-name { font-family: var(--fh); font-size: 16px; color: var(--ink); background: var(--yellow); border: 3px solid var(--ink); padding: 2px 14px; border-radius: 10px; transform: rotate(-2deg); box-shadow: 0 3px 0 var(--ink); cursor: pointer; max-width: 92%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; transition: transform .12s; flex-shrink: 0; /* never squashed in the fixed-height column (UI-13) */ }
.den-name:hover { transform: rotate(-2deg) scale(1.05); }
.essence-box { text-align: center; margin-top: 8px; }
.essence-line { display: flex; align-items: center; justify-content: center; gap: 8px; font-family: var(--fh); font-size: 54px; line-height: 1.05; color: #fff; text-shadow: var(--ol); }
.ess-ico svg { width: 40px; height: 40px; display: block; filter: drop-shadow(0 3px 0 var(--ink)); }
.essence-label { font-family: var(--fh); font-size: 16px; color: #ffe9a8; text-shadow: 0 2px 0 var(--ink), 1px 1px 0 var(--ink), -1px 1px 0 var(--ink), 1px -1px 0 var(--ink), -1px -1px 0 var(--ink); margin-top: -2px; }
.eps-line { margin-top: 5px; font-size: 14px; font-weight: 700; color: var(--ink); background: var(--cream); border: 3px solid var(--ink); padding: 2px 12px; border-radius: 10px; display: inline-block; box-shadow: 0 3px 0 var(--ink); cursor: default; }
.eps-line b { color: var(--blue-text); font-family: var(--fh); font-weight: 400; font-size: 16px; }
/* what the battle estimates assume (D39) */
.est-note { font-size: 11px; margin: 2px 0 6px; line-height: 1.3; }
/* goal line under production (D38): one short suggestion; a click opens the tab it names */
.goal-line { display: block; margin: 8px auto 0; max-width: 220px; padding: 3px 10px; font: 700 12px/1.3 var(--fb); color: var(--ink); background: var(--cream); border: 3px solid var(--ink); border-radius: 10px; box-shadow: 0 3px 0 var(--ink); cursor: pointer; text-align: center; overflow-wrap: anywhere; }
.goal-line[hidden] { display: none; }
.goal-line:disabled { cursor: default; }
.goal-line:not(:disabled):hover { background: #fff; }
.buffs { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 10px; min-height: 32px; }
.buff { display: flex; align-items: center; gap: 6px; padding: 3px 10px 5px 5px; border-radius: 10px; background: var(--orange); border: 3px solid var(--ink); box-shadow: 0 3px 0 var(--ink); font-family: var(--fh); font-size: 14px; color: #fff; text-shadow: var(--ols); position: relative; overflow: hidden; animation: popIn .3s ease; }
.buff .bt { background: var(--ink); color: var(--yellow); border-radius: 6px; padding: 0 5px; font-size: 12px; text-shadow: none; }
.buff .bar { position: absolute; left: 0; bottom: 0; height: 3px; background: rgba(255, 255, 255, .8); }
.buff.clickfury { background: #ff5fb5; }
.buff.surge { background: var(--green); }
.buff.fervor { background: var(--red); }
.buff svg { width: 20px; height: 20px; filter: drop-shadow(0 1px 0 var(--ink)); }
.partner-zone { position: relative; flex: 1; width: 100%; display: flex; align-items: center; justify-content: center; min-height: 200px; }
.partner-glow { position: absolute; width: 70%; max-width: 300px; aspect-ratio: 1; border-radius: 50%; background: radial-gradient(circle, rgba(255, 255, 255, .42), rgba(255, 255, 255, 0) 65%); animation: glowPulse 3s ease-in-out infinite; pointer-events: none; }
@keyframes glowPulse { 0%, 100% { transform: scale(.92); opacity: .65; } 50% { transform: scale(1.05); opacity: 1; } }
.partner { position: relative; width: min(290px, 82%); aspect-ratio: 1; background: none; border: 0; padding: 0; cursor: pointer; outline: none; -webkit-tap-highlight-color: transparent; }
.partner .pbob { width: 100%; height: 100%; animation: pBob 3.2s ease-in-out infinite; }
.partner svg { width: 100%; height: 100%; display: block; filter: drop-shadow(0 8px 0 rgba(27, 21, 52, .22)); }
.partner:hover svg { filter: drop-shadow(0 8px 0 rgba(27, 21, 52, .22)) brightness(1.05); }
.partner:focus-visible svg { filter: drop-shadow(0 0 0 #fff) drop-shadow(0 0 6px var(--yellow)); }
.partner.squish { animation: squish .2s ease-out; }
@keyframes pBob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }
@keyframes squish { 0% { transform: scale(1, 1); } 35% { transform: scale(1.08, .9); } 70% { transform: scale(.96, 1.05); } 100% { transform: scale(1, 1); } }
.partner-info { font-size: 14px; font-weight: 700; color: var(--ink); background: var(--cream); border: 3px solid var(--ink); border-radius: 10px; padding: 3px 12px; display: flex; gap: 6px; align-items: center; margin-bottom: 6px; box-shadow: 0 3px 0 var(--ink); }
.partner-info b { font-family: var(--fh); font-weight: 400; font-size: 16px; }
.partner-info .muted { color: var(--muted); }
.wave-banner { width: 100%; border-radius: 16px; padding: 8px 10px; background: #ffe1e3; background-image: repeating-linear-gradient(-45deg, rgba(255, 77, 94, .16) 0 12px, transparent 12px 24px); border: 3.5px solid var(--ink); box-shadow: 0 5px 0 var(--ink); display: flex; flex-wrap: wrap; align-items: center; gap: 8px; animation: waveBounce 2.4s ease-in-out infinite; }
.wave-banner .wb-text { min-width: 120px; } /* in a narrow den column the text wraps above the button instead of 67 px wide (audit) */
.wave-banner .btn { margin-left: auto; }
.wave-banner .wb-text { flex: 1; font-size: 12px; font-weight: 700; line-height: 1.3; }
.wave-banner .wb-text b { font-family: var(--fh); font-weight: 400; font-size: 17px; color: var(--red); text-shadow: var(--ols); color: #fff; }
.wave-banner .muted { color: #8a5a5a; }
.wave-banner img { width: 48px; height: 48px; }
@keyframes waveBounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }

/* ---------- center column ---------- */
#center { display: flex; flex-direction: column; }
.tabs { display: flex; gap: 4px; padding: 0 10px; position: relative; z-index: 2; margin-bottom: -4px; }
.tab { position: relative; flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 2px 8px; border: 3.5px solid var(--ink); border-bottom: 0; border-radius: 14px 14px 0 0; background: var(--blue2); cursor: pointer; transition: transform .1s, background .15s; }
.tab svg { width: 22px; height: 22px; filter: drop-shadow(0 2px 0 var(--ink)); }
.tab .tl { font-family: var(--fh); font-size: 13px; color: #fff; text-shadow: var(--ols); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tab:hover { background: var(--sky); }
.tab.active { background: var(--yellow); padding-top: 9px; margin-top: -4px; }
.tab.active::after { content: ''; position: absolute; left: 0; right: 0; bottom: -6px; height: 8px; background: var(--yellow); }
/* a first-time guide lights the tab it talks about until it is opened (D38) */
/* D39: a guide's "!" on the tab it talks about (until the tab is opened) and an outline on the button to press */
.tab .mark { position: absolute; top: -8px; left: -4px; min-width: 20px; height: 20px; padding: 0 4px; border-radius: 10px; background: var(--yellow); border: 3px solid var(--ink); font: 400 13px/14px var(--fh); color: var(--ink); text-align: center; pointer-events: none; animation: dotPop 1.6s ease-in-out infinite; }
.guide-target { outline: 3px solid var(--yellow); outline-offset: 2px; animation: guidePulse 1.2s ease-in-out infinite; }
@keyframes guidePulse { 50% { outline-color: var(--ink); } }
.tab .dot { position: absolute; top: -7px; right: -4px; width: 16px; height: 16px; border-radius: 50%; background: var(--red); border: 3px solid var(--ink); animation: dotPop 1.6s ease-in-out infinite; }
@keyframes dotPop { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.18); } }
.panel { flex: 1; overflow-y: auto; padding: 16px 16px 20px; min-height: 0; background: var(--cream); border: 4px solid var(--ink); border-top: 6px solid var(--yellow); outline: 4px solid var(--ink); outline-offset: -4px; border-radius: 22px; box-shadow: 0 7px 0 var(--ink); position: relative; }
.panel-title { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.panel-title h2 { font-size: 30px; color: var(--yellow); text-shadow: var(--ol); }
.panel-title .muted { font-weight: 700; font-size: 13px; }
.card { background: #fff; border: 3.5px solid var(--ink); border-radius: 18px; padding: 14px; margin-bottom: 14px; box-shadow: var(--hard); }
.card h3 { font-size: 20px; margin-bottom: 6px; display: flex; align-items: center; gap: 6px; }
.card h3 svg { width: 22px; height: 22px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 9px; border-radius: 9px; font-size: 12px; font-weight: 700; background: #f1ead6; border: 2.5px solid var(--ink); white-space: nowrap; color: var(--ink); }
.chip .eicon, .chip svg { width: 14px; height: 14px; }
.chip.good { background: #c9f7cf; }
.chip.bad { background: #ffd0d4; }
.chip.gold { background: #fff0a8; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 18px 10px; border-radius: 14px; border: 3.5px solid var(--ink); cursor: pointer; font-family: var(--fh); font-weight: 400; font-size: 18px; color: #fff; text-shadow: var(--ols); background: var(--sky); box-shadow: inset 0 -5px 0 var(--sky2), inset 0 3px 0 rgba(255, 255, 255, .5), 0 4px 0 var(--ink); transition: transform .06s, filter .15s; letter-spacing: .3px; }
.btn:hover { filter: brightness(1.07); }
.btn:active { transform: translateY(3px); box-shadow: inset 0 -2px 0 var(--sky2), inset 0 2px 0 rgba(255, 255, 255, .4), 0 1px 0 var(--ink); }
.btn.pink { background: var(--yellow); box-shadow: inset 0 -5px 0 var(--yellow2), inset 0 3px 0 rgba(255, 255, 255, .6), 0 4px 0 var(--ink); }
.btn.pink:active { box-shadow: inset 0 -2px 0 var(--yellow2), 0 1px 0 var(--ink); }
.btn.gold { background: var(--orange); box-shadow: inset 0 -5px 0 var(--orange2), inset 0 3px 0 rgba(255, 255, 255, .45), 0 4px 0 var(--ink); }
.btn.gold:active { box-shadow: inset 0 -2px 0 var(--orange2), 0 1px 0 var(--ink); }
.btn.green { background: var(--green); box-shadow: inset 0 -5px 0 var(--green2), inset 0 3px 0 rgba(255, 255, 255, .45), 0 4px 0 var(--ink); }
.btn.green:active { box-shadow: inset 0 -2px 0 var(--green2), 0 1px 0 var(--ink); }
.btn.red { background: var(--red); box-shadow: inset 0 -5px 0 var(--red2), inset 0 3px 0 rgba(255, 255, 255, .4), 0 4px 0 var(--ink); }
.btn.red:active { box-shadow: inset 0 -2px 0 var(--red2), 0 1px 0 var(--ink); }
.btn.ghost { background: var(--paper); color: var(--ink); text-shadow: none; box-shadow: inset 0 -4px 0 var(--cream2), 0 4px 0 var(--ink); }
.btn.ghost:active { box-shadow: inset 0 -2px 0 var(--cream2), 0 1px 0 var(--ink); }
.btn.small { padding: 4px 11px 7px; font-size: 15px; border-radius: 11px; border-width: 3px; }
.btn.small.tiny { padding: 3px 9px 4px; font-size: 12px; min-height: 26px; }
/* touch: no double-tap zoom delay on things that are tapped quickly */
button, [role="button"], .btn, .tab, .up, #partner { touch-action: manipulation; }
.btn.big { padding: 9px 24px 12px; font-size: 22px; }
.btn[disabled], .btn.disabled { filter: grayscale(.85) brightness(.92); opacity: .7; cursor: not-allowed; transform: none !important; }
.btn svg { width: 20px; height: 20px; filter: drop-shadow(0 2px 0 var(--ink)); }
.btn .gem-cost svg { width: 15px; height: 15px; }

/* progress bars */
.bar-wrap { height: 14px; border-radius: 8px; background: #e9dcbc; overflow: hidden; border: 2.5px solid var(--ink); position: relative; }
.bar-fill { height: 100%; background: var(--sky); box-shadow: inset 0 3px 0 rgba(255, 255, 255, .45); transition: width .15s linear; }

/* ---------- right column (store) ---------- */
#right { display: flex; flex-direction: column; background: var(--cream); border: 4px solid var(--ink); border-radius: 22px; box-shadow: 0 7px 0 var(--ink); overflow: hidden; }
.store-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; padding: 10px 12px 8px; gap: 8px; } /* wraps: Max was out of reach at 320-375 px */
.store-head h2 { font-size: 26px; color: var(--sky); text-shadow: var(--ol); }
#up-count { font-weight: 700; font-size: 12px; }
.upgrades { display: flex; flex-wrap: wrap; gap: 9px; padding: 6px 14px 14px; max-height: 188px; overflow-y: auto; min-height: 66px; align-content: flex-start; border-bottom: 3px dashed rgba(27, 21, 52, .18); }
.upgrades .empty { color: var(--muted); font-size: 12px; font-weight: 600; padding: 8px 2px; }
.up { width: 52px; height: 52px; border-radius: 12px; border: 3px solid var(--ink); background: #fff; cursor: pointer; padding: 4px; position: relative; display: grid; place-items: center; box-shadow: 0 4px 0 var(--ink); transition: transform .08s; }
.up:hover { transform: translateY(-2px); }
.up:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.up.can { background: #fff2b0; box-shadow: 0 4px 0 var(--ink), 0 0 0 3px var(--yellow); }
.up.evo.can { background: #c6f1ff; box-shadow: 0 4px 0 var(--ink), 0 0 0 3px #59d0ff; }
.up.cant { filter: saturate(.35); opacity: .72; }
.up img, .up svg { width: 100%; height: 100%; display: block; }
.up .tier { position: absolute; right: -8px; bottom: -8px; font-size: 11px; background: var(--ink); color: #fff; font-family: var(--fh); border-radius: 7px; padding: 0 5px; line-height: 17px; }
.up .pair { position: relative; width: 100%; height: 100%; }
.up .pair img { position: absolute; width: 70%; height: 70%; }
.up .pair img:first-child { left: 0; top: 0; }
.up .pair img:last-child { right: 0; bottom: 0; }
.buy-mode { display: flex; gap: 2px; background: var(--ink); border-radius: 10px; padding: 3px; }
.buy-mode button { border: 0; background: none; padding: 4px 8px; min-height: 26px; min-width: 26px; border-radius: 7px; cursor: pointer; font-family: var(--fh); font-size: 13px; color: #c9c3e6; }
.buy-mode button.on { background: var(--yellow); color: var(--ink); }
.buy-mode button.sell.on { background: var(--red); color: #fff; }
.buy-mode .sep { width: 2px; background: #4a4370; margin: 2px 2px; }
.store { flex: 1; overflow-y: auto; padding: 6px 12px 14px; display: flex; flex-direction: column; gap: 9px; }
.sp-row { position: relative; display: grid; grid-template-columns: 58px 1fr auto; align-items: center; gap: 10px; padding: 5px 12px 5px 5px; border-radius: 14px; cursor: pointer; border: 3px solid var(--ink); background: #fff; box-shadow: 0 4px 0 var(--ink); transition: transform .08s; flex: none; }
.sp-row:hover { transform: translateY(-2px); }
.sp-row:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.sp-row > img { width: 58px; height: 58px; display: block; background: var(--el); border: 3px solid var(--ink); border-radius: 12px; padding: 2px; box-shadow: inset 0 -5px 0 rgba(0, 0, 0, .15); }
.sp-name { font-family: var(--fh); font-size: 18px; line-height: 1.1; display: flex; align-items: center; gap: 4px; }
.sp-name .eicon { width: 14px; height: 14px; }
.sp-cost { font-size: 13px; font-weight: 700; display: inline-flex; align-items: center; gap: 3px; margin-top: 2px; background: #dff7e2; border: 2px solid var(--ink); border-radius: 8px; padding: 0 7px; width: max-content; max-width: 100%; }
.sp-cost svg { width: 14px; height: 14px; }
.sp-cost .muted { color: var(--muted); }
.sp-owned { font-family: var(--fh); font-size: 30px; color: #fff; text-shadow: var(--ol); min-width: 30px; text-align: right; }
.sp-row.cant { background: #efe7d6; }
.sp-row.cant .sp-cost { background: #ffe0e3; color: var(--red2); }
.sp-row.locked { cursor: default; background: #cfc6b4; }
.sp-row.locked:hover { transform: none; }
.sp-row.locked > img { filter: brightness(0) opacity(.5); background: #8f8778; }
.sp-row.locked .sp-name { color: #6a6152; }
.sp-row.locked .sp-cost { background: #e9e2d2; color: #6a6152; }
.sp-row.sellmode { background: #ffe9eb; }
.sp-row.sellmode .sp-cost { background: #fff0a8; }
.sp-row.pulse { animation: rowPulse .3s ease; }
@keyframes rowPulse { 40% { transform: scale(1.03); } }

/* ---------- tooltip ---------- */
.tooltip { position: fixed; z-index: 100; max-width: 330px; min-width: 200px; background: var(--paper); color: var(--ink); border: 3px solid var(--ink); border-radius: 14px; padding: 10px 12px; box-shadow: 0 5px 0 var(--ink); pointer-events: none; font-size: 13px; line-height: 1.4; }
.tt-head { display: flex; gap: 10px; align-items: center; margin-bottom: 6px; }
.tt-head img, .tt-head .tt-ico { width: 46px; height: 46px; flex: none; }
.tt-head .tt-ico svg { width: 100%; height: 100%; }
.tt-head .up { box-shadow: none; border: 0; background: none; }
.tt-title { font-family: var(--fh); font-size: 18px; line-height: 1.15; }
.tt-sub { font-size: 12px; color: var(--muted); font-weight: 600; }
.tt-cost { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; color: var(--blue-text); }
.tt-cost svg { width: 14px; height: 14px; }
.tt-cost.cant { color: var(--bad); }
.tt-desc { margin: 4px 0; font-weight: 500; }
.tt-desc.good, .tt-desc .good { color: var(--good); font-weight: 700; }
.tt-flavor { font-style: italic; color: var(--muted); font-size: 12px; margin-top: 6px; }
.tt-line { border-top: 2px dashed rgba(27, 21, 52, .2); margin: 6px 0; }
.tt-stat { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; font-weight: 500; }
.tt-stat span:last-child { font-weight: 700; }
.tooltip .rec img { width: 34px; height: 34px; }

/* ---------- toasts ---------- */
.file-row { align-items: center; gap: 10px; margin-bottom: 8px; }
.file-pick { position: relative; overflow: hidden; cursor: pointer; }
.file-pick input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; } /* the real picker, invisible */
.file-pick:focus-within { outline: 3px solid var(--ink); outline-offset: 3px; }
.file-name { font-size: 12px; font-weight: 700; overflow-wrap: anywhere; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; } /* read aloud, not shown (top-bar units) */
/* bottom centre, not over the den column: bottom-left notices covered the partner and the "Defend!" button (audit) */
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: 16px; z-index: 90; display: flex; flex-direction: column-reverse; gap: 10px; pointer-events: none; width: max-content; max-width: min(340px, calc(100vw - 24px)); }
@media (max-width: 1000px) { .toasts { top: 8px; bottom: auto; flex-direction: column; } } /* one column: the partner is at the bottom of the view */
.toast { display: flex; gap: 10px; align-items: center; padding: 8px 14px 8px 8px; border-radius: 14px; background: #fff; border: 3px solid var(--ink); border-left-width: 9px; border-left-color: var(--sky); box-shadow: 0 4px 0 var(--ink); animation: toastIn .35s cubic-bezier(.2, 1.4, .4, 1); pointer-events: auto; cursor: pointer; }
.toast.out { animation: toastOut .3s ease forwards; }
.toast.t-guide { border-left-color: var(--yellow); }
.toast .t-ico { width: 40px; height: 40px; flex: none; display: grid; place-items: center; }
.toast .t-ico svg, .toast .t-ico img { width: 100%; height: 100%; }
.toast .t-title { font-family: var(--fh); font-size: 16px; line-height: 1.2; }
.toast .t-text { font-size: 12px; color: var(--muted); font-weight: 600; }
.toast .t-text .gold { color: var(--gold-text); }
.toast.t-ach { border-left-color: var(--yellow); }
.toast.t-warn { border-left-color: var(--red); }
.toast.t-evo { border-left-color: var(--green); }
.pause-overlay { position: fixed; inset: 0; z-index: 150; background: rgba(15, 35, 90, .75); display: grid; place-items: center; padding: 20px; animation: fadeIn .2s ease; }
.selftest-banner { position: fixed; left: 0; right: 0; top: 0; z-index: 200; padding: 6px 12px; background: var(--red); color: #fff; border-bottom: 3px solid var(--ink); font-weight: 800; font-size: 13px; text-align: center; pointer-events: none; }
@keyframes toastIn { from { transform: translateX(-120%); } to { transform: none; } }
@keyframes toastOut { to { transform: translateX(-120%); opacity: 0; } }

/* ---------- modal ---------- */
.modal-overlay { position: fixed; inset: 0; z-index: 80; background: rgba(15, 35, 90, .6); display: grid; place-items: center; padding: 20px; animation: fadeIn .2s ease; }
.modal { width: min(560px, 100%); max-height: 90vh; overflow-y: auto; background: var(--cream); color: var(--ink); border: 5px solid var(--ink); border-radius: 26px; padding: 22px; box-shadow: 0 10px 0 var(--ink); animation: popIn .3s cubic-bezier(.2, 1.4, .4, 1); position: relative; }
.modal.wide { width: min(820px, 100%); }
.modal h2 { font-size: 34px; text-align: center; margin-bottom: 6px; color: var(--yellow); text-shadow: var(--ol); }
.modal:has(> .modal-close) h2 { padding: 0 30px; } /* a long title ran under the close button on phones (D27 check) */
@media (max-width: 420px) { .modal h2 { font-size: 28px; } }
.modal .sub { text-align: center; color: var(--muted); font-weight: 700; margin-bottom: 14px; }
.modal p { line-height: 1.5; }
.modal-actions { display: flex; gap: 12px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
/* short screens: a long dialog keeps its buttons in view (audit: "Begin" needed 218 px of scrolling at 320x640) */
@media (max-height: 760px) {
  .modal-actions { position: sticky; bottom: -22px; z-index: 2; background: var(--cream); padding: 10px 0 14px; margin-bottom: -14px; gap: 8px; }
  .modal-actions .btn.big { font-size: 18px; padding: 8px 16px; } /* compact, so the sticky bar leaves room for the content */
}
.modal-close { position: absolute; top: 12px; right: 12px; width: 36px; height: 36px; border-radius: 12px; border: 3px solid var(--ink); background: var(--red); color: #fff; cursor: pointer; font-family: var(--fh); font-size: 22px; line-height: 1; text-shadow: var(--ols); box-shadow: inset 0 -4px 0 var(--red2), 0 3px 0 var(--ink); padding: 0 0 3px; }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes popIn { from { transform: scale(.85); opacity: 0; } }
.starter-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.starter { background: #fff; border: 4px solid var(--ink); border-radius: 20px; padding: 10px; cursor: pointer; text-align: center; box-shadow: 0 6px 0 var(--ink); transition: transform .12s, background .15s; }
.starter:hover { transform: translateY(-4px); }
.starter.sel { background: #fff2b0; transform: translateY(-6px); box-shadow: 0 10px 0 var(--ink), 0 0 0 4px var(--yellow); }
.starter .mon { width: 100%; height: auto; aspect-ratio: 1; }
.starter h3 { font-size: 22px; }
.starter p { font-size: 12px; color: var(--muted); font-weight: 700; margin: 6px 0 0; }

/* ---------- fx ---------- */
.fx-layer, .shiny-layer { position: fixed; inset: 0; pointer-events: none; z-index: 60; overflow: hidden; }
.shiny-layer { z-index: 55; }
.float-text { position: absolute; font-family: var(--fh); font-size: 24px; color: #fff; text-shadow: var(--ols); animation: floatUp 1.1s ease-out forwards; white-space: nowrap; transform: translate(-50%, -50%); }
.float-text.crit { color: var(--yellow); font-size: 32px; text-shadow: var(--ol); }
.float-text.dmg { color: #fff; font-size: 22px; }
.float-text.super { color: #8dffb0; }
.float-text.weak { color: var(--yellow); }
.float-text.resist { color: #cfc8e0; font-size: 18px; }
.float-text.big { font-size: 40px; color: var(--yellow); text-shadow: var(--ol); }
.float-text.gem { color: #ff9fd0; }
@keyframes floatUp { 0% { opacity: 0; transform: translate(-50%, -20%) scale(.7); } 15% { opacity: 1; transform: translate(-50%, -60%) scale(1.15); } 100% { opacity: 0; transform: translate(-50%, -260%) scale(1); } }
.particle { position: absolute; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--ink); animation: particle .8s ease-out forwards; }
@keyframes particle { 0% { transform: translate(-50%, -50%) scale(1); opacity: 1; } 100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(.2); opacity: 0; } }
.ring-fx { position: absolute; width: 20px; height: 20px; border-radius: 50%; border: 4px solid #fff; transform: translate(-50%, -50%); animation: ringFx .5s ease-out forwards; }
@keyframes ringFx { to { width: 130px; height: 130px; opacity: 0; border-width: 1px; } }
.big-announce { position: absolute; left: 50%; top: 32%; transform: translate(-50%, -50%); font-family: var(--fh); font-size: 54px; color: var(--yellow); text-shadow: 3px 3px 0 var(--ink), -3px 3px 0 var(--ink), 3px -3px 0 var(--ink), -3px -3px 0 var(--ink), 0 3px 0 var(--ink), 0 -3px 0 var(--ink), 3px 0 0 var(--ink), -3px 0 0 var(--ink), 0 7px 0 var(--ink); animation: announce 2.2s ease forwards; white-space: nowrap; text-align: center; }
.big-announce small { display: block; font-size: 22px; color: #fff; text-shadow: var(--ols); }
@keyframes announce { 0% { opacity: 0; transform: translate(-50%, -50%) scale(.4) rotate(-6deg); } 12% { opacity: 1; transform: translate(-50%, -50%) scale(1.1) rotate(-3deg); } 22% { transform: translate(-50%, -50%) scale(1) rotate(-3deg); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -70%) rotate(-3deg); } }

/* shiny monster */
.shiny { position: absolute; width: 104px; height: 104px; pointer-events: auto; cursor: pointer; border: 0; background: none; padding: 0; animation: shinyIn .6s cubic-bezier(.2, 1.5, .4, 1); }
.shiny .sh-inner { width: 100%; height: 100%; animation: shinyDrift 4s ease-in-out infinite; position: relative; }
.shiny .sh-rays { position: absolute; inset: -30%; background: conic-gradient(from 0deg, rgba(255, 230, 120, 0), rgba(255, 230, 120, .6), rgba(255, 230, 120, 0) 12%, rgba(255, 230, 120, 0) 25%, rgba(255, 230, 120, .6) 37%, rgba(255, 230, 120, 0) 50%, rgba(255, 230, 120, 0) 62%, rgba(255, 230, 120, .6) 75%, rgba(255, 230, 120, 0) 87%); border-radius: 50%; animation: spin 6s linear infinite; mask: radial-gradient(circle, #000 20%, transparent 68%); -webkit-mask: radial-gradient(circle, #000 20%, transparent 68%); }
.shiny img { position: relative; width: 100%; height: 100%; }
.shiny.fading { animation: shinyOut .8s ease forwards; }
@keyframes shinyIn { from { transform: scale(0) rotate(-30deg); opacity: 0; } }
@keyframes shinyOut { to { transform: scale(0) rotate(30deg); opacity: 0; } }
@keyframes shinyDrift { 0%, 100% { transform: translate(0, 0) rotate(-4deg); } 25% { transform: translate(10px, -14px) rotate(3deg); } 50% { transform: translate(-6px, -22px) rotate(6deg); } 75% { transform: translate(-12px, -6px) rotate(-2deg); } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- den tab ---------- */
.den-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat-tile { background: #fff; border: 3px solid var(--ink); border-radius: 14px; padding: 8px 12px; box-shadow: 0 4px 0 var(--ink); }
.stat-tile .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; font-weight: 700; }
.stat-tile .v { font-family: var(--fh); font-size: 22px; }
.den-row { position: relative; border-radius: 18px; overflow: hidden; margin-bottom: 14px; border: 3.5px solid var(--ink); background: #fff; box-shadow: var(--hard); }
.den-head { position: relative; display: flex; align-items: center; gap: 8px; padding: 6px 12px; background: var(--el); border-bottom: 3px solid var(--ink); }
.den-head .eicon { filter: drop-shadow(0 1px 0 var(--ink)); }
.den-head h3 { font-size: 19px; color: #fff; text-shadow: var(--ols); }
.den-head .muted { font-size: 13px; font-weight: 700; color: var(--ink); }
.den-head .prod { background: #fff; border: 2.5px solid var(--ink); border-radius: 8px; padding: 0 8px; }
.yard { position: relative; height: 98px; background: #eef9ff; background: color-mix(in srgb, var(--el) 18%, #fff); }
.yard .ground { position: absolute; left: 0; right: 0; bottom: 0; height: 22px; background: color-mix(in srgb, var(--el) 30%, #fff); border-top: 3px dashed rgba(27, 21, 52, .12); }
.mini { position: absolute; bottom: 6px; width: 62px; height: 62px; cursor: pointer; pointer-events: auto; }
.mini img { width: 100%; height: 100%; display: block; animation: hop 2.4s ease-in-out infinite; transform-origin: 50% 100%; }
.mini.flip img { transform: scaleX(-1); animation-name: hopFlip; }
.mini.waddle img { animation-name: waddle; }
.mini.flip.waddle img { animation-name: waddleFlip; }
@keyframes hop { 0%, 60%, 100% { transform: translateY(0) scale(1, 1); } 70% { transform: translateY(0) scale(1.06, .92); } 80% { transform: translateY(-14px) scale(.96, 1.05); } 90% { transform: translateY(0) scale(1.05, .95); } }
@keyframes hopFlip { 0%, 60%, 100% { transform: scaleX(-1) translateY(0); } 70% { transform: scaleX(-1.06) scaleY(.92); } 80% { transform: scaleX(-.96) translateY(-14px) scaleY(1.05); } 90% { transform: scaleX(-1.05) scaleY(.95); } }
@keyframes waddle { 0%, 100% { transform: rotate(-5deg); } 50% { transform: rotate(5deg); } }
@keyframes waddleFlip { 0%, 100% { transform: scaleX(-1) rotate(-5deg); } 50% { transform: scaleX(-1) rotate(5deg); } }
.heart-fx { position: absolute; width: 24px; height: 24px; animation: floatUp 1s ease-out forwards; transform: translate(-50%, -50%); }
.empty-state { text-align: center; padding: 26px 20px; color: var(--muted); font-weight: 600; }
.empty-state h3 { color: var(--ink); font-size: 22px; }
.empty-state .mon { width: 150px; height: 150px; }

/* ---------- battle tab ---------- */
.regions { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; margin-bottom: 14px; }
.region { border-radius: 11px; padding: 5px 7px; background: #fff; border: 3px solid var(--ink); box-shadow: 0 3px 0 var(--ink); font-size: 11px; position: relative; overflow: hidden; }
.region::before { content: ''; position: absolute; left: 0; right: 0; top: 0; height: 5px; background: var(--el); }
.region > * { position: relative; }
.region .rn { font-family: var(--fh); font-size: 12px; display: flex; align-items: center; gap: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.region .pips { display: flex; gap: 4px; margin-top: 4px; }
.region .pip { width: 13px; height: 13px; border-radius: 50%; background: #e7dcc0; border: 2px solid var(--ink); }
.region .pip.done { background: var(--green); }
.region .pip.next { background: var(--yellow); animation: dotPop 1.4s infinite; }
.region .pip.lord { border-radius: 3px; transform: rotate(45deg) scale(.86); }
.region .pip.lord.next { animation: none; }
.region.locked { background: #d9d2c2; filter: saturate(.25); opacity: .75; }
.region.current { background: #fff6cf; transform: translateY(-3px); box-shadow: 0 6px 0 var(--ink); }
.boss-card { display: grid; grid-template-columns: 200px 1fr; gap: 16px; align-items: center; }
.boss-portrait { position: relative; border-radius: 16px; overflow: hidden; aspect-ratio: 1; background: #120d24; border: 3.5px solid var(--ink); }
.boss-portrait .scene { position: absolute; inset: 0; width: 100%; height: 100%; }
.boss-portrait .mon { position: relative; width: 100%; height: 100%; }
.boss-name { font-family: var(--fh); font-size: 36px; line-height: 1.05; color: var(--orange); text-shadow: var(--ol); }
.boss-title { color: var(--muted); font-weight: 700; margin: 2px 0 8px; }
.boss-title .gold { color: var(--red2); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 14px; font-size: 13px; margin: 10px 0; }
.kv .k { color: var(--muted); font-weight: 600; }
.kv .v { font-family: var(--fh); font-size: 15px; display: inline-flex; align-items: center; gap: 4px; }
.mech-list { display: flex; flex-wrap: wrap; gap: 5px; margin: 8px 0 4px; }
.mech { font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 8px; background: var(--ink); color: #fff; cursor: help; }
.eta-good { color: var(--good); }
.eta-ok { color: var(--gold-text); }
.eta-bad { color: var(--bad); }
.rec { display: flex; gap: 5px; flex-wrap: wrap; align-items: center; }
.rec img { width: 38px; height: 38px; background: #b9e4ff; border: 2.5px solid var(--ink); border-radius: 50%; }
.side-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.side-cards .card p { line-height: 1.45; font-weight: 500; }
.wave-card { background: #ffe1e3; background-image: repeating-linear-gradient(-45deg, rgba(255, 77, 94, .12) 0 14px, transparent 14px 28px); }
.wave-card h3 { color: #fff; text-shadow: var(--ols); }
.rift-card { background: #ece2ff; background-image: radial-gradient(circle at 20% 30%, rgba(138, 92, 255, .2) 2px, transparent 3px), radial-gradient(circle at 70% 60%, rgba(138, 92, 255, .2) 2px, transparent 3px); background-size: 40px 40px; }
.mini-portrait { width: 84px; height: 84px; flex: none; }
.help-list { margin: 6px 0 0; padding-left: 20px; color: var(--ink); font-size: 13px; line-height: 1.55; font-weight: 500; }

/* arena */
.arena { position: relative; height: min(520px, 62vh); min-height: 390px; border-radius: 20px; overflow: hidden; border: 4px solid var(--ink); box-shadow: var(--hard); background: #0d0920; }
.arena .scene { position: absolute; inset: 0; width: 100%; height: 100%; }
.arena-shade { position: absolute; inset: 0; background: linear-gradient(180deg, rgba(27, 21, 52, .5), rgba(27, 21, 52, 0) 32%, rgba(27, 21, 52, 0) 75%, rgba(27, 21, 52, .35)); pointer-events: none; }
.arena-top { position: absolute; left: 14px; right: 14px; top: 10px; z-index: 3; }
.arena-name { display: flex; align-items: center; gap: 8px; font-family: var(--fh); font-size: 24px; color: #fff; text-shadow: var(--ol); }
.arena-name .sub { font-size: 14px; color: #ffe9a8; text-shadow: var(--ols); }
.arena-name .eicon { filter: drop-shadow(0 2px 0 var(--ink)); }
.hpbar { position: relative; height: 26px; border-radius: 12px; background: #3a2f5a; border: 3px solid var(--ink); overflow: hidden; margin-top: 6px; box-shadow: 0 3px 0 var(--ink); }
.hpbar .hp { position: absolute; left: 0; top: 0; bottom: 0; background: var(--red); box-shadow: inset 0 4px 0 rgba(255, 255, 255, .35), inset 0 -4px 0 rgba(0, 0, 0, .15); transition: width .12s linear; }
.hpbar .hp-lag { position: absolute; left: 0; top: 0; bottom: 0; background: var(--yellow); transition: width .6s ease .2s; }
.hpbar .shield { position: absolute; right: 0; top: 0; bottom: 0; background: repeating-linear-gradient(45deg, #7ec8ff 0 8px, #4fa8ff 8px 16px); border-left: 3px solid var(--ink); transition: width .12s linear; }
.hpbar .hp-text { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--fh); font-size: 13px; color: #fff; text-shadow: var(--ols); }
.timer-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-family: var(--fh); font-size: 16px; color: #fff; text-shadow: var(--ols); }
.timer-row svg { filter: drop-shadow(0 2px 0 var(--ink)); }
.timer-row .bar-wrap { flex: 1; height: 14px; background: #3a2f5a; }
.timer-row .bar-fill { background: var(--yellow); }
.timer-row.enraged .bar-fill { background: var(--red); }
.arena-top .mech-list { margin-top: 6px; }
.wave-prog { display: flex; gap: 4px; }
.wave-prog span { width: 14px; height: 14px; border-radius: 50%; background: #e7dcc0; border: 2.5px solid var(--ink); }
.wave-prog span.done { background: var(--green); }
.wave-prog span.cur { background: var(--yellow); }
.enemy-wrap { position: absolute; left: 50%; top: 56%; width: min(330px, 62%); aspect-ratio: 1; transform: translate(-50%, -50%); z-index: 2; cursor: crosshair; }
.enemy-wrap.evasive { animation: evade 7s ease-in-out infinite; }
@keyframes evade { 0%, 100% { left: 50%; top: 56%; } 20% { left: 30%; top: 52%; } 40% { left: 68%; top: 60%; } 60% { left: 38%; top: 63%; } 80% { left: 66%; top: 50%; } }
.enemy { width: 100%; height: 100%; transition: filter .1s; }
.enemy .mon { width: 100%; height: 100%; filter: drop-shadow(0 8px 0 rgba(0, 0, 0, .25)); }
.enemy.hit { animation: hitShake .14s; filter: brightness(1.6) saturate(.7); }
.enemy.invuln { filter: brightness(1.5) drop-shadow(0 0 20px #fff); opacity: .75; }
.enemy.entering { animation: enemyIn .5s cubic-bezier(.2, 1.4, .4, 1); }
.enemy.dying { animation: enemyOut .5s ease forwards; }
@keyframes hitShake { 25% { transform: translate(-5px, 2px) scale(1.02, .98); } 50% { transform: translate(5px, -2px); } 75% { transform: translate(-2px, 1px); } }
@keyframes enemyIn { from { transform: scale(.3) translateY(40px); opacity: 0; } }
@keyframes enemyOut { to { transform: scale(.2) rotate(25deg); opacity: 0; filter: brightness(3); } }
.shield-bubble { position: absolute; inset: 4%; border-radius: 50%; border: 4px solid var(--ink); background: radial-gradient(circle, rgba(126, 200, 255, .08) 55%, rgba(126, 200, 255, .45)); box-shadow: inset 0 0 0 4px rgba(255, 255, 255, .6); pointer-events: none; animation: bubble 1.4s ease-in-out infinite; }
@keyframes bubble { 50% { transform: scale(1.03); } }
.weak-spot { position: absolute; width: 60px; height: 60px; transform: translate(-50%, -50%); z-index: 4; cursor: pointer; border: 0; padding: 0; background: none; animation: weakIn .25s ease; }
.weak-spot svg { width: 100%; height: 100%; animation: weakPulse .6s ease-in-out infinite alternate; filter: drop-shadow(0 3px 0 var(--ink)); }
@keyframes weakIn { from { transform: translate(-50%, -50%) scale(0); } }
@keyframes weakPulse { from { transform: scale(.9) rotate(0); } to { transform: scale(1.12) rotate(20deg); } }
.minion { position: absolute; width: 76px; height: 76px; transform: translate(-50%, -50%); z-index: 3; cursor: pointer; border: 0; padding: 0; background: none; animation: enemyIn .4s ease; }
.minion img { width: 100%; height: 100%; animation: waddle .8s ease-in-out infinite; }
.minion .mhp { position: absolute; left: 12%; right: 12%; bottom: -2px; height: 9px; border-radius: 5px; background: #3a2f5a; border: 2px solid var(--ink); overflow: hidden; }
.minion .mhp i { display: block; height: 100%; background: var(--red); }
/* overlays let clicks through to the enemy (audit: at 320 px they covered 40% of its clickable box, so weak spots
   there could not be tapped); only the mechanic chips (tooltips) and Retreat take clicks */
.arena-top, .arena-bottom, .dps-readout { pointer-events: none; }
.arena-top .mech, .arena-bottom .btn { pointer-events: auto; }
.party-strip { position: absolute; left: 10px; bottom: 10px; display: flex; gap: 2px; z-index: 3; pointer-events: none; max-width: calc(100% - 150px); overflow: hidden; }
@media (max-width: 640px) { .party-strip .pm { width: 40px; height: 40px; } } /* six members ran 156 px past a 320 px arena */
.party-strip .pm { width: 64px; height: 64px; animation: partyAtk 1.2s ease-in-out infinite; filter: drop-shadow(0 3px 0 rgba(0, 0, 0, .3)); }
.party-strip .pm:nth-child(2) { animation-delay: .2s; }
.party-strip .pm:nth-child(3) { animation-delay: .4s; }
.party-strip .pm:nth-child(4) { animation-delay: .6s; }
.party-strip .pm:nth-child(5) { animation-delay: .8s; }
.party-strip .pm:nth-child(6) { animation-delay: 1s; }
@keyframes partyAtk { 0%, 70%, 100% { transform: translate(0, 0); } 80% { transform: translate(10px, -10px) rotate(8deg); } }
.arena-bottom { position: absolute; right: 12px; bottom: 12px; z-index: 3; text-align: right; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.dps-readout { background: #fff; border: 3px solid var(--ink); box-shadow: 0 3px 0 var(--ink); border-radius: 12px; padding: 5px 10px; font-size: 12px; font-weight: 600; line-height: 1.4; }
.dps-readout b { font-family: var(--fh); font-weight: 400; font-size: 15px; }
.dps-readout .gold { color: var(--gold-text); font-weight: 700; }
.arena-alert { position: absolute; left: 50%; top: 26%; transform: translateX(-50%); font-family: var(--fh); font-size: 30px; color: var(--yellow); z-index: 5; text-shadow: var(--ol); animation: announce 1.6s ease forwards; pointer-events: none; white-space: nowrap; }
.result { position: absolute; inset: 0; z-index: 10; display: grid; place-items: center; background: rgba(15, 35, 90, .55); animation: fadeIn .3s; }
/* a result taller than the arena (a region lord's, short windows) scrolls instead of cutting off Continue; browsers
   without "safe" keep the line above */
.result { place-items: safe center; overflow-y: auto; padding: 6px 0; }
.result-box { text-align: center; padding: 20px 24px; max-width: 440px; background: var(--cream); border: 4px solid var(--ink); border-radius: 22px; box-shadow: 0 8px 0 var(--ink); animation: popIn .35s cubic-bezier(.2, 1.4, .4, 1); }
.result-box h2 { font-size: 50px; line-height: 1.1; text-shadow: var(--ol); }
.result-box.win h2 { color: var(--yellow); }
.result-box.lose h2 { color: var(--red); }
.result-box .muted { font-weight: 700; }
.result-box p { font-size: 13px; }
.reward-list { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 14px 0; }
.reward { display: flex; align-items: center; gap: 6px; background: #fff; border: 3px solid var(--ink); border-radius: 12px; padding: 4px 10px; font-family: var(--fh); font-size: 15px; box-shadow: 0 3px 0 var(--ink); animation: popIn .4s ease backwards; }
.reward svg, .reward img { width: 28px; height: 28px; }
/* a region lord's fall (overnight round, Phase 2, D41): a banner over the title, the freed Mythlings side by side */
.result-box.lord { max-width: 470px; padding-top: 14px; padding-bottom: 16px; }
.result-box.lord h2 { font-size: 44px; }
.result-box.lord .reward-list { margin: 10px 0; }
.lord-ribbon { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; margin: -4px auto 6px; padding: 3px 14px; font-family: var(--fh); font-size: 17px; line-height: 1.15; color: #fff; text-shadow: var(--ols); background: var(--purple); border: 3px solid var(--ink); border-radius: 18px; box-shadow: 0 3px 0 var(--ink); transform: rotate(-2deg); animation: popIn .4s .1s both; text-wrap: balance; }
.lord-ribbon svg { width: 18px; height: 18px; flex: none; filter: drop-shadow(0 1px 0 var(--ink)); }
.unlock-reveal { margin: 4px 0 14px; padding: 8px 8px 10px; background: #fff7dc; border: 3px solid var(--ink); border-radius: 16px; box-shadow: inset 0 -4px 0 rgba(27, 21, 52, .08); }
.ur-head { font-family: var(--fh); font-size: 17px; color: var(--gold-text); margin-bottom: 4px; }
.ur-row { display: flex; justify-content: center; gap: 10px; }
.ur-mon { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; animation: popIn .45s cubic-bezier(.2, 1.4, .4, 1) both; }
.ur-txt { display: flex; flex-direction: column; align-items: center; gap: 1px; }
.ur-mon img { width: 72px; height: 72px; flex: none; filter: drop-shadow(0 4px 0 rgba(27, 21, 52, .2)); }
.ur-mon b { font-family: var(--fh); font-weight: 400; font-size: 18px; line-height: 1.1; }
.ur-el { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 700; color: var(--muted); }
.ur-el svg { width: 14px; height: 14px; }
/* the result overlay is sized by the arena, never by its content: it can be a size container. A lord's result
   compacts to the arena it gets, so Continue stays in view at laptop and landscape-phone heights (D41 review:
   1366x657, 1280x720 and 1024x768 hid it). Without container queries it stays tall and the overlay scrolls. */
.result { container: result / size; grid-template-columns: minmax(0, 1fr); } /* the box may be narrower than its widest word row */
.result-box { min-width: 0; }
@container result (max-width: 400px) {
  .result-box.lord { padding: 12px 10px 14px; }
  .result-box.lord h2 { font-size: 38px; }
  .result-box.lord .reward-list { gap: 6px; margin: 8px 0; }
  .result-box.lord .reward { font-size: 14px; padding: 3px 8px; }
  .lord-ribbon { font-size: 15px; padding: 2px 10px; }
  .ur-mon img { width: 60px; height: 60px; }
  .ur-mon b { font-size: 16px; }
}
@container result (max-height: 540px) {
  .result-box.lord { padding-top: 10px; padding-bottom: 12px; }
  .result-box.lord h2 { font-size: 36px; }
  .result-box.lord .muted { font-size: 13px; }
  .result-box.lord .reward-list { gap: 6px; margin: 6px 0 8px; }
  .result-box.lord .reward { font-size: 13px; padding: 2px 8px; }
  .result-box.lord .reward svg, .result-box.lord .reward img { width: 22px; height: 22px; }
  .lord-ribbon { font-size: 14px; padding: 2px 10px; margin-bottom: 4px; }
  .unlock-reveal { margin-bottom: 8px; padding: 4px 6px 6px; }
  .ur-head { font-size: 14px; margin-bottom: 2px; }
  .ur-mon img { width: 48px; height: 48px; }
  .ur-mon b { font-size: 15px; }
}
@container result (max-height: 420px) {
  .result-box.lord h2 { font-size: 30px; }
  .ur-head { display: none; } /* very short arenas: the pictures and names alone */
  .ur-mon img { width: 36px; height: 36px; }
  .result-box.lord .btn.big { padding-top: 6px; padding-bottom: 8px; }
}
@container result (max-height: 420px) and (max-width: 400px) { .ur-el { display: none; } } /* the smallest phones: names only */
@container result (max-height: 420px) and (min-width: 401px) { /* short and wide (landscape): picture beside name */
  .ur-mon { flex-direction: row; justify-content: center; gap: 6px; }
  .ur-txt { align-items: flex-start; }
}
.screen-shake { animation: screenShake .3s; }
@keyframes screenShake { 20% { transform: translate(-6px, 3px); } 40% { transform: translate(6px, -3px); } 60% { transform: translate(-3px, 2px); } 80% { transform: translate(2px, -1px); } }

/* ---------- hatchery ---------- */
.incubators { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.incubator { background: #fff; border: 3px solid var(--ink); border-radius: 18px; padding: 10px; text-align: center; position: relative; box-shadow: 0 4px 0 var(--ink); }
.incubator.empty { border-style: dashed; background: var(--paper); box-shadow: none; color: var(--muted); font-weight: 700; display: grid; place-items: center; min-height: 196px; }
.incubator.empty svg { opacity: .55; }
.incubator .egg { width: 86px; height: 100px; }
.incubator.ready { background: #fff2b0; box-shadow: 0 4px 0 var(--ink), 0 0 0 4px var(--yellow); }
.incubator.ready .egg-wrap { animation: eggWobble .9s ease-in-out infinite; }
@keyframes eggWobble { 0%, 100% { transform: rotate(0); } 20% { transform: rotate(-9deg); } 40% { transform: rotate(8deg); } 60% { transform: rotate(-5deg); } 80% { transform: rotate(3deg); } }
.egg-wrap { display: inline-block; transform-origin: 50% 90%; }
.incubator .rar { font-family: var(--fh); font-size: 16px; text-shadow: var(--ols); }
.incubator .time { font-size: 12px; color: var(--muted); margin: 3px 0 6px; font-weight: 700; }
.egg-inv { display: flex; flex-wrap: wrap; gap: 8px; }
.egg-chip { display: flex; flex-direction: column; align-items: center; gap: 2px; background: #fff; border: 3px solid var(--ink); border-radius: 12px; padding: 6px; width: 78px; font-family: var(--fh); font-size: 12px; box-shadow: 0 3px 0 var(--ink); }
.egg-chip > span { text-shadow: var(--ols); }
.egg-chip .egg { width: 44px; height: 52px; }
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); gap: 10px; }
.shop-item { display: flex; gap: 10px; align-items: center; background: #fff; border: 3px solid var(--ink); border-radius: 14px; padding: 8px 10px; box-shadow: 0 3px 0 var(--ink); }
.shop-item .si-ico { width: 40px; height: 40px; flex: none; }
.shop-item .si-ico svg { width: 100%; height: 100%; }
.shop-item .si-name { font-family: var(--fh); font-size: 15px; line-height: 1.1; }
.shop-item .si-desc { font-size: 11px; color: var(--muted); line-height: 1.25; font-weight: 500; }
/* the price goes under the text at every width: beside it, descriptions were squeezed to ~50-86 px (UI-15 on phones, then
   the audit at 768-1920 px); prices stay inside the card */
.shop-item { flex-wrap: wrap; }
.shop-item > .grow { flex: 1 1 calc(100% - 50px); min-width: 0; }
.shop-item > .btn, .shop-item > .chip { margin-left: 50px; }
.gem-cost { display: inline-flex; align-items: center; gap: 3px; }
.gem-cost svg { width: 14px; height: 14px; }
.hatch-stage { position: relative; height: 260px; display: grid; place-items: center; }
.hatch-stage .egg { width: 150px; height: 175px; }
.hatch-stage .egg-wrap.shake { animation: eggWobble .5s ease-in-out infinite; }
.hatch-stage .mon { width: 240px; height: 240px; animation: revealPop .6s cubic-bezier(.2, 1.5, .4, 1); }
.hatch-flash { position: absolute; inset: 0; background: radial-gradient(circle, #fff, rgba(255, 255, 255, 0) 60%); animation: flash .7s ease forwards; pointer-events: none; }@keyframes flash { from { opacity: 1; transform: scale(.4); } to { opacity: 0; transform: scale(1.6); } }
@keyframes revealPop { from { transform: scale(.2); opacity: 0; } }
.badge-new { display: inline-block; background: var(--yellow); color: #fff; font-family: var(--fh); padding: 1px 12px 3px; border: 3px solid var(--ink); border-radius: 10px; font-size: 15px; text-shadow: var(--ols); box-shadow: 0 3px 0 var(--ink); animation: popIn .4s; }

/* ---------- collection ---------- */
.party-bar { display: flex; gap: 10px; flex-wrap: wrap; padding-top: 6px; }
#party-bonus { display: flex; flex-wrap: wrap; gap: 6px; }
#party-bonus .chip { white-space: normal; } /* long bonus texts ran out of the card on phones */
.party-slot { width: 94px; height: 116px; border-radius: 14px; background: #fff; border: 3px solid var(--ink); text-align: center; font-family: var(--fh); font-size: 13px; padding: 4px; cursor: pointer; position: relative; box-shadow: 0 4px 0 var(--ink); transition: transform .1s; }
.party-slot:hover { transform: translateY(-2px); }
.party-slot img { width: 78px; height: 78px; display: block; margin: 0 auto; }
.party-slot.partner { background: #fff2b0; }
.party-slot.partner::after { content: '★ Partner'; position: absolute; top: -10px; left: 50%; transform: translateX(-50%) rotate(-3deg); font-size: 11px; background: var(--red); color: #fff; padding: 0 7px 1px; border: 2.5px solid var(--ink); border-radius: 7px; white-space: nowrap; text-shadow: none; }
.party-slot.empty { border-style: dashed; color: var(--muted); display: grid; place-items: center; cursor: default; background: var(--paper); box-shadow: none; }
.dex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.dex-card { border-radius: 14px; background: #fff; border: 3px solid var(--ink); box-shadow: 0 4px 0 var(--ink), inset 0 7px 0 var(--rc, #ccc); padding: 9px 6px 6px; text-align: center; cursor: pointer; position: relative; transition: transform .12s; }
.dex-card:hover { transform: translateY(-3px); }
.dex-card img { width: 84px; height: 84px; display: block; margin: 0 auto; }
.dex-card.unknown { cursor: default; background: #e9e2d2; box-shadow: 0 4px 0 var(--ink), inset 0 7px 0 #bdb5a3; }
.dex-card.unknown img { filter: brightness(0) opacity(.4); }
.dex-card.unknown:hover { transform: none; }
.dex-card .dn { font-family: var(--fh); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dex-card .dl { font-size: 11px; color: var(--muted); font-weight: 700; }
.dex-card .inparty { position: absolute; top: 10px; right: 5px; width: 20px; height: 20px; }
.lvl-stars { color: var(--orange2); /* 3.4:1, was 2.2:1 (audit) */ letter-spacing: -1px; font-size: 13px; }
.detail { display: grid; grid-template-columns: 220px 1fr; gap: 16px; align-items: center; }
.detail .mon { width: 220px; height: 220px; }
.rarity-tag { font-family: var(--fh); font-size: 13px; padding: 0 10px 1px; border: 2.5px solid var(--ink); border-radius: 8px; color: #fff; text-shadow: var(--ols); }
.codex-row { display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 14px; background: #fff; border: 3px solid var(--ink); box-shadow: 0 3px 0 var(--ink); margin-bottom: 10px; flex-wrap: wrap; }
.codex-row img { width: 70px; height: 70px; }
.codex-row img.locked { filter: brightness(0) opacity(.3); }
.codex-row .arrow { color: var(--ink); font-family: var(--fh); font-size: 20px; }
.codex-row .cx-info { flex: 1; min-width: 170px; }
.codex-row .sp-name { font-size: 17px; }
.subtabs { display: flex; gap: 8px; margin-bottom: 12px; }

/* ---------- constellation ---------- */
.asc-head { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; }
.star-map { position: relative; width: 100%; aspect-ratio: 1000 / 700; border-radius: 20px; overflow: hidden; border: 4px solid var(--ink); box-shadow: var(--hard); background: radial-gradient(ellipse at 50% 45%, #2d4fae, #142456 70%); margin-bottom: 14px; }
.star-map svg { width: 100%; height: 100%; display: block; }
/* Narrow panels (phones, laptops with three columns): keep star labels readable (≥ ~12 px) and let the map scroll
   inside its frame instead of shrinking. Browsers without container queries keep the scaled-down map. */
.panel { container-type: inline-size; }
@container (max-width: 760px) {
  .star-map { aspect-ratio: auto; height: min(62vh, 500px); overflow: auto; overscroll-behavior: contain; }
  .star-map svg { width: 820px; height: 574px; }
}
/* the Battle tab follows the panel's width, not the window's: at 1001-1300 px windows the panel is only 390-530 px,
   so region names were cut to 47 px and the side cards squeezed (audit) */
@container (max-width: 620px) { .regions { grid-template-columns: repeat(3, 1fr); } .side-cards { grid-template-columns: 1fr; } }
@container (max-width: 430px) { .regions { grid-template-columns: repeat(2, 1fr); } }
.star-map .link { stroke: rgba(255, 255, 255, .22); stroke-width: 4; stroke-dasharray: 2 10; stroke-linecap: round; }
.star-map .link.on { stroke: var(--yellow); stroke-width: 6; stroke-dasharray: none; }
.star-map .node { cursor: pointer; }
.star-map .node .core { fill: #6b7fc4; stroke: var(--ink); stroke-width: 3.5; stroke-linejoin: round; transition: fill .2s; }
.star-map .node.avail .core { fill: #9fd8ff; }
.star-map .node.avail.afford .core { fill: #fff; }
.star-map .node.avail.afford .halo { opacity: .9; }
.star-map .node.owned .core { fill: var(--yellow); }
.star-map .node.locked .core { fill: #4a5a90; }
.star-map .node .halo { fill: url(#starHalo); opacity: 0; }
.star-map .node.owned .halo { opacity: .55; }
.star-map .node:hover .core { stroke-width: 5; }
.star-map .node text { fill: #fff; font-size: 15px; font-family: var(--fh); text-anchor: middle; pointer-events: none; paint-order: stroke; stroke: var(--ink); stroke-width: 5px; stroke-linejoin: round; }
.star-map .node.locked text { fill: #b8c2e8; }
.star-map .bgstar { fill: #fff; }

/* ---------- achievements ---------- */
.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 8px; }
.ach { aspect-ratio: 1; border-radius: 12px; display: grid; place-items: center; background: #e9e2d2; border: 3px solid var(--ink); cursor: help; box-shadow: 0 3px 0 var(--ink); }
.ach svg, .ach img { width: 72%; height: 72%; }
.ach.got { background: #fff2b0; }
.ach.no svg, .ach.no img { filter: grayscale(1) opacity(.45); }
.ach.hidden-ach { font-family: var(--fh); font-size: 22px; color: var(--muted); }
.ach-cat { font-family: var(--fh); font-size: 18px; margin: 16px 0 8px; }
.ach-cat .muted { font-family: var(--fb); font-size: 12px; font-weight: 700; }

/* ---------- stats & settings ---------- */
.stats-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.stats-table td { padding: 6px 4px; border-bottom: 2px dashed rgba(27, 21, 52, .14); font-weight: 500; }
.stats-table td:last-child { text-align: right; font-family: var(--fh); font-size: 14px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 2px dashed rgba(27, 21, 52, .14); }
.set-row:last-child { border-bottom: 0; }
.set-row .sl { font-family: var(--fh); font-size: 16px; }
.set-row .sd { font-size: 12px; color: var(--muted); font-weight: 500; }
.toggle { position: relative; width: 54px; height: 30px; border-radius: 10px; background: #d9d0bd; border: 3px solid var(--ink); cursor: pointer; flex: none; transition: background .15s; box-shadow: inset 0 3px 0 rgba(0, 0, 0, .12); }
.toggle::after { content: ''; position: absolute; top: 1px; left: 1px; width: 22px; height: 22px; border-radius: 7px; background: #fff; border: 2.5px solid var(--ink); box-sizing: border-box; transition: transform .15s; }
.toggle.on { background: var(--green); }
.toggle.on::after { transform: translateX(24px); }
select, input[type=text], textarea { background: #fff; color: var(--ink); border: 3px solid var(--ink); border-radius: 10px; padding: 6px 10px; font-family: var(--fb); font-size: 13px; font-weight: 600; user-select: text; -webkit-user-select: text; }
select:focus, input[type=text]:focus, textarea:focus { outline: 3px solid var(--yellow); }
textarea { width: 100%; min-height: 90px; resize: vertical; font-family: Consolas, monospace; font-size: 11px; }
input[type=range] { accent-color: var(--orange); width: 160px; }
.save-flash { font-family: var(--fh); font-size: 16px; color: var(--green); text-shadow: var(--ols); opacity: 0; transition: opacity .3s; }
.save-flash.on { opacity: 1; }
/* keyboard focus: always visible, dark ring that works on every theme colour */
[role="button"]:focus-visible, [role="switch"]:focus-visible, .btn:focus-visible, .tab:focus-visible, .up:focus-visible,
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; box-shadow: 0 0 0 6px #fff; }
.star-map .node:focus { outline: none; }
.star-map .node:focus-visible .core { stroke: #fff; stroke-width: 6; }
.save-flash.bad { color: var(--red); }
.save-warn { height: 38px; padding: 0 12px; border-radius: 12px; border: 3px solid var(--ink); background: var(--red); color: #fff; font-family: var(--fh); font-size: 15px; text-shadow: var(--ols); cursor: pointer; box-shadow: 0 3px 0 var(--ink); }
.save-warn.hidden { display: none; }
.toasts.blocked, .toasts.blocked .toast { pointer-events: none; }

/* ---------- misc ---------- */
.noscript { position: fixed; inset: 0; display: grid; place-items: center; font-size: 20px; }
.kbd { font-family: Consolas, monospace; background: #fff; border: 2px solid var(--ink); border-radius: 5px; padding: 0 5px; font-size: 11px; }

/* reduced motion */
body.reduce-motion *, body.reduce-motion *::before, body.reduce-motion *::after { animation-duration: .001s !important; animation-iteration-count: 1 !important; transition: none !important; }
body.reduce-motion .news-text { animation: none !important; padding-left: 12px; }

/* ---------- responsive ---------- */
@media (max-width: 1240px) {
  #layout { grid-template-columns: minmax(240px, 25%) minmax(380px, 1fr) minmax(280px, 310px); gap: 12px; }
  .boss-card { grid-template-columns: 160px 1fr; }
  .tab .tl { font-size: 12px; }
  .tabs { gap: 3px; padding: 0 6px; }
}
@media (max-width: 1080px) and (min-width: 1001px) {
  .tab .tl { font-size: 11px; } /* three-column layout at its narrowest: keep all tab labels whole */
}
@media (max-width: 1000px) {
  body { overflow: auto; }
  #app { height: auto; min-height: 100vh; }
  #layout { display: flex; flex-direction: column; gap: 16px; }
  #left { height: auto; min-height: 560px; flex: none; } /* grows when long numbers or a wave banner need room (playtest) */
  .left-inner { min-height: 552px; }
  #center { height: 82vh; min-height: 560px; flex: none; }
  #right { height: 740px; flex: none; }
  .side-cards { grid-template-columns: 1fr; }
  /* one column (phones, tablets): ui.js placeColumns puts the store right under the den (Mythlings first, upgrades
     under them) and the tabs after it, in the page order itself (D41). Before, the first Mythling to buy was ~1,670 px
     down at 375 px, below the tabs and the whole panel. Guides and the goal line scroll to the tab they open. */
  #center { scroll-margin-top: 8px; }
  .store-up { border-top: 3px dashed rgba(27, 21, 52, .18); }
  #upgrades { border-bottom: 0; }
}
@media (max-width: 640px) {
  #topbar { gap: 8px; padding: 0 10px; }
  .logo-text { font-size: 26px; }
  /* the logo gives way (ellipsis) so counters, the "Not saved" warning and mute always stay whole (UI-13) */
  .logo { min-width: 46px; flex-shrink: 1; } /* never narrower than the mark: no overlap with the chips */
  .logo-mark { flex: none; }
  .logo-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 2px 3px; }
  .top-res, #btn-mute { flex: none; }
  .boss-card, .detail { grid-template-columns: 1fr; }
  .boss-portrait { max-width: 240px; margin: 0 auto; width: 100%; }
  .detail .mon { margin: 0 auto; }
  .regions { grid-template-columns: repeat(2, 1fr); }
  .starter-grid { grid-template-columns: 1fr; }
  .starter .mon { width: 150px; }
  .news { display: none; }
  .tab .tl { display: none; }
  .tab { padding: 7px 2px 9px; }
  /* phones (playtest): the starter cards side by side with their text, so all three and "Begin" fit on one screen */
  .starter-grid { gap: 10px; }
  .starter { display: grid; grid-template-columns: 84px 1fr; column-gap: 10px; align-items: center; text-align: left; padding: 8px; }
  .starter .mon { width: 84px; grid-row: span 3; }
  .starter h3 { font-size: 20px; }
  .starter p { margin-top: 2px; }
  .starter.sel { transform: none; }
  /* touch: bigger targets; 16 px text in fields, or iOS zooms the page in on focus */
  .buy-mode button { min-height: 36px; min-width: 36px; }
  select, input[type=text], textarea { font-size: 16px; }
  .set-row select { min-width: 0; max-width: 62%; } /* 16 px text made the number-format list 11 px too wide at 320 px */
  .den-head { flex-wrap: wrap; row-gap: 2px; }
}
/* a compact den on phones, upright or on their side: the partner stays a big tap target (~190 px), the empty sky
   above it goes (the column was 560 px, the whole first screen at 375x812) */
@media (max-width: 640px), (max-width: 1000px) and (max-height: 520px) {
  #left { min-height: 400px; }
  .left-inner { min-height: 392px; padding-top: 10px; }
  .essence-line { font-size: 46px; }
  .partner-zone { min-height: 150px; }
  .partner { width: min(210px, 60%); }
}
@media (max-width: 420px) { /* phones: logo + gems + shards + mute were ~413 px, wider than a 375 px screen (UI-13) */
  .logo-text { display: none; } /* the mark alone: an ellipsis of a few px looked broken (review) */
  .top-res { gap: 6px; }
  .res-chip { height: 34px; padding: 0 8px 0 2px; }
  .res-chip .res-num { font-size: 16px; }
  .save-warn { height: 34px; padding: 0 8px; font-size: 13px; }
}
@media (max-width: 400px) { .region .rn { white-space: normal; line-height: 1.1; } } /* whole region names, two lines */
@media (max-width: 420px) { /* playtest at 320-375 px: these ran past their panels */
  .asc-head { grid-template-columns: 1fr; }
  .codex-row { gap: 4px; }
  .codex-row img { width: 56px; height: 56px; }
  .codex-row .arrow { font-size: 16px; }
}
@media (max-width: 374px) { /* smallest phones: the "Not saved" warning becomes a "!" badge (text kept for screen readers, tooltip) */
  .save-warn { font-size: 0; padding: 0 10px; }
  .save-warn::after { content: '!'; font-size: 18px; }
  .res-chip { padding: 0 6px 0 2px; }
  #topbar { gap: 6px; padding: 0 6px; }
}

/* ==========================================================================
   Monster animations (inside generated SVGs)
   ========================================================================== */
.mon { overflow: visible; }
.mon.anim .m-blink { animation: mBlink 4.2s infinite; }
@keyframes mBlink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(.1); } }
.mon.anim .m-flap { animation: mFlap 1.1s ease-in-out infinite alternate; }
@keyframes mFlap { from { transform: rotate(6deg); } to { transform: rotate(-14deg); } }
.mon.anim .m-wag { animation: mWag 1.6s ease-in-out infinite alternate; }
@keyframes mWag { from { transform: rotate(-8deg); } to { transform: rotate(10deg); } }
.mon.anim .m-flick { animation: mFlick .45s ease-in-out infinite alternate; }
@keyframes mFlick { from { transform: scale(1, 1); } to { transform: scale(.9, 1.1); } }
.mon.anim .m-body { transform-box: fill-box; transform-origin: 50% 100%; animation: mBreath 2.4s ease-in-out infinite; }
@keyframes mBreath { 0%, 100% { transform: scale(1, 1); } 50% { transform: scale(1.025, .975); } }
.mon.anim .m-hover { animation: mHover 3s ease-in-out infinite; }
@keyframes mHover { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
.mon.anim .m-shadow { transform-box: fill-box; transform-origin: center; animation: mShadow 3s ease-in-out infinite; }
@keyframes mShadow { 0%, 100% { transform: scale(1); } 50% { transform: scale(.85); } }
.mon.anim .m-aura { transform-box: fill-box; transform-origin: center; animation: mAura 3s ease-in-out infinite; }
@keyframes mAura { 0%, 100% { opacity: .75; transform: scale(1); } 50% { opacity: 1; transform: scale(1.06); } }
.mon .m-rise { animation: mRise 3s linear infinite; }
@keyframes mRise { 0% { transform: translateY(10px); opacity: 0; } 20% { opacity: 1; } 100% { transform: translateY(-50px); opacity: 0; } }
.mon .m-fall { animation: mFall 3s linear infinite; }
@keyframes mFall { 0% { transform: translateY(-30px); opacity: 0; } 20% { opacity: 1; } 100% { transform: translateY(30px); opacity: 0; } }
.mon.anim .m-spin { transform-box: fill-box; transform-origin: center; animation: mSpin 14s linear infinite; }
@keyframes mSpin { to { transform: rotate(360deg); } }
.mon .m-twinkle { transform-box: fill-box; transform-origin: center; animation: mTwinkle 2s ease-in-out infinite; }
@keyframes mTwinkle { 0%, 100% { opacity: 0; transform: scale(.3); } 50% { opacity: 1; transform: scale(1); } }
.egg .m-aura { transform-box: fill-box; transform-origin: center; animation: mAura 2.4s ease-in-out infinite; }

/* ---------- Rift relics (D27) ---------- */
.relic-line { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.relic-chip { cursor: default; }
.relic-pick { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.relic-card { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; background: #fff; border: 3px solid var(--ink); border-radius: 14px; box-shadow: 0 4px 0 var(--ink); padding: 10px; cursor: pointer; font: inherit; color: var(--ink); transition: transform .12s; }
.relic-card:hover, .relic-card:focus-visible { transform: translateY(-3px); background: #fff7d6; }
.relic-card .rc-ico svg { width: 40px; height: 40px; }
.relic-card .rc-name { font-family: var(--fh); font-size: 17px; }
.relic-card .rc-desc { font-size: 12px; color: var(--muted); font-weight: 600; line-height: 1.3; }
.relic-card .rc-have { font-size: 11px; font-weight: 700; color: var(--blue-text); }
.goal-list { display: grid; gap: 8px; }
.goal { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; align-items: center; }
.goal .gname { font-family: var(--fh); font-size: 15px; }
.goal .gdesc { grid-column: 1 / -1; font-size: 12px; }
.goal .bar-wrap { grid-column: 1; }
.goal .gnum { font-size: 12px; font-weight: 700; white-space: nowrap; }

/* Eclipse and autopilot (D29) */
.btn.moon { background: #4b3f9e; color: #fff; box-shadow: inset 0 -5px 0 #2f2770, inset 0 3px 0 rgba(255, 255, 255, .3), 0 4px 0 var(--ink); }
.btn.moon:active { box-shadow: inset 0 -2px 0 #2f2770, 0 1px 0 var(--ink); }
.chip.moon { background: #dcd6ff; }
.boon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr)); gap: 10px; }
.boon { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; background: #fff; border: 3px solid var(--ink); border-radius: 14px; padding: 8px 10px; box-shadow: 0 3px 0 var(--ink); }
.boon.owned { background: #efeaff; }
.boon .b-ico { width: 40px; height: 40px; flex: none; }
.boon .b-ico svg { width: 100%; height: 100%; }
.boon > .grow { flex: 1 1 calc(100% - 50px); min-width: 0; }
.boon > .btn, .boon > .chip { margin-left: 50px; }
.boon .b-name { font-family: var(--fh); font-size: 15px; line-height: 1.1; }
.boon .b-desc { font-size: 12px; color: var(--muted); line-height: 1.3; font-weight: 500; }
.boon .b-req { font-size: 11px; font-weight: 700; color: var(--bad, #b42318); }
.oath-list, .auto-toggles, .keep-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.keep-list .btn { flex: 1 1 220px; max-width: 340px; min-height: 40px; text-align: left; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; white-space: normal; }
.keep-list .kp-name { font-size: 14px; }
.keep-list .kp-desc { font-family: var(--fb, inherit); font-size: 11px; font-weight: 600; text-shadow: none; opacity: .85; line-height: 1.25; }
.auto-card .auto-log { font-size: 12px; color: var(--muted); font-weight: 600; margin-top: 4px; }