:root{
  --paper:#efe4d0;
  --ink:#14100e;
  --rust:#c4551f;
  --blue:#2c6b8f;
  --grey:#8c8880;
  --green:#4c5a3c;
  --yellow:#e0a81f;
  --bright:#f7ecd6;
  --disp:'Bangers', Impact, sans-serif;
  --hand:'Patrick Hand', 'Comic Sans MS', cursive;
  --num:'Barlow Condensed', 'Arial Narrow', sans-serif;
}

*{box-sizing:border-box;}

html,body{height:100%;}

body{
  margin:0;
  height:100dvh;
  overflow:hidden;
  background:var(--paper);
  color:var(--ink);
  font-family:var(--hand);
  -webkit-tap-highlight-color:transparent;
  user-select:none;
}

body::before{
  content:"";
  position:fixed;
  inset:0;
  z-index:0;
  pointer-events:none;
  background-image:
    radial-gradient(circle at 12% 18%, rgba(20,16,14,.05) 0 .8px, transparent 1.4px),
    radial-gradient(circle at 68% 62%, rgba(20,16,14,.05) 0 .7px, transparent 1.2px),
    radial-gradient(circle at 38% 84%, rgba(196,85,31,.05) 0 1px, transparent 1.6px),
    repeating-radial-gradient(circle at 30% 30%, rgba(20,16,14,.028) 0 .6px, transparent 1.2px);
  background-size: 37px 41px, 53px 59px, 71px 67px, 6px 6px;
  opacity:.8;
}

body::after{
  content:"";
  position:fixed;
  inset:0;
  z-index:0;
  pointer-events:none;
  box-shadow: inset 0 0 90px rgba(20,16,14,.13);
}

.defs{position:absolute;width:0;height:0;overflow:hidden;}

.page{
  position:relative;
  z-index:1;
  display:grid;
  grid-template-rows:auto minmax(0,1fr) auto;
  gap:8px;
  height:100dvh;
  padding:8px 10px;
}

/* ---------- masthead ---------- */
.masthead{
  display:flex;
  align-items:stretch;
  gap:10px;
  min-height:0;
}

.brand{
  display:flex;
  align-items:center;
  gap:8px;
  flex:0 0 auto;
}

.portrait{
  width:clamp(52px, 7vw, 92px);
  height:clamp(52px, 7vw, 92px);
  flex:0 0 auto;
  border:3px solid var(--ink);
  border-radius:50%;
  overflow:hidden;
  background:#0d0b09;
  box-shadow:3px 4px 0 rgba(20,16,14,.25);
}
.portrait img{width:100%;height:100%;object-fit:cover;transform:scale(1.04);}

.brandtext{
  display:flex;
  flex-direction:column;
  gap:3px;
  align-items:flex-start;
  justify-content:center;
}
.title{
  width:clamp(126px, 17vw, 250px);
  display:block;
  transform:rotate(-2deg);
  filter:drop-shadow(1px 2px 0 rgba(20,16,14,.12));
}

.lvlstamp{
  display:inline-flex;
  align-items:center;
  gap:7px;
  padding:2px 8px;
  border:2px solid var(--ink);
  border-radius:4px 7px 3px 6px;
  font-family:var(--num);
  font-size:11px;
  line-height:1;
  background:var(--paper);
  transform:rotate(-1.4deg);
  margin-left:14px;
  box-shadow:2px 2px 0 rgba(20,16,14,.22);
}
.lvlstamp span{font-weight:900;letter-spacing:.04em;}
.lvlstamp b{font-weight:700;letter-spacing:.06em;color:var(--rust);}

.scorebar{
  position:relative;
  flex:1 1 auto;
  display:flex;
  align-items:stretch;
  min-width:0;
  border:3px solid var(--ink);
  border-radius:6px 9px 5px 8px / 7px 6px 9px 5px;
  background:var(--paper);
  box-shadow:4px 5px 0 rgba(20,16,14,.18);
  overflow:hidden;
}
.scorebar::after{
  content:"";
  position:absolute;
  inset:3px;
  border:1px solid rgba(20,16,14,.35);
  border-radius:3px;
  pointer-events:none;
}

.stat{
  position:relative;
  padding:3px 14px;
  display:flex;
  flex-direction:column;
  justify-content:center;
  gap:0;
  border-right:2px solid var(--ink);
  flex:0 0 auto;
}
.stat:last-child{border-right:0;}
.stat.wide{flex:1 1 0;min-width:0;}

.klabel{
  font-family:var(--num);
  font-weight:700;
  font-size:clamp(8px, .82vw, 11px);
  letter-spacing:.1em;
  line-height:1.1;
  opacity:.8;
  white-space:nowrap;
}
.kval{
  font-family:var(--num);
  font-weight:900;
  font-size:clamp(19px, 2.3vw, 33px);
  line-height:.9;
  letter-spacing:.02em;
  font-variant-numeric:tabular-nums;
}
.kval.small{font-size:clamp(13px, 1.4vw, 21px);letter-spacing:.03em;}
.kval.rust{
  background:var(--rust);
  color:var(--paper);
  padding:0 5px;
  transform:skew(-4deg);
  align-self:flex-start;
  margin-top:1px;
}

