:root {
  /* Plan: one pixel-art world, dark only. Brickwork behind everything, the map as a slab of rough stone with painted rooms,
     panels like wooden notice boards with a gold edge. Map on the left, the big room view and the notes on the right. */
  color-scheme: dark;
  --bg: #12152a;
  --panel: #1b1f38;
  --panel-edge: #434b78;
  --ink: #ece6d3;
  --ink-soft: #a9a8bd;
  --gold: #ffcd75;
  --red: #ff6a55;
  --green: #6fd08c;
  --line: #333a5e;
  --stone: #8f97a8;      /* corridor floor */
  --stone-edge: #262b3d;
  --spd: 1;
  --display: 'Pixelify Sans', 'Courier New', monospace;
  --body: 'Alegreya Sans', 'Trebuchet MS', 'Segoe UI', sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  color: var(--ink);
  font: 400 17px/1.45 var(--body);
  background: var(--bg) var(--tex-wall, none) 0 0 / 256px 256px;
  image-rendering: pixelated;
}
.page { max-width: 1080px; margin: 0 auto; padding: 22px 16px 56px; display: flex; flex-direction: column; gap: 20px; }
h1, h2, h3 { font-family: var(--display); font-weight: 700; margin: 0; text-wrap: balance; line-height: 1.05; }
p { margin: 0; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* Masthead */
.mast { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; border-bottom: 4px solid var(--panel-edge); padding-bottom: 12px; }
.mast h1 { font-size: clamp(38px, 8vw, 60px); color: var(--gold); text-shadow: 0 4px 0 #0a0c18; letter-spacing: .01em; }
.sub { color: var(--ink-soft); font-size: 16px; }
.mast-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.seg { display: inline-flex; border: 2px solid var(--panel-edge); border-radius: 3px; overflow: hidden; background: var(--panel); }
.seg button { border: 0; background: transparent; padding: 6px 14px; cursor: pointer; font-weight: 500; }
.seg button[aria-pressed="true"] { background: var(--gold); color: #171a2e; font-weight: 700; }
.btn { border: 2px solid var(--panel-edge); border-radius: 3px; background: #2a3054; padding: 6px 14px; cursor: pointer; font-weight: 500; box-shadow: 0 3px 0 #0a0c18; }
.btn:hover { background: #343b66; }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #0a0c18; }
.btn.primary { background: var(--gold); border-color: #a9772a; color: #171a2e; font-weight: 700; padding: 10px 18px; font-size: 18px; }
.btn.primary:hover { background: #ffd98f; }
.btn:disabled { opacity: .45; cursor: default; }

.layout { display: grid; grid-template-columns: minmax(0, 560px) minmax(280px, 1fr); gap: 28px 32px; align-items: start; }
.mapcol { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.side { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
/* Hero stats */
.hud { display: grid; grid-template-columns: minmax(0, 1fr) auto auto auto; gap: 8px 20px; align-items: end; background: var(--panel); border: 2px solid var(--panel-edge); border-radius: 3px; padding: 10px 12px; }
.stat { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.stat .lbl { font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-soft); font-weight: 700; }
.stat .val { font: 700 26px/1 var(--display); font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat .val small { font: 500 15px var(--body); color: var(--ink-soft); }
.stat .vrow { display: flex; align-items: center; gap: 4px; }
.stat .si { --spr: 22px; }
.hpline { display: flex; align-items: center; gap: 10px; }
.hpbar { display: grid; gap: 1px; flex: 1; min-width: 0; height: 14px; overflow: hidden; }
.hpbar i { border: 1px solid #e0483c; border-radius: 1px; min-width: 0; }
.hpbar i.on { background: #e0483c; }

/* Sprites */
.spr { display: block; width: var(--spr, 32px); height: var(--spr, 32px); flex: none; background-repeat: no-repeat; background-position: 0 0; image-rendering: crisp-edges; image-rendering: pixelated; }
.spr.live { animation: idle .9s step-end infinite; }
.spr.live.walk { animation: walkc .28s step-end infinite; }
.spr.left { scale: -1 1; }
@keyframes idle { 0% { background-position: 0 0; } 50% { background-position: var(--f1) 0; } }
/* Enemies with a special ability glow and stand on a ring of light, so the rooms that need thought stand out at a glance.
   Those whose ability reaches into other rooms also send out rings. */
:where(.special) > .spr.live { animation: idle .9s step-end infinite, glow 1.7s ease-in-out infinite; }
@keyframes glow { 0%, 100% { filter: drop-shadow(0 0 0 rgba(255, 205, 117, 0)); } 50% { filter: drop-shadow(0 0 2px #ffcd75) drop-shadow(0 0 5px rgba(255, 205, 117, .9)); } }
.special::after { content: ''; position: absolute; left: 2%; right: 2%; bottom: -9%; height: 30%; border-radius: 50%; border: 2px solid #ffcd75; box-shadow: 0 0 6px 1px rgba(255, 205, 117, .85), inset 0 0 5px rgba(255, 205, 117, .7); animation: aura 1.7s ease-in-out infinite; z-index: -1; pointer-events: none; }
@keyframes aura { 0%, 100% { opacity: .45; transform: scale(.86); } 50% { opacity: 1; transform: scale(1.06); } }
.fig.remote::before { content: ''; position: absolute; left: 2%; right: 2%; bottom: -9%; height: 30%; border-radius: 50%; border: 2px solid #ffcd75; animation: ping 2.4s ease-out infinite; z-index: -1; pointer-events: none; }
@keyframes ping { 0% { transform: scale(.9); opacity: .9; } 70%, 100% { transform: scale(2.7); opacity: 0; } }
.fig.down::before, .fig.down::after, .af.dying::after { display: none; }
@keyframes walkc { 0% { background-position: 0 0; } 50% { background-position: var(--f2) 0; } }
.fx { position: absolute; inset: 0; z-index: 4; animation: pop calc(var(--spd) * 380ms) ease-out forwards; }
.fx.s-slash { animation: none; }
.spr.a-lunge { animation: lunge calc(var(--spd) * 240ms) ease-in-out; }
.spr.a-blink { animation: blink calc(var(--spd) * 220ms) linear; }
.spr.a-hurt { animation: hurt calc(var(--spd) * 280ms) ease-out; }
.spr.a-die { animation: die calc(var(--spd) * 220ms) ease-in forwards; }
.spr.a-rise { animation: rise calc(var(--spd) * 320ms) ease-out; }
.spr.a-pickup { animation: pickup calc(var(--spd) * 240ms) ease-in forwards; }
.spr.a-hop { animation: hop calc(var(--spd) * 520ms) ease-in-out; }
.spr.a-heave { animation: heave calc(var(--spd) * 300ms) ease-in-out; }
.spr.a-recoil { animation: recoil calc(var(--spd) * 220ms) ease-out; }
.spr.a-split { animation: split calc(var(--spd) * 260ms) ease-in-out; }
.spr.strike { animation: thrust calc(var(--spd) * 290ms) ease-in-out; background-position: 100% 0; }
.spr.fallen { animation: none; transform: rotate(-90deg) translateX(-18%); filter: grayscale(1); }
@keyframes lunge { 50% { transform: translateX(-55%); } }
@keyframes thrust { 45% { transform: translateX(22%); } }
@keyframes blink { 0%, 100% { opacity: 1; } 25%, 75% { opacity: .1; } 50% { opacity: 1; transform: translateX(14%); } }
@keyframes hurt { 20% { transform: translateX(-12%); filter: sepia(1) saturate(9) hue-rotate(-45deg); } 60% { transform: translateX(6%); } }
@keyframes die { 0%, 40% { opacity: 1; } 20%, 60% { opacity: .15; } 100% { opacity: 0; transform: translateY(25%) scale(.55); } }
@keyframes rise { from { opacity: 0; transform: translateY(55%); } }
@keyframes pickup { to { opacity: 0; transform: translateY(-75%) scale(1.25); } }
@keyframes hop { 25%, 75% { transform: translateY(-30%); } 0%, 50%, 100% { transform: none; } }
@keyframes heave { 50% { transform: translateY(-18%); } }
@keyframes recoil { 35% { transform: translateX(14%); } }
@keyframes split { 30% { transform: scaleX(1.5) scaleY(.7); } 60% { transform: scaleX(.8) scaleY(1.2); } }
@keyframes pop { 0% { transform: scale(.4); opacity: 0; } 30% { transform: scale(1.2); opacity: 1; } 75% { opacity: 1; } 100% { opacity: 0; } }
.str { position: absolute; display: inline-grid; place-items: center; padding: 0 3px; border-radius: 99px; background: #1a1c2c; color: #f4f4f4; border: 1px solid #f4f4f4; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; white-space: nowrap; }
.str.buffed { background: #b3261e; }

/* Room view: this is where the fighting happens */
.side section.arenabox { background: none; border: 0; padding: 0; box-shadow: none; gap: 6px; }
.arena { position: relative; aspect-ratio: 112 / 48; container-type: inline-size; overflow: hidden; border: 3px solid #a9772a; border-radius: 2px; box-shadow: 0 4px 0 #0a0c18; background-color: #3a4058; background-size: 100% 100%; image-rendering: crisp-edges; image-rendering: pixelated; transition: filter 120ms linear; }
.arena.lost { filter: saturate(.5) brightness(.8); }
.arena.shake { animation: shake calc(var(--spd) * 240ms) linear; }
@keyframes shake { 20% { transform: translate(-3px, 2px); } 40% { transform: translate(3px, -2px); } 60% { transform: translate(-2px, -1px); } 80% { transform: translate(2px, 1px); } }
.arena.cast::after { content: ''; position: absolute; inset: 0; z-index: 90; background: #7a3cc0; animation: cast calc(var(--spd) * 420ms) ease-out forwards; pointer-events: none; }
@keyframes cast { 0% { opacity: 0; } 25% { opacity: .5; } 100% { opacity: 0; } }
/* the room itself can pan: sideways to the next room of a row, upward when the hero takes the stairs down */
.aview { position: absolute; inset: 0; background-size: 100% 100%; image-rendering: crisp-edges; image-rendering: pixelated; }
.aview.out-left { animation: panOutL calc(var(--spd) * 420ms) ease-in-out forwards; }
.aview.in-left { animation: panInL calc(var(--spd) * 420ms) ease-in-out; }
.aview.out-up { animation: panOutU calc(var(--spd) * 420ms) ease-in-out forwards; }
.aview.in-up { animation: panInU calc(var(--spd) * 420ms) ease-in-out; }
@keyframes panOutL { to { transform: translateX(-100%); } }
@keyframes panInL { from { transform: translateX(100%); } }
@keyframes panOutU { to { transform: translateY(-100%); } }
@keyframes panInU { from { transform: translateY(100%); } }
.alayer { position: absolute; inset: 0; }
.adoor { position: absolute; top: 44%; height: 46%; width: 16%; pointer-events: none; z-index: 3; }
.adoor.l { left: 0; background: linear-gradient(90deg, rgba(255, 233, 168, .6), rgba(255, 233, 168, 0)); }
.adoor.r { right: 0; background: linear-gradient(270deg, rgba(255, 233, 168, .6), rgba(255, 233, 168, 0)); }
.af { position: absolute; width: 14.2857%; aspect-ratio: 1; transition: left 140ms linear, top 140ms linear, opacity 140ms linear; }
.af.ahero { width: 21.4286%; }
.arena.jump .af { transition: none !important; }
.af .spr { width: 100%; height: 100%; }
.af.foe::before, .af.ahero::before, .af.item::before { content: ''; position: absolute; left: 12%; right: 12%; bottom: -3%; height: 14%; border-radius: 50%; background: rgba(0, 0, 0, .3); }
.af .str { left: 50%; top: -30%; transform: translateX(-50%); height: clamp(15px, 5cqw, 22px); min-width: clamp(15px, 5cqw, 22px); font-size: clamp(11px, 3.6cqw, 16px); }
.af.ghost .spr { filter: grayscale(1) brightness(1.25) drop-shadow(0 0 3px #b06cff); opacity: .9; }
.af.ghost .str { background: #5d275d; }
.af.dying .str { display: none; }
.af.boom { z-index: 180 !important; width: 26%; }
.af .inside { position: absolute; right: -18%; top: -22%; width: 55%; height: 55%; }
.ahp { position: absolute; left: 14%; right: 14%; top: -9%; height: 5px; background: #1a1c2c; border: 1px solid #f4f4f4; border-radius: 1px; }
.ahp i { display: block; height: 100%; background: #e0483c; transition: width 150ms linear; }
.achip { position: absolute; top: 5px; z-index: 300; padding: 1px 8px; border-radius: 2px; background: rgba(16, 19, 31, .85); color: #f1ecd9; font: 700 15px/1.35 var(--display); }
.achip.l { left: 6px; font-size: 17px; }
.achip.r { right: 6px; }
.afloat { position: absolute; z-index: 200; pointer-events: none; white-space: nowrap; padding: 0 7px; border-radius: 3px; background: #10131f; color: #fff; font-weight: 700; font-size: clamp(13px, 4.2cqw, 20px); animation: floatup .9s ease-out forwards; }
.afloat.bad { background: #c0392b; }
.afloat.good { background: #2a7751; }
@keyframes floatup { 0% { transform: translate(-50%, 10%); opacity: 0; } 15% { opacity: 1; } 75% { opacity: 1; } 100% { transform: translate(-50%, -120%); opacity: 0; } }
.acap { font-size: 15.5px; color: var(--ink-soft); min-height: 1.45em; }
.acap b { color: var(--ink); }
.minilog, .tabs { display: none; }

/* Map: everything sits on one pixel grid of 188 x 176 that is drawn as a single picture; --u is one of its pixels */
.board { container-type: inline-size; position: relative; margin: 30px 0; border: 3px solid var(--panel-edge); border-radius: 2px; box-shadow: 0 4px 0 #0a0c18; background: #0d101d; }
.board > * { --u: calc(100cqw / 188); --spr: calc(16 * var(--u)); }
.grid { position: relative; width: 100cqw; height: calc(176 * var(--u)); background-size: 100% 100%; image-rendering: crisp-edges; image-rendering: pixelated; }
.gate { position: absolute; font: 700 17px/1 var(--display); color: var(--gold); white-space: nowrap; }
.gate.in { top: -24px; left: 0; }
.gate.out { bottom: -24px; right: 0; }
.loading { position: absolute; inset: 0; display: grid; place-items: center; font: 700 22px var(--display); color: var(--gold); background: #0d101d; z-index: 40; text-align: center; padding: 16px; }

.slot { position: absolute; width: calc(48 * var(--u)); height: calc(48 * var(--u)); left: calc((14 + var(--c) * 56) * var(--u)); top: calc((8 + var(--r) * 56) * var(--u)); z-index: 1; }
.slot.lift { z-index: 20; }
/* dragging: drop zone, swap partner, everything else dimmed */
.slot.target { z-index: 15; background: rgba(255, 205, 117, .4); outline: 3px dashed #ffcd75; outline-offset: -3px; }
.room.swapping { box-shadow: 0 0 0 4px #ffcd75, 0 8px 18px rgba(0, 0, 0, .45); }
.room.swapping::before { content: '⇄'; position: absolute; z-index: 70; left: 50%; top: 50%; translate: -50% -50%; display: grid; place-items: center; width: clamp(26px, 8cqw, 42px); height: clamp(26px, 8cqw, 42px); border-radius: 50%; background: #ffcd75; color: #10131f; border: 2px solid #10131f; font: 700 clamp(16px, 5cqw, 26px)/1 var(--body); }
.board.dragmode .room:not(.dragging):not(.swapping) { filter: brightness(.5) saturate(.6); }
.board.dragmode .slot.hoverslot .room:not(.swapping) { filter: brightness(.8); box-shadow: 0 0 0 3px #ffcd75; }
.num { position: absolute; left: calc(3 * var(--u)); top: calc(1.5 * var(--u)); z-index: 3; pointer-events: none; font: 700 clamp(12px, 3.3cqw, 19px)/1 var(--display); color: #f1ecd9; text-shadow: 0 1px 0 #000, 0 0 3px #000; }

/* Room tile: a painted room with its inhabitants */
.room {
  position: absolute; inset: 0; overflow: hidden;
  background-color: var(--stone); background-size: 100% 100%; image-rendering: crisp-edges; image-rendering: pixelated;
  cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; will-change: transform;
}
.room.dragging { cursor: grabbing; box-shadow: 0 0 0 3px #fff, 0 14px 26px rgba(0, 0, 0, .55); }
.room.sel { box-shadow: 0 0 0 3px #fff, 0 0 0 6px #10131f; }
.board.locked .room { cursor: default; }
.room::after { content: ''; position: absolute; inset: 0; pointer-events: none; background: transparent; transition: background 150ms linear; }
.room.cleared::after { background: rgba(16, 19, 31, .5); }
.room.fell::after { background: rgba(170, 30, 20, .42); }
.room.here { box-shadow: 0 0 0 3px #ff6a55; }
.room.boom { animation: roomboom calc(var(--spd) * 420ms) ease-out; }
@keyframes roomboom { 0% { filter: brightness(3) saturate(2); transform: scale(1.04); } 100% { filter: none; transform: none; } }
.marks { position: absolute; right: 1cqw; top: .8cqw; z-index: 60; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 1px 2px; max-width: 75%; }
.marks > span { display: flex; align-items: center; background: #fff; color: #b3261e; border-radius: 2px; padding: 0 3px 0 1px; font-weight: 700; font-size: clamp(10px, 2.4cqw, 13px); line-height: 1.25; }
.marks > span.good { color: #1f6b46; padding-right: 1px; }
.marks .spr { width: 16px; height: 16px; margin: -2px 0; }
/* what the selected room does to other fields */
.eff { position: absolute; inset: 0; z-index: 4; pointer-events: none; border-radius: 3px; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.eff.act { display: flex; outline: 4px solid #ffcd75; outline-offset: -4px; background: rgba(255, 205, 117, .34); }
.eff .chip { display: flex; align-items: center; gap: 1px; background: #10131f; color: #fff; border: 1px solid #ffcd75; border-radius: 3px; padding: 0 6px 0 2px; font-weight: 700; font-size: clamp(12px, 3.2cqw, 17px); line-height: 1.35; }
.eff .chip .spr { width: clamp(16px, 4.4cqw, 24px); height: clamp(16px, 4.4cqw, 24px); }
.fig { position: absolute; width: 33.33%; aspect-ratio: 1; }
.fig.small { width: 25%; }
.fig .spr { width: 100%; height: 100%; }
.fig .str { right: -3%; bottom: 0; height: clamp(14px, 4.3cqw, 22px); min-width: clamp(14px, 4.3cqw, 22px); font-size: clamp(10.5px, 3.1cqw, 15px); }
.fig .inside { position: absolute; right: -14%; bottom: -6%; width: 58%; height: 58%; }
.fig.down { opacity: .75; }
.fig.down .str { display: none; }
.fig.taken { opacity: .2; filter: grayscale(1); }
.fig.wasted > .spr:first-child { filter: grayscale(1) brightness(.75); }
.fig.wasted::after { content: '✕'; position: absolute; left: -6%; top: -12%; color: #ff6a55; font: 700 clamp(11px, 3.4cqw, 17px)/1 var(--body); text-shadow: 0 0 2px #000, 0 1px 0 #000; }

.hero { position: absolute; left: 0; top: 0; z-index: 25; width: var(--spr); height: var(--spr); pointer-events: none;
  transform: translate(calc(var(--hx) * var(--u) - 50%), calc(var(--hy) * var(--u) - 50%));
  transition: transform calc(var(--spd) * 115ms) linear, opacity calc(var(--spd) * 115ms) linear; }
.hero.jump { transition: none; }
.hero.gone { opacity: 0; }
.hero .spr { width: 100%; height: 100%; }
.proj { position: absolute; left: 0; top: 0; z-index: 28; pointer-events: none; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.hint { color: var(--ink-soft); font-size: 15.5px; max-width: 62ch; text-shadow: 0 1px 0 #0a0c18; }
.dragnote { min-height: 1.45em; font-weight: 700; color: var(--gold); }

/* Side column */
.side section { background: var(--panel); border: 2px solid var(--panel-edge); border-radius: 3px; box-shadow: 0 4px 0 #0a0c18; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.side h2 { font-size: 24px; color: var(--gold); }
.side section.result { border-color: var(--gold); }
.result h2 { font-size: 32px; }
.result.win h2 { color: var(--green); }
.result.lose h2 { color: var(--red); }
.result .row { display: flex; flex-wrap: wrap; gap: 8px; }
.result textarea { width: 100%; font: 14px/1.3 ui-monospace, Menlo, Consolas, monospace; background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 3px; padding: 6px; resize: vertical; }
.note { color: var(--ink-soft); font-size: 15px; }

/* Attempts: one row per run, each cell shows who lived in the room at that position */
.tries { display: grid; gap: 4px; }
.try { display: grid; grid-template-columns: 22px repeat(9, minmax(0, 1fr)); gap: 3px; align-items: center; border: 0; padding: 0; background: none; text-align: left; width: 100%; }
button.try { cursor: pointer; }
button.try:hover .cell { border-color: var(--gold); }
.try .tn { font: 700 16px/1 var(--display); color: var(--ink-soft); }
.try .cell { position: relative; aspect-ratio: 1; border: 2px solid var(--line); border-radius: 2px; background: #252a47; display: flex; flex-wrap: wrap; align-content: center; justify-content: center; overflow: hidden; }
.try.head .cell { border: 0; background: none; aspect-ratio: auto; font: 700 13px/1 var(--display); color: var(--ink-soft); }
.try .cell.ok { background: #2c6b48; border-color: #6fd08c; }
.try .cell.dead { background: #8a2a22; border-color: #ff6a55; }
.try .cell.unseen { opacity: .55; }
.try.next .cell { border-style: dashed; border-color: #6a7299; background: none; }
.try .cell .spr { width: 50%; height: 50%; }
.try .cell.n1 .spr { width: 74%; height: 74%; }

.ent { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 2px 10px; align-items: start; }
.ent .ei { --spr: 32px; }
.ent b { font-weight: 700; }
.ent p { grid-column: 2; max-width: 60ch; }
.key .now { color: var(--red); font-weight: 500; }
.key .ent .plain { display: flex; gap: 2px; }
.key .ent.many { grid-template-columns: auto minmax(0, 1fr); }

.log { list-style: none; margin: 0; padding: 0; max-height: 300px; overflow-y: auto; border: 1px solid var(--line); background: #14172b; border-radius: 3px; }
.log li { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; gap: 8px; padding: 3px 10px; font-size: 15.5px; align-items: baseline; }
.log li.first { border-top: 1px dashed var(--line); }
.log li:first-child { border-top: 0; }
.log .ln { font: 700 15px/1 var(--display); color: var(--ink-soft); }
.log .lh { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.log .lh::before { content: '\2665\FE0E\00a0'; color: var(--red); }
.log li.bad .lt { color: var(--red); font-weight: 700; }
.log li.good .lt { color: var(--green); font-weight: 700; }
.log .empty { display: block; color: var(--ink-soft); padding: 10px; }

/* Tutorial */
.tut { align-items: stretch; text-align: left; gap: 12px; }
.tut h2 { font-size: 26px; }
.tut p { max-width: 62ch; min-height: 5.8em; }
.tstage { width: min(100%, 380px); margin: 0 auto; }
.tutboard { margin: 0; pointer-events: none; }
.tutboard .slot.tlift { z-index: 20; }
.thero { position: absolute; z-index: 30; width: calc(16 * var(--u)); height: calc(16 * var(--u)); translate: -50% -50%; left: 3.2%; top: 19.9%; }
.thero .spr, .tarrow .spr { width: 100%; height: 100%; }
.thero.twalk { animation: twalk 8s linear infinite; }
@keyframes twalk {
  0% { left: 3.2%; top: 19.9%; opacity: 1; }
  6% { left: 12.2%; top: 19.9%; } 14% { left: 42%; top: 19.9%; } 22% { left: 71.8%; top: 19.9%; opacity: 1; }
  27% { left: 97%; top: 21.5%; opacity: 0; } 28% { left: 1.6%; top: 53.3%; opacity: 0; }
  33% { left: 12.2%; top: 51.7%; opacity: 1; } 41% { left: 42%; top: 51.7%; } 49% { left: 71.8%; top: 51.7%; opacity: 1; }
  54% { left: 97%; top: 53.3%; opacity: 0; } 55% { left: 1.6%; top: 85.1%; opacity: 0; }
  60% { left: 12.2%; top: 83.5%; opacity: 1; } 68% { left: 42%; top: 83.5%; } 76% { left: 71.8%; top: 83.5%; }
  84%, 100% { left: 97%; top: 83.5%; opacity: 1; }
}
.thero.thit .spr { animation: thit 2s linear infinite; }
@keyframes thit { 0%, 54%, 72%, 100% { filter: none; transform: none; } 58% { filter: sepia(1) saturate(9) hue-rotate(-45deg); transform: translateX(-12%); } 66% { filter: sepia(1) saturate(9) hue-rotate(-45deg); transform: translateX(6%); } }
.tarrow { position: absolute; z-index: 29; width: calc(16 * var(--u)); height: calc(16 * var(--u)); translate: -50% -50%; top: 19.9%; left: 68%; opacity: 0; }
.tarrow.loop { animation: tarrow 2s linear infinite; }
@keyframes tarrow { 0% { left: 68%; opacity: 0; } 8% { opacity: 1; } 55% { left: 15%; opacity: 1; } 60%, 100% { left: 15%; opacity: 0; } }
.tarrow.once { animation: tarrow3 7s linear infinite; }
@keyframes tarrow3 { 0% { left: 68%; opacity: 0; } 2% { opacity: 1; } 12% { left: 15%; opacity: 1; } 13% { left: 15%; opacity: 0; } 14% { left: 68%; opacity: 0; } 16% { opacity: 1; } 26% { left: 15%; opacity: 1; } 27%, 100% { left: 15%; opacity: 0; } }
.tutboard .room.tswap-a { animation: tswapA 7s ease-in-out infinite; }
.tutboard .room.tswap-b { animation: tswapB 7s ease-in-out infinite; }
@keyframes tswapA { 0%, 32% { transform: none; box-shadow: none; } 36% { transform: scale(1.06); box-shadow: 0 0 0 3px #fff; } 50%, 90% { transform: translateX(calc(112 * var(--u))); box-shadow: none; } 100% { transform: none; } }
@keyframes tswapB { 0%, 36% { transform: none; box-shadow: none; } 40% { box-shadow: 0 0 0 4px #ffcd75; } 50%, 90% { transform: translateX(calc(-112 * var(--u))); box-shadow: none; } 100% { transform: none; } }
.tutboard .eff.tfade { animation: tfade 7s linear infinite; }
@keyframes tfade { 0%, 32% { opacity: 1; } 38%, 94% { opacity: 0; } 100% { opacity: 1; } }
.tutarena { margin: 0; }
.tnav { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.tdots { display: flex; gap: 8px; }
.tdots i { width: 10px; height: 10px; background: var(--line); border: 1px solid var(--panel-edge); }
.tdots i.on { background: var(--gold); border-color: var(--gold); }
.tskip { align-self: center; background: none; border: 0; color: var(--ink-soft); text-decoration: underline; cursor: pointer; padding: 4px 8px; font-size: 15px; }
.hbtns { display: flex; gap: 8px; }

/* Rules */
dialog { border: 3px solid var(--gold); border-radius: 3px; background: var(--panel); color: var(--ink); padding: 0; width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 48px); }
dialog::backdrop { background: rgba(5, 7, 14, .7); }
.dlg { padding: 20px 22px 22px; display: flex; flex-direction: column; gap: 14px; }
.dlg header { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.dlg h2 { font-size: 32px; color: var(--gold); }
.dlg h3 { font-size: 22px; margin-top: 4px; color: var(--gold); }
.dlg ol { margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 6px; max-width: 64ch; }
.dlg .ents { display: grid; gap: 8px; }

@media (prefers-reduced-motion: reduce) {
  .hero, .af, .ahp i { transition: none; }
  .spr, .afloat, .arena, .aview, .room, .special::after, .thero, .tarrow, .tutboard .eff { animation: none !important; }
  .fig.remote::before { display: none; }
}

/* Phones and narrow windows: one screen without page scrolling. Header, stats, map and buttons are fixed,
   the panel below takes the rest: room notes while you plan, the room view while the hero is inside, attempts and log as tabs. */
@media (max-width: 860px) {
  html, body { height: 100%; overflow: hidden; }
  .page { height: 100%; max-width: 640px; padding: 8px 10px; gap: 6px; container-type: size; }
  .mast { flex-wrap: nowrap; align-items: center; gap: 8px; border-bottom-width: 2px; padding-bottom: 5px; }
  .mast > div:first-child { min-width: 0; }
  .mast h1 { font-size: 22px; text-shadow: 0 2px 0 #0a0c18; white-space: nowrap; }
  .sub { font-size: 12px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .mast-actions { flex-wrap: nowrap; gap: 6px; flex: none; }
  .seg button, .mast .btn { padding: 4px 8px; font-size: 14px; }
  .layout { display: flex; flex-direction: column; align-items: stretch; gap: 6px; flex: 1; min-height: 0; }
  .mapcol { display: contents; }
  .hud { order: 1; grid-template-columns: minmax(0, 1fr) auto auto auto; gap: 4px 12px; padding: 4px 8px; align-items: center; flex: none; }
  .stat .lbl { display: none; }
  .stat .val { font-size: 19px; }
  .stat .val small { font-size: 12px; }
  .stat .si { --spr: 20px; }
  .hpbar { height: 12px; }
  .board { order: 2; flex: none; margin: 0 auto; width: min(100%, calc((100cqh - 322px) * 1.068)); box-shadow: none; }
  .tutboard { width: 100%; }
  .gate, .hint, .dragnote { display: none; }
  .actions { order: 3; gap: 6px; flex: none; }
  .actions .btn { padding: 6px 9px; font-size: 14px; white-space: nowrap; box-shadow: 0 2px 0 #0a0c18; }
  .actions .btn.primary { flex: 1 1 150px; padding: 7px 8px; font-size: 16px; min-width: 0; }
  .side { order: 4; flex: 1; min-height: 0; overflow-y: auto; gap: 8px; background: var(--panel); border: 2px solid var(--panel-edge); border-radius: 3px; padding: 0 8px 8px; font-size: 14.5px; line-height: 1.32; }
  .tabs { display: flex; position: sticky; top: 0; z-index: 400; background: var(--panel); margin: 0 -8px; border-bottom: 2px solid var(--panel-edge); flex: none; }
  .tabs button { flex: 1; border: 0; background: none; padding: 5px 4px; font: 700 15px/1.2 var(--display); color: var(--ink-soft); cursor: pointer; }
  .tabs button[aria-selected="true"] { color: #171a2e; background: var(--gold); }
  .side section { background: none; border: 0; box-shadow: none; padding: 0; gap: 5px; }
  .side section.result { border: 0; padding: 0; }
  .side[data-tab="room"] section:not(.t-room), .side[data-tab="tries"] section:not(.t-tries), .side[data-tab="log"] section:not(.t-log) { display: none; }
  .side:not(.show-arena) .arenabox, .side.show-arena .key { display: none; }
  .side h2 { font-size: 18px; }
  .result h2 { font-size: 22px; }
  .arena { box-shadow: none; border-width: 2px; }
  .acap { font-size: 13.5px; min-height: 0; }
  /* while the hero is inside, the room view fills the panel and the latest log line sits on its lower edge */
  .side.show-arena .arenabox { flex: 1; min-height: 0; container-type: size; }
  .side.show-arena .arena { width: min(100cqw, calc(100cqh * 112 / 48)); margin: 0 auto; }
  .side.show-arena .acap { display: none; }
  .minilog { display: block; position: absolute; left: 0; right: 0; bottom: 0; z-index: 310; list-style: none; margin: 0; padding: 1px 7px; font-size: 13px; line-height: 1.3; background: rgba(16, 19, 31, .84); color: #f1ecd9; }
  .minilog li { display: flex; justify-content: space-between; gap: 8px; }
  .minilog li:not(:last-child) { display: none; }
  .minilog li.bad { color: var(--red); } .minilog li.good { color: var(--green); }
  .minilog li span:last-child::before { content: '\2665\FE0E\00a0'; color: var(--red); }
  .ent { grid-template-columns: 26px minmax(0, 1fr); gap: 0 8px; }
  .ent .ei { --spr: 24px; }
  .note { font-size: 13.5px; }
  .log { max-height: none; }
  .log li { font-size: 14px; }
  .tut h2 { font-size: 21px; }
  .tut p { font-size: 15.5px; min-height: 7.6em; }
  .dlg { padding: 14px 14px 16px; }
  dialog { max-height: calc(100% - 20px); }
}