.hprow{display:flex;align-items:center;gap:7px;min-width:0;}
.kmax{
  font-family:var(--num);
  font-weight:700;
  font-size:clamp(9px, .9vw, 13px);
  letter-spacing:.02em;
  opacity:.55;
  line-height:1;
  margin-top:.2em;
}
.hpbar{
  flex:1 1 auto;
  height:11px;
  min-width:40px;
  max-width:none;
  border:2px solid var(--ink);
  background:var(--paper);
  border-radius:2px;
  overflow:hidden;
}
.hpbar i{
  display:block;
  height:100%;
  width:100%;
  background:repeating-linear-gradient(90deg,var(--rust) 0 8px,#a3461a 8px 11px);
  transition:width .25s ease-out;
}

/* ---------- stage ---------- */
.stage{
  display:grid;
  grid-template-columns:minmax(132px,152px) minmax(0,1fr) minmax(108px,150px);
  gap:10px;
  min-height:0;
}

.rail{
  display:flex;
  flex-direction:column;
  gap:6px;
  min-height:0;
  overflow:hidden;
}

.tcard{
  position:relative;
  flex:1 1 0;
  min-height:44px;
  max-height:100px;
  display:grid;
  grid-template-columns:clamp(38px, 4.4vw, 54px) 1fr;
  align-items:center;
  gap:6px;
  padding:3px 6px 3px 5px;
  background:var(--paper);
  border:2.5px solid var(--ink);
  border-radius:8px 5px 9px 6px / 6px 9px 5px 8px;
  box-shadow:3px 4px 0 rgba(20,16,14,.75);
  cursor:pointer;
  text-align:left;
  font:inherit;
  color:var(--ink);
  transition:transform .07s ease-out, box-shadow .08s, background .12s;
  overflow:visible;
}
.tcard::before{
  content:"";
  position:absolute;
  inset:2px;
  border:1px solid rgba(20,16,14,.5);
  border-radius:inherit;
  pointer-events:none;
}
.tcard img{
  width:100%;
  height:100%;
  max-height:58px;
  object-fit:contain;
  pointer-events:none;
  filter:drop-shadow(1px 1px 0 rgba(20,16,14,.18));
}
.tcard .meta{
  display:flex;
  flex-direction:column;
  gap:2px;
  min-width:0;
}
.tcard .tname{
  font-family:var(--num);
  font-weight:800;
  font-size:clamp(9px, 1.02vw, 13px);
  line-height:1;
  letter-spacing:.02em;
  text-transform:uppercase;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}
.tcard .costrow{
  display:flex;
  align-items:center;
  gap:4px;
  font-family:var(--num);
  font-weight:800;
  font-size:clamp(9px, .95vw, 12px);
  line-height:1;
}
.costbadge{
  background:var(--rust);
  color:var(--paper);
  padding:0 4px;
  transform:skew(-4deg);
  border:1.5px solid var(--ink);
  letter-spacing:.02em;
}
.tcard .trange{opacity:.55;font-size:.9em;}
.keybadge{
  position:absolute;
  top:-5px;
  left:-5px;
  width:17px;
  height:17px;
  background:var(--paper);
  border:1.5px solid var(--ink);
  font-family:var(--num);
  font-weight:900;
  font-size:11px;
  line-height:1;
  display:flex;
  align-items:center;
  justify-content:center;
  transform:rotate(-3deg);
  z-index:2;
}
.tcard.sel{
  background:var(--bright);
  transform:translateY(4px) rotate(-.4deg);
  box-shadow:0 0 0 rgba(20,16,14,0);
  outline:3px solid var(--rust);
  outline-offset:1px;
}
.tcard.poor{opacity:.44;filter:saturate(.35);}
.tcard.poor .costbadge{background:var(--grey);}
.tcard:active{transform:translateY(3px);box-shadow:none;}
.tcard.sel:active{transform:translateY(4px);}
.tcard:hover:not(.sel){background:var(--bright);}

/* ---------- board ---------- */
.boardwrap{
  position:relative;
  min-width:0;
  min-height:0;
  display:flex;
}

.board{
  position:relative;
  width:100%;
  height:100%;
  min-height:0;
  border:5px solid var(--ink);
  border-radius:12px 7px 14px 8px / 8px 14px 7px 12px;
  overflow:hidden;
  background:#c9bca4;
  box-shadow:6px 7px 0 rgba(20,16,14,.2);
  touch-action:manipulation;
}
.board::after{
  content:"";
  position:absolute;
  inset:2px;
  border:1.5px solid rgba(20,16,14,.55);
  border-radius:8px 4px 10px 5px;
  pointer-events:none;
  z-index:10;
}

#board{
  position:absolute;
  inset:0;
  overflow:hidden;
}
#board canvas{display:block;width:100%!important;height:100%!important;}

.gridhint{
  position:absolute;
  left:50%;
  bottom:7px;
  transform:translateX(-50%);
  z-index:6;
  padding:2px 9px;
  background:var(--yellow);
  border:2px solid var(--ink);
  border-radius:3px;
  font-family:var(--num);
  font-weight:900;
  font-size:11px;
  letter-spacing:.06em;
  white-space:nowrap;
  opacity:0;
  transition:opacity .16s;
  pointer-events:none;
  box-shadow:2px 2px 0 rgba(20,16,14,.4);
}
.board.placing .gridhint{opacity:1;}

.floatovers{position:absolute;inset:0;z-index:7;pointer-events:none;overflow:hidden;}

.fbubble{
  position:absolute;
  width:clamp(104px, 12%, 158px);
  aspect-ratio:357 / 285;
  transform:translate(-76%,-100%) rotate(-2deg);
  transform-origin:80% 100%;
  background-image:url(assets/speech_bubbles_03_thought_bubble.webp);
  background-size:100% 100%;
  background-repeat:no-repeat;
  padding:0;
  font-family:var(--hand);
  font-size:clamp(9px, .95vw, 12px);
  line-height:1.02;
  text-align:center;
  text-transform:uppercase;
  opacity:0;
  transition:opacity .25s;
  filter:drop-shadow(1px 2px 0 rgba(20,16,14,.18));
  pointer-events:none;
}
.fbubble span{
  position:absolute;
  inset:12% 12% 28% 10%;
  display:flex;
  align-items:center;
  justify-content:center;
}
.fbubble::before{content:"";position:absolute;left:8%;right:8%;top:5%;bottom:25%;background:var(--paper);border-radius:50%;z-index:-1;}
.fbubble.on{opacity:1;}
.fbubble b{font-family:var(--disp);font-weight:400;letter-spacing:.03em;}

.blackout{
  position:absolute;
  inset:0;
  z-index:9;
  background:#0d0b09;
  opacity:0;
  pointer-events:none;
  transition:opacity .16s linear;
  display:flex;
  align-items:center;
  justify-content:center;
  overflow:hidden;
}
.blackout.on{opacity:1;}
.krakburst{
  width:38%;
  max-width:280px;
  transform:rotate(-6deg);
  opacity:0;
  transition:opacity .08s;
}
.blackout.showkrak .krakburst{
  opacity:1;
  animation:krakjitter .1s steps(2,end) infinite;
}
@keyframes krakjitter{
  0%{transform:rotate(-6deg) translate(0,0) scale(1);}
  50%{transform:rotate(-2deg) translate(4px,-2px) scale(1.05);}
  100%{transform:rotate(-8deg) translate(-2px,3px) scale(.98);}
}

.endcard{
  position:absolute;
  inset:0;
  z-index:12;
  display:flex;
  align-items:flex-start;
  justify-content:center;
  padding:9px;
  background:rgba(13,11,9,.16);
}
.endcard[hidden]{display:none;}
.endcard-inner{
  position:relative;
  width:min(68%, 272px);
  max-height:74%;
  background-image:url(assets/panel_frames_04_level_end_stamp.webp);
  background-size:100% 100%;
  background-repeat:no-repeat;
  aspect-ratio:358 / 333;
  padding:0;
  display:block;
  transform:rotate(-1deg);
  filter:drop-shadow(8px 9px 0 rgba(0,0,0,.35));
  animation:stampIn .3s cubic-bezier(.2,1.7,.45,1);
}
@keyframes stampIn{
  0%{transform:scale(1.25) rotate(-4deg);opacity:0;}
  70%{transform:scale(.97) rotate(-.5deg);opacity:1;}
  100%{transform:scale(1) rotate(-1deg);}
}
.endkicker{
  position:absolute;
  left:12%;right:24%;top:12.5%;
  text-align:center;
  font-family:var(--num);font-weight:700;font-size:10px;letter-spacing:.16em;opacity:.62;
}
.endcard h2{
  position:absolute;
  left:6%;right:6%;top:17%;
  font-family:var(--disp);
  font-weight:400;
  font-size:clamp(28px, 3.7vw, 42px);
  line-height:.88;
  letter-spacing:.03em;
  margin:0;
  text-align:center;
  text-shadow:2px 2px 0 rgba(196,85,31,.45);
}
.endstats{
  position:absolute;
  left:10%;right:10%;top:52%;
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:3px 14px;
  padding:5px 9px;
  background:var(--paper);
  border:2px solid var(--ink);
  border-radius:3px 5px 2px 4px;
  box-shadow:2px 2px 0 rgba(20,16,14,.35);
  font-family:var(--num);
  font-weight:700;
  font-size:clamp(10px,1.05vw,13px);
  letter-spacing:.04em;
  text-transform:uppercase;
  line-height:1.3;
  color:var(--ink);
}
.endstats span{display:flex;justify-content:space-between;gap:6px;border-bottom:1px solid rgba(20,16,14,.24);}
.endstats span:last-child,.endstats span:nth-last-child(2){border-bottom:0;}
.endstats b{font-weight:900;font-size:1.25em;}
.endcard .stampbtn{
  position:absolute;
  left:50%;bottom:11%;
  transform:translateX(-50%) rotate(-1.4deg);
  font-size:clamp(14px,1.7vw,19px);
  padding:6px 14px;
  box-shadow:3px 4px 0 rgba(20,16,14,.8);
}
.endcard .stampbtn:active{transform:translateX(-50%) translateY(3px) rotate(-1.4deg);box-shadow:none;}

.stampbtn{
  font-family:var(--disp);
  font-weight:400;
  font-size:clamp(16px, 1.8vw, 21px);
  letter-spacing:.04em;
  line-height:1;
  color:var(--ink);
  background:var(--yellow);
  border:3px solid var(--ink);
  border-radius:6px 10px 5px 9px / 8px 5px 10px 6px;
  padding:7px 13px;
  cursor:pointer;
  transform:rotate(-1deg);
  box-shadow:4px 5px 0 rgba(20,16,14,.8);
  transition:transform .07s, box-shadow .07s;
}
.stampbtn:active{transform:translateY(3px);box-shadow:none;}
.stampbtn.small{font-size:clamp(11px,1vw,14px);padding:4px 5px;box-shadow:3px 3px 0 rgba(20,16,14,.7);}

.pausecard{
  position:absolute;
  inset:0;
  z-index:11;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap:8px;
  background:rgba(239,228,208,.94);
  text-align:center;
  padding:16px;
}
.pausecard[hidden]{display:none;}
.pausetitle{font-family:var(--disp);font-size:clamp(34px,5vw,56px);line-height:.9;transform:rotate(-2deg);}
.pausecard p{font-family:var(--hand);font-size:14px;margin:0;max-width:280px;}

/* mobile-only board controls */
.mobilecontrols{display:none;}

/* ---------- side column ---------- */
.sidecol{
  display:flex;
  flex-direction:column;
  gap:7px;
  min-height:0;
}
.shiftnote{
  position:relative;
  flex:1 1 auto;
  display:flex;
  flex-direction:column;
  gap:5px;
  padding:7px 8px;
  min-height:0;
  border:2.5px solid var(--ink);
  border-radius:7px 11px 6px 10px / 9px 6px 11px 5px;
  background:var(--paper);
  box-shadow:4px 5px 0 rgba(20,16,14,.18);
  overflow:hidden;
}
.shiftnote::after{
  content:"";
  position:absolute;
  right:-18px;
  bottom:-20px;
  width:82px;
  height:82px;
  border-radius:50%;
  background-image:radial-gradient(var(--rust) 1px, transparent 1.3px);
  background-size:5px 5px;
  opacity:.4;
  transform:rotate(12deg);
  pointer-events:none;
}
.notehead{
  font-family:var(--num);
  font-weight:900;
  font-size:11px;
  letter-spacing:.12em;
  border-bottom:2px solid var(--ink);
  padding-bottom:2px;
}
.shiftnote p{
  font-family:var(--hand);
  font-size:clamp(10px,1vw,12px);
  line-height:1.2;
  margin:0;
  text-transform:uppercase;
  letter-spacing:.01em;
}
.shiftcount{
  margin-top:auto;
  display:flex;
  align-items:flex-end;
  justify-content:space-between;
  font-family:var(--num);
  position:relative;
  z-index:1;
}
.shiftcount span{font-weight:700;font-size:9px;letter-spacing:.1em;}
.shiftcount b{font-weight:900;font-size:clamp(22px,2.2vw,32px);line-height:.8;color:var(--rust);}
.sidebtns{display:flex;flex-direction:column;gap:6px;}

/* ---------- bottom strip ---------- */
.bottom{
  position:relative;
  display:flex;
  align-items:stretch;
  gap:8px;
  padding:7px 9px;
  height:132px;
  min-height:104px;
  border:3px solid var(--ink);
  border-radius:8px 6px 11px 7px / 6px 11px 6px 9px;
  background:var(--paper);
  box-shadow:5px 6px 0 rgba(20,16,14,.18);
  overflow:hidden;
}
.bottom::after{
  content:"";
  position:absolute;
  inset:3px;
  border:1px solid rgba(20,16,14,.3);
  border-radius:5px;
  pointer-events:none;
  z-index:3;
}
.foreman{
  position:relative;
  flex:0 0 clamp(56px, 9vw, 112px);
  overflow:hidden;
  align-self:stretch;
  z-index:2;
}
.foreman img{
  position:absolute;
  top:0;
  left:50%;
  transform:translateX(-50%);
  width:auto;
  height:205%;
  max-width:none;
  filter:contrast(1.03);
}
.speech{
  position:relative;
  flex:1 1 auto;
  max-width:680px;
  min-width:0;
  min-height:80px;
  z-index:2;
  background-image:url(assets/speech_bubbles_01_speech_bubble_left.webp);
  background-repeat:no-repeat;
  background-size:100% 100%;
  transform-origin:10% 70%;
}
.speech.pop{animation:bubblepop .3s cubic-bezier(.2,1.6,.4,1);}
@keyframes bubblepop{
  0%{transform:scale(.86);}
  60%{transform:scale(1.035);}
  100%{transform:scale(1);}
}
#speechText{
  position:absolute;
  inset:9% 10% 25% 8%;
  display:flex;
  align-items:center;
  justify-content:center;
  text-align:center;
  font-family:var(--hand);
  font-size:clamp(11px, 1.15vw, 17px);
  line-height:1.06;
  text-transform:uppercase;
  letter-spacing:.01em;
  overflow:hidden;
}
#speechText b{
  font-family:var(--disp);
  font-weight:400;
  letter-spacing:.04em;
  text-decoration:underline;
  text-decoration-thickness:2px;
  text-underline-offset:2px;
}
.bottomright{
  margin-left:auto;
  flex:0 1 clamp(190px, 26%, 340px);
  min-width:0;
  display:flex;
  flex-direction:column;
  justify-content:space-between;
  gap:5px;
  z-index:2;
}
.howto{
  font-family:var(--num);
  font-weight:600;
  font-size:clamp(8px,.9vw,10.5px);
  line-height:1.25;
  letter-spacing:.02em;
  text-transform:uppercase;
  border-left:2px solid rgba(20,16,14,.3);
  padding-left:7px;
  color:var(--ink);
}
.howto b{color:var(--rust);font-weight:900;}
.wavebar{
  position:relative;
  height:18px;
  border:2px solid var(--ink);
  border-radius:3px;
  background:var(--paper);
  overflow:hidden;
}
.wavebar i{
  position:absolute;
  inset:0;
  width:0%;
  background:repeating-linear-gradient(90deg,var(--blue) 0 8px,#235b79 8px 11px);
  transition:width .3s ease-out;
}
.wavebar span{
  position:absolute;
  inset:0;
  display:flex;
  align-items:center;
  justify-content:center;
  font-family:var(--num);
  font-weight:900;
  font-size:11px;
  letter-spacing:.08em;
  color:var(--ink);
  text-shadow:0 0 3px var(--paper),0 0 3px var(--paper),0 0 3px var(--paper);
}

/* ---------- short screens / portrait ---------- */
@media (max-height:560px) and (min-aspect-ratio:1/1){
  .page{padding:4px 6px;gap:5px;}
  .masthead{gap:6px;}
  .portrait{width:42px;height:42px;border-width:2px;}
  .title{width:118px;}
  .lvlstamp{display:none;}
  .scorebar{border-width:2px;}
  .stage{grid-template-columns:118px minmax(0,1fr) 92px;gap:6px;}
  .rail{gap:4px;}
  .tcard{grid-template-columns:32px 1fr;padding:2px 4px;border-width:2px;box-shadow:2px 2px 0 rgba(20,16,14,.7);}
  .tcard img{max-height:34px;}
  .tcard .tname{font-size:8.5px;}
  .tcard .costrow{font-size:8.5px;}
  .keybadge{width:13px;height:13px;font-size:9px;top:-4px;left:-4px;}
  .bottom{height:86px;min-height:74px;padding:4px 6px;}
  .foreman{flex-basis:66px;}
  .speech{min-height:60px;}
  #speechText{font-size:10.5px;inset:8% 9% 25% 7%;}
  .rail{gap:3px;}
  .tcard{min-height:42px;}
  .tcard img{max-height:36px;}
  .sidecol{display:none;}
  .mobilecontrols{display:flex;position:absolute;top:6px;right:8px;gap:5px;z-index:8;}
  .mobilecontrols .stampbtn{font-size:12px;padding:6px 8px;min-width:44px;min-height:44px;border-width:2px;box-shadow:2px 2px 0 rgba(20,16,14,.7);}
  .scorebar .stat{padding:1px 8px;}
  .kval{font-size:22px;}
  .klabel{font-size:8px;}
}

@media (max-aspect-ratio:1/1){
  .page{
    grid-template-columns:1fr;
    grid-template-rows:auto minmax(0,1fr) auto auto;
    grid-template-areas:"head" "board" "bottom" "rail";
    gap:6px;
    padding:6px;
    height:100dvh;
  }
  .masthead{
    grid-area:head;
    display:grid;
    grid-template-columns:auto 1fr;
    gap:5px;
    align-items:center;
  }
  .brand{gap:6px;}
  .portrait{width:48px;height:48px;border-width:2px;}
  .title{width:clamp(110px,34vw,172px);}
  .lvlstamp{display:none;}
  .brandtext{gap:0;}
  .scorebar{
    grid-column:1 / -1;
    height:46px;
    border-width:2px;
    box-shadow:3px 3px 0 rgba(20,16,14,.18);
  }
  .stat{padding:1px 8px;}
  .klabel{font-size:8px;letter-spacing:.06em;}
  .kval{font-size:21px;}
  .kval.small{font-size:13px;}
  .hpbar{height:9px;min-width:30px;}
  .stage{display:contents;}
  .sidecol{display:none;}
  .boardwrap{grid-area:board;min-height:0;}
  .board{border-width:3px;border-radius:9px 6px 11px 6px;box-shadow:4px 4px 0 rgba(20,16,14,.2);}
  .bottom{
    grid-area:bottom;
    height:98px;
    min-height:88px;
    padding:5px 6px;
    gap:5px;
    border-width:2.5px;
    box-shadow:3px 4px 0 rgba(20,16,14,.18);
  }
  .foreman{flex-basis:62px;}
  .foreman img{height:225%;}
  .speech{min-height:80px;}
  #speechText{font-size:11px;inset:8% 9% 26% 7%;}
  .bottomright{
    flex:0 0 auto;
    width:82px;
    max-width:82px;
    gap:4px;
    justify-content:center;
  }
  .howto{display:none;}
  .bottomright .howto{margin-top:auto;}
  .wavebar{height:16px;}
  .wavebar span{font-size:9px;letter-spacing:.02em;}
  .mobilecontrols{display:flex;position:absolute;top:5px;right:7px;gap:5px;z-index:8;}
  .mobilecontrols .stampbtn{font-size:12px;padding:6px 8px;min-width:44px;min-height:44px;border-width:2px;box-shadow:2px 2px 0 rgba(20,16,14,.7);}
  .rail{
    grid-area:rail;
    height:96px;
    flex-direction:row;
    gap:6px;
    overflow-x:auto;
    overflow-y:hidden;
    padding:2px 4px 6px;
    scrollbar-width:none;
    -webkit-overflow-scrolling:touch;
  }
  .rail::-webkit-scrollbar{display:none;}
  .tcard{
    flex:0 0 92px;
    height:82px;
    min-height:0;
    max-height:none;
    grid-template-columns:1fr;
    grid-template-rows:42px 1fr;
    gap:1px;
    padding:3px 4px;
    border-width:2px;
    box-shadow:2px 3px 0 rgba(20,16,14,.72);
  }
  .tcard img{width:100%;height:42px;max-height:42px;}
  .tcard .meta{align-items:center;gap:1px;}
  .tcard .tname{font-size:9px;white-space:normal;text-align:center;line-height:.95;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;min-height:17px;}
  .tcard .costrow{font-size:9px;}
  .keybadge{display:none;}
  .tcard.sel{transform:translateY(3px);}
  .gridhint{font-size:9.5px;padding:1px 7px;bottom:5px;}
  .endcard-inner{width:min(96%,380px);}
}

@media (max-aspect-ratio:1/1) and (max-height:700px){
  .rail{height:82px;}
  .tcard{height:70px;flex-basis:82px;grid-template-rows:34px 1fr;}
  .tcard img{height:34px;}
  .bottom{height:86px;min-height:78px;}
  .foreman{flex-basis:54px;}
  .speech{min-height:70px;}
  .masthead .scorebar{height:42px;}
}

@media (min-aspect-ratio:1/1) and (max-width:780px){
  .stage{grid-template-columns:110px minmax(0,1fr) 84px;}
  .sidecol{gap:5px;}
  .shiftnote p{font-size:9px;}
  .bottomright{flex-basis:170px;}
  .howto{font-size:8px;}
}

.floatgain{
  position:absolute;
  transform:translate(-50%,-50%);
  font-family:var(--num);
  font-weight:900;
  font-size:clamp(13px,1.5vw,19px);
  line-height:1;
  letter-spacing:.02em;
  color:var(--ink);
  text-shadow:0 0 3px var(--paper),0 0 3px var(--paper),1px 1px 0 var(--paper);
  pointer-events:none;
  animation:floatup .85s ease-out forwards;
}
.floatgain.rust{color:var(--rust);}
.floatgain.blue{color:var(--blue);}
@keyframes floatup{
  0%{opacity:0;transform:translate(-50%,-30%) scale(.7) rotate(-3deg);}
  18%{opacity:1;transform:translate(-50%,-60%) scale(1.08) rotate(2deg);}
  100%{opacity:0;transform:translate(-50%,-160%) scale(1) rotate(-1deg);}
}

.mobilecontrols{display:none;}

/* one wide board, like the reference page */
.sidecol{display:none;}
.stage{grid-template-columns:minmax(136px,156px) minmax(0,1fr);}
.mobilecontrols{
  display:flex;
  position:absolute;
  top:6px;
  right:8px;
  gap:5px;
  z-index:8;
}
.mobilecontrols .stampbtn{font-size:12px;padding:6px 8px;min-width:44px;min-height:44px;border-width:2px;box-shadow:2px 2px 0 rgba(20,16,14,.7);}
.tcard{grid-template-columns:clamp(36px,4vw,48px) 1fr;}
.tcard .tname{
  white-space:normal;
  display:-webkit-box;
  -webkit-line-clamp:2;
  -webkit-box-orient:vertical;
  line-height:1;
  min-height:2em;
  font-size:clamp(9px,.98vw,12px);
}
@media (max-aspect-ratio:1/1){
  .stage{display:contents;}
  .mobilecontrols{display:flex;}
}
@media (max-height:560px) and (min-aspect-ratio:1/1){
  .mobilecontrols{display:flex;}
}

/* tight landscape phones: keep every card reachable and the board usable */
@media (max-height:560px) and (min-aspect-ratio:1/1){
  .page{padding:4px 6px;gap:5px;}
  .masthead{gap:6px;}
  .portrait{width:38px;height:38px;border-width:2px;}
  .title{width:96px;}
  .brand{gap:5px;}
  .scorebar{border-width:2px;}
  .stat{padding:1px 7px;}
  .klabel{font-size:8px;}
  .kval{font-size:20px;}
  .stage{grid-template-columns:112px minmax(0,1fr);gap:5px;}
  .rail{gap:1px;}
  .tcard{
    min-height:45px;
    max-height:none;
    grid-template-columns:32px 1fr;
    gap:4px;
    padding:1px 4px;
    border-width:2px;
    box-shadow:2px 2px 0 rgba(20,16,14,.7);
  }
  .tcard img{max-height:38px;}
  .tcard .tname{font-size:8.5px;min-height:2em;}
  .tcard .costrow{font-size:8.5px;}
  .tcard .keybadge{display:none;}
  .tcard.sel{transform:translateY(2px);}
  .bottom{height:74px;min-height:64px;padding:3px 6px;}
  .foreman{flex-basis:54px;}
  .speech{min-height:56px;}
  #speechText{font-size:9.5px;inset:8% 9% 26% 7%;}
  .bottomright{flex-basis:150px;gap:3px;}
  .howto{font-size:8px;}
  .wavebar{height:15px;}
  .endcard-inner{width:min(76%, 248px);}
}

/* final comic page proportions: title block, wide board, right gutter */
.sidecol{display:flex;}
.stage{grid-template-columns:minmax(140px,158px) minmax(0,1fr) minmax(140px,188px);gap:10px;}
.mobilecontrols{display:none;}
.portrait{width:clamp(50px,5.4vw,72px);height:clamp(50px,5.4vw,72px);}
.title{width:clamp(132px,12.4vw,176px);}
.scorebar{align-self:center;height:clamp(58px,9vh,80px);}
.bottom{height:118px;min-height:104px;}
.foreman{flex-basis:clamp(60px,7vw,98px);}
.speech{max-width:620px;min-height:86px;}
.bottomright{flex-basis:clamp(180px,25%,320px);}

@media (max-aspect-ratio:1/1){
  .gatetag{font-size:9px;padding:1px 5px 2px;}
  .sidecol{display:none;}
  .stage{display:contents;}
  .mobilecontrols{display:flex;}
  .portrait{width:48px;height:48px;}
  .title{width:clamp(116px,34vw,172px);}
  .scorebar{height:46px;}
  .bottom{height:98px;min-height:88px;}
  .rail{gap:5px;}
  .tcard{
    flex:0 0 clamp(62px,17.5vw,82px);
    display:grid;
    grid-template-columns:1fr;
    grid-template-rows:42px 1fr;
    gap:1px;
    padding:3px 4px;
    height:82px;
  }
  .tcard img{width:100%;height:42px;max-height:42px;margin:0 auto;}
  .tcard .meta{align-items:center;gap:1px;}
  .tcard .costrow{justify-content:center;}
}

@media (max-height:560px) and (min-aspect-ratio:1/1){
  .sidecol{display:none;}
  .stage{grid-template-columns:112px minmax(0,1fr);gap:5px;}
  .mobilecontrols{display:flex;}
  .portrait{width:38px;height:38px;}
  .title{width:96px;}
  .scorebar{height:auto;align-self:stretch;}
  .bottom{height:74px;min-height:64px;}
}


.gatetag{
  position:absolute;
  z-index:8;
  transform:translate(-50%,-100%);
  pointer-events:none;
  padding:2px 7px 3px;
  background:var(--paper);
  border:2px solid var(--blue);
  border-radius:3px 6px 2px 5px;
  box-shadow:2px 3px 0 rgba(20,16,14,.55);
  font-family:var(--num);
  font-weight:900;
  font-size:11px;
  letter-spacing:.08em;
  line-height:1;
  color:var(--blue);
  white-space:nowrap;
  transition:left .18s, top .18s;
}
.gatetag::after{
  content:"";
  position:absolute;
  left:50%;
  bottom:-6px;
  width:8px;
  height:8px;
  transform:translateX(-50%) rotate(45deg);
  background:var(--paper);
  border-right:2px solid var(--blue);
  border-bottom:2px solid var(--blue);
}

@media (max-aspect-ratio:1/1){
  .tcard .tname{
    font-size:8.5px;
    line-height:1;
    white-space:nowrap;
    display:block;
    -webkit-line-clamp:unset;
    min-height:0;
    overflow:hidden;
    text-overflow:ellipsis;
  }
  .tcard .meta{gap:2px;}
  .tcard .trange{display:none;}
  .tcard .costrow{font-size:9px;}
}

/* crisp comic ink pass */
.tcard{border-width:3px;box-shadow:4px 5px 0 rgba(20,16,14,.85);}
.tcard::before{filter:url(#wobbleSmall);border-width:1.3px;}
.scorebar{border-width:4px;}
.scorebar::after,.bottom::after,.board::after{filter:url(#wobbleSmall);}
.bottom{border-width:4px;}
.shiftnote{border-width:3px;}
.shiftnote::before{content:"";position:absolute;inset:2px;border:1px solid rgba(20,16,14,.45);border-radius:inherit;filter:url(#wobbleSmall);pointer-events:none;}
.lvlstamp,.stampbtn{position:relative;}
.lvlstamp::after,.gridhint::before,.stampbtn::before,.gatetag::before{content:"";position:absolute;inset:2px;border:1.3px solid rgba(20,16,14,.5);border-radius:inherit;filter:url(#wobbleSmall);pointer-events:none;}
.gridhint::before{inset:1px;border-width:1px;}
.gatetag::before{border-color:rgba(44,107,143,.75);inset:1px;}
.lvlstamp::after{inset:1px;border-width:1px;}
.tcard .timgwrap{filter:drop-shadow(1px 1px 0 rgba(20,16,14,.3));}


.cartag{
  position:absolute;
  z-index:8;
  transform:translate(-50%,-100%);
  pointer-events:none;
  padding:2px 7px 3px;
  background:var(--paper);
  border:2px solid var(--rust);
  border-radius:3px 6px 2px 5px;
  box-shadow:2px 3px 0 rgba(20,16,14,.55);
  font-family:var(--num);
  font-weight:900;
  font-size:11px;
  letter-spacing:.08em;
  line-height:1;
  color:var(--rust);
  white-space:nowrap;
}
.cartag::before{
  content:"";
  position:absolute;
  inset:1px;
  border:1.2px solid rgba(196,85,31,.65);
  border-radius:inherit;
  filter:url(#wobbleSmall);
  pointer-events:none;
}
.cartag::after{
  content:"";
  position:absolute;
  left:50%;
  bottom:-6px;
  width:8px;
  height:8px;
  transform:translateX(-50%) rotate(45deg);
  background:var(--paper);
  border-right:2px solid var(--rust);
  border-bottom:2px solid var(--rust);
}
@media (max-aspect-ratio:1/1){
  .cartag{font-size:9px;padding:1px 5px 2px;}
}

/* end of level: a strip report, never over the playfield */
.bottom .endcard{
  position:absolute;
  inset:0;
  z-index:12;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:6px 10px;
  background:var(--paper);
}
.bottom .endcard[hidden]{display:none;}
.bottom .endcard-inner{
  display:flex;
  align-items:center;
  justify-content:center;
  flex-wrap:wrap;
  gap:4px 12px;
  width:100%;
  max-height:none;
  aspect-ratio:auto;
  background:none;
  padding:0;
  filter:none;
  transform:rotate(-.5deg);
  animation:none;
  box-shadow:none;
  border:0;
}
.bottom .endcard h2{
  position:static;
  font-size:clamp(20px,2.5vw,32px);
  line-height:.9;
  margin:0;
  text-shadow:2px 2px 0 rgba(196,85,31,.45);
}
.bottom .endstats{
  position:static;
  display:flex;
  flex-wrap:wrap;
  justify-content:center;
  gap:3px 11px;
  background:none;
  border:0;
  box-shadow:none;
  padding:0;
  font-size:clamp(9px,.95vw,12px);
}
.bottom .endstats span{border:0;display:flex;gap:4px;}
.bottom .endstats b{font-weight:900;}
.bottom .endcard .stampbtn{
  position:static;
  transform:rotate(-1deg);
  font-size:clamp(13px,1.5vw,18px);
  padding:4px 10px;
  box-shadow:2px 3px 0 rgba(20,16,14,.7);
}
@media (max-aspect-ratio:1/1){
  .bottom .endcard h2{font-size:20px;}
  .bottom .endstats{font-size:9px;}
  .bottom .endcard .stampbtn{font-size:12px;padding:3px 8px;}
}
